rtnetlink.c (77162022ab26a1f99d3af30c03760a76f86e193d) rtnetlink.c (d83b060360485454fcd6870340ec01d6f96f2295)
1/*
2 * INET An implementation of the TCP/IP protocol suite for the LINUX
3 * operating system. INET is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
5 *
6 * Routing netlink socket interface: protocol independent part.
7 *
8 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>

--- 1966 unchanged lines hidden (view full) ---

1975 }
1976 rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL, GFP_KERNEL);
1977 return;
1978errout:
1979 if (err < 0)
1980 rtnl_set_sk_err(net, RTNLGRP_LINK, err);
1981}
1982
1/*
2 * INET An implementation of the TCP/IP protocol suite for the LINUX
3 * operating system. INET is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
5 *
6 * Routing netlink socket interface: protocol independent part.
7 *
8 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>

--- 1966 unchanged lines hidden (view full) ---

1975 }
1976 rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL, GFP_KERNEL);
1977 return;
1978errout:
1979 if (err < 0)
1980 rtnl_set_sk_err(net, RTNLGRP_LINK, err);
1981}
1982
1983static int nlmsg_populate_fdb_fill(struct sk_buff *skb,
1984 struct net_device *dev,
1985 u8 *addr, u32 pid, u32 seq,
1986 int type, unsigned int flags)
1987{
1988 struct nlmsghdr *nlh;
1989 struct ndmsg *ndm;
1990
1991 nlh = nlmsg_put(skb, pid, seq, type, sizeof(*ndm), NLM_F_MULTI);
1992 if (!nlh)
1993 return -EMSGSIZE;
1994
1995 ndm = nlmsg_data(nlh);
1996 ndm->ndm_family = AF_BRIDGE;
1997 ndm->ndm_pad1 = 0;
1998 ndm->ndm_pad2 = 0;
1999 ndm->ndm_flags = flags;
2000 ndm->ndm_type = 0;
2001 ndm->ndm_ifindex = dev->ifindex;
2002 ndm->ndm_state = NUD_PERMANENT;
2003
2004 if (nla_put(skb, NDA_LLADDR, ETH_ALEN, addr))
2005 goto nla_put_failure;
2006
2007 return nlmsg_end(skb, nlh);
2008
2009nla_put_failure:
2010 nlmsg_cancel(skb, nlh);
2011 return -EMSGSIZE;
2012}
2013
1983static int rtnl_fdb_add(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
1984{
1985 struct net *net = sock_net(skb->sk);
1986 struct net_device *master = NULL;
1987 struct ndmsg *ndm;
1988 struct nlattr *tb[NDA_MAX+1];
1989 struct net_device *dev;
1990 u8 *addr;

--- 105 unchanged lines hidden (view full) ---

2096
2097 if (!err)
2098 ndm->ndm_flags &= ~NTF_SELF;
2099 }
2100out:
2101 return err;
2102}
2103
2014static int rtnl_fdb_add(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
2015{
2016 struct net *net = sock_net(skb->sk);
2017 struct net_device *master = NULL;
2018 struct ndmsg *ndm;
2019 struct nlattr *tb[NDA_MAX+1];
2020 struct net_device *dev;
2021 u8 *addr;

--- 105 unchanged lines hidden (view full) ---

2127
2128 if (!err)
2129 ndm->ndm_flags &= ~NTF_SELF;
2130 }
2131out:
2132 return err;
2133}
2134
2135static int nlmsg_populate_fdb(struct sk_buff *skb,
2136 struct netlink_callback *cb,
2137 struct net_device *dev,
2138 int *idx,
2139 struct netdev_hw_addr_list *list)
2140{
2141 struct netdev_hw_addr *ha;
2142 int err;
2143 u32 pid, seq;
2144
2145 pid = NETLINK_CB(cb->skb).pid;
2146 seq = cb->nlh->nlmsg_seq;
2147
2148 list_for_each_entry(ha, &list->list, list) {
2149 if (*idx < cb->args[0])
2150 goto skip;
2151
2152 err = nlmsg_populate_fdb_fill(skb, dev, ha->addr,
2153 pid, seq, 0, NTF_SELF);
2154 if (err < 0)
2155 return err;
2156skip:
2157 *idx += 1;
2158 }
2159 return 0;
2160}
2161
2162/**
2163 * ndo_dflt_fdb_dump: default netdevice operation to dump an FDB table.
2164 * @nlh: netlink message header
2165 * @dev: netdevice
2166 *
2167 * Default netdevice operation to dump the existing unicast address list.
2168 * Returns zero on success.
2169 */
2170int ndo_dflt_fdb_dump(struct sk_buff *skb,
2171 struct netlink_callback *cb,
2172 struct net_device *dev,
2173 int idx)
2174{
2175 int err;
2176
2177 netif_addr_lock_bh(dev);
2178 err = nlmsg_populate_fdb(skb, cb, dev, &idx, &dev->uc);
2179 if (err)
2180 goto out;
2181 nlmsg_populate_fdb(skb, cb, dev, &idx, &dev->mc);
2182out:
2183 netif_addr_unlock_bh(dev);
2184 return idx;
2185}
2186EXPORT_SYMBOL(ndo_dflt_fdb_dump);
2187
2104static int rtnl_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb)
2105{
2106 int idx = 0;
2107 struct net *net = sock_net(skb->sk);
2108 struct net_device *dev;
2109
2110 rcu_read_lock();
2111 for_each_netdev_rcu(net, dev) {

--- 195 unchanged lines hidden ---
2188static int rtnl_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb)
2189{
2190 int idx = 0;
2191 struct net *net = sock_net(skb->sk);
2192 struct net_device *dev;
2193
2194 rcu_read_lock();
2195 for_each_netdev_rcu(net, dev) {

--- 195 unchanged lines hidden ---