History

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.

Anjali Kulkarni committed 3 years ago

Commit a4c9a561 parent a3377383 files · +11 −0Browse files

Unified · Split

3 files
  1. include/linux/netlink.h +1 −0
  2. net/netlink/af_netlink.c +6 −0
  3. net/netlink/af_netlink.h +4 −0
include/linux/netlink.h+1−0
@@ -50,6 +50,7 @@ struct netlink_kernel_cfg { · 49 unmodified lines
5050 struct mutex *cb_mutex;
5151 int (*bind)(struct net *net, int group);
5252 void (*unbind)(struct net *net, int group);
53+ void (*release) (struct sock *sk, unsigned long *groups);
5354 };
5455
5556 struct sock *__netlink_kernel_create(struct net *net, int unit,
net/netlink/af_netlink.c+6−0
@@ -677,6 +677,7 @@ static int netlink_create(struct net *net, struct socket *sock, int protocol, · 676 unmodified lines
677677 struct netlink_sock *nlk;
678678 int (*bind)(struct net *net, int group);
679679 void (*unbind)(struct net *net, int group);
680+ void (*release)(struct sock *sock, unsigned long *groups);
680681 int err = 0;
681682
682683 sock->state = SS_UNCONNECTED;
@@ -704,6 +705,7 @@ static int netlink_create(struct net *net, struct socket *sock, int protocol, · 21 unmodified lines
704705 cb_mutex = nl_table[protocol].cb_mutex;
705706 bind = nl_table[protocol].bind;
706707 unbind = nl_table[protocol].unbind;
708+ release = nl_table[protocol].release;
707709 netlink_unlock_table();
708710
709711 if (err < 0)
@@ -719,6 +721,7 @@ static int netlink_create(struct net *net, struct socket *sock, int protocol, · 9 unmodified lines
719721 nlk->module = module;
720722 nlk->netlink_bind = bind;
721723 nlk->netlink_unbind = unbind;
724+ nlk->netlink_release = release;
722725 out:
723726 return err;
724727
@@ -763,6 +766,8 @@ static int netlink_release(struct socket *sock) · 38 unmodified lines
763766 * OK. Socket is unlinked, any packets that arrive now
764767 * will be purged.
765768 */
769+ if (nlk->netlink_release)
770+ nlk->netlink_release(sk, nlk->groups);
766771
767772 /* must not acquire netlink_table_lock in any way again before unbind
768773 * 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, · 1320 unmodified lines
20892094 if (cfg) {
20902095 nl_table[unit].bind = cfg->bind;
20912096 nl_table[unit].unbind = cfg->unbind;
2097+ nl_table[unit].release = cfg->release;
20922098 nl_table[unit].flags = cfg->flags;
20932099 }
20942100 nl_table[unit].registered = 1;
net/netlink/af_netlink.h+4−0
@@ -42,6 +42,8 @@ struct netlink_sock { · 41 unmodified lines
4242 void (*netlink_rcv)(struct sk_buff *skb);
4343 int (*netlink_bind)(struct net *net, int group);
4444 void (*netlink_unbind)(struct net *net, int group);
45+ void (*netlink_release)(struct sock *sk,
46+ unsigned long *groups);
4547 struct module *module;
4648
4749 struct rhash_head node;
@@ -64,6 +66,8 @@ struct netlink_table { · 16 unmodified lines
6466 struct module *module;
6567 int (*bind)(struct net *net, int group);
6668 void (*unbind)(struct net *net, int group);
69+ void (*release)(struct sock *sk,
70+ unsigned long *groups);
6771 int registered;
6872 };
6973

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t