From 525e31f580e909cb544cce88db555efbddaff35a Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Sat, 19 Apr 2003 14:26:12 -0300 Subject: [PATCH] o net: new module infrastructure for net_proto_family Next batch of changesets will fix the legacy protocols (IPX, LLC, etc). Tested with LLC and IPX already. --- include/linux/net.h | 13 ++++++++----- net/socket.c | 19 ++++++++++++++----- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/include/linux/net.h b/include/linux/net.h index 6ba6e10385211..fc6b655dcdc3a 100644 --- a/include/linux/net.h +++ b/include/linux/net.h @@ -127,14 +127,17 @@ struct proto_ops { int offset, size_t size, int flags); }; +struct module; + struct net_proto_family { - int family; - int (*create)(struct socket *sock, int protocol); + int family; + int (*create)(struct socket *sock, int protocol); /* These are counters for the number of different methods of each we support */ - short authentication; - short encryption; - short encrypt_net; + short authentication; + short encryption; + short encrypt_net; + struct module *owner; }; struct iovec; diff --git a/net/socket.c b/net/socket.c index 1e2d9463c34df..0d8a2e9d5a04e 100644 --- a/net/socket.c +++ b/net/socket.c @@ -506,8 +506,13 @@ struct file_operations bad_sock_fops = { void sock_release(struct socket *sock) { - if (sock->ops) + if (sock->ops) { + const int family = sock->ops->family; + sock->ops->release(sock); + sock->ops = NULL; + module_put(net_families[family]->owner); + } if (sock->fasync_list) printk(KERN_ERR "sock_release: fasync list not empty!\n"); @@ -1058,11 +1063,12 @@ int sock_create(int family, int type, int protocol, struct socket **res) sock->type = type; + i = -EBUSY; + if (!try_module_get(net_families[family]->owner)) + goto out_release; + if ((i = net_families[family]->create(sock, protocol)) < 0) - { - sock_release(sock); - goto out; - } + goto out_release; *res = sock; security_socket_post_create(sock, family, type, protocol); @@ -1070,6 +1076,9 @@ int sock_create(int family, int type, int protocol, struct socket **res) out: net_family_read_unlock(); return i; +out_release: + sock_release(sock); + goto out; } asmlinkage long sys_socket(int family, int type, int protocol) -- 2.53.0