patch-2.3.15 linux/net/ipv4/protocol.c

Next file: linux/net/ipv4/rarp.c
Previous file: linux/net/ipv4/ipmr.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.3.14/linux/net/ipv4/protocol.c linux/net/ipv4/protocol.c
@@ -5,7 +5,7 @@
  *
  *		INET protocol dispatch tables.
  *
- * Version:	$Id: protocol.c,v 1.9 1997/10/29 20:27:34 kuznet Exp $
+ * Version:	$Id: protocol.c,v 1.10 1999/08/20 11:05:55 davem Exp $
  *
  * Authors:	Ross Biro, <bir7@leland.Stanford.Edu>
  *		Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
@@ -116,25 +116,7 @@
 	NULL
 };
 
-
-/*
- *	Find a protocol in the protocol tables given its
- *	IP type.
- */
-
-struct inet_protocol *inet_get_protocol(unsigned char prot)
-{
-	unsigned char hash;
-	struct inet_protocol *p;
-
-	hash = prot & (MAX_INET_PROTOS - 1);
-	for (p = inet_protos[hash] ; p != NULL; p=p->next) 
-	{
-		if (p->protocol == prot) 
-			return((struct inet_protocol *) p);
-	}
-	return(NULL);
-}
+rwlock_t inet_protocol_lock = RW_LOCK_UNLOCKED;
 
 /*
  *	Add a protocol handler to the hash tables
@@ -146,6 +128,7 @@
 	struct inet_protocol *p2;
 
 	hash = prot->protocol & (MAX_INET_PROTOS - 1);
+	write_lock_bh(&inet_protocol_lock);
 	prot ->next = inet_protos[hash];
 	inet_protos[hash] = prot;
 	prot->copy = 0;
@@ -164,6 +147,7 @@
 		}
 		p2 = (struct inet_protocol *) p2->next;
 	}
+	write_unlock_bh(&inet_protocol_lock);
 }
 
 /*
@@ -177,9 +161,11 @@
 	unsigned char hash;
 
 	hash = prot->protocol & (MAX_INET_PROTOS - 1);
+	write_lock_bh(&inet_protocol_lock);
 	if (prot == inet_protos[hash]) 
 	{
 		inet_protos[hash] = (struct inet_protocol *) inet_protos[hash]->next;
+		write_unlock_bh(&inet_protocol_lock);
 		return(0);
 	}
 
@@ -200,6 +186,7 @@
 			if (p->copy == 0 && lp != NULL) 
 				lp->copy = 0;
 			p->next = prot->next;
+			write_unlock_bh(&inet_protocol_lock);
 			return(0);
 		}
 		if (p->next != NULL && p->next->protocol == prot->protocol) 
@@ -207,5 +194,6 @@
 
 		p = (struct inet_protocol *) p->next;
 	}
+	write_unlock_bh(&inet_protocol_lock);
 	return(-1);
 }

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)