Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Anjali Kulkarni <anjali.k.kulkarni@oracle.com>
Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Acked-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Anjali Kulkarni and committed by
David S. Miller
a4c9a56e a3377386

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