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

Commit a31f2d17 authored by Pablo Neira Ayuso's avatar Pablo Neira Ayuso Committed by David S. Miller
Browse files

netlink: add netlink_kernel_cfg parameter to netlink_kernel_create



This patch adds the following structure:

struct netlink_kernel_cfg {
        unsigned int    groups;
        void            (*input)(struct sk_buff *skb);
        struct mutex    *cb_mutex;
};

That can be passed to netlink_kernel_create to set optional configurations
for netlink kernel sockets.

I've populated this structure by looking for NULL and zero parameters at the
existing code. The remaining parameters that always need to be set are still
left in the original interface.

That includes optional parameters for the netlink socket creation. This allows
easy extensibility of this interface in the future.

This patch also adapts all callers to use this new interface.

Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent dd7f36ba
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -496,9 +496,12 @@ static void crypto_netlink_rcv(struct sk_buff *skb)

static int __init crypto_user_init(void)
{
	struct netlink_kernel_cfg cfg = {
		.input	= crypto_netlink_rcv,
	};

	crypto_nlsk = netlink_kernel_create(&init_net, NETLINK_CRYPTO,
					    0, crypto_netlink_rcv,
					    NULL, THIS_MODULE);
					    THIS_MODULE, &cfg);
	if (!crypto_nlsk)
		return -ENOMEM;

+9 −4
Original line number Diff line number Diff line
@@ -251,15 +251,20 @@ static const struct file_operations cn_file_ops = {
	.release = single_release
};

static struct cn_dev cdev = {
	.input   = cn_rx_skb,
};

static int __devinit cn_init(void)
{
	struct cn_dev *dev = &cdev;

	dev->input = cn_rx_skb;
	struct netlink_kernel_cfg cfg = {
		.groups	= CN_NETLINK_USERS + 0xf,
		.input	= dev->input,
	};

	dev->nls = netlink_kernel_create(&init_net, NETLINK_CONNECTOR,
					 CN_NETLINK_USERS + 0xf,
					 dev->input, NULL, THIS_MODULE);
					 THIS_MODULE, &cfg);
	if (!dev->nls)
		return -EIO;

+5 −2
Original line number Diff line number Diff line
@@ -173,8 +173,11 @@ static void ibnl_rcv(struct sk_buff *skb)

int __init ibnl_init(void)
{
	nls = netlink_kernel_create(&init_net, NETLINK_RDMA, 0, ibnl_rcv,
				    NULL, THIS_MODULE);
	struct netlink_kernel_cfg cfg = {
		.input	= ibnl_rcv,
	};

	nls = netlink_kernel_create(&init_net, NETLINK_RDMA, THIS_MODULE, &cfg);
	if (!nls) {
		pr_warn("Failed to create netlink socket\n");
		return -ENOMEM;
+5 −2
Original line number Diff line number Diff line
@@ -486,6 +486,10 @@ void
scsi_netlink_init(void)
{
	int error;
	struct netlink_kernel_cfg cfg = {
		.input	= scsi_nl_rcv_msg,
		.groups	= SCSI_NL_GRP_CNT,
	};

	INIT_LIST_HEAD(&scsi_nl_drivers);

@@ -497,8 +501,7 @@ scsi_netlink_init(void)
	}

	scsi_nl_sock = netlink_kernel_create(&init_net, NETLINK_SCSITRANSPORT,
				SCSI_NL_GRP_CNT, scsi_nl_rcv_msg, NULL,
				THIS_MODULE);
					     THIS_MODULE, &cfg);
	if (!scsi_nl_sock) {
		printk(KERN_ERR "%s: register of receive handler failed\n",
				__func__);
+6 −3
Original line number Diff line number Diff line
@@ -2936,7 +2936,10 @@ EXPORT_SYMBOL_GPL(iscsi_unregister_transport);
static __init int iscsi_transport_init(void)
{
	int err;

	struct netlink_kernel_cfg cfg = {
		.groups	= 1,
		.input	= iscsi_if_rx,
	};
	printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
		ISCSI_TRANSPORT_VERSION);

@@ -2966,8 +2969,8 @@ static __init int iscsi_transport_init(void)
	if (err)
		goto unregister_conn_class;

	nls = netlink_kernel_create(&init_net, NETLINK_ISCSI, 1, iscsi_if_rx,
				    NULL, THIS_MODULE);
	nls = netlink_kernel_create(&init_net, NETLINK_ISCSI,
				    THIS_MODULE, &cfg);
	if (!nls) {
		err = -ENOBUFS;
		goto unregister_session_class;
Loading