netlink: call unbind when releasing socket
authorJohannes Berg <johannes.berg@intel.com>
Mon, 22 Dec 2014 17:56:38 +0000 (18:56 +0100)
committerDavid S. Miller <davem@davemloft.net>
Sat, 27 Dec 2014 07:20:23 +0000 (02:20 -0500)
Currently, netlink_unbind() is only called when the socket
explicitly unbinds, which limits its usefulness (luckily
there are no users of it yet anyway.)

Call netlink_unbind() also when a socket is released, so it
becomes possible to track listeners with this callback and
without also implementing a netlink notifier (and checking
netlink_has_listeners() in there.)

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/netlink/af_netlink.c

index 6a9fb7c489a87100de634338c37cd3b0d2be23da..f29b63fad9320f951f5d27a06e686de121490d81 100644 (file)
@@ -1246,6 +1246,13 @@ static int netlink_release(struct socket *sock)
                netlink_table_ungrab();
        }
 
+       if (nlk->netlink_unbind) {
+               int i;
+
+               for (i = 0; i < nlk->ngroups; i++)
+                       if (test_bit(i, nlk->groups))
+                               nlk->netlink_unbind(i + 1);
+       }
        kfree(nlk->groups);
        nlk->groups = NULL;