rtnetlink.c (f92ce7618f0cb0ced87ea1cfe994d2e8473c61b4) rtnetlink.c (dd461d6aa894761fe67c30ddf81eec0d08be216b)
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>

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

91
92int rtnl_is_locked(void)
93{
94 return mutex_is_locked(&rtnl_mutex);
95}
96EXPORT_SYMBOL(rtnl_is_locked);
97
98#ifdef CONFIG_PROVE_LOCKING
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>

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

91
92int rtnl_is_locked(void)
93{
94 return mutex_is_locked(&rtnl_mutex);
95}
96EXPORT_SYMBOL(rtnl_is_locked);
97
98#ifdef CONFIG_PROVE_LOCKING
99int lockdep_rtnl_is_held(void)
99bool lockdep_rtnl_is_held(void)
100{
101 return lockdep_is_held(&rtnl_mutex);
102}
103EXPORT_SYMBOL(lockdep_rtnl_is_held);
104#endif /* #ifdef CONFIG_PROVE_LOCKING */
105
106static struct rtnl_link *rtnl_msg_handlers[RTNL_FAMILY_MAX + 1];
107

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

492void rtnl_af_unregister(struct rtnl_af_ops *ops)
493{
494 rtnl_lock();
495 __rtnl_af_unregister(ops);
496 rtnl_unlock();
497}
498EXPORT_SYMBOL_GPL(rtnl_af_unregister);
499
100{
101 return lockdep_is_held(&rtnl_mutex);
102}
103EXPORT_SYMBOL(lockdep_rtnl_is_held);
104#endif /* #ifdef CONFIG_PROVE_LOCKING */
105
106static struct rtnl_link *rtnl_msg_handlers[RTNL_FAMILY_MAX + 1];
107

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

492void rtnl_af_unregister(struct rtnl_af_ops *ops)
493{
494 rtnl_lock();
495 __rtnl_af_unregister(ops);
496 rtnl_unlock();
497}
498EXPORT_SYMBOL_GPL(rtnl_af_unregister);
499
500static size_t rtnl_link_get_af_size(const struct net_device *dev)
500static size_t rtnl_link_get_af_size(const struct net_device *dev,
501 u32 ext_filter_mask)
501{
502 struct rtnl_af_ops *af_ops;
503 size_t size;
504
505 /* IFLA_AF_SPEC */
506 size = nla_total_size(sizeof(struct nlattr));
507
508 list_for_each_entry(af_ops, &rtnl_af_ops, list) {
509 if (af_ops->get_link_af_size) {
510 /* AF_* + nested data */
511 size += nla_total_size(sizeof(struct nlattr)) +
502{
503 struct rtnl_af_ops *af_ops;
504 size_t size;
505
506 /* IFLA_AF_SPEC */
507 size = nla_total_size(sizeof(struct nlattr));
508
509 list_for_each_entry(af_ops, &rtnl_af_ops, list) {
510 if (af_ops->get_link_af_size) {
511 /* AF_* + nested data */
512 size += nla_total_size(sizeof(struct nlattr)) +
512 af_ops->get_link_af_size(dev);
513 af_ops->get_link_af_size(dev, ext_filter_mask);
513 }
514 }
515
516 return size;
517}
518
519static bool rtnl_have_link_slave_info(const struct net_device *dev)
520{

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

832 nla_total_size(sizeof(__u64)) +
833 /* IFLA_VF_STATS_RX_BYTES */
834 nla_total_size(sizeof(__u64)) +
835 /* IFLA_VF_STATS_TX_BYTES */
836 nla_total_size(sizeof(__u64)) +
837 /* IFLA_VF_STATS_BROADCAST */
838 nla_total_size(sizeof(__u64)) +
839 /* IFLA_VF_STATS_MULTICAST */
514 }
515 }
516
517 return size;
518}
519
520static bool rtnl_have_link_slave_info(const struct net_device *dev)
521{

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

833 nla_total_size(sizeof(__u64)) +
834 /* IFLA_VF_STATS_RX_BYTES */
835 nla_total_size(sizeof(__u64)) +
836 /* IFLA_VF_STATS_TX_BYTES */
837 nla_total_size(sizeof(__u64)) +
838 /* IFLA_VF_STATS_BROADCAST */
839 nla_total_size(sizeof(__u64)) +
840 /* IFLA_VF_STATS_MULTICAST */
840 nla_total_size(sizeof(__u64)));
841 nla_total_size(sizeof(__u64)) +
842 nla_total_size(sizeof(struct ifla_vf_trust)));
841 return size;
842 } else
843 return 0;
844}
845
846static size_t rtnl_port_size(const struct net_device *dev,
847 u32 ext_filter_mask)
848{

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

895 + nla_total_size(1) /* IFLA_LINKMODE */
896 + nla_total_size(4) /* IFLA_CARRIER_CHANGES */
897 + nla_total_size(4) /* IFLA_LINK_NETNSID */
898 + nla_total_size(ext_filter_mask
899 & RTEXT_FILTER_VF ? 4 : 0) /* IFLA_NUM_VF */
900 + rtnl_vfinfo_size(dev, ext_filter_mask) /* IFLA_VFINFO_LIST */
901 + rtnl_port_size(dev, ext_filter_mask) /* IFLA_VF_PORTS + IFLA_PORT_SELF */
902 + rtnl_link_get_size(dev) /* IFLA_LINKINFO */
843 return size;
844 } else
845 return 0;
846}
847
848static size_t rtnl_port_size(const struct net_device *dev,
849 u32 ext_filter_mask)
850{

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

897 + nla_total_size(1) /* IFLA_LINKMODE */
898 + nla_total_size(4) /* IFLA_CARRIER_CHANGES */
899 + nla_total_size(4) /* IFLA_LINK_NETNSID */
900 + nla_total_size(ext_filter_mask
901 & RTEXT_FILTER_VF ? 4 : 0) /* IFLA_NUM_VF */
902 + rtnl_vfinfo_size(dev, ext_filter_mask) /* IFLA_VFINFO_LIST */
903 + rtnl_port_size(dev, ext_filter_mask) /* IFLA_VF_PORTS + IFLA_PORT_SELF */
904 + rtnl_link_get_size(dev) /* IFLA_LINKINFO */
903 + rtnl_link_get_af_size(dev) /* IFLA_AF_SPEC */
905 + rtnl_link_get_af_size(dev, ext_filter_mask) /* IFLA_AF_SPEC */
904 + nla_total_size(MAX_PHYS_ITEM_ID_LEN) /* IFLA_PHYS_PORT_ID */
905 + nla_total_size(MAX_PHYS_ITEM_ID_LEN) /* IFLA_PHYS_SWITCH_ID */
906 + nla_total_size(1); /* IFLA_PROTO_DOWN */
907
908}
909
910static int rtnl_vf_ports_fill(struct sk_buff *skb, struct net_device *dev)
911{

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

1020
1021 return 0;
1022}
1023
1024static int rtnl_phys_switch_id_fill(struct sk_buff *skb, struct net_device *dev)
1025{
1026 int err;
1027 struct switchdev_attr attr = {
906 + nla_total_size(MAX_PHYS_ITEM_ID_LEN) /* IFLA_PHYS_PORT_ID */
907 + nla_total_size(MAX_PHYS_ITEM_ID_LEN) /* IFLA_PHYS_SWITCH_ID */
908 + nla_total_size(1); /* IFLA_PROTO_DOWN */
909
910}
911
912static int rtnl_vf_ports_fill(struct sk_buff *skb, struct net_device *dev)
913{

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

1022
1023 return 0;
1024}
1025
1026static int rtnl_phys_switch_id_fill(struct sk_buff *skb, struct net_device *dev)
1027{
1028 int err;
1029 struct switchdev_attr attr = {
1028 .id = SWITCHDEV_ATTR_PORT_PARENT_ID,
1030 .id = SWITCHDEV_ATTR_ID_PORT_PARENT_ID,
1029 .flags = SWITCHDEV_F_NO_RECURSE,
1030 };
1031
1032 err = switchdev_port_attr_get(dev, &attr);
1033 if (err) {
1034 if (err == -EOPNOTSUPP)
1035 return 0;
1036 return err;

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

1155 struct ifla_vf_mac vf_mac;
1156 struct ifla_vf_vlan vf_vlan;
1157 struct ifla_vf_rate vf_rate;
1158 struct ifla_vf_tx_rate vf_tx_rate;
1159 struct ifla_vf_spoofchk vf_spoofchk;
1160 struct ifla_vf_link_state vf_linkstate;
1161 struct ifla_vf_rss_query_en vf_rss_query_en;
1162 struct ifla_vf_stats vf_stats;
1031 .flags = SWITCHDEV_F_NO_RECURSE,
1032 };
1033
1034 err = switchdev_port_attr_get(dev, &attr);
1035 if (err) {
1036 if (err == -EOPNOTSUPP)
1037 return 0;
1038 return err;

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

1157 struct ifla_vf_mac vf_mac;
1158 struct ifla_vf_vlan vf_vlan;
1159 struct ifla_vf_rate vf_rate;
1160 struct ifla_vf_tx_rate vf_tx_rate;
1161 struct ifla_vf_spoofchk vf_spoofchk;
1162 struct ifla_vf_link_state vf_linkstate;
1163 struct ifla_vf_rss_query_en vf_rss_query_en;
1164 struct ifla_vf_stats vf_stats;
1165 struct ifla_vf_trust vf_trust;
1163
1164 /*
1165 * Not all SR-IOV capable drivers support the
1166 * spoofcheck and "RSS query enable" query. Preset to
1167 * -1 so the user space tool can detect that the driver
1168 * didn't report anything.
1169 */
1170 ivi.spoofchk = -1;
1171 ivi.rss_query_en = -1;
1166
1167 /*
1168 * Not all SR-IOV capable drivers support the
1169 * spoofcheck and "RSS query enable" query. Preset to
1170 * -1 so the user space tool can detect that the driver
1171 * didn't report anything.
1172 */
1173 ivi.spoofchk = -1;
1174 ivi.rss_query_en = -1;
1175 ivi.trusted = -1;
1172 memset(ivi.mac, 0, sizeof(ivi.mac));
1173 /* The default value for VF link state is "auto"
1174 * IFLA_VF_LINK_STATE_AUTO which equals zero
1175 */
1176 ivi.linkstate = 0;
1177 if (dev->netdev_ops->ndo_get_vf_config(dev, i, &ivi))
1178 break;
1179 vf_mac.vf =
1180 vf_vlan.vf =
1181 vf_rate.vf =
1182 vf_tx_rate.vf =
1183 vf_spoofchk.vf =
1184 vf_linkstate.vf =
1176 memset(ivi.mac, 0, sizeof(ivi.mac));
1177 /* The default value for VF link state is "auto"
1178 * IFLA_VF_LINK_STATE_AUTO which equals zero
1179 */
1180 ivi.linkstate = 0;
1181 if (dev->netdev_ops->ndo_get_vf_config(dev, i, &ivi))
1182 break;
1183 vf_mac.vf =
1184 vf_vlan.vf =
1185 vf_rate.vf =
1186 vf_tx_rate.vf =
1187 vf_spoofchk.vf =
1188 vf_linkstate.vf =
1185 vf_rss_query_en.vf = ivi.vf;
1189 vf_rss_query_en.vf =
1190 vf_trust.vf = ivi.vf;
1186
1187 memcpy(vf_mac.mac, ivi.mac, sizeof(ivi.mac));
1188 vf_vlan.vlan = ivi.vlan;
1189 vf_vlan.qos = ivi.qos;
1190 vf_tx_rate.rate = ivi.max_tx_rate;
1191 vf_rate.min_tx_rate = ivi.min_tx_rate;
1192 vf_rate.max_tx_rate = ivi.max_tx_rate;
1193 vf_spoofchk.setting = ivi.spoofchk;
1194 vf_linkstate.link_state = ivi.linkstate;
1195 vf_rss_query_en.setting = ivi.rss_query_en;
1191
1192 memcpy(vf_mac.mac, ivi.mac, sizeof(ivi.mac));
1193 vf_vlan.vlan = ivi.vlan;
1194 vf_vlan.qos = ivi.qos;
1195 vf_tx_rate.rate = ivi.max_tx_rate;
1196 vf_rate.min_tx_rate = ivi.min_tx_rate;
1197 vf_rate.max_tx_rate = ivi.max_tx_rate;
1198 vf_spoofchk.setting = ivi.spoofchk;
1199 vf_linkstate.link_state = ivi.linkstate;
1200 vf_rss_query_en.setting = ivi.rss_query_en;
1201 vf_trust.setting = ivi.trusted;
1196 vf = nla_nest_start(skb, IFLA_VF_INFO);
1197 if (!vf) {
1198 nla_nest_cancel(skb, vfinfo);
1199 goto nla_put_failure;
1200 }
1201 if (nla_put(skb, IFLA_VF_MAC, sizeof(vf_mac), &vf_mac) ||
1202 nla_put(skb, IFLA_VF_VLAN, sizeof(vf_vlan), &vf_vlan) ||
1203 nla_put(skb, IFLA_VF_RATE, sizeof(vf_rate),
1204 &vf_rate) ||
1205 nla_put(skb, IFLA_VF_TX_RATE, sizeof(vf_tx_rate),
1206 &vf_tx_rate) ||
1207 nla_put(skb, IFLA_VF_SPOOFCHK, sizeof(vf_spoofchk),
1208 &vf_spoofchk) ||
1209 nla_put(skb, IFLA_VF_LINK_STATE, sizeof(vf_linkstate),
1210 &vf_linkstate) ||
1211 nla_put(skb, IFLA_VF_RSS_QUERY_EN,
1212 sizeof(vf_rss_query_en),
1202 vf = nla_nest_start(skb, IFLA_VF_INFO);
1203 if (!vf) {
1204 nla_nest_cancel(skb, vfinfo);
1205 goto nla_put_failure;
1206 }
1207 if (nla_put(skb, IFLA_VF_MAC, sizeof(vf_mac), &vf_mac) ||
1208 nla_put(skb, IFLA_VF_VLAN, sizeof(vf_vlan), &vf_vlan) ||
1209 nla_put(skb, IFLA_VF_RATE, sizeof(vf_rate),
1210 &vf_rate) ||
1211 nla_put(skb, IFLA_VF_TX_RATE, sizeof(vf_tx_rate),
1212 &vf_tx_rate) ||
1213 nla_put(skb, IFLA_VF_SPOOFCHK, sizeof(vf_spoofchk),
1214 &vf_spoofchk) ||
1215 nla_put(skb, IFLA_VF_LINK_STATE, sizeof(vf_linkstate),
1216 &vf_linkstate) ||
1217 nla_put(skb, IFLA_VF_RSS_QUERY_EN,
1218 sizeof(vf_rss_query_en),
1213 &vf_rss_query_en))
1219 &vf_rss_query_en) ||
1220 nla_put(skb, IFLA_VF_TRUST,
1221 sizeof(vf_trust), &vf_trust))
1214 goto nla_put_failure;
1215 memset(&vf_stats, 0, sizeof(vf_stats));
1216 if (dev->netdev_ops->ndo_get_vf_stats)
1217 dev->netdev_ops->ndo_get_vf_stats(dev, i,
1218 &vf_stats);
1219 vfstats = nla_nest_start(skb, IFLA_VF_STATS);
1220 if (!vfstats) {
1221 nla_nest_cancel(skb, vf);

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

1267 list_for_each_entry(af_ops, &rtnl_af_ops, list) {
1268 if (af_ops->fill_link_af) {
1269 struct nlattr *af;
1270 int err;
1271
1272 if (!(af = nla_nest_start(skb, af_ops->family)))
1273 goto nla_put_failure;
1274
1222 goto nla_put_failure;
1223 memset(&vf_stats, 0, sizeof(vf_stats));
1224 if (dev->netdev_ops->ndo_get_vf_stats)
1225 dev->netdev_ops->ndo_get_vf_stats(dev, i,
1226 &vf_stats);
1227 vfstats = nla_nest_start(skb, IFLA_VF_STATS);
1228 if (!vfstats) {
1229 nla_nest_cancel(skb, vf);

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

1275 list_for_each_entry(af_ops, &rtnl_af_ops, list) {
1276 if (af_ops->fill_link_af) {
1277 struct nlattr *af;
1278 int err;
1279
1280 if (!(af = nla_nest_start(skb, af_ops->family)))
1281 goto nla_put_failure;
1282
1275 err = af_ops->fill_link_af(skb, dev);
1283 err = af_ops->fill_link_af(skb, dev, ext_filter_mask);
1276
1277 /*
1278 * Caller may return ENODATA to indicate that there
1279 * was no data to be dumped. This is not an error, it
1280 * means we should trim the attribute header and
1281 * continue.
1282 */
1283 if (err == -ENODATA)

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

1342 [IFLA_VF_MAC] = { .len = sizeof(struct ifla_vf_mac) },
1343 [IFLA_VF_VLAN] = { .len = sizeof(struct ifla_vf_vlan) },
1344 [IFLA_VF_TX_RATE] = { .len = sizeof(struct ifla_vf_tx_rate) },
1345 [IFLA_VF_SPOOFCHK] = { .len = sizeof(struct ifla_vf_spoofchk) },
1346 [IFLA_VF_RATE] = { .len = sizeof(struct ifla_vf_rate) },
1347 [IFLA_VF_LINK_STATE] = { .len = sizeof(struct ifla_vf_link_state) },
1348 [IFLA_VF_RSS_QUERY_EN] = { .len = sizeof(struct ifla_vf_rss_query_en) },
1349 [IFLA_VF_STATS] = { .type = NLA_NESTED },
1284
1285 /*
1286 * Caller may return ENODATA to indicate that there
1287 * was no data to be dumped. This is not an error, it
1288 * means we should trim the attribute header and
1289 * continue.
1290 */
1291 if (err == -ENODATA)

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

1350 [IFLA_VF_MAC] = { .len = sizeof(struct ifla_vf_mac) },
1351 [IFLA_VF_VLAN] = { .len = sizeof(struct ifla_vf_vlan) },
1352 [IFLA_VF_TX_RATE] = { .len = sizeof(struct ifla_vf_tx_rate) },
1353 [IFLA_VF_SPOOFCHK] = { .len = sizeof(struct ifla_vf_spoofchk) },
1354 [IFLA_VF_RATE] = { .len = sizeof(struct ifla_vf_rate) },
1355 [IFLA_VF_LINK_STATE] = { .len = sizeof(struct ifla_vf_link_state) },
1356 [IFLA_VF_RSS_QUERY_EN] = { .len = sizeof(struct ifla_vf_rss_query_en) },
1357 [IFLA_VF_STATS] = { .type = NLA_NESTED },
1358 [IFLA_VF_TRUST] = { .len = sizeof(struct ifla_vf_trust) },
1350};
1351
1352static const struct nla_policy ifla_vf_stats_policy[IFLA_VF_STATS_MAX + 1] = {
1353 [IFLA_VF_STATS_RX_PACKETS] = { .type = NLA_U64 },
1354 [IFLA_VF_STATS_TX_PACKETS] = { .type = NLA_U64 },
1355 [IFLA_VF_STATS_RX_BYTES] = { .type = NLA_U64 },
1356 [IFLA_VF_STATS_TX_BYTES] = { .type = NLA_U64 },
1357 [IFLA_VF_STATS_BROADCAST] = { .type = NLA_U64 },

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

1581 ivrssq_en = nla_data(tb[IFLA_VF_RSS_QUERY_EN]);
1582 if (ops->ndo_set_vf_rss_query_en)
1583 err = ops->ndo_set_vf_rss_query_en(dev, ivrssq_en->vf,
1584 ivrssq_en->setting);
1585 if (err < 0)
1586 return err;
1587 }
1588
1359};
1360
1361static const struct nla_policy ifla_vf_stats_policy[IFLA_VF_STATS_MAX + 1] = {
1362 [IFLA_VF_STATS_RX_PACKETS] = { .type = NLA_U64 },
1363 [IFLA_VF_STATS_TX_PACKETS] = { .type = NLA_U64 },
1364 [IFLA_VF_STATS_RX_BYTES] = { .type = NLA_U64 },
1365 [IFLA_VF_STATS_TX_BYTES] = { .type = NLA_U64 },
1366 [IFLA_VF_STATS_BROADCAST] = { .type = NLA_U64 },

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

1590 ivrssq_en = nla_data(tb[IFLA_VF_RSS_QUERY_EN]);
1591 if (ops->ndo_set_vf_rss_query_en)
1592 err = ops->ndo_set_vf_rss_query_en(dev, ivrssq_en->vf,
1593 ivrssq_en->setting);
1594 if (err < 0)
1595 return err;
1596 }
1597
1598 if (tb[IFLA_VF_TRUST]) {
1599 struct ifla_vf_trust *ivt = nla_data(tb[IFLA_VF_TRUST]);
1600
1601 err = -EOPNOTSUPP;
1602 if (ops->ndo_set_vf_trust)
1603 err = ops->ndo_set_vf_trust(dev, ivt->vf, ivt->setting);
1604 if (err < 0)
1605 return err;
1606 }
1607
1589 return err;
1590}
1591
1592static int do_set_master(struct net_device *dev, int ifindex)
1593{
1594 struct net_device *upper_dev = netdev_master_upper_dev_get(dev);
1595 const struct net_device_ops *ops;
1596 int err;

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

3438 rtnl_register(PF_BRIDGE, RTM_NEWNEIGH, rtnl_fdb_add, NULL, NULL);
3439 rtnl_register(PF_BRIDGE, RTM_DELNEIGH, rtnl_fdb_del, NULL, NULL);
3440 rtnl_register(PF_BRIDGE, RTM_GETNEIGH, NULL, rtnl_fdb_dump, NULL);
3441
3442 rtnl_register(PF_BRIDGE, RTM_GETLINK, NULL, rtnl_bridge_getlink, NULL);
3443 rtnl_register(PF_BRIDGE, RTM_DELLINK, rtnl_bridge_dellink, NULL, NULL);
3444 rtnl_register(PF_BRIDGE, RTM_SETLINK, rtnl_bridge_setlink, NULL, NULL);
3445}
1608 return err;
1609}
1610
1611static int do_set_master(struct net_device *dev, int ifindex)
1612{
1613 struct net_device *upper_dev = netdev_master_upper_dev_get(dev);
1614 const struct net_device_ops *ops;
1615 int err;

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

3457 rtnl_register(PF_BRIDGE, RTM_NEWNEIGH, rtnl_fdb_add, NULL, NULL);
3458 rtnl_register(PF_BRIDGE, RTM_DELNEIGH, rtnl_fdb_del, NULL, NULL);
3459 rtnl_register(PF_BRIDGE, RTM_GETNEIGH, NULL, rtnl_fdb_dump, NULL);
3460
3461 rtnl_register(PF_BRIDGE, RTM_GETLINK, NULL, rtnl_bridge_getlink, NULL);
3462 rtnl_register(PF_BRIDGE, RTM_DELLINK, rtnl_bridge_dellink, NULL, NULL);
3463 rtnl_register(PF_BRIDGE, RTM_SETLINK, rtnl_bridge_setlink, NULL, NULL);
3464}
3446