patch-2.1.102 linux/net/ipv6/ndisc.c

Next file: linux/net/ipv6/route.c
Previous file: linux/net/ipv6/mcast.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.101/linux/net/ipv6/ndisc.c linux/net/ipv6/ndisc.c
@@ -74,8 +74,7 @@
 #include <net/checksum.h>
 #include <linux/proc_fs.h>
 
-static struct inode ndisc_inode;
-static struct socket *ndisc_socket=&ndisc_inode.u.socket_i;
+static struct socket *ndisc_socket;
 
 static int ndisc_constructor(struct neighbour *neigh);
 static void ndisc_solicit(struct neighbour *neigh, struct sk_buff *skb);
@@ -1134,23 +1133,29 @@
 
 
 
-__initfunc(void ndisc_init(struct net_proto_family *ops))
+__initfunc(int ndisc_init(struct net_proto_family *ops))
 {
 	struct sock *sk;
         int err;
 
-        ndisc_inode.i_mode = S_IFSOCK;
-        ndisc_inode.i_sock = 1;
-        ndisc_inode.i_uid = 0;
-        ndisc_inode.i_gid = 0;
-
-        ndisc_socket->inode = &ndisc_inode;
-        ndisc_socket->state = SS_UNCONNECTED;
-        ndisc_socket->type  = SOCK_RAW;
+	ndisc_socket = sock_alloc();
+	if (ndisc_socket == NULL) {
+		printk(KERN_ERR
+		       "Failed to create the NDISC control socket.\n");
+		return -1;
+	}
+	ndisc_socket->inode->i_uid = 0;
+	ndisc_socket->inode->i_gid = 0;
+	ndisc_socket->type = SOCK_RAW;
 
-	if((err=ops->create(ndisc_socket, IPPROTO_ICMPV6))<0)
+	if((err = ops->create(ndisc_socket, IPPROTO_ICMPV6)) < 0) {
 		printk(KERN_DEBUG 
-		       "Failed to create the NDISC control socket.\n");
+		       "Failed to initializee the NDISC control socket (err %d).\n",
+		       err);
+		sock_release(ndisc_socket);
+		ndisc_socket = NULL; /* For safety. */
+		return err;
+	}
 
 	sk = ndisc_socket->sk;
 	sk->allocation = GFP_ATOMIC;
@@ -1174,9 +1179,10 @@
 #ifdef CONFIG_SYSCTL
 	neigh_sysctl_register(NULL, &nd_tbl.parms, NET_IPV6, NET_IPV6_NEIGH, "ipv6");
 #endif
+
+	return 0;
 }
 
-#ifdef MODULE
 void ndisc_cleanup(void)
 {
 #ifdef CONFIG_PROC_FS
@@ -1185,5 +1191,6 @@
 #endif
 #endif
 	neigh_table_clear(&nd_tbl);
+	sock_release(ndisc_socket);
+	ndisc_socket = NULL; /* For safety. */
 }
-#endif

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov