aboutsummaryrefslogtreecommitdiffstats
path: root/net/core/rtnetlink.c
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2019-04-27 17:03:44 -0400
committerDavid S. Miller <davem@davemloft.net>2019-04-27 17:03:44 -0400
commitf6ad55a6a184ebdf3d98a90eab0895f73ce9797e (patch)
treeb49e3af8f5cac309bae80ad390ee8fc3b3679065 /net/core/rtnetlink.c
parentc7881b4a97e21b617b8243094dfa4b62028b956c (diff)
parentf78c6032c4cb89b408190afd4feb61ff4461a114 (diff)
Merge branch 'nla_nest_start'
Michal Kubecek says: ==================== make nla_nest_start() add NLA_F_NESTED flag One of the comments in recent review of the ethtool netlink series pointed out that proposed ethnl_nest_start() helper which adds NLA_F_NESTED to second argument of nla_nest_start() is not really specific to ethtool netlink code. That is hard to argue with as closer inspection revealed that exactly the same helper already exists in ipset code (except it's a macro rather than an inline function). Another observation was that even if NLA_F_NESTED flag was introduced in 2007, only few netlink based interfaces set it in kernel generated messages and even many recently added APIs omit it. That is unfortunate as without the flag, message parsers not familiar with attribute semantics cannot recognize nested attributes and do not see message structure; this affects e.g. wireshark dissector or mnl_nlmsg_fprintf() from libmnl. This is why I'm suggesting to rename existing nla_nest_start() to different name (nla_nest_start_noflag) and reintroduce nla_nest_start() as a wrapper adding NLA_F_NESTED flag. This is implemented in first patch which is mostly generated by spatch. Second patch drops ipset helper macros which lose their purpose. Third patch cleans up minor coding style issues found by checkpatch.pl in first patch. We could leave nla_nest_start() untouched and simply add a wrapper adding NLA_F_NESTED but that would probably preserve the state when even most new code doesn't set the flag. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core/rtnetlink.c')
-rw-r--r--net/core/rtnetlink.c48
1 files changed, 25 insertions, 23 deletions
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 5fa5bf3e9945..8ad44b299e72 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -634,7 +634,7 @@ static int rtnl_link_slave_info_fill(struct sk_buff *skb,
634 if (nla_put_string(skb, IFLA_INFO_SLAVE_KIND, ops->kind) < 0) 634 if (nla_put_string(skb, IFLA_INFO_SLAVE_KIND, ops->kind) < 0)
635 return -EMSGSIZE; 635 return -EMSGSIZE;
636 if (ops->fill_slave_info) { 636 if (ops->fill_slave_info) {
637 slave_data = nla_nest_start(skb, IFLA_INFO_SLAVE_DATA); 637 slave_data = nla_nest_start_noflag(skb, IFLA_INFO_SLAVE_DATA);
638 if (!slave_data) 638 if (!slave_data)
639 return -EMSGSIZE; 639 return -EMSGSIZE;
640 err = ops->fill_slave_info(skb, master_dev, dev); 640 err = ops->fill_slave_info(skb, master_dev, dev);
@@ -666,7 +666,7 @@ static int rtnl_link_info_fill(struct sk_buff *skb,
666 return err; 666 return err;
667 } 667 }
668 if (ops->fill_info) { 668 if (ops->fill_info) {
669 data = nla_nest_start(skb, IFLA_INFO_DATA); 669 data = nla_nest_start_noflag(skb, IFLA_INFO_DATA);
670 if (data == NULL) 670 if (data == NULL)
671 return -EMSGSIZE; 671 return -EMSGSIZE;
672 err = ops->fill_info(skb, dev); 672 err = ops->fill_info(skb, dev);
@@ -686,7 +686,7 @@ static int rtnl_link_fill(struct sk_buff *skb, const struct net_device *dev)
686 struct nlattr *linkinfo; 686 struct nlattr *linkinfo;
687 int err = -EMSGSIZE; 687 int err = -EMSGSIZE;
688 688
689 linkinfo = nla_nest_start(skb, IFLA_LINKINFO); 689 linkinfo = nla_nest_start_noflag(skb, IFLA_LINKINFO);
690 if (linkinfo == NULL) 690 if (linkinfo == NULL)
691 goto out; 691 goto out;
692 692
@@ -755,7 +755,7 @@ int rtnetlink_put_metrics(struct sk_buff *skb, u32 *metrics)
755 struct nlattr *mx; 755 struct nlattr *mx;
756 int i, valid = 0; 756 int i, valid = 0;
757 757
758 mx = nla_nest_start(skb, RTA_METRICS); 758 mx = nla_nest_start_noflag(skb, RTA_METRICS);
759 if (mx == NULL) 759 if (mx == NULL)
760 return -ENOBUFS; 760 return -ENOBUFS;
761 761
@@ -1036,12 +1036,12 @@ static int rtnl_vf_ports_fill(struct sk_buff *skb, struct net_device *dev)
1036 int vf; 1036 int vf;
1037 int err; 1037 int err;
1038 1038
1039 vf_ports = nla_nest_start(skb, IFLA_VF_PORTS); 1039 vf_ports = nla_nest_start_noflag(skb, IFLA_VF_PORTS);
1040 if (!vf_ports) 1040 if (!vf_ports)
1041 return -EMSGSIZE; 1041 return -EMSGSIZE;
1042 1042
1043 for (vf = 0; vf < dev_num_vf(dev->dev.parent); vf++) { 1043 for (vf = 0; vf < dev_num_vf(dev->dev.parent); vf++) {
1044 vf_port = nla_nest_start(skb, IFLA_VF_PORT); 1044 vf_port = nla_nest_start_noflag(skb, IFLA_VF_PORT);
1045 if (!vf_port) 1045 if (!vf_port)
1046 goto nla_put_failure; 1046 goto nla_put_failure;
1047 if (nla_put_u32(skb, IFLA_PORT_VF, vf)) 1047 if (nla_put_u32(skb, IFLA_PORT_VF, vf))
@@ -1070,7 +1070,7 @@ static int rtnl_port_self_fill(struct sk_buff *skb, struct net_device *dev)
1070 struct nlattr *port_self; 1070 struct nlattr *port_self;
1071 int err; 1071 int err;
1072 1072
1073 port_self = nla_nest_start(skb, IFLA_PORT_SELF); 1073 port_self = nla_nest_start_noflag(skb, IFLA_PORT_SELF);
1074 if (!port_self) 1074 if (!port_self)
1075 return -EMSGSIZE; 1075 return -EMSGSIZE;
1076 1076
@@ -1247,7 +1247,7 @@ static noinline_for_stack int rtnl_fill_vfinfo(struct sk_buff *skb,
1247 vf_linkstate.link_state = ivi.linkstate; 1247 vf_linkstate.link_state = ivi.linkstate;
1248 vf_rss_query_en.setting = ivi.rss_query_en; 1248 vf_rss_query_en.setting = ivi.rss_query_en;
1249 vf_trust.setting = ivi.trusted; 1249 vf_trust.setting = ivi.trusted;
1250 vf = nla_nest_start(skb, IFLA_VF_INFO); 1250 vf = nla_nest_start_noflag(skb, IFLA_VF_INFO);
1251 if (!vf) 1251 if (!vf)
1252 goto nla_put_vfinfo_failure; 1252 goto nla_put_vfinfo_failure;
1253 if (nla_put(skb, IFLA_VF_MAC, sizeof(vf_mac), &vf_mac) || 1253 if (nla_put(skb, IFLA_VF_MAC, sizeof(vf_mac), &vf_mac) ||
@@ -1266,7 +1266,7 @@ static noinline_for_stack int rtnl_fill_vfinfo(struct sk_buff *skb,
1266 nla_put(skb, IFLA_VF_TRUST, 1266 nla_put(skb, IFLA_VF_TRUST,
1267 sizeof(vf_trust), &vf_trust)) 1267 sizeof(vf_trust), &vf_trust))
1268 goto nla_put_vf_failure; 1268 goto nla_put_vf_failure;
1269 vfvlanlist = nla_nest_start(skb, IFLA_VF_VLAN_LIST); 1269 vfvlanlist = nla_nest_start_noflag(skb, IFLA_VF_VLAN_LIST);
1270 if (!vfvlanlist) 1270 if (!vfvlanlist)
1271 goto nla_put_vf_failure; 1271 goto nla_put_vf_failure;
1272 if (nla_put(skb, IFLA_VF_VLAN_INFO, sizeof(vf_vlan_info), 1272 if (nla_put(skb, IFLA_VF_VLAN_INFO, sizeof(vf_vlan_info),
@@ -1279,7 +1279,7 @@ static noinline_for_stack int rtnl_fill_vfinfo(struct sk_buff *skb,
1279 if (dev->netdev_ops->ndo_get_vf_stats) 1279 if (dev->netdev_ops->ndo_get_vf_stats)
1280 dev->netdev_ops->ndo_get_vf_stats(dev, vfs_num, 1280 dev->netdev_ops->ndo_get_vf_stats(dev, vfs_num,
1281 &vf_stats); 1281 &vf_stats);
1282 vfstats = nla_nest_start(skb, IFLA_VF_STATS); 1282 vfstats = nla_nest_start_noflag(skb, IFLA_VF_STATS);
1283 if (!vfstats) 1283 if (!vfstats)
1284 goto nla_put_vf_failure; 1284 goto nla_put_vf_failure;
1285 if (nla_put_u64_64bit(skb, IFLA_VF_STATS_RX_PACKETS, 1285 if (nla_put_u64_64bit(skb, IFLA_VF_STATS_RX_PACKETS,
@@ -1329,7 +1329,7 @@ static noinline_for_stack int rtnl_fill_vf(struct sk_buff *skb,
1329 if (!dev->netdev_ops->ndo_get_vf_config) 1329 if (!dev->netdev_ops->ndo_get_vf_config)
1330 return 0; 1330 return 0;
1331 1331
1332 vfinfo = nla_nest_start(skb, IFLA_VFINFO_LIST); 1332 vfinfo = nla_nest_start_noflag(skb, IFLA_VFINFO_LIST);
1333 if (!vfinfo) 1333 if (!vfinfo)
1334 return -EMSGSIZE; 1334 return -EMSGSIZE;
1335 1335
@@ -1414,7 +1414,7 @@ static int rtnl_xdp_fill(struct sk_buff *skb, struct net_device *dev)
1414 int err; 1414 int err;
1415 u8 mode; 1415 u8 mode;
1416 1416
1417 xdp = nla_nest_start(skb, IFLA_XDP); 1417 xdp = nla_nest_start_noflag(skb, IFLA_XDP);
1418 if (!xdp) 1418 if (!xdp)
1419 return -EMSGSIZE; 1419 return -EMSGSIZE;
1420 1420
@@ -1541,7 +1541,7 @@ static int rtnl_fill_link_af(struct sk_buff *skb,
1541 const struct rtnl_af_ops *af_ops; 1541 const struct rtnl_af_ops *af_ops;
1542 struct nlattr *af_spec; 1542 struct nlattr *af_spec;
1543 1543
1544 af_spec = nla_nest_start(skb, IFLA_AF_SPEC); 1544 af_spec = nla_nest_start_noflag(skb, IFLA_AF_SPEC);
1545 if (!af_spec) 1545 if (!af_spec)
1546 return -EMSGSIZE; 1546 return -EMSGSIZE;
1547 1547
@@ -1552,7 +1552,7 @@ static int rtnl_fill_link_af(struct sk_buff *skb,
1552 if (!af_ops->fill_link_af) 1552 if (!af_ops->fill_link_af)
1553 continue; 1553 continue;
1554 1554
1555 af = nla_nest_start(skb, af_ops->family); 1555 af = nla_nest_start_noflag(skb, af_ops->family);
1556 if (!af) 1556 if (!af)
1557 return -EMSGSIZE; 1557 return -EMSGSIZE;
1558 1558
@@ -4273,7 +4273,7 @@ int ndo_dflt_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
4273 nla_put_u32(skb, IFLA_LINK, dev_get_iflink(dev)))) 4273 nla_put_u32(skb, IFLA_LINK, dev_get_iflink(dev))))
4274 goto nla_put_failure; 4274 goto nla_put_failure;
4275 4275
4276 br_afspec = nla_nest_start(skb, IFLA_AF_SPEC); 4276 br_afspec = nla_nest_start_noflag(skb, IFLA_AF_SPEC);
4277 if (!br_afspec) 4277 if (!br_afspec)
4278 goto nla_put_failure; 4278 goto nla_put_failure;
4279 4279
@@ -4297,7 +4297,7 @@ int ndo_dflt_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
4297 } 4297 }
4298 nla_nest_end(skb, br_afspec); 4298 nla_nest_end(skb, br_afspec);
4299 4299
4300 protinfo = nla_nest_start(skb, IFLA_PROTINFO | NLA_F_NESTED); 4300 protinfo = nla_nest_start(skb, IFLA_PROTINFO);
4301 if (!protinfo) 4301 if (!protinfo)
4302 goto nla_put_failure; 4302 goto nla_put_failure;
4303 4303
@@ -4776,8 +4776,8 @@ static int rtnl_fill_statsinfo(struct sk_buff *skb, struct net_device *dev,
4776 4776
4777 if (ops && ops->fill_linkxstats) { 4777 if (ops && ops->fill_linkxstats) {
4778 *idxattr = IFLA_STATS_LINK_XSTATS; 4778 *idxattr = IFLA_STATS_LINK_XSTATS;
4779 attr = nla_nest_start(skb, 4779 attr = nla_nest_start_noflag(skb,
4780 IFLA_STATS_LINK_XSTATS); 4780 IFLA_STATS_LINK_XSTATS);
4781 if (!attr) 4781 if (!attr)
4782 goto nla_put_failure; 4782 goto nla_put_failure;
4783 4783
@@ -4799,8 +4799,8 @@ static int rtnl_fill_statsinfo(struct sk_buff *skb, struct net_device *dev,
4799 ops = master->rtnl_link_ops; 4799 ops = master->rtnl_link_ops;
4800 if (ops && ops->fill_linkxstats) { 4800 if (ops && ops->fill_linkxstats) {
4801 *idxattr = IFLA_STATS_LINK_XSTATS_SLAVE; 4801 *idxattr = IFLA_STATS_LINK_XSTATS_SLAVE;
4802 attr = nla_nest_start(skb, 4802 attr = nla_nest_start_noflag(skb,
4803 IFLA_STATS_LINK_XSTATS_SLAVE); 4803 IFLA_STATS_LINK_XSTATS_SLAVE);
4804 if (!attr) 4804 if (!attr)
4805 goto nla_put_failure; 4805 goto nla_put_failure;
4806 4806
@@ -4815,7 +4815,8 @@ static int rtnl_fill_statsinfo(struct sk_buff *skb, struct net_device *dev,
4815 if (stats_attr_valid(filter_mask, IFLA_STATS_LINK_OFFLOAD_XSTATS, 4815 if (stats_attr_valid(filter_mask, IFLA_STATS_LINK_OFFLOAD_XSTATS,
4816 *idxattr)) { 4816 *idxattr)) {
4817 *idxattr = IFLA_STATS_LINK_OFFLOAD_XSTATS; 4817 *idxattr = IFLA_STATS_LINK_OFFLOAD_XSTATS;
4818 attr = nla_nest_start(skb, IFLA_STATS_LINK_OFFLOAD_XSTATS); 4818 attr = nla_nest_start_noflag(skb,
4819 IFLA_STATS_LINK_OFFLOAD_XSTATS);
4819 if (!attr) 4820 if (!attr)
4820 goto nla_put_failure; 4821 goto nla_put_failure;
4821 4822
@@ -4834,7 +4835,7 @@ static int rtnl_fill_statsinfo(struct sk_buff *skb, struct net_device *dev,
4834 struct rtnl_af_ops *af_ops; 4835 struct rtnl_af_ops *af_ops;
4835 4836
4836 *idxattr = IFLA_STATS_AF_SPEC; 4837 *idxattr = IFLA_STATS_AF_SPEC;
4837 attr = nla_nest_start(skb, IFLA_STATS_AF_SPEC); 4838 attr = nla_nest_start_noflag(skb, IFLA_STATS_AF_SPEC);
4838 if (!attr) 4839 if (!attr)
4839 goto nla_put_failure; 4840 goto nla_put_failure;
4840 4841
@@ -4844,7 +4845,8 @@ static int rtnl_fill_statsinfo(struct sk_buff *skb, struct net_device *dev,
4844 struct nlattr *af; 4845 struct nlattr *af;
4845 int err; 4846 int err;
4846 4847
4847 af = nla_nest_start(skb, af_ops->family); 4848 af = nla_nest_start_noflag(skb,
4849 af_ops->family);
4848 if (!af) { 4850 if (!af) {
4849 rcu_read_unlock(); 4851 rcu_read_unlock();
4850 goto nla_put_failure; 4852 goto nla_put_failure;