Skip to content

Commit a31f2d1

Browse files
ummakynesdavem330
authored andcommitted
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: Pablo Neira Ayuso <pablo@netfilter.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent dd7f36b commit a31f2d1

20 files changed

Lines changed: 117 additions & 51 deletions

File tree

‎crypto/crypto_user.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,9 +496,12 @@ static void crypto_netlink_rcv(struct sk_buff *skb)
496496

497497
static int __init crypto_user_init(void)
498498
{
499+
struct netlink_kernel_cfg cfg = {
500+
.input = crypto_netlink_rcv,
501+
};
502+
499503
crypto_nlsk = netlink_kernel_create(&init_net, NETLINK_CRYPTO,
500-
0, crypto_netlink_rcv,
501-
NULL, THIS_MODULE);
504+
THIS_MODULE, &cfg);
502505
if (!crypto_nlsk)
503506
return -ENOMEM;
504507

‎drivers/connector/connector.c‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,15 +251,20 @@ static const struct file_operations cn_file_ops = {
251251
.release = single_release
252252
};
253253

254+
static struct cn_dev cdev = {
255+
.input = cn_rx_skb,
256+
};
257+
254258
static int __devinit cn_init(void)
255259
{
256260
struct cn_dev *dev = &cdev;
257-
258-
dev->input = cn_rx_skb;
261+
struct netlink_kernel_cfg cfg = {
262+
.groups = CN_NETLINK_USERS + 0xf,
263+
.input = dev->input,
264+
};
259265

260266
dev->nls = netlink_kernel_create(&init_net, NETLINK_CONNECTOR,
261-
CN_NETLINK_USERS + 0xf,
262-
dev->input, NULL, THIS_MODULE);
267+
THIS_MODULE, &cfg);
263268
if (!dev->nls)
264269
return -EIO;
265270

‎drivers/infiniband/core/netlink.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,11 @@ static void ibnl_rcv(struct sk_buff *skb)
173173

174174
int __init ibnl_init(void)
175175
{
176-
nls = netlink_kernel_create(&init_net, NETLINK_RDMA, 0, ibnl_rcv,
177-
NULL, THIS_MODULE);
176+
struct netlink_kernel_cfg cfg = {
177+
.input = ibnl_rcv,
178+
};
179+
180+
nls = netlink_kernel_create(&init_net, NETLINK_RDMA, THIS_MODULE, &cfg);
178181
if (!nls) {
179182
pr_warn("Failed to create netlink socket\n");
180183
return -ENOMEM;

‎drivers/scsi/scsi_netlink.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,10 @@ void
486486
scsi_netlink_init(void)
487487
{
488488
int error;
489+
struct netlink_kernel_cfg cfg = {
490+
.input = scsi_nl_rcv_msg,
491+
.groups = SCSI_NL_GRP_CNT,
492+
};
489493

490494
INIT_LIST_HEAD(&scsi_nl_drivers);
491495

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

499503
scsi_nl_sock = netlink_kernel_create(&init_net, NETLINK_SCSITRANSPORT,
500-
SCSI_NL_GRP_CNT, scsi_nl_rcv_msg, NULL,
501-
THIS_MODULE);
504+
THIS_MODULE, &cfg);
502505
if (!scsi_nl_sock) {
503506
printk(KERN_ERR "%s: register of receive handler failed\n",
504507
__func__);

‎drivers/scsi/scsi_transport_iscsi.c‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2936,7 +2936,10 @@ EXPORT_SYMBOL_GPL(iscsi_unregister_transport);
29362936
static __init int iscsi_transport_init(void)
29372937
{
29382938
int err;
2939-
2939+
struct netlink_kernel_cfg cfg = {
2940+
.groups = 1,
2941+
.input = iscsi_if_rx,
2942+
};
29402943
printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
29412944
ISCSI_TRANSPORT_VERSION);
29422945

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

2969-
nls = netlink_kernel_create(&init_net, NETLINK_ISCSI, 1, iscsi_if_rx,
2970-
NULL, THIS_MODULE);
2972+
nls = netlink_kernel_create(&init_net, NETLINK_ISCSI,
2973+
THIS_MODULE, &cfg);
29712974
if (!nls) {
29722975
err = -ENOBUFS;
29732976
goto unregister_session_class;

‎drivers/staging/gdm72xx/netlink_k.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,15 @@ struct sock *netlink_init(int unit, void (*cb)(struct net_device *dev, u16 type,
8888
void *msg, int len))
8989
{
9090
struct sock *sock;
91+
struct netlink_kernel_cfg cfg = {
92+
.input = netlink_rcv,
93+
};
9194

9295
#if !defined(DEFINE_MUTEX)
9396
init_MUTEX(&netlink_mutex);
9497
#endif
9598

96-
sock = netlink_kernel_create(&init_net, unit, 0, netlink_rcv, NULL,
97-
THIS_MODULE);
99+
sock = netlink_kernel_create(&init_net, unit, THIS_MODULE, &cfg);
98100

99101
if (sock)
100102
rcv_cb = cb;

‎include/linux/netlink.h‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,16 @@ struct netlink_skb_parms {
174174
extern void netlink_table_grab(void);
175175
extern void netlink_table_ungrab(void);
176176

177-
extern struct sock *netlink_kernel_create(struct net *net,
178-
int unit,unsigned int groups,
179-
void (*input)(struct sk_buff *skb),
180-
struct mutex *cb_mutex,
181-
struct module *module);
177+
/* optional Netlink kernel configuration parameters */
178+
struct netlink_kernel_cfg {
179+
unsigned int groups;
180+
void (*input)(struct sk_buff *skb);
181+
struct mutex *cb_mutex;
182+
};
183+
184+
extern struct sock *netlink_kernel_create(struct net *net, int unit,
185+
struct module *module,
186+
struct netlink_kernel_cfg *cfg);
182187
extern void netlink_kernel_release(struct sock *sk);
183188
extern int __netlink_change_ngroups(struct sock *sk, unsigned int groups);
184189
extern int netlink_change_ngroups(struct sock *sk, unsigned int groups);

‎kernel/audit.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -962,14 +962,17 @@ static void audit_receive(struct sk_buff *skb)
962962
static int __init audit_init(void)
963963
{
964964
int i;
965+
struct netlink_kernel_cfg cfg = {
966+
.input = audit_receive,
967+
};
965968

966969
if (audit_initialized == AUDIT_DISABLED)
967970
return 0;
968971

969972
printk(KERN_INFO "audit: initializing netlink socket (%s)\n",
970973
audit_default ? "enabled" : "disabled");
971-
audit_sock = netlink_kernel_create(&init_net, NETLINK_AUDIT, 0,
972-
audit_receive, NULL, THIS_MODULE);
974+
audit_sock = netlink_kernel_create(&init_net, NETLINK_AUDIT,
975+
THIS_MODULE, &cfg);
973976
if (!audit_sock)
974977
audit_panic("cannot initialize netlink socket");
975978
else

‎lib/kobject_uevent.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,13 +373,16 @@ EXPORT_SYMBOL_GPL(add_uevent_var);
373373
static int uevent_net_init(struct net *net)
374374
{
375375
struct uevent_sock *ue_sk;
376+
struct netlink_kernel_cfg cfg = {
377+
.groups = 1,
378+
};
376379

377380
ue_sk = kzalloc(sizeof(*ue_sk), GFP_KERNEL);
378381
if (!ue_sk)
379382
return -ENOMEM;
380383

381384
ue_sk->sk = netlink_kernel_create(net, NETLINK_KOBJECT_UEVENT,
382-
1, NULL, NULL, THIS_MODULE);
385+
THIS_MODULE, &cfg);
383386
if (!ue_sk->sk) {
384387
printk(KERN_ERR
385388
"kobject_uevent: unable to create netlink socket!\n");

‎net/bridge/netfilter/ebt_ulog.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,9 @@ static int __init ebt_ulog_init(void)
282282
{
283283
int ret;
284284
int i;
285+
struct netlink_kernel_cfg cfg = {
286+
.groups = EBT_ULOG_MAXNLGROUPS,
287+
};
285288

286289
if (nlbufsiz >= 128*1024) {
287290
pr_warning("Netlink buffer has to be <= 128kB,"
@@ -296,8 +299,7 @@ static int __init ebt_ulog_init(void)
296299
}
297300

298301
ebtulognl = netlink_kernel_create(&init_net, NETLINK_NFLOG,
299-
EBT_ULOG_MAXNLGROUPS, NULL, NULL,
300-
THIS_MODULE);
302+
THIS_MODULE, &cfg);
301303
if (!ebtulognl)
302304
ret = -ENOMEM;
303305
else if ((ret = xt_register_target(&ebt_ulog_tg_reg)) != 0)

0 commit comments

Comments
 (0)