Skip to content

Commit a07ea4d

Browse files
jmberg-inteldavem330
authored andcommitted
genetlink: no longer support using static family IDs
Static family IDs have never really been used, the only use case was the workaround I introduced for those users that assumed their family ID was also their multicast group ID. Additionally, because static family IDs would never be reserved by the generic netlink code, using a relatively low ID would only work for built-in families that can be registered immediately after generic netlink is started, which is basically only the control family (apart from the workaround code, which I also had to add code for so it would reserve those IDs) Thus, anything other than GENL_ID_GENERATE is flawed and luckily not used except in the cases I mentioned. Move those workarounds into a few lines of code, and then get rid of GENL_ID_GENERATE entirely, making it more robust. Signed-off-by: Johannes Berg <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c90c39d commit a07ea4d

File tree

37 files changed

+24
-69
lines changed

37 files changed

+24
-69
lines changed

drivers/acpi/event.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ static const struct genl_multicast_group acpi_event_mcgrps[] = {
8383
};
8484

8585
static struct genl_family acpi_event_genl_family = {
86-
.id = GENL_ID_GENERATE,
8786
.name = ACPI_GENL_FAMILY_NAME,
8887
.version = ACPI_GENL_VERSION,
8988
.maxattr = ACPI_GENL_ATTR_MAX,

drivers/net/gtp.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,6 @@ static int gtp_genl_del_pdp(struct sk_buff *skb, struct genl_info *info)
10951095
}
10961096

10971097
static struct genl_family gtp_genl_family = {
1098-
.id = GENL_ID_GENERATE,
10991098
.name = "gtp",
11001099
.version = 0,
11011100
.hdrsize = 0,

drivers/net/macsec.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,6 @@ static void clear_tx_sa(struct macsec_tx_sa *tx_sa)
14221422
}
14231423

14241424
static struct genl_family macsec_fam = {
1425-
.id = GENL_ID_GENERATE,
14261425
.name = MACSEC_GENL_NAME,
14271426
.hdrsize = 0,
14281427
.version = MACSEC_GENL_VERSION,

drivers/net/team/team.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2151,7 +2151,6 @@ static struct rtnl_link_ops team_link_ops __read_mostly = {
21512151
***********************************/
21522152

21532153
static struct genl_family team_nl_family = {
2154-
.id = GENL_ID_GENERATE,
21552154
.name = TEAM_GENL_NAME,
21562155
.version = TEAM_GENL_VERSION,
21572156
.maxattr = TEAM_ATTR_MAX,

drivers/net/wireless/mac80211_hwsim.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,6 @@ struct hwsim_radiotap_ack_hdr {
589589

590590
/* MAC80211_HWSIM netlinf family */
591591
static struct genl_family hwsim_genl_family = {
592-
.id = GENL_ID_GENERATE,
593592
.hdrsize = 0,
594593
.name = "MAC80211_HWSIM",
595594
.version = 1,

drivers/scsi/pmcraid.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,12 +1369,6 @@ static struct genl_multicast_group pmcraid_mcgrps[] = {
13691369
};
13701370

13711371
static struct genl_family pmcraid_event_family = {
1372-
/*
1373-
* Due to prior multicast group abuse (the code having assumed that
1374-
* the family ID can be used as a multicast group ID) we need to
1375-
* statically allocate a family (and thus group) ID.
1376-
*/
1377-
.id = GENL_ID_PMCRAID,
13781372
.name = "pmcraid",
13791373
.version = 1,
13801374
.maxattr = PMCRAID_AEN_ATTR_MAX,

drivers/target/target_core_user.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ static const struct genl_multicast_group tcmu_mcgrps[] = {
148148

149149
/* Our generic netlink family */
150150
static struct genl_family tcmu_genl_family = {
151-
.id = GENL_ID_GENERATE,
152151
.hdrsize = 0,
153152
.name = "TCM-USER",
154153
.version = 1,

drivers/thermal/thermal_core.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2164,7 +2164,6 @@ static const struct genl_multicast_group thermal_event_mcgrps[] = {
21642164
};
21652165

21662166
static struct genl_family thermal_event_genl_family = {
2167-
.id = GENL_ID_GENERATE,
21682167
.name = THERMAL_GENL_FAMILY_NAME,
21692168
.version = THERMAL_GENL_VERSION,
21702169
.maxattr = THERMAL_GENL_ATTR_MAX,

fs/dlm/netlink.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ static uint32_t dlm_nl_seqnum;
1717
static uint32_t listener_nlportid;
1818

1919
static struct genl_family family = {
20-
.id = GENL_ID_GENERATE,
2120
.name = DLM_GENL_NAME,
2221
.version = DLM_GENL_VERSION,
2322
};

fs/quota/netlink.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@ static const struct genl_multicast_group quota_mcgrps[] = {
1313

1414
/* Netlink family structure for quota */
1515
static struct genl_family quota_genl_family = {
16-
/*
17-
* Needed due to multicast group ID abuse - old code assumed
18-
* the family ID was also a valid multicast group ID (which
19-
* isn't true) and userspace might thus rely on it. Assign a
20-
* static ID for this group to make dealing with that easier.
21-
*/
22-
.id = GENL_ID_VFS_DQUOT,
2316
.hdrsize = 0,
2417
.name = "VFS_DQUOT",
2518
.version = 1,

include/linux/genl_magic_func.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
260260
*/
261261
#define ZZZ_genl_family CONCAT_(GENL_MAGIC_FAMILY, _genl_family)
262262
static struct genl_family ZZZ_genl_family __read_mostly = {
263-
.id = GENL_ID_GENERATE,
264263
.name = __stringify(GENL_MAGIC_FAMILY),
265264
.version = GENL_MAGIC_VERSION,
266265
#ifdef GENL_MAGIC_FAMILY_HDRSZ

include/net/genetlink.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct genl_info;
2020

2121
/**
2222
* struct genl_family - generic netlink family
23-
* @id: protocol family idenfitier
23+
* @id: protocol family identifier (private)
2424
* @hdrsize: length of user specific header in bytes
2525
* @name: name of family
2626
* @version: protocol version
@@ -48,7 +48,7 @@ struct genl_info;
4848
* @n_ops: number of operations supported by this family (private)
4949
*/
5050
struct genl_family {
51-
unsigned int id;
51+
unsigned int id; /* private */
5252
unsigned int hdrsize;
5353
char name[GENL_NAMSIZ];
5454
unsigned int version;
@@ -149,9 +149,6 @@ static inline int genl_register_family(struct genl_family *family)
149149
* Registers the specified family and operations from the specified table.
150150
* Only one family may be registered with the same family name or identifier.
151151
*
152-
* The family id may equal GENL_ID_GENERATE causing an unique id to
153-
* be automatically generated and assigned.
154-
*
155152
* Either a doit or dumpit callback must be specified for every registered
156153
* operation or the function will fail. Only one operation structure per
157154
* command identifier may be registered.

include/uapi/linux/genetlink.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ struct genlmsghdr {
2626
/*
2727
* List of reserved static generic netlink identifiers:
2828
*/
29-
#define GENL_ID_GENERATE 0
3029
#define GENL_ID_CTRL NLMSG_MIN_TYPE
3130
#define GENL_ID_VFS_DQUOT (NLMSG_MIN_TYPE + 1)
3231
#define GENL_ID_PMCRAID (NLMSG_MIN_TYPE + 2)

kernel/taskstats.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ static int family_registered;
4242
struct kmem_cache *taskstats_cache;
4343

4444
static struct genl_family family = {
45-
.id = GENL_ID_GENERATE,
4645
.name = TASKSTATS_GENL_NAME,
4746
.version = TASKSTATS_GENL_VERSION,
4847
.maxattr = TASKSTATS_CMD_ATTR_MAX,

net/batman-adv/netlink.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
#include "translation-table.h"
5050

5151
struct genl_family batadv_netlink_family = {
52-
.id = GENL_ID_GENERATE,
5352
.hdrsize = 0,
5453
.name = BATADV_NL_NAME,
5554
.version = 1,

net/core/devlink.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,6 @@ static void devlink_nl_post_doit(const struct genl_ops *ops,
342342
}
343343

344344
static struct genl_family devlink_nl_family = {
345-
.id = GENL_ID_GENERATE,
346345
.name = DEVLINK_GENL_NAME,
347346
.version = DEVLINK_GENL_VERSION,
348347
.maxattr = DEVLINK_ATTR_MAX,

net/core/drop_monitor.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ struct dm_hw_stat_delta {
6060
};
6161

6262
static struct genl_family net_drop_monitor_family = {
63-
.id = GENL_ID_GENERATE,
6463
.hdrsize = 0,
6564
.name = "NET_DM",
6665
.version = 2,

net/hsr/hsr_netlink.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ static const struct nla_policy hsr_genl_policy[HSR_A_MAX + 1] = {
132132
};
133133

134134
static struct genl_family hsr_genl_family = {
135-
.id = GENL_ID_GENERATE,
136135
.hdrsize = 0,
137136
.name = "HSR",
138137
.version = 1,

net/ieee802154/netlink.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ static unsigned int ieee802154_seq_num;
2929
static DEFINE_SPINLOCK(ieee802154_seq_lock);
3030

3131
struct genl_family nl802154_family = {
32-
.id = GENL_ID_GENERATE,
3332
.hdrsize = 0,
3433
.name = IEEE802154_NL_NAME,
3534
.version = 1,

net/ieee802154/nl802154.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ static void nl802154_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
3434

3535
/* the netlink family */
3636
static struct genl_family nl802154_fam = {
37-
.id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
3837
.name = NL802154_GENL_NAME, /* have users key off the name instead */
3938
.hdrsize = 0, /* no private header */
4039
.version = 1, /* no particular meaning now */

net/ipv4/fou.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,6 @@ static int fou_destroy(struct net *net, struct fou_cfg *cfg)
623623
}
624624

625625
static struct genl_family fou_nl_family = {
626-
.id = GENL_ID_GENERATE,
627626
.hdrsize = 0,
628627
.name = FOU_GENL_NAME,
629628
.version = FOU_GENL_VERSION,

net/ipv4/tcp_metrics.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,6 @@ void tcp_fastopen_cache_set(struct sock *sk, u16 mss,
743743
}
744744

745745
static struct genl_family tcp_metrics_nl_family = {
746-
.id = GENL_ID_GENERATE,
747746
.hdrsize = 0,
748747
.name = TCP_METRICS_GENL_NAME,
749748
.version = TCP_METRICS_GENL_VERSION,

net/ipv6/ila/ila_xlat.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ static const struct rhashtable_params rht_params = {
119119
};
120120

121121
static struct genl_family ila_nl_family = {
122-
.id = GENL_ID_GENERATE,
123122
.hdrsize = 0,
124123
.name = ILA_GENL_NAME,
125124
.version = ILA_GENL_VERSION,

net/irda/irnetlink.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626

2727
static struct genl_family irda_nl_family = {
28-
.id = GENL_ID_GENERATE,
2928
.name = IRDA_NL_NAME,
3029
.hdrsize = 0,
3130
.version = IRDA_NL_VERSION,

net/l2tp/l2tp_netlink.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232

3333

3434
static struct genl_family l2tp_nl_family = {
35-
.id = GENL_ID_GENERATE,
3635
.name = L2TP_GENL_NAME,
3736
.version = L2TP_GENL_VERSION,
3837
.hdrsize = 0,

net/netfilter/ipvs/ip_vs_ctl.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2841,7 +2841,6 @@ static struct nf_sockopt_ops ip_vs_sockopts = {
28412841

28422842
/* IPVS genetlink family */
28432843
static struct genl_family ip_vs_genl_family = {
2844-
.id = GENL_ID_GENERATE,
28452844
.hdrsize = 0,
28462845
.name = IPVS_GENL_NAME,
28472846
.version = IPVS_GENL_VERSION,

net/netlabel/netlabel_calipso.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ struct netlbl_domhsh_walk_arg {
6161

6262
/* NetLabel Generic NETLINK CALIPSO family */
6363
static struct genl_family netlbl_calipso_gnl_family = {
64-
.id = GENL_ID_GENERATE,
6564
.hdrsize = 0,
6665
.name = NETLBL_NLTYPE_CALIPSO_NAME,
6766
.version = NETLBL_PROTO_VERSION,

net/netlabel/netlabel_cipso_v4.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ struct netlbl_domhsh_walk_arg {
6060

6161
/* NetLabel Generic NETLINK CIPSOv4 family */
6262
static struct genl_family netlbl_cipsov4_gnl_family = {
63-
.id = GENL_ID_GENERATE,
6463
.hdrsize = 0,
6564
.name = NETLBL_NLTYPE_CIPSOV4_NAME,
6665
.version = NETLBL_PROTO_VERSION,

net/netlabel/netlabel_mgmt.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ struct netlbl_domhsh_walk_arg {
6161

6262
/* NetLabel Generic NETLINK CIPSOv4 family */
6363
static struct genl_family netlbl_mgmt_gnl_family = {
64-
.id = GENL_ID_GENERATE,
6564
.hdrsize = 0,
6665
.name = NETLBL_NLTYPE_MGMT_NAME,
6766
.version = NETLBL_PROTO_VERSION,

net/netlabel/netlabel_unlabeled.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ static u8 netlabel_unlabel_acceptflg;
124124

125125
/* NetLabel Generic NETLINK unlabeled family */
126126
static struct genl_family netlbl_unlabel_gnl_family = {
127-
.id = GENL_ID_GENERATE,
128127
.hdrsize = 0,
129128
.name = NETLBL_NLTYPE_UNLABELED_NAME,
130129
.version = NETLBL_PROTO_VERSION,

net/netlink/genetlink.c

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,6 @@ static int genl_validate_ops(const struct genl_family *family)
349349
*
350350
* Registers the specified family after validating it first. Only one
351351
* family may be registered with the same family name or identifier.
352-
* The family id may equal GENL_ID_GENERATE causing an unique id to
353-
* be automatically generated and assigned.
354352
*
355353
* The family's ops array must already be assigned, you can use the
356354
* genl_register_family_with_ops() helper function.
@@ -359,13 +357,7 @@ static int genl_validate_ops(const struct genl_family *family)
359357
*/
360358
int __genl_register_family(struct genl_family *family)
361359
{
362-
int err = -EINVAL, i;
363-
364-
if (family->id && family->id < GENL_MIN_ID)
365-
goto errout;
366-
367-
if (family->id > GENL_MAX_ID)
368-
goto errout;
360+
int err, i;
369361

370362
err = genl_validate_ops(family);
371363
if (err)
@@ -378,18 +370,34 @@ int __genl_register_family(struct genl_family *family)
378370
goto errout_locked;
379371
}
380372

381-
if (family->id == GENL_ID_GENERATE) {
382-
u16 newid = genl_generate_id();
373+
if (family == &genl_ctrl) {
374+
family->id = GENL_ID_CTRL;
375+
} else {
376+
u16 newid;
377+
378+
/* this should be left zero in the struct */
379+
WARN_ON(family->id);
380+
381+
/*
382+
* Sadly, a few cases need to be special-cased
383+
* due to them having previously abused the API
384+
* and having used their family ID also as their
385+
* multicast group ID, so we use reserved IDs
386+
* for both to be sure we can do that mapping.
387+
*/
388+
if (strcmp(family->name, "pmcraid") == 0)
389+
newid = GENL_ID_PMCRAID;
390+
else if (strcmp(family->name, "VFS_DQUOT") == 0)
391+
newid = GENL_ID_VFS_DQUOT;
392+
else
393+
newid = genl_generate_id();
383394

384395
if (!newid) {
385396
err = -ENOMEM;
386397
goto errout_locked;
387398
}
388399

389400
family->id = newid;
390-
} else if (genl_family_find_byid(family->id)) {
391-
err = -EEXIST;
392-
goto errout_locked;
393401
}
394402

395403
if (family->maxattr && !family->parallel_ops) {
@@ -419,7 +427,6 @@ int __genl_register_family(struct genl_family *family)
419427

420428
errout_locked:
421429
genl_unlock_all();
422-
errout:
423430
return err;
424431
}
425432
EXPORT_SYMBOL(__genl_register_family);

net/nfc/netlink.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ static const struct genl_multicast_group nfc_genl_mcgrps[] = {
3939
};
4040

4141
static struct genl_family nfc_genl_family = {
42-
.id = GENL_ID_GENERATE,
4342
.hdrsize = 0,
4443
.name = NFC_GENL_NAME,
4544
.version = NFC_GENL_VERSION,

net/openvswitch/datapath.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,6 @@ static const struct genl_ops dp_packet_genl_ops[] = {
671671
};
672672

673673
static struct genl_family dp_packet_genl_family = {
674-
.id = GENL_ID_GENERATE,
675674
.hdrsize = sizeof(struct ovs_header),
676675
.name = OVS_PACKET_FAMILY,
677676
.version = OVS_PACKET_VERSION,
@@ -1436,7 +1435,6 @@ static const struct genl_ops dp_flow_genl_ops[] = {
14361435
};
14371436

14381437
static struct genl_family dp_flow_genl_family = {
1439-
.id = GENL_ID_GENERATE,
14401438
.hdrsize = sizeof(struct ovs_header),
14411439
.name = OVS_FLOW_FAMILY,
14421440
.version = OVS_FLOW_VERSION,
@@ -1822,7 +1820,6 @@ static const struct genl_ops dp_datapath_genl_ops[] = {
18221820
};
18231821

18241822
static struct genl_family dp_datapath_genl_family = {
1825-
.id = GENL_ID_GENERATE,
18261823
.hdrsize = sizeof(struct ovs_header),
18271824
.name = OVS_DATAPATH_FAMILY,
18281825
.version = OVS_DATAPATH_VERSION,
@@ -2244,7 +2241,6 @@ static const struct genl_ops dp_vport_genl_ops[] = {
22442241
};
22452242

22462243
struct genl_family dp_vport_genl_family = {
2247-
.id = GENL_ID_GENERATE,
22482244
.hdrsize = sizeof(struct ovs_header),
22492245
.name = OVS_VPORT_FAMILY,
22502246
.version = OVS_VPORT_VERSION,

net/tipc/netlink.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ const struct nla_policy tipc_nl_udp_policy[TIPC_NLA_UDP_MAX + 1] = {
136136
* so we have a separate genl handling for the new API.
137137
*/
138138
struct genl_family tipc_genl_family = {
139-
.id = GENL_ID_GENERATE,
140139
.name = TIPC_GENL_V2_NAME,
141140
.version = TIPC_GENL_V2_VERSION,
142141
.hdrsize = 0,

net/tipc/netlink_compat.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,6 @@ static int tipc_nl_compat_recv(struct sk_buff *skb, struct genl_info *info)
12161216
}
12171217

12181218
static struct genl_family tipc_genl_compat_family = {
1219-
.id = GENL_ID_GENERATE,
12201219
.name = TIPC_GENL_NAME,
12211220
.version = TIPC_GENL_VERSION,
12221221
.hdrsize = TIPC_GENL_HDRLEN,

0 commit comments

Comments
 (0)