mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-07-23 23:32:14 +00:00
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>
This commit is contained in:
parent
dd7f36ba3c
commit
a31f2d17b3
20 changed files with 117 additions and 51 deletions
|
@ -1503,14 +1503,16 @@ static void netlink_data_ready(struct sock *sk, int len)
|
|||
*/
|
||||
|
||||
struct sock *
|
||||
netlink_kernel_create(struct net *net, int unit, unsigned int groups,
|
||||
void (*input)(struct sk_buff *skb),
|
||||
struct mutex *cb_mutex, struct module *module)
|
||||
netlink_kernel_create(struct net *net, int unit,
|
||||
struct module *module,
|
||||
struct netlink_kernel_cfg *cfg)
|
||||
{
|
||||
struct socket *sock;
|
||||
struct sock *sk;
|
||||
struct netlink_sock *nlk;
|
||||
struct listeners *listeners = NULL;
|
||||
struct mutex *cb_mutex = cfg ? cfg->cb_mutex : NULL;
|
||||
unsigned int groups;
|
||||
|
||||
BUG_ON(!nl_table);
|
||||
|
||||
|
@ -1532,16 +1534,18 @@ netlink_kernel_create(struct net *net, int unit, unsigned int groups,
|
|||
sk = sock->sk;
|
||||
sk_change_net(sk, net);
|
||||
|
||||
if (groups < 32)
|
||||
if (!cfg || cfg->groups < 32)
|
||||
groups = 32;
|
||||
else
|
||||
groups = cfg->groups;
|
||||
|
||||
listeners = kzalloc(sizeof(*listeners) + NLGRPSZ(groups), GFP_KERNEL);
|
||||
if (!listeners)
|
||||
goto out_sock_release;
|
||||
|
||||
sk->sk_data_ready = netlink_data_ready;
|
||||
if (input)
|
||||
nlk_sk(sk)->netlink_rcv = input;
|
||||
if (cfg && cfg->input)
|
||||
nlk_sk(sk)->netlink_rcv = cfg->input;
|
||||
|
||||
if (netlink_insert(sk, net, 0))
|
||||
goto out_sock_release;
|
||||
|
|
|
@ -915,10 +915,14 @@ static struct genl_multicast_group notify_grp = {
|
|||
|
||||
static int __net_init genl_pernet_init(struct net *net)
|
||||
{
|
||||
struct netlink_kernel_cfg cfg = {
|
||||
.input = genl_rcv,
|
||||
.cb_mutex = &genl_mutex,
|
||||
};
|
||||
|
||||
/* we'll bump the group number right afterwards */
|
||||
net->genl_sock = netlink_kernel_create(net, NETLINK_GENERIC, 0,
|
||||
genl_rcv, &genl_mutex,
|
||||
THIS_MODULE);
|
||||
net->genl_sock = netlink_kernel_create(net, NETLINK_GENERIC,
|
||||
THIS_MODULE, &cfg);
|
||||
|
||||
if (!net->genl_sock && net_eq(net, &init_net))
|
||||
panic("GENL: Cannot initialize generic netlink\n");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue