patch-1.3.82 linux/net/core/sock.c

Next file: linux/net/core/sysctl_net_core.c
Previous file: linux/net/core/skbuff.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v1.3.81/linux/net/core/sock.c linux/net/core/sock.c
@@ -68,6 +68,8 @@
  *		Alan Cox	:	Allocator for a socket is settable.
  *		Alan Cox	:	SO_ERROR includes soft errors.
  *		Alan Cox	:	Allow NULL arguments on some SO_ opts
+ *		Alan Cox	: 	Generic socket allocation to make hooks
+ *					easier (suggested by Craig Metz).
  *
  * To Fix:
  *
@@ -324,6 +326,21 @@
   	return(0);
 }
 
+struct sock *sk_alloc(int priority)
+{
+	struct sock *sk=(struct sock *)kmalloc(sizeof(*sk), priority);
+	if(!sk)
+		return NULL;
+	memset(sk, 0, sizeof(*sk));
+	return sk;
+}
+
+void sk_free(struct sock *sk)
+{
+	kfree_s(sk,sizeof(*sk));
+}
+
+
 struct sk_buff *sock_wmalloc(struct sock *sk, unsigned long size, int force, int priority)
 {
 	if (sk) {
@@ -393,9 +410,9 @@
 	kfree_skbmem(skb);
 	if (sk) 
 	{
-		atomic_sub(s, &sk->wmem_alloc);
 		/* In case it might be waiting for more memory. */
 		sk->write_space(sk);
+		atomic_sub(s, &sk->wmem_alloc);
 	}
 }
 

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov with Sam's (original) version
of this