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
50 struct mutex *cb_mutex;50 struct mutex *cb_mutex;
51 int (*bind)(struct net *net, int group);51 int (*bind)(struct net *net, int group);
52 void (*unbind)(struct net *net, int group);52 void (*unbind)(struct net *net, int group);
53 void (*release) (struct sock *sk, unsigned long *groups);
53};54};
54 55
55struct sock *__netlink_kernel_create(struct net *net, int unit,56struct 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
677 struct netlink_sock *nlk;677 struct netlink_sock *nlk;
678 int (*bind)(struct net *net, int group);678 int (*bind)(struct net *net, int group);
679 void (*unbind)(struct net *net, int group);679 void (*unbind)(struct net *net, int group);
680 void (*release)(struct sock *sock, unsigned long *groups);
680 int err = 0;681 int err = 0;
681 682
682 sock->state = SS_UNCONNECTED;683 sock->state = SS_UNCONNECTED;
@@ -704,6 +705,7 @@ static int netlink_create(struct net *net, struct socket *sock, int protocol, · 21 unmodified lines
704 cb_mutex = nl_table[protocol].cb_mutex;705 cb_mutex = nl_table[protocol].cb_mutex;
705 bind = nl_table[protocol].bind;706 bind = nl_table[protocol].bind;
706 unbind = nl_table[protocol].unbind;707 unbind = nl_table[protocol].unbind;
708 release = nl_table[protocol].release;
707 netlink_unlock_table();709 netlink_unlock_table();
708 710
709 if (err < 0)711 if (err < 0)
@@ -719,6 +721,7 @@ static int netlink_create(struct net *net, struct socket *sock, int protocol, · 9 unmodified lines
719 nlk->module = module;721 nlk->module = module;
720 nlk->netlink_bind = bind;722 nlk->netlink_bind = bind;
721 nlk->netlink_unbind = unbind;723 nlk->netlink_unbind = unbind;
724 nlk->netlink_release = release;
722out:725out:
723 return err;726 return err;
724 727
@@ -763,6 +766,8 @@ static int netlink_release(struct socket *sock) · 38 unmodified lines
763 * OK. Socket is unlinked, any packets that arrive now766 * OK. Socket is unlinked, any packets that arrive now
764 * will be purged.767 * will be purged.
765 */768 */
769 if (nlk->netlink_release)
770 nlk->netlink_release(sk, nlk->groups);
766 771
767 /* must not acquire netlink_table_lock in any way again before unbind772 /* must not acquire netlink_table_lock in any way again before unbind
768 * and notifying genetlink is done as otherwise it might deadlock773 * 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
2089 if (cfg) {2094 if (cfg) {
2090 nl_table[unit].bind = cfg->bind;2095 nl_table[unit].bind = cfg->bind;
2091 nl_table[unit].unbind = cfg->unbind;2096 nl_table[unit].unbind = cfg->unbind;
2097 nl_table[unit].release = cfg->release;
2092 nl_table[unit].flags = cfg->flags;2098 nl_table[unit].flags = cfg->flags;
2093 }2099 }
2094 nl_table[unit].registered = 1;2100 nl_table[unit].registered = 1;
net/netlink/af_netlink.h+4−0
@@ -42,6 +42,8 @@ struct netlink_sock { · 41 unmodified lines
42 void (*netlink_rcv)(struct sk_buff *skb);42 void (*netlink_rcv)(struct sk_buff *skb);
43 int (*netlink_bind)(struct net *net, int group);43 int (*netlink_bind)(struct net *net, int group);
44 void (*netlink_unbind)(struct net *net, int group);44 void (*netlink_unbind)(struct net *net, int group);
45 void (*netlink_release)(struct sock *sk,
46 unsigned long *groups);
45 struct module *module;47 struct module *module;
46 48
47 struct rhash_head node;49 struct rhash_head node;
@@ -64,6 +66,8 @@ struct netlink_table { · 16 unmodified lines
64 struct module *module;66 struct module *module;
65 int (*bind)(struct net *net, int group);67 int (*bind)(struct net *net, int group);
66 void (*unbind)(struct net *net, int group);68 void (*unbind)(struct net *net, int group);
69 void (*release)(struct sock *sk,
70 unsigned long *groups);
67 int registered;71 int registered;
68};72};
69 73

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