Skip to content

Commit 4fdb3bb

Browse files
laf0rgeDavid S. Miller
authored andcommitted
[NETLINK]: Add properly module refcounting for kernel netlink sockets.
- Remove bogus code for compiling netlink as module - Add module refcounting support for modules implementing a netlink protocol - Add support for autoloading modules that implement a netlink protocol as soon as someone opens a socket for that protocol Signed-off-by: Harald Welte <laforge@netfilter.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 020b4c1 commit 4fdb3bb

17 files changed

Lines changed: 119 additions & 36 deletions

File tree

‎drivers/w1/w1_int.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static struct w1_master * w1_alloc_dev(u32 id, int slave_count, int slave_ttl,
8888

8989
dev->groups = 23;
9090
dev->seq = 1;
91-
dev->nls = netlink_kernel_create(NETLINK_W1, NULL);
91+
dev->nls = netlink_kernel_create(NETLINK_W1, NULL, THIS_MODULE);
9292
if (!dev->nls) {
9393
printk(KERN_ERR "Failed to create new netlink socket(%u) for w1 master %s.\n",
9494
NETLINK_NFLOG, dev->dev.bus_id);
@@ -225,3 +225,5 @@ void w1_remove_master_device(struct w1_bus_master *bm)
225225

226226
EXPORT_SYMBOL(w1_add_master_device);
227227
EXPORT_SYMBOL(w1_remove_master_device);
228+
229+
MODULE_ALIAS_NET_PF_PROTO(PF_NETLINK, NETLINK_W1);

‎include/linux/net.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,5 +282,8 @@ static struct proto_ops name##_ops = { \
282282
#define MODULE_ALIAS_NETPROTO(proto) \
283283
MODULE_ALIAS("net-pf-" __stringify(proto))
284284

285+
#define MODULE_ALIAS_NET_PF_PROTO(pf, proto) \
286+
MODULE_ALIAS("net-pf-" __stringify(pf) "-proto-" __stringify(proto))
287+
285288
#endif /* __KERNEL__ */
286289
#endif /* _LINUX_NET_H */

‎include/linux/netlink.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ struct netlink_skb_parms
117117
#define NETLINK_CREDS(skb) (&NETLINK_CB((skb)).creds)
118118

119119

120-
extern struct sock *netlink_kernel_create(int unit, void (*input)(struct sock *sk, int len));
120+
extern struct sock *netlink_kernel_create(int unit, void (*input)(struct sock *sk, int len), struct module *module);
121121
extern void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err);
122122
extern int netlink_unicast(struct sock *ssk, struct sk_buff *skb, __u32 pid, int nonblock);
123123
extern int netlink_broadcast(struct sock *ssk, struct sk_buff *skb, __u32 pid,

‎kernel/audit.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,8 @@ static int __init audit_init(void)
514514
{
515515
printk(KERN_INFO "audit: initializing netlink socket (%s)\n",
516516
audit_default ? "enabled" : "disabled");
517-
audit_sock = netlink_kernel_create(NETLINK_AUDIT, audit_receive);
517+
audit_sock = netlink_kernel_create(NETLINK_AUDIT, audit_receive,
518+
THIS_MODULE);
518519
if (!audit_sock)
519520
audit_panic("cannot initialize netlink socket");
520521

‎lib/kobject_uevent.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ EXPORT_SYMBOL_GPL(kobject_uevent_atomic);
153153

154154
static int __init kobject_uevent_init(void)
155155
{
156-
uevent_sock = netlink_kernel_create(NETLINK_KOBJECT_UEVENT, NULL);
156+
uevent_sock = netlink_kernel_create(NETLINK_KOBJECT_UEVENT, NULL,
157+
THIS_MODULE);
157158

158159
if (!uevent_sock) {
159160
printk(KERN_ERR

‎net/bridge/netfilter/ebt_ulog.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ static int __init init(void)
258258
spin_lock_init(&ulog_buffers[i].lock);
259259
}
260260

261-
ebtulognl = netlink_kernel_create(NETLINK_NFLOG, NULL);
261+
ebtulognl = netlink_kernel_create(NETLINK_NFLOG, NULL, THIS_MODULE);
262262
if (!ebtulognl)
263263
ret = -ENOMEM;
264264
else if ((ret = ebt_register_watcher(&ulog)))

‎net/core/rtnetlink.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ void __init rtnetlink_init(void)
708708
if (!rta_buf)
709709
panic("rtnetlink_init: cannot allocate rta_buf\n");
710710

711-
rtnl = netlink_kernel_create(NETLINK_ROUTE, rtnetlink_rcv);
711+
rtnl = netlink_kernel_create(NETLINK_ROUTE, rtnetlink_rcv, THIS_MODULE);
712712
if (rtnl == NULL)
713713
panic("rtnetlink_init: cannot initialize rtnetlink\n");
714714
netlink_set_nonroot(NETLINK_ROUTE, NL_NONROOT_RECV);

‎net/decnet/netfilter/dn_rtmsg.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ static int __init init(void)
138138
{
139139
int rv = 0;
140140

141-
dnrmg = netlink_kernel_create(NETLINK_DNRTMSG, dnrmg_receive_user_sk);
141+
dnrmg = netlink_kernel_create(NETLINK_DNRTMSG, dnrmg_receive_user_sk,
142+
THIS_MODULE);
142143
if (dnrmg == NULL) {
143144
printk(KERN_ERR "dn_rtmsg: Cannot create netlink socket");
144145
return -ENOMEM;
@@ -162,6 +163,7 @@ static void __exit fini(void)
162163
MODULE_DESCRIPTION("DECnet Routing Message Grabulator");
163164
MODULE_AUTHOR("Steven Whitehouse <steve@chygwyn.com>");
164165
MODULE_LICENSE("GPL");
166+
MODULE_ALIAS_NET_PF_PROTO(PF_NETLINK, NETLINK_DNRTMSG);
165167

166168
module_init(init);
167169
module_exit(fini);

‎net/ipv4/fib_frontend.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ static void nl_fib_input(struct sock *sk, int len)
567567

568568
static void nl_fib_lookup_init(void)
569569
{
570-
netlink_kernel_create(NETLINK_FIB_LOOKUP, nl_fib_input);
570+
netlink_kernel_create(NETLINK_FIB_LOOKUP, nl_fib_input, THIS_MODULE);
571571
}
572572

573573
static void fib_disable_ip(struct net_device *dev, int force)

‎net/ipv4/netfilter/ip_queue.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,8 @@ init_or_cleanup(int init)
692692
goto cleanup;
693693

694694
netlink_register_notifier(&ipq_nl_notifier);
695-
ipqnl = netlink_kernel_create(NETLINK_FIREWALL, ipq_rcv_sk);
695+
ipqnl = netlink_kernel_create(NETLINK_FIREWALL, ipq_rcv_sk,
696+
THIS_MODULE);
696697
if (ipqnl == NULL) {
697698
printk(KERN_ERR "ip_queue: failed to create netlink socket\n");
698699
goto cleanup_netlink_notifier;

0 commit comments

Comments
 (0)