Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0fb6af70 authored by David S. Miller's avatar David S. Miller
Browse files

Merge branch 'genetlink-improvements'



Johannes Berg says:

====================
genetlink improvements

This series contains some generic netlink improvements, making
the API safer to use, and making the function pointers in the
family struct safer by allowing it to be __ro_after_init.

The first patch, introducing genl_family_attrbuf(), just ensures
that the users of family->attrbuf aren't actually racy, but making
them use the indirection function for obtaining a reference and
checking that the context can actually do so.

The second patch removes the more or less broken ability to have
a static family ID, the three IDs that need to be static because
it's simply needed (genl controller), or due to old API misused.
Everything else couldn't be static anyway, or could fail when the
family is registered, if somebody else already got a static ID.

The third patch statically initializes the families, mostly to save
some code. I wrote this initially because I thought I could make
them all const, but that ends up being very inefficient (it would
require always doing some kind of family -> id lookup), so now it's
just here because I had it already and it reduces the code size.

The fourth patch then, finally, lays the groundwork for what I had
really wanted - now with __ro_after_init instead of const; I remove
code there to do the ID->family hash table mapping in genetlink and
use IDR instead to both allocate and map the IDs, which again ends
up saving some code size.

Finally, the fifth patch updates all families, as it turns out, no
families exist that really dynamically register/unregister. This
last patch should perhaps be split up, I could submit it for each
subsystem separately, but it'd depend on the second and third to
go in first, so would take a while. I can do that though, if that
seems better to you.
====================

Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 4fe77d82 56989f6d
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -82,8 +82,8 @@ static const struct genl_multicast_group acpi_event_mcgrps[] = {
	{ .name = ACPI_GENL_MCAST_GROUP_NAME, },
};

static struct genl_family acpi_event_genl_family = {
	.id = GENL_ID_GENERATE,
static struct genl_family acpi_event_genl_family __ro_after_init = {
	.module = THIS_MODULE,
	.name = ACPI_GENL_FAMILY_NAME,
	.version = ACPI_GENL_VERSION,
	.maxattr = ACPI_GENL_ATTR_MAX,
@@ -144,7 +144,7 @@ int acpi_bus_generate_netlink_event(const char *device_class,

EXPORT_SYMBOL(acpi_bus_generate_netlink_event);

static int acpi_event_genetlink_init(void)
static int __init acpi_event_genetlink_init(void)
{
	return genl_register_family(&acpi_event_genl_family);
}
+13 −9
Original line number Diff line number Diff line
@@ -1094,14 +1094,7 @@ static int gtp_genl_del_pdp(struct sk_buff *skb, struct genl_info *info)
	return 0;
}

static struct genl_family gtp_genl_family = {
	.id		= GENL_ID_GENERATE,
	.name		= "gtp",
	.version	= 0,
	.hdrsize	= 0,
	.maxattr	= GTPA_MAX,
	.netnsok	= true,
};
static struct genl_family gtp_genl_family;

static int gtp_genl_fill_info(struct sk_buff *skb, u32 snd_portid, u32 snd_seq,
			      u32 type, struct pdp_ctx *pctx)
@@ -1297,6 +1290,17 @@ static const struct genl_ops gtp_genl_ops[] = {
	},
};

static struct genl_family gtp_genl_family __ro_after_init = {
	.name		= "gtp",
	.version	= 0,
	.hdrsize	= 0,
	.maxattr	= GTPA_MAX,
	.netnsok	= true,
	.module		= THIS_MODULE,
	.ops		= gtp_genl_ops,
	.n_ops		= ARRAY_SIZE(gtp_genl_ops),
};

static int __net_init gtp_net_init(struct net *net)
{
	struct gtp_net *gn = net_generic(net, gtp_net_id);
@@ -1336,7 +1340,7 @@ static int __init gtp_init(void)
	if (err < 0)
		goto error_out;

	err = genl_register_family_with_ops(&gtp_genl_family, gtp_genl_ops);
	err = genl_register_family(&gtp_genl_family);
	if (err < 0)
		goto unreg_rtnl_link;

+13 −9
Original line number Diff line number Diff line
@@ -1421,14 +1421,7 @@ static void clear_tx_sa(struct macsec_tx_sa *tx_sa)
	macsec_txsa_put(tx_sa);
}

static struct genl_family macsec_fam = {
	.id		= GENL_ID_GENERATE,
	.name		= MACSEC_GENL_NAME,
	.hdrsize	= 0,
	.version	= MACSEC_GENL_VERSION,
	.maxattr	= MACSEC_ATTR_MAX,
	.netnsok	= true,
};
static struct genl_family macsec_fam;

static struct net_device *get_dev_from_nl(struct net *net,
					  struct nlattr **attrs)
@@ -2655,6 +2648,17 @@ static const struct genl_ops macsec_genl_ops[] = {
	},
};

static struct genl_family macsec_fam __ro_after_init = {
	.name		= MACSEC_GENL_NAME,
	.hdrsize	= 0,
	.version	= MACSEC_GENL_VERSION,
	.maxattr	= MACSEC_ATTR_MAX,
	.netnsok	= true,
	.module		= THIS_MODULE,
	.ops		= macsec_genl_ops,
	.n_ops		= ARRAY_SIZE(macsec_genl_ops),
};

static netdev_tx_t macsec_start_xmit(struct sk_buff *skb,
				     struct net_device *dev)
{
@@ -3462,7 +3466,7 @@ static int __init macsec_init(void)
	if (err)
		goto notifier;

	err = genl_register_family_with_ops(&macsec_fam, macsec_genl_ops);
	err = genl_register_family(&macsec_fam);
	if (err)
		goto rtnl;

+15 −10
Original line number Diff line number Diff line
@@ -2150,13 +2150,7 @@ static struct rtnl_link_ops team_link_ops __read_mostly = {
 * Generic netlink custom interface
 ***********************************/

static struct genl_family team_nl_family = {
	.id		= GENL_ID_GENERATE,
	.name		= TEAM_GENL_NAME,
	.version	= TEAM_GENL_VERSION,
	.maxattr	= TEAM_ATTR_MAX,
	.netnsok	= true,
};
static struct genl_family team_nl_family;

static const struct nla_policy team_nl_policy[TEAM_ATTR_MAX + 1] = {
	[TEAM_ATTR_UNSPEC]			= { .type = NLA_UNSPEC, },
@@ -2746,6 +2740,18 @@ static const struct genl_multicast_group team_nl_mcgrps[] = {
	{ .name = TEAM_GENL_CHANGE_EVENT_MC_GRP_NAME, },
};

static struct genl_family team_nl_family __ro_after_init = {
	.name		= TEAM_GENL_NAME,
	.version	= TEAM_GENL_VERSION,
	.maxattr	= TEAM_ATTR_MAX,
	.netnsok	= true,
	.module		= THIS_MODULE,
	.ops		= team_nl_ops,
	.n_ops		= ARRAY_SIZE(team_nl_ops),
	.mcgrps		= team_nl_mcgrps,
	.n_mcgrps	= ARRAY_SIZE(team_nl_mcgrps),
};

static int team_nl_send_multicast(struct sk_buff *skb,
				  struct team *team, u32 portid)
{
@@ -2767,10 +2773,9 @@ static int team_nl_send_event_port_get(struct team *team,
					  port);
}

static int team_nl_init(void)
static int __init team_nl_init(void)
{
	return genl_register_family_with_ops_groups(&team_nl_family, team_nl_ops,
						    team_nl_mcgrps);
	return genl_register_family(&team_nl_family);
}

static void team_nl_fini(void)
+16 −13
Original line number Diff line number Diff line
@@ -587,15 +587,8 @@ struct hwsim_radiotap_ack_hdr {
	__le16 rt_chbitmask;
} __packed;

/* MAC80211_HWSIM netlinf family */
static struct genl_family hwsim_genl_family = {
	.id = GENL_ID_GENERATE,
	.hdrsize = 0,
	.name = "MAC80211_HWSIM",
	.version = 1,
	.maxattr = HWSIM_ATTR_MAX,
	.netnsok = true,
};
/* MAC80211_HWSIM netlink family */
static struct genl_family hwsim_genl_family;

enum hwsim_multicast_groups {
	HWSIM_MCGRP_CONFIG,
@@ -3235,6 +3228,18 @@ static const struct genl_ops hwsim_ops[] = {
	},
};

static struct genl_family hwsim_genl_family __ro_after_init = {
	.name = "MAC80211_HWSIM",
	.version = 1,
	.maxattr = HWSIM_ATTR_MAX,
	.netnsok = true,
	.module = THIS_MODULE,
	.ops = hwsim_ops,
	.n_ops = ARRAY_SIZE(hwsim_ops),
	.mcgrps = hwsim_mcgrps,
	.n_mcgrps = ARRAY_SIZE(hwsim_mcgrps),
};

static void destroy_radio(struct work_struct *work)
{
	struct mac80211_hwsim_data *data =
@@ -3282,15 +3287,13 @@ static struct notifier_block hwsim_netlink_notifier = {
	.notifier_call = mac80211_hwsim_netlink_notify,
};

static int hwsim_init_netlink(void)
static int __init hwsim_init_netlink(void)
{
	int rc;

	printk(KERN_INFO "mac80211_hwsim: initializing netlink\n");

	rc = genl_register_family_with_ops_groups(&hwsim_genl_family,
						  hwsim_ops,
						  hwsim_mcgrps);
	rc = genl_register_family(&hwsim_genl_family);
	if (rc)
		goto failure;

Loading