Commit a4c9a56e authored by Anjali Kulkarni's avatar Anjali Kulkarni Committed by David S. Miller

netlink: Add new netlink_release function

A new function netlink_release is added in netlink_sock to store the
protocol's release function. This is called when the socket is deleted.
This can be supplied by the protocol via the release function in
netlink_kernel_cfg. This is being added for the NETLINK_CONNECTOR
protocol, so it can free it's data when socket is deleted.
Signed-off-by: default avatarAnjali Kulkarni <anjali.k.kulkarni@oracle.com>
Reviewed-by: default avatarLiam R. Howlett <Liam.Howlett@oracle.com>
Acked-by: default avatarJakub Kicinski <kuba@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a3377386
...@@ -50,6 +50,7 @@ struct netlink_kernel_cfg { ...@@ -50,6 +50,7 @@ struct netlink_kernel_cfg {
struct mutex *cb_mutex; struct mutex *cb_mutex;
int (*bind)(struct net *net, int group); int (*bind)(struct net *net, int group);
void (*unbind)(struct net *net, int group); void (*unbind)(struct net *net, int group);
void (*release) (struct sock *sk, unsigned long *groups);
}; };
struct sock *__netlink_kernel_create(struct net *net, int unit, struct sock *__netlink_kernel_create(struct net *net, int unit,
......
...@@ -677,6 +677,7 @@ static int netlink_create(struct net *net, struct socket *sock, int protocol, ...@@ -677,6 +677,7 @@ static int netlink_create(struct net *net, struct socket *sock, int protocol,
struct netlink_sock *nlk; struct netlink_sock *nlk;
int (*bind)(struct net *net, int group); int (*bind)(struct net *net, int group);
void (*unbind)(struct net *net, int group); void (*unbind)(struct net *net, int group);
void (*release)(struct sock *sock, unsigned long *groups);
int err = 0; int err = 0;
sock->state = SS_UNCONNECTED; sock->state = SS_UNCONNECTED;
...@@ -704,6 +705,7 @@ static int netlink_create(struct net *net, struct socket *sock, int protocol, ...@@ -704,6 +705,7 @@ static int netlink_create(struct net *net, struct socket *sock, int protocol,
cb_mutex = nl_table[protocol].cb_mutex; cb_mutex = nl_table[protocol].cb_mutex;
bind = nl_table[protocol].bind; bind = nl_table[protocol].bind;
unbind = nl_table[protocol].unbind; unbind = nl_table[protocol].unbind;
release = nl_table[protocol].release;
netlink_unlock_table(); netlink_unlock_table();
if (err < 0) if (err < 0)
...@@ -719,6 +721,7 @@ static int netlink_create(struct net *net, struct socket *sock, int protocol, ...@@ -719,6 +721,7 @@ static int netlink_create(struct net *net, struct socket *sock, int protocol,
nlk->module = module; nlk->module = module;
nlk->netlink_bind = bind; nlk->netlink_bind = bind;
nlk->netlink_unbind = unbind; nlk->netlink_unbind = unbind;
nlk->netlink_release = release;
out: out:
return err; return err;
...@@ -763,6 +766,8 @@ static int netlink_release(struct socket *sock) ...@@ -763,6 +766,8 @@ static int netlink_release(struct socket *sock)
* OK. Socket is unlinked, any packets that arrive now * OK. Socket is unlinked, any packets that arrive now
* will be purged. * will be purged.
*/ */
if (nlk->netlink_release)
nlk->netlink_release(sk, nlk->groups);
/* must not acquire netlink_table_lock in any way again before unbind /* must not acquire netlink_table_lock in any way again before unbind
* and notifying genetlink is done as otherwise it might deadlock * and notifying genetlink is done as otherwise it might deadlock
...@@ -2089,6 +2094,7 @@ __netlink_kernel_create(struct net *net, int unit, struct module *module, ...@@ -2089,6 +2094,7 @@ __netlink_kernel_create(struct net *net, int unit, struct module *module,
if (cfg) { if (cfg) {
nl_table[unit].bind = cfg->bind; nl_table[unit].bind = cfg->bind;
nl_table[unit].unbind = cfg->unbind; nl_table[unit].unbind = cfg->unbind;
nl_table[unit].release = cfg->release;
nl_table[unit].flags = cfg->flags; nl_table[unit].flags = cfg->flags;
} }
nl_table[unit].registered = 1; nl_table[unit].registered = 1;
......
...@@ -42,6 +42,8 @@ struct netlink_sock { ...@@ -42,6 +42,8 @@ struct netlink_sock {
void (*netlink_rcv)(struct sk_buff *skb); void (*netlink_rcv)(struct sk_buff *skb);
int (*netlink_bind)(struct net *net, int group); int (*netlink_bind)(struct net *net, int group);
void (*netlink_unbind)(struct net *net, int group); void (*netlink_unbind)(struct net *net, int group);
void (*netlink_release)(struct sock *sk,
unsigned long *groups);
struct module *module; struct module *module;
struct rhash_head node; struct rhash_head node;
...@@ -64,6 +66,8 @@ struct netlink_table { ...@@ -64,6 +66,8 @@ struct netlink_table {
struct module *module; struct module *module;
int (*bind)(struct net *net, int group); int (*bind)(struct net *net, int group);
void (*unbind)(struct net *net, int group); void (*unbind)(struct net *net, int group);
void (*release)(struct sock *sk,
unsigned long *groups);
int registered; int registered;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment