rtnetlink.c (f0cd9ae5d0df8668e76359a3e0e99856aa9c53b9) rtnetlink.c (5f729eaabef9308cfaa4b27c9b3f120253eff79b)
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>

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

34#include <linux/init.h>
35#include <linux/security.h>
36#include <linux/mutex.h>
37#include <linux/if_addr.h>
38#include <linux/if_bridge.h>
39#include <linux/if_vlan.h>
40#include <linux/pci.h>
41#include <linux/etherdevice.h>
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>

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

34#include <linux/init.h>
35#include <linux/security.h>
36#include <linux/mutex.h>
37#include <linux/if_addr.h>
38#include <linux/if_bridge.h>
39#include <linux/if_vlan.h>
40#include <linux/pci.h>
41#include <linux/etherdevice.h>
42#include <linux/bpf.h>
42
43#include <linux/uaccess.h>
44
45#include <linux/inet.h>
46#include <linux/netdevice.h>
47#include <net/switchdev.h>
48#include <net/ip.h>
49#include <net/protocol.h>

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

894 vf_port_size * dev_num_vf(dev->dev.parent);
895 else
896 return port_self_size;
897}
898
899static size_t rtnl_xdp_size(void)
900{
901 size_t xdp_size = nla_total_size(0) + /* nest IFLA_XDP */
43
44#include <linux/uaccess.h>
45
46#include <linux/inet.h>
47#include <linux/netdevice.h>
48#include <net/switchdev.h>
49#include <net/ip.h>
50#include <net/protocol.h>

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

895 vf_port_size * dev_num_vf(dev->dev.parent);
896 else
897 return port_self_size;
898}
899
900static size_t rtnl_xdp_size(void)
901{
902 size_t xdp_size = nla_total_size(0) + /* nest IFLA_XDP */
902 nla_total_size(1); /* XDP_ATTACHED */
903 nla_total_size(1) + /* XDP_ATTACHED */
904 nla_total_size(4); /* XDP_PROG_ID */
903
904 return xdp_size;
905}
906
907static noinline size_t if_nlmsg_size(const struct net_device *dev,
908 u32 ext_filter_mask)
909{
910 return NLMSG_ALIGN(sizeof(struct ifinfomsg))

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

936 + rtnl_vfinfo_size(dev, ext_filter_mask) /* IFLA_VFINFO_LIST */
937 + rtnl_port_size(dev, ext_filter_mask) /* IFLA_VF_PORTS + IFLA_PORT_SELF */
938 + rtnl_link_get_size(dev) /* IFLA_LINKINFO */
939 + rtnl_link_get_af_size(dev, ext_filter_mask) /* IFLA_AF_SPEC */
940 + nla_total_size(MAX_PHYS_ITEM_ID_LEN) /* IFLA_PHYS_PORT_ID */
941 + nla_total_size(MAX_PHYS_ITEM_ID_LEN) /* IFLA_PHYS_SWITCH_ID */
942 + nla_total_size(IFNAMSIZ) /* IFLA_PHYS_PORT_NAME */
943 + rtnl_xdp_size() /* IFLA_XDP */
905
906 return xdp_size;
907}
908
909static noinline size_t if_nlmsg_size(const struct net_device *dev,
910 u32 ext_filter_mask)
911{
912 return NLMSG_ALIGN(sizeof(struct ifinfomsg))

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

938 + rtnl_vfinfo_size(dev, ext_filter_mask) /* IFLA_VFINFO_LIST */
939 + rtnl_port_size(dev, ext_filter_mask) /* IFLA_VF_PORTS + IFLA_PORT_SELF */
940 + rtnl_link_get_size(dev) /* IFLA_LINKINFO */
941 + rtnl_link_get_af_size(dev, ext_filter_mask) /* IFLA_AF_SPEC */
942 + nla_total_size(MAX_PHYS_ITEM_ID_LEN) /* IFLA_PHYS_PORT_ID */
943 + nla_total_size(MAX_PHYS_ITEM_ID_LEN) /* IFLA_PHYS_SWITCH_ID */
944 + nla_total_size(IFNAMSIZ) /* IFLA_PHYS_PORT_NAME */
945 + rtnl_xdp_size() /* IFLA_XDP */
946 + nla_total_size(4) /* IFLA_EVENT */
944 + nla_total_size(1); /* IFLA_PROTO_DOWN */
945
946}
947
948static int rtnl_vf_ports_fill(struct sk_buff *skb, struct net_device *dev)
949{
950 struct nlattr *vf_ports;
951 struct nlattr *vf_port;

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

1242 map.port = dev->if_port;
1243
1244 if (nla_put_64bit(skb, IFLA_MAP, sizeof(map), &map, IFLA_PAD))
1245 return -EMSGSIZE;
1246
1247 return 0;
1248}
1249
947 + nla_total_size(1); /* IFLA_PROTO_DOWN */
948
949}
950
951static int rtnl_vf_ports_fill(struct sk_buff *skb, struct net_device *dev)
952{
953 struct nlattr *vf_ports;
954 struct nlattr *vf_port;

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

1245 map.port = dev->if_port;
1246
1247 if (nla_put_64bit(skb, IFLA_MAP, sizeof(map), &map, IFLA_PAD))
1248 return -EMSGSIZE;
1249
1250 return 0;
1251}
1252
1250static u8 rtnl_xdp_attached_mode(struct net_device *dev)
1253static u8 rtnl_xdp_attached_mode(struct net_device *dev, u32 *prog_id)
1251{
1252 const struct net_device_ops *ops = dev->netdev_ops;
1254{
1255 const struct net_device_ops *ops = dev->netdev_ops;
1256 const struct bpf_prog *generic_xdp_prog;
1253
1254 ASSERT_RTNL();
1255
1257
1258 ASSERT_RTNL();
1259
1256 if (rcu_access_pointer(dev->xdp_prog))
1260 *prog_id = 0;
1261 generic_xdp_prog = rtnl_dereference(dev->xdp_prog);
1262 if (generic_xdp_prog) {
1263 *prog_id = generic_xdp_prog->aux->id;
1257 return XDP_ATTACHED_SKB;
1264 return XDP_ATTACHED_SKB;
1258 if (ops->ndo_xdp && __dev_xdp_attached(dev, ops->ndo_xdp))
1265 }
1266 if (ops->ndo_xdp && __dev_xdp_attached(dev, ops->ndo_xdp, prog_id))
1259 return XDP_ATTACHED_DRV;
1260
1261 return XDP_ATTACHED_NONE;
1262}
1263
1264static int rtnl_xdp_fill(struct sk_buff *skb, struct net_device *dev)
1265{
1266 struct nlattr *xdp;
1267 return XDP_ATTACHED_DRV;
1268
1269 return XDP_ATTACHED_NONE;
1270}
1271
1272static int rtnl_xdp_fill(struct sk_buff *skb, struct net_device *dev)
1273{
1274 struct nlattr *xdp;
1275 u32 prog_id;
1267 int err;
1268
1269 xdp = nla_nest_start(skb, IFLA_XDP);
1270 if (!xdp)
1271 return -EMSGSIZE;
1272
1273 err = nla_put_u8(skb, IFLA_XDP_ATTACHED,
1276 int err;
1277
1278 xdp = nla_nest_start(skb, IFLA_XDP);
1279 if (!xdp)
1280 return -EMSGSIZE;
1281
1282 err = nla_put_u8(skb, IFLA_XDP_ATTACHED,
1274 rtnl_xdp_attached_mode(dev));
1283 rtnl_xdp_attached_mode(dev, &prog_id));
1275 if (err)
1276 goto err_cancel;
1277
1284 if (err)
1285 goto err_cancel;
1286
1287 if (prog_id) {
1288 err = nla_put_u32(skb, IFLA_XDP_PROG_ID, prog_id);
1289 if (err)
1290 goto err_cancel;
1291 }
1292
1278 nla_nest_end(skb, xdp);
1279 return 0;
1280
1281err_cancel:
1282 nla_nest_cancel(skb, xdp);
1283 return err;
1284}
1285
1293 nla_nest_end(skb, xdp);
1294 return 0;
1295
1296err_cancel:
1297 nla_nest_cancel(skb, xdp);
1298 return err;
1299}
1300
1301static u32 rtnl_get_event(unsigned long event)
1302{
1303 u32 rtnl_event_type = IFLA_EVENT_NONE;
1304
1305 switch (event) {
1306 case NETDEV_REBOOT:
1307 rtnl_event_type = IFLA_EVENT_REBOOT;
1308 break;
1309 case NETDEV_FEAT_CHANGE:
1310 rtnl_event_type = IFLA_EVENT_FEATURES;
1311 break;
1312 case NETDEV_BONDING_FAILOVER:
1313 rtnl_event_type = IFLA_EVENT_BONDING_FAILOVER;
1314 break;
1315 case NETDEV_NOTIFY_PEERS:
1316 rtnl_event_type = IFLA_EVENT_NOTIFY_PEERS;
1317 break;
1318 case NETDEV_RESEND_IGMP:
1319 rtnl_event_type = IFLA_EVENT_IGMP_RESEND;
1320 break;
1321 case NETDEV_CHANGEINFODATA:
1322 rtnl_event_type = IFLA_EVENT_BONDING_OPTIONS;
1323 break;
1324 default:
1325 break;
1326 }
1327
1328 return rtnl_event_type;
1329}
1330
1286static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
1287 int type, u32 pid, u32 seq, u32 change,
1331static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
1332 int type, u32 pid, u32 seq, u32 change,
1288 unsigned int flags, u32 ext_filter_mask)
1333 unsigned int flags, u32 ext_filter_mask,
1334 u32 event)
1289{
1290 struct ifinfomsg *ifm;
1291 struct nlmsghdr *nlh;
1292 struct nlattr *af_spec;
1293 struct rtnl_af_ops *af_ops;
1294 struct net_device *upper_dev = netdev_master_upper_dev_get(dev);
1295
1296 ASSERT_RTNL();

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

1329 nla_put_string(skb, IFLA_QDISC, dev->qdisc->ops->id)) ||
1330 (dev->ifalias &&
1331 nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)) ||
1332 nla_put_u32(skb, IFLA_CARRIER_CHANGES,
1333 atomic_read(&dev->carrier_changes)) ||
1334 nla_put_u8(skb, IFLA_PROTO_DOWN, dev->proto_down))
1335 goto nla_put_failure;
1336
1335{
1336 struct ifinfomsg *ifm;
1337 struct nlmsghdr *nlh;
1338 struct nlattr *af_spec;
1339 struct rtnl_af_ops *af_ops;
1340 struct net_device *upper_dev = netdev_master_upper_dev_get(dev);
1341
1342 ASSERT_RTNL();

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

1375 nla_put_string(skb, IFLA_QDISC, dev->qdisc->ops->id)) ||
1376 (dev->ifalias &&
1377 nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)) ||
1378 nla_put_u32(skb, IFLA_CARRIER_CHANGES,
1379 atomic_read(&dev->carrier_changes)) ||
1380 nla_put_u8(skb, IFLA_PROTO_DOWN, dev->proto_down))
1381 goto nla_put_failure;
1382
1383 if (event != IFLA_EVENT_NONE) {
1384 if (nla_put_u32(skb, IFLA_EVENT, event))
1385 goto nla_put_failure;
1386 }
1387
1337 if (rtnl_fill_link_ifmap(skb, dev))
1338 goto nla_put_failure;
1339
1340 if (dev->addr_len) {
1341 if (nla_put(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr) ||
1342 nla_put(skb, IFLA_BROADCAST, dev->addr_len, dev->broadcast))
1343 goto nla_put_failure;
1344 }

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

1463 [IFLA_NUM_TX_QUEUES] = { .type = NLA_U32 },
1464 [IFLA_NUM_RX_QUEUES] = { .type = NLA_U32 },
1465 [IFLA_PHYS_PORT_ID] = { .type = NLA_BINARY, .len = MAX_PHYS_ITEM_ID_LEN },
1466 [IFLA_CARRIER_CHANGES] = { .type = NLA_U32 }, /* ignored */
1467 [IFLA_PHYS_SWITCH_ID] = { .type = NLA_BINARY, .len = MAX_PHYS_ITEM_ID_LEN },
1468 [IFLA_LINK_NETNSID] = { .type = NLA_S32 },
1469 [IFLA_PROTO_DOWN] = { .type = NLA_U8 },
1470 [IFLA_XDP] = { .type = NLA_NESTED },
1388 if (rtnl_fill_link_ifmap(skb, dev))
1389 goto nla_put_failure;
1390
1391 if (dev->addr_len) {
1392 if (nla_put(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr) ||
1393 nla_put(skb, IFLA_BROADCAST, dev->addr_len, dev->broadcast))
1394 goto nla_put_failure;
1395 }

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

1514 [IFLA_NUM_TX_QUEUES] = { .type = NLA_U32 },
1515 [IFLA_NUM_RX_QUEUES] = { .type = NLA_U32 },
1516 [IFLA_PHYS_PORT_ID] = { .type = NLA_BINARY, .len = MAX_PHYS_ITEM_ID_LEN },
1517 [IFLA_CARRIER_CHANGES] = { .type = NLA_U32 }, /* ignored */
1518 [IFLA_PHYS_SWITCH_ID] = { .type = NLA_BINARY, .len = MAX_PHYS_ITEM_ID_LEN },
1519 [IFLA_LINK_NETNSID] = { .type = NLA_S32 },
1520 [IFLA_PROTO_DOWN] = { .type = NLA_U8 },
1521 [IFLA_XDP] = { .type = NLA_NESTED },
1522 [IFLA_EVENT] = { .type = NLA_U32 },
1471};
1472
1473static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = {
1474 [IFLA_INFO_KIND] = { .type = NLA_STRING },
1475 [IFLA_INFO_DATA] = { .type = NLA_NESTED },
1476 [IFLA_INFO_SLAVE_KIND] = { .type = NLA_STRING },
1477 [IFLA_INFO_SLAVE_DATA] = { .type = NLA_NESTED },
1478};

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

1510 [IFLA_PORT_VSI_TYPE] = { .type = NLA_BINARY,
1511 .len = sizeof(struct ifla_port_vsi) },
1512};
1513
1514static const struct nla_policy ifla_xdp_policy[IFLA_XDP_MAX + 1] = {
1515 [IFLA_XDP_FD] = { .type = NLA_S32 },
1516 [IFLA_XDP_ATTACHED] = { .type = NLA_U8 },
1517 [IFLA_XDP_FLAGS] = { .type = NLA_U32 },
1523};
1524
1525static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = {
1526 [IFLA_INFO_KIND] = { .type = NLA_STRING },
1527 [IFLA_INFO_DATA] = { .type = NLA_NESTED },
1528 [IFLA_INFO_SLAVE_KIND] = { .type = NLA_STRING },
1529 [IFLA_INFO_SLAVE_DATA] = { .type = NLA_NESTED },
1530};

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

1562 [IFLA_PORT_VSI_TYPE] = { .type = NLA_BINARY,
1563 .len = sizeof(struct ifla_port_vsi) },
1564};
1565
1566static const struct nla_policy ifla_xdp_policy[IFLA_XDP_MAX + 1] = {
1567 [IFLA_XDP_FD] = { .type = NLA_S32 },
1568 [IFLA_XDP_ATTACHED] = { .type = NLA_U8 },
1569 [IFLA_XDP_FLAGS] = { .type = NLA_U32 },
1570 [IFLA_XDP_PROG_ID] = { .type = NLA_U32 },
1518};
1519
1520static const struct rtnl_link_ops *linkinfo_to_kind_ops(const struct nlattr *nla)
1521{
1522 const struct rtnl_link_ops *ops = NULL;
1523 struct nlattr *linfo[IFLA_INFO_MAX + 1];
1524
1525 if (nla_parse_nested(linfo, IFLA_INFO_MAX, nla,

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

1622 if (link_dump_filtered(dev, master_idx, kind_ops))
1623 goto cont;
1624 if (idx < s_idx)
1625 goto cont;
1626 err = rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
1627 NETLINK_CB(cb->skb).portid,
1628 cb->nlh->nlmsg_seq, 0,
1629 flags,
1571};
1572
1573static const struct rtnl_link_ops *linkinfo_to_kind_ops(const struct nlattr *nla)
1574{
1575 const struct rtnl_link_ops *ops = NULL;
1576 struct nlattr *linfo[IFLA_INFO_MAX + 1];
1577
1578 if (nla_parse_nested(linfo, IFLA_INFO_MAX, nla,

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

1675 if (link_dump_filtered(dev, master_idx, kind_ops))
1676 goto cont;
1677 if (idx < s_idx)
1678 goto cont;
1679 err = rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
1680 NETLINK_CB(cb->skb).portid,
1681 cb->nlh->nlmsg_seq, 0,
1682 flags,
1630 ext_filter_mask);
1683 ext_filter_mask, 0);
1631
1632 if (err < 0) {
1633 if (likely(skb->len))
1634 goto out;
1635
1636 goto out_err;
1637 }
1638

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

2044 if (tb[IFLA_CARRIER]) {
2045 err = dev_change_carrier(dev, nla_get_u8(tb[IFLA_CARRIER]));
2046 if (err)
2047 goto errout;
2048 status |= DO_SETLINK_MODIFIED;
2049 }
2050
2051 if (tb[IFLA_TXQLEN]) {
1684
1685 if (err < 0) {
1686 if (likely(skb->len))
1687 goto out;
1688
1689 goto out_err;
1690 }
1691

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

2097 if (tb[IFLA_CARRIER]) {
2098 err = dev_change_carrier(dev, nla_get_u8(tb[IFLA_CARRIER]));
2099 if (err)
2100 goto errout;
2101 status |= DO_SETLINK_MODIFIED;
2102 }
2103
2104 if (tb[IFLA_TXQLEN]) {
2052 unsigned long value = nla_get_u32(tb[IFLA_TXQLEN]);
2053 unsigned long orig_len = dev->tx_queue_len;
2105 unsigned int value = nla_get_u32(tb[IFLA_TXQLEN]);
2106 unsigned int orig_len = dev->tx_queue_len;
2054
2055 if (dev->tx_queue_len ^ value) {
2056 dev->tx_queue_len = value;
2057 err = call_netdevice_notifiers(
2058 NETDEV_CHANGE_TX_QUEUE_LEN, dev);
2059 err = notifier_to_errno(err);
2060 if (err) {
2061 dev->tx_queue_len = orig_len;

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

2182 struct nlattr *xdp[IFLA_XDP_MAX + 1];
2183 u32 xdp_flags = 0;
2184
2185 err = nla_parse_nested(xdp, IFLA_XDP_MAX, tb[IFLA_XDP],
2186 ifla_xdp_policy, NULL);
2187 if (err < 0)
2188 goto errout;
2189
2107
2108 if (dev->tx_queue_len ^ value) {
2109 dev->tx_queue_len = value;
2110 err = call_netdevice_notifiers(
2111 NETDEV_CHANGE_TX_QUEUE_LEN, dev);
2112 err = notifier_to_errno(err);
2113 if (err) {
2114 dev->tx_queue_len = orig_len;

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

2235 struct nlattr *xdp[IFLA_XDP_MAX + 1];
2236 u32 xdp_flags = 0;
2237
2238 err = nla_parse_nested(xdp, IFLA_XDP_MAX, tb[IFLA_XDP],
2239 ifla_xdp_policy, NULL);
2240 if (err < 0)
2241 goto errout;
2242
2190 if (xdp[IFLA_XDP_ATTACHED]) {
2243 if (xdp[IFLA_XDP_ATTACHED] || xdp[IFLA_XDP_PROG_ID]) {
2191 err = -EINVAL;
2192 goto errout;
2193 }
2194
2195 if (xdp[IFLA_XDP_FLAGS]) {
2196 xdp_flags = nla_get_u32(xdp[IFLA_XDP_FLAGS]);
2197 if (xdp_flags & ~XDP_FLAGS_MASK) {
2198 err = -EINVAL;

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

2732 if (dev == NULL)
2733 return -ENODEV;
2734
2735 nskb = nlmsg_new(if_nlmsg_size(dev, ext_filter_mask), GFP_KERNEL);
2736 if (nskb == NULL)
2737 return -ENOBUFS;
2738
2739 err = rtnl_fill_ifinfo(nskb, dev, RTM_NEWLINK, NETLINK_CB(skb).portid,
2244 err = -EINVAL;
2245 goto errout;
2246 }
2247
2248 if (xdp[IFLA_XDP_FLAGS]) {
2249 xdp_flags = nla_get_u32(xdp[IFLA_XDP_FLAGS]);
2250 if (xdp_flags & ~XDP_FLAGS_MASK) {
2251 err = -EINVAL;

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

2785 if (dev == NULL)
2786 return -ENODEV;
2787
2788 nskb = nlmsg_new(if_nlmsg_size(dev, ext_filter_mask), GFP_KERNEL);
2789 if (nskb == NULL)
2790 return -ENOBUFS;
2791
2792 err = rtnl_fill_ifinfo(nskb, dev, RTM_NEWLINK, NETLINK_CB(skb).portid,
2740 nlh->nlmsg_seq, 0, 0, ext_filter_mask);
2793 nlh->nlmsg_seq, 0, 0, ext_filter_mask, 0);
2741 if (err < 0) {
2742 /* -EMSGSIZE implies BUG in if_nlmsg_size */
2743 WARN_ON(err == -EMSGSIZE);
2744 kfree_skb(nskb);
2745 } else
2746 err = rtnl_unicast(nskb, net, NETLINK_CB(skb).portid);
2747
2748 return err;

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

2804 break;
2805 }
2806 cb->family = idx;
2807
2808 return skb->len;
2809}
2810
2811struct sk_buff *rtmsg_ifinfo_build_skb(int type, struct net_device *dev,
2794 if (err < 0) {
2795 /* -EMSGSIZE implies BUG in if_nlmsg_size */
2796 WARN_ON(err == -EMSGSIZE);
2797 kfree_skb(nskb);
2798 } else
2799 err = rtnl_unicast(nskb, net, NETLINK_CB(skb).portid);
2800
2801 return err;

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

2857 break;
2858 }
2859 cb->family = idx;
2860
2861 return skb->len;
2862}
2863
2864struct sk_buff *rtmsg_ifinfo_build_skb(int type, struct net_device *dev,
2812 unsigned int change, gfp_t flags)
2865 unsigned int change,
2866 u32 event, gfp_t flags)
2813{
2814 struct net *net = dev_net(dev);
2815 struct sk_buff *skb;
2816 int err = -ENOBUFS;
2817 size_t if_info_size;
2818
2819 skb = nlmsg_new((if_info_size = if_nlmsg_size(dev, 0)), flags);
2820 if (skb == NULL)
2821 goto errout;
2822
2867{
2868 struct net *net = dev_net(dev);
2869 struct sk_buff *skb;
2870 int err = -ENOBUFS;
2871 size_t if_info_size;
2872
2873 skb = nlmsg_new((if_info_size = if_nlmsg_size(dev, 0)), flags);
2874 if (skb == NULL)
2875 goto errout;
2876
2823 err = rtnl_fill_ifinfo(skb, dev, type, 0, 0, change, 0, 0);
2877 err = rtnl_fill_ifinfo(skb, dev, type, 0, 0, change, 0, 0, event);
2824 if (err < 0) {
2825 /* -EMSGSIZE implies BUG in if_nlmsg_size() */
2826 WARN_ON(err == -EMSGSIZE);
2827 kfree_skb(skb);
2828 goto errout;
2829 }
2830 return skb;
2831errout:

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

2836
2837void rtmsg_ifinfo_send(struct sk_buff *skb, struct net_device *dev, gfp_t flags)
2838{
2839 struct net *net = dev_net(dev);
2840
2841 rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL, flags);
2842}
2843
2878 if (err < 0) {
2879 /* -EMSGSIZE implies BUG in if_nlmsg_size() */
2880 WARN_ON(err == -EMSGSIZE);
2881 kfree_skb(skb);
2882 goto errout;
2883 }
2884 return skb;
2885errout:

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

2890
2891void rtmsg_ifinfo_send(struct sk_buff *skb, struct net_device *dev, gfp_t flags)
2892{
2893 struct net *net = dev_net(dev);
2894
2895 rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL, flags);
2896}
2897
2844void rtmsg_ifinfo(int type, struct net_device *dev, unsigned int change,
2845 gfp_t flags)
2898static void rtmsg_ifinfo_event(int type, struct net_device *dev,
2899 unsigned int change, u32 event,
2900 gfp_t flags)
2846{
2847 struct sk_buff *skb;
2848
2849 if (dev->reg_state != NETREG_REGISTERED)
2850 return;
2851
2901{
2902 struct sk_buff *skb;
2903
2904 if (dev->reg_state != NETREG_REGISTERED)
2905 return;
2906
2852 skb = rtmsg_ifinfo_build_skb(type, dev, change, flags);
2907 skb = rtmsg_ifinfo_build_skb(type, dev, change, event, flags);
2853 if (skb)
2854 rtmsg_ifinfo_send(skb, dev, flags);
2855}
2908 if (skb)
2909 rtmsg_ifinfo_send(skb, dev, flags);
2910}
2911
2912void rtmsg_ifinfo(int type, struct net_device *dev, unsigned int change,
2913 gfp_t flags)
2914{
2915 rtmsg_ifinfo_event(type, dev, change, rtnl_get_event(0), flags);
2916}
2856EXPORT_SYMBOL(rtmsg_ifinfo);
2857
2858static int nlmsg_populate_fdb_fill(struct sk_buff *skb,
2859 struct net_device *dev,
2860 u8 *addr, u16 vid, u32 pid, u32 seq,
2861 int type, unsigned int flags,
2862 int nlflags, u16 ndm_state)
2863{

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

4152
4153static void rtnetlink_rcv(struct sk_buff *skb)
4154{
4155 rtnl_lock();
4156 netlink_rcv_skb(skb, &rtnetlink_rcv_msg);
4157 rtnl_unlock();
4158}
4159
2917EXPORT_SYMBOL(rtmsg_ifinfo);
2918
2919static int nlmsg_populate_fdb_fill(struct sk_buff *skb,
2920 struct net_device *dev,
2921 u8 *addr, u16 vid, u32 pid, u32 seq,
2922 int type, unsigned int flags,
2923 int nlflags, u16 ndm_state)
2924{

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

4213
4214static void rtnetlink_rcv(struct sk_buff *skb)
4215{
4216 rtnl_lock();
4217 netlink_rcv_skb(skb, &rtnetlink_rcv_msg);
4218 rtnl_unlock();
4219}
4220
4221static int rtnetlink_bind(struct net *net, int group)
4222{
4223 switch (group) {
4224 case RTNLGRP_IPV4_MROUTE_R:
4225 case RTNLGRP_IPV6_MROUTE_R:
4226 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
4227 return -EPERM;
4228 break;
4229 }
4230 return 0;
4231}
4232
4160static int rtnetlink_event(struct notifier_block *this, unsigned long event, void *ptr)
4161{
4162 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
4163
4164 switch (event) {
4165 case NETDEV_REBOOT:
4166 case NETDEV_CHANGENAME:
4167 case NETDEV_FEAT_CHANGE:
4168 case NETDEV_BONDING_FAILOVER:
4169 case NETDEV_NOTIFY_PEERS:
4170 case NETDEV_RESEND_IGMP:
4171 case NETDEV_CHANGEINFODATA:
4233static int rtnetlink_event(struct notifier_block *this, unsigned long event, void *ptr)
4234{
4235 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
4236
4237 switch (event) {
4238 case NETDEV_REBOOT:
4239 case NETDEV_CHANGENAME:
4240 case NETDEV_FEAT_CHANGE:
4241 case NETDEV_BONDING_FAILOVER:
4242 case NETDEV_NOTIFY_PEERS:
4243 case NETDEV_RESEND_IGMP:
4244 case NETDEV_CHANGEINFODATA:
4172 rtmsg_ifinfo(RTM_NEWLINK, dev, 0, GFP_KERNEL);
4245 rtmsg_ifinfo_event(RTM_NEWLINK, dev, 0, rtnl_get_event(event),
4246 GFP_KERNEL);
4173 break;
4174 default:
4175 break;
4176 }
4177 return NOTIFY_DONE;
4178}
4179
4180static struct notifier_block rtnetlink_dev_notifier = {

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

4185static int __net_init rtnetlink_net_init(struct net *net)
4186{
4187 struct sock *sk;
4188 struct netlink_kernel_cfg cfg = {
4189 .groups = RTNLGRP_MAX,
4190 .input = rtnetlink_rcv,
4191 .cb_mutex = &rtnl_mutex,
4192 .flags = NL_CFG_F_NONROOT_RECV,
4247 break;
4248 default:
4249 break;
4250 }
4251 return NOTIFY_DONE;
4252}
4253
4254static struct notifier_block rtnetlink_dev_notifier = {

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

4259static int __net_init rtnetlink_net_init(struct net *net)
4260{
4261 struct sock *sk;
4262 struct netlink_kernel_cfg cfg = {
4263 .groups = RTNLGRP_MAX,
4264 .input = rtnetlink_rcv,
4265 .cb_mutex = &rtnl_mutex,
4266 .flags = NL_CFG_F_NONROOT_RECV,
4267 .bind = rtnetlink_bind,
4193 };
4194
4195 sk = netlink_kernel_create(net, NETLINK_ROUTE, &cfg);
4196 if (!sk)
4197 return -ENOMEM;
4198 net->rtnl = sk;
4199 return 0;
4200}

--- 40 unchanged lines hidden ---
4268 };
4269
4270 sk = netlink_kernel_create(net, NETLINK_ROUTE, &cfg);
4271 if (!sk)
4272 return -ENOMEM;
4273 net->rtnl = sk;
4274 return 0;
4275}

--- 40 unchanged lines hidden ---