aboutsummaryrefslogtreecommitdiffstats
path: root/net/netlink/af_netlink.c
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2012-06-29 02:15:21 -0400
committerDavid S. Miller <davem@davemloft.net>2012-06-29 19:46:02 -0400
commita31f2d17b331db970259e875b7223d3aba7e3821 (patch)
tree0d10021be81446ab360f4240b0d16729f518387f /net/netlink/af_netlink.c
parentdd7f36ba3ce17d4fe85987d83efd5901b0935816 (diff)
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>
Diffstat (limited to 'net/netlink/af_netlink.c')
-rw-r--r--net/netlink/af_netlink.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index b3025a603d56..43a124feaad8 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -1503,14 +1503,16 @@ static void netlink_data_ready(struct sock *sk, int len)
1503 */ 1503 */
1504 1504
1505struct sock * 1505struct sock *
1506netlink_kernel_create(struct net *net, int unit, unsigned int groups, 1506netlink_kernel_create(struct net *net, int unit,
1507 void (*input)(struct sk_buff *skb), 1507 struct module *module,
1508 struct mutex *cb_mutex, struct module *module) 1508 struct netlink_kernel_cfg *cfg)
1509{ 1509{
1510 struct socket *sock; 1510 struct socket *sock;
1511 struct sock *sk; 1511 struct sock *sk;
1512 struct netlink_sock *nlk; 1512 struct netlink_sock *nlk;
1513 struct listeners *listeners = NULL; 1513 struct listeners *listeners = NULL;
1514 struct mutex *cb_mutex = cfg ? cfg->cb_mutex : NULL;
1515 unsigned int groups;
1514 1516
1515 BUG_ON(!nl_table); 1517 BUG_ON(!nl_table);
1516 1518
@@ -1532,16 +1534,18 @@ netlink_kernel_create(struct net *net, int unit, unsigned int groups,
1532 sk = sock->sk; 1534 sk = sock->sk;
1533 sk_change_net(sk, net); 1535 sk_change_net(sk, net);
1534 1536
1535 if (groups < 32) 1537 if (!cfg || cfg->groups < 32)
1536 groups = 32; 1538 groups = 32;
1539 else
1540 groups = cfg->groups;
1537 1541
1538 listeners = kzalloc(sizeof(*listeners) + NLGRPSZ(groups), GFP_KERNEL); 1542 listeners = kzalloc(sizeof(*listeners) + NLGRPSZ(groups), GFP_KERNEL);
1539 if (!listeners) 1543 if (!listeners)
1540 goto out_sock_release; 1544 goto out_sock_release;
1541 1545
1542 sk->sk_data_ready = netlink_data_ready; 1546 sk->sk_data_ready = netlink_data_ready;
1543 if (input) 1547 if (cfg && cfg->input)
1544 nlk_sk(sk)->netlink_rcv = input; 1548 nlk_sk(sk)->netlink_rcv = cfg->input;
1545 1549
1546 if (netlink_insert(sk, net, 0)) 1550 if (netlink_insert(sk, net, 0))
1547 goto out_sock_release; 1551 goto out_sock_release;