Skip to content

Commit f6ad55a

Browse files
committed
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 <[email protected]>
2 parents c7881b4 + f78c603 commit f6ad55a

File tree

114 files changed

+565
-494
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+565
-494
lines changed

drivers/block/drbd/drbd_nl.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ static int drbd_msg_put_info(struct sk_buff *skb, const char *info)
114114
if (!info || !info[0])
115115
return 0;
116116

117-
nla = nla_nest_start(skb, DRBD_NLA_CFG_REPLY);
117+
nla = nla_nest_start_noflag(skb, DRBD_NLA_CFG_REPLY);
118118
if (!nla)
119119
return err;
120120

@@ -135,7 +135,7 @@ static int drbd_msg_sprintf_info(struct sk_buff *skb, const char *fmt, ...)
135135
int err = -EMSGSIZE;
136136
int len;
137137

138-
nla = nla_nest_start(skb, DRBD_NLA_CFG_REPLY);
138+
nla = nla_nest_start_noflag(skb, DRBD_NLA_CFG_REPLY);
139139
if (!nla)
140140
return err;
141141

@@ -3269,7 +3269,7 @@ static int nla_put_drbd_cfg_context(struct sk_buff *skb,
32693269
struct drbd_device *device)
32703270
{
32713271
struct nlattr *nla;
3272-
nla = nla_nest_start(skb, DRBD_NLA_CFG_CONTEXT);
3272+
nla = nla_nest_start_noflag(skb, DRBD_NLA_CFG_CONTEXT);
32733273
if (!nla)
32743274
goto nla_put_failure;
32753275
if (device &&
@@ -3837,7 +3837,7 @@ static int nla_put_status_info(struct sk_buff *skb, struct drbd_device *device,
38373837
if (err)
38383838
goto nla_put_failure;
38393839

3840-
nla = nla_nest_start(skb, DRBD_NLA_STATE_INFO);
3840+
nla = nla_nest_start_noflag(skb, DRBD_NLA_STATE_INFO);
38413841
if (!nla)
38423842
goto nla_put_failure;
38433843
if (nla_put_u32(skb, T_sib_reason, sib ? sib->sib_reason : SIB_GET_STATUS_REPLY) ||

drivers/block/nbd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,7 +2047,7 @@ static int populate_nbd_status(struct nbd_device *nbd, struct sk_buff *reply)
20472047
*/
20482048
if (refcount_read(&nbd->config_refs))
20492049
connected = 1;
2050-
dev_opt = nla_nest_start(reply, NBD_DEVICE_ITEM);
2050+
dev_opt = nla_nest_start_noflag(reply, NBD_DEVICE_ITEM);
20512051
if (!dev_opt)
20522052
return -EMSGSIZE;
20532053
ret = nla_put_u32(reply, NBD_DEVICE_INDEX, nbd->index);
@@ -2095,7 +2095,7 @@ static int nbd_genl_status(struct sk_buff *skb, struct genl_info *info)
20952095
goto out;
20962096
}
20972097

2098-
dev_list = nla_nest_start(reply, NBD_ATTR_DEVICE_LIST);
2098+
dev_list = nla_nest_start_noflag(reply, NBD_ATTR_DEVICE_LIST);
20992099
if (index == -1) {
21002100
ret = idr_for_each(&nbd_index_idr, &status_cb, reply);
21012101
if (ret) {

drivers/infiniband/core/nldev.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@ static int fill_res_info_entry(struct sk_buff *msg,
292292
{
293293
struct nlattr *entry_attr;
294294

295-
entry_attr = nla_nest_start(msg, RDMA_NLDEV_ATTR_RES_SUMMARY_ENTRY);
295+
entry_attr = nla_nest_start_noflag(msg,
296+
RDMA_NLDEV_ATTR_RES_SUMMARY_ENTRY);
296297
if (!entry_attr)
297298
return -EMSGSIZE;
298299

@@ -327,7 +328,7 @@ static int fill_res_info(struct sk_buff *msg, struct ib_device *device)
327328
if (fill_nldev_handle(msg, device))
328329
return -EMSGSIZE;
329330

330-
table_attr = nla_nest_start(msg, RDMA_NLDEV_ATTR_RES_SUMMARY);
331+
table_attr = nla_nest_start_noflag(msg, RDMA_NLDEV_ATTR_RES_SUMMARY);
331332
if (!table_attr)
332333
return -EMSGSIZE;
333334

@@ -1108,7 +1109,7 @@ static int res_get_common_dumpit(struct sk_buff *skb,
11081109
goto err;
11091110
}
11101111

1111-
table_attr = nla_nest_start(skb, fe->nldev_attr);
1112+
table_attr = nla_nest_start_noflag(skb, fe->nldev_attr);
11121113
if (!table_attr) {
11131114
ret = -EMSGSIZE;
11141115
goto err;
@@ -1134,7 +1135,7 @@ static int res_get_common_dumpit(struct sk_buff *skb,
11341135

11351136
filled = true;
11361137

1137-
entry_attr = nla_nest_start(skb, fe->entry);
1138+
entry_attr = nla_nest_start_noflag(skb, fe->entry);
11381139
if (!entry_attr) {
11391140
ret = -EMSGSIZE;
11401141
rdma_restrack_put(res);

drivers/infiniband/hw/cxgb4/restrack.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ static int fill_res_qp_entry(struct sk_buff *msg,
149149
if (qhp->ucontext)
150150
return 0;
151151

152-
table_attr = nla_nest_start(msg, RDMA_NLDEV_ATTR_DRIVER);
152+
table_attr = nla_nest_start_noflag(msg, RDMA_NLDEV_ATTR_DRIVER);
153153
if (!table_attr)
154154
goto err;
155155

@@ -216,7 +216,7 @@ static int fill_res_ep_entry(struct sk_buff *msg,
216216
if (!uep)
217217
return 0;
218218

219-
table_attr = nla_nest_start(msg, RDMA_NLDEV_ATTR_DRIVER);
219+
table_attr = nla_nest_start_noflag(msg, RDMA_NLDEV_ATTR_DRIVER);
220220
if (!table_attr)
221221
goto err_free_uep;
222222

@@ -387,7 +387,7 @@ static int fill_res_cq_entry(struct sk_buff *msg,
387387
if (ibcq->uobject)
388388
return 0;
389389

390-
table_attr = nla_nest_start(msg, RDMA_NLDEV_ATTR_DRIVER);
390+
table_attr = nla_nest_start_noflag(msg, RDMA_NLDEV_ATTR_DRIVER);
391391
if (!table_attr)
392392
goto err;
393393

@@ -447,7 +447,7 @@ static int fill_res_mr_entry(struct sk_buff *msg,
447447
if (!stag)
448448
return 0;
449449

450-
table_attr = nla_nest_start(msg, RDMA_NLDEV_ATTR_DRIVER);
450+
table_attr = nla_nest_start_noflag(msg, RDMA_NLDEV_ATTR_DRIVER);
451451
if (!table_attr)
452452
goto err;
453453

drivers/net/bonding/bond_netlink.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ static int bond_fill_info(struct sk_buff *skb,
546546
if (nla_put_u32(skb, IFLA_BOND_ARP_INTERVAL, bond->params.arp_interval))
547547
goto nla_put_failure;
548548

549-
targets = nla_nest_start(skb, IFLA_BOND_ARP_IP_TARGET);
549+
targets = nla_nest_start_noflag(skb, IFLA_BOND_ARP_IP_TARGET);
550550
if (!targets)
551551
goto nla_put_failure;
552552

@@ -644,7 +644,7 @@ static int bond_fill_info(struct sk_buff *skb,
644644
if (!bond_3ad_get_active_agg_info(bond, &info)) {
645645
struct nlattr *nest;
646646

647-
nest = nla_nest_start(skb, IFLA_BOND_AD_INFO);
647+
nest = nla_nest_start_noflag(skb, IFLA_BOND_AD_INFO);
648648
if (!nest)
649649
goto nla_put_failure;
650650

@@ -711,7 +711,7 @@ static int bond_fill_linkxstats(struct sk_buff *skb,
711711
return -EINVAL;
712712
}
713713

714-
nest = nla_nest_start(skb, LINK_XSTATS_TYPE_BOND);
714+
nest = nla_nest_start_noflag(skb, LINK_XSTATS_TYPE_BOND);
715715
if (!nest)
716716
return -EMSGSIZE;
717717
if (BOND_MODE(bond) == BOND_MODE_8023AD) {
@@ -722,7 +722,7 @@ static int bond_fill_linkxstats(struct sk_buff *skb,
722722
else
723723
stats = &BOND_AD_INFO(bond).stats;
724724

725-
nest2 = nla_nest_start(skb, BOND_XSTATS_3AD);
725+
nest2 = nla_nest_start_noflag(skb, BOND_XSTATS_3AD);
726726
if (!nest2) {
727727
nla_nest_end(skb, nest);
728728
return -EMSGSIZE;

drivers/net/ieee802154/mac802154_hwsim.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,16 @@ static int append_radio_msg(struct sk_buff *skb, struct hwsim_phy *phy)
227227
return 0;
228228
}
229229

230-
nl_edges = nla_nest_start(skb, MAC802154_HWSIM_ATTR_RADIO_EDGES);
230+
nl_edges = nla_nest_start_noflag(skb,
231+
MAC802154_HWSIM_ATTR_RADIO_EDGES);
231232
if (!nl_edges) {
232233
rcu_read_unlock();
233234
return -ENOBUFS;
234235
}
235236

236237
list_for_each_entry_rcu(e, &phy->edges, list) {
237-
nl_edge = nla_nest_start(skb, MAC802154_HWSIM_ATTR_RADIO_EDGE);
238+
nl_edge = nla_nest_start_noflag(skb,
239+
MAC802154_HWSIM_ATTR_RADIO_EDGE);
238240
if (!nl_edge) {
239241
rcu_read_unlock();
240242
nla_nest_cancel(skb, nl_edges);

drivers/net/macsec.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2365,7 +2365,8 @@ copy_secy_stats(struct sk_buff *skb, struct pcpu_secy_stats __percpu *pstats)
23652365
static int nla_put_secy(struct macsec_secy *secy, struct sk_buff *skb)
23662366
{
23672367
struct macsec_tx_sc *tx_sc = &secy->tx_sc;
2368-
struct nlattr *secy_nest = nla_nest_start(skb, MACSEC_ATTR_SECY);
2368+
struct nlattr *secy_nest = nla_nest_start_noflag(skb,
2369+
MACSEC_ATTR_SECY);
23692370
u64 csid;
23702371

23712372
if (!secy_nest)
@@ -2435,7 +2436,7 @@ dump_secy(struct macsec_secy *secy, struct net_device *dev,
24352436
if (nla_put_secy(secy, skb))
24362437
goto nla_put_failure;
24372438

2438-
attr = nla_nest_start(skb, MACSEC_ATTR_TXSC_STATS);
2439+
attr = nla_nest_start_noflag(skb, MACSEC_ATTR_TXSC_STATS);
24392440
if (!attr)
24402441
goto nla_put_failure;
24412442
if (copy_tx_sc_stats(skb, tx_sc->stats)) {
@@ -2444,7 +2445,7 @@ dump_secy(struct macsec_secy *secy, struct net_device *dev,
24442445
}
24452446
nla_nest_end(skb, attr);
24462447

2447-
attr = nla_nest_start(skb, MACSEC_ATTR_SECY_STATS);
2448+
attr = nla_nest_start_noflag(skb, MACSEC_ATTR_SECY_STATS);
24482449
if (!attr)
24492450
goto nla_put_failure;
24502451
if (copy_secy_stats(skb, macsec_priv(dev)->stats)) {
@@ -2453,7 +2454,7 @@ dump_secy(struct macsec_secy *secy, struct net_device *dev,
24532454
}
24542455
nla_nest_end(skb, attr);
24552456

2456-
txsa_list = nla_nest_start(skb, MACSEC_ATTR_TXSA_LIST);
2457+
txsa_list = nla_nest_start_noflag(skb, MACSEC_ATTR_TXSA_LIST);
24572458
if (!txsa_list)
24582459
goto nla_put_failure;
24592460
for (i = 0, j = 1; i < MACSEC_NUM_AN; i++) {
@@ -2463,7 +2464,7 @@ dump_secy(struct macsec_secy *secy, struct net_device *dev,
24632464
if (!tx_sa)
24642465
continue;
24652466

2466-
txsa_nest = nla_nest_start(skb, j++);
2467+
txsa_nest = nla_nest_start_noflag(skb, j++);
24672468
if (!txsa_nest) {
24682469
nla_nest_cancel(skb, txsa_list);
24692470
goto nla_put_failure;
@@ -2478,7 +2479,7 @@ dump_secy(struct macsec_secy *secy, struct net_device *dev,
24782479
goto nla_put_failure;
24792480
}
24802481

2481-
attr = nla_nest_start(skb, MACSEC_SA_ATTR_STATS);
2482+
attr = nla_nest_start_noflag(skb, MACSEC_SA_ATTR_STATS);
24822483
if (!attr) {
24832484
nla_nest_cancel(skb, txsa_nest);
24842485
nla_nest_cancel(skb, txsa_list);
@@ -2496,15 +2497,15 @@ dump_secy(struct macsec_secy *secy, struct net_device *dev,
24962497
}
24972498
nla_nest_end(skb, txsa_list);
24982499

2499-
rxsc_list = nla_nest_start(skb, MACSEC_ATTR_RXSC_LIST);
2500+
rxsc_list = nla_nest_start_noflag(skb, MACSEC_ATTR_RXSC_LIST);
25002501
if (!rxsc_list)
25012502
goto nla_put_failure;
25022503

25032504
j = 1;
25042505
for_each_rxsc_rtnl(secy, rx_sc) {
25052506
int k;
25062507
struct nlattr *rxsa_list;
2507-
struct nlattr *rxsc_nest = nla_nest_start(skb, j++);
2508+
struct nlattr *rxsc_nest = nla_nest_start_noflag(skb, j++);
25082509

25092510
if (!rxsc_nest) {
25102511
nla_nest_cancel(skb, rxsc_list);
@@ -2519,7 +2520,7 @@ dump_secy(struct macsec_secy *secy, struct net_device *dev,
25192520
goto nla_put_failure;
25202521
}
25212522

2522-
attr = nla_nest_start(skb, MACSEC_RXSC_ATTR_STATS);
2523+
attr = nla_nest_start_noflag(skb, MACSEC_RXSC_ATTR_STATS);
25232524
if (!attr) {
25242525
nla_nest_cancel(skb, rxsc_nest);
25252526
nla_nest_cancel(skb, rxsc_list);
@@ -2533,7 +2534,8 @@ dump_secy(struct macsec_secy *secy, struct net_device *dev,
25332534
}
25342535
nla_nest_end(skb, attr);
25352536

2536-
rxsa_list = nla_nest_start(skb, MACSEC_RXSC_ATTR_SA_LIST);
2537+
rxsa_list = nla_nest_start_noflag(skb,
2538+
MACSEC_RXSC_ATTR_SA_LIST);
25372539
if (!rxsa_list) {
25382540
nla_nest_cancel(skb, rxsc_nest);
25392541
nla_nest_cancel(skb, rxsc_list);
@@ -2547,15 +2549,16 @@ dump_secy(struct macsec_secy *secy, struct net_device *dev,
25472549
if (!rx_sa)
25482550
continue;
25492551

2550-
rxsa_nest = nla_nest_start(skb, k++);
2552+
rxsa_nest = nla_nest_start_noflag(skb, k++);
25512553
if (!rxsa_nest) {
25522554
nla_nest_cancel(skb, rxsa_list);
25532555
nla_nest_cancel(skb, rxsc_nest);
25542556
nla_nest_cancel(skb, rxsc_list);
25552557
goto nla_put_failure;
25562558
}
25572559

2558-
attr = nla_nest_start(skb, MACSEC_SA_ATTR_STATS);
2560+
attr = nla_nest_start_noflag(skb,
2561+
MACSEC_SA_ATTR_STATS);
25592562
if (!attr) {
25602563
nla_nest_cancel(skb, rxsa_list);
25612564
nla_nest_cancel(skb, rxsc_nest);

drivers/net/macvlan.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1624,7 +1624,7 @@ static int macvlan_fill_info(struct sk_buff *skb,
16241624
if (nla_put_u32(skb, IFLA_MACVLAN_MACADDR_COUNT, vlan->macaddr_count))
16251625
goto nla_put_failure;
16261626
if (vlan->macaddr_count > 0) {
1627-
nest = nla_nest_start(skb, IFLA_MACVLAN_MACADDR_DATA);
1627+
nest = nla_nest_start_noflag(skb, IFLA_MACVLAN_MACADDR_DATA);
16281628
if (nest == NULL)
16291629
goto nla_put_failure;
16301630

drivers/net/team/team.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,7 +2290,7 @@ static int team_nl_fill_one_option_get(struct sk_buff *skb, struct team *team,
22902290
if (err)
22912291
return err;
22922292

2293-
option_item = nla_nest_start(skb, TEAM_ATTR_ITEM_OPTION);
2293+
option_item = nla_nest_start_noflag(skb, TEAM_ATTR_ITEM_OPTION);
22942294
if (!option_item)
22952295
return -EMSGSIZE;
22962296

@@ -2404,7 +2404,7 @@ static int team_nl_send_options_get(struct team *team, u32 portid, u32 seq,
24042404

24052405
if (nla_put_u32(skb, TEAM_ATTR_TEAM_IFINDEX, team->dev->ifindex))
24062406
goto nla_put_failure;
2407-
option_list = nla_nest_start(skb, TEAM_ATTR_LIST_OPTION);
2407+
option_list = nla_nest_start_noflag(skb, TEAM_ATTR_LIST_OPTION);
24082408
if (!option_list)
24092409
goto nla_put_failure;
24102410

@@ -2626,7 +2626,7 @@ static int team_nl_fill_one_port_get(struct sk_buff *skb,
26262626
{
26272627
struct nlattr *port_item;
26282628

2629-
port_item = nla_nest_start(skb, TEAM_ATTR_ITEM_PORT);
2629+
port_item = nla_nest_start_noflag(skb, TEAM_ATTR_ITEM_PORT);
26302630
if (!port_item)
26312631
goto nest_cancel;
26322632
if (nla_put_u32(skb, TEAM_ATTR_PORT_IFINDEX, port->dev->ifindex))
@@ -2681,7 +2681,7 @@ static int team_nl_send_port_list_get(struct team *team, u32 portid, u32 seq,
26812681

26822682
if (nla_put_u32(skb, TEAM_ATTR_TEAM_IFINDEX, team->dev->ifindex))
26832683
goto nla_put_failure;
2684-
port_list = nla_nest_start(skb, TEAM_ATTR_LIST_PORT);
2684+
port_list = nla_nest_start_noflag(skb, TEAM_ATTR_LIST_PORT);
26852685
if (!port_list)
26862686
goto nla_put_failure;
26872687

drivers/net/wireless/ath/wil6210/cfg80211.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2679,13 +2679,13 @@ static int wil_rf_sector_get_cfg(struct wiphy *wiphy,
26792679
QCA_ATTR_PAD))
26802680
goto nla_put_failure;
26812681

2682-
nl_cfgs = nla_nest_start(msg, QCA_ATTR_DMG_RF_SECTOR_CFG);
2682+
nl_cfgs = nla_nest_start_noflag(msg, QCA_ATTR_DMG_RF_SECTOR_CFG);
26832683
if (!nl_cfgs)
26842684
goto nla_put_failure;
26852685
for (i = 0; i < WMI_MAX_RF_MODULES_NUM; i++) {
26862686
if (!(rf_modules_vec & BIT(i)))
26872687
continue;
2688-
nl_cfg = nla_nest_start(msg, i);
2688+
nl_cfg = nla_nest_start_noflag(msg, i);
26892689
if (!nl_cfg)
26902690
goto nla_put_failure;
26912691
si = &reply.evt.sectors_info[i];

include/linux/netfilter/ipset/ip_set.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -401,33 +401,30 @@ ip_set_get_h16(const struct nlattr *attr)
401401
return ntohs(nla_get_be16(attr));
402402
}
403403

404-
#define ipset_nest_start(skb, attr) nla_nest_start(skb, attr | NLA_F_NESTED)
405-
#define ipset_nest_end(skb, start) nla_nest_end(skb, start)
406-
407404
static inline int nla_put_ipaddr4(struct sk_buff *skb, int type, __be32 ipaddr)
408405
{
409-
struct nlattr *__nested = ipset_nest_start(skb, type);
406+
struct nlattr *__nested = nla_nest_start(skb, type);
410407
int ret;
411408

412409
if (!__nested)
413410
return -EMSGSIZE;
414411
ret = nla_put_in_addr(skb, IPSET_ATTR_IPADDR_IPV4, ipaddr);
415412
if (!ret)
416-
ipset_nest_end(skb, __nested);
413+
nla_nest_end(skb, __nested);
417414
return ret;
418415
}
419416

420417
static inline int nla_put_ipaddr6(struct sk_buff *skb, int type,
421418
const struct in6_addr *ipaddrptr)
422419
{
423-
struct nlattr *__nested = ipset_nest_start(skb, type);
420+
struct nlattr *__nested = nla_nest_start(skb, type);
424421
int ret;
425422

426423
if (!__nested)
427424
return -EMSGSIZE;
428425
ret = nla_put_in6_addr(skb, IPSET_ATTR_IPADDR_IPV6, ipaddrptr);
429426
if (!ret)
430-
ipset_nest_end(skb, __nested);
427+
nla_nest_end(skb, __nested);
431428
return ret;
432429
}
433430

0 commit comments

Comments
 (0)