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

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

diff -u --recursive --new-file v1.3.25/linux/net/ipv4/protocol.c linux/net/ipv4/protocol.c
@@ -22,6 +22,7 @@
  *		as published by the Free Software Foundation; either version
  *		2 of the License, or (at your option) any later version.
  */
+
 #include <asm/segment.h>
 #include <asm/system.h>
 #include <linux/types.h>
@@ -48,154 +49,172 @@
 #ifdef CONFIG_IP_FORWARD
 #ifdef CONFIG_NET_IPIP
 
-static struct inet_protocol ipip_protocol = {
-  ipip_rcv,             /* IPIP handler          */
-  NULL,                 /* Will be UDP fraglist handler */
-  NULL,                 /* TUNNEL error control    */
-  0,                    /* next                 */
-  IPPROTO_IPIP,         /* protocol ID          */
-  0,                    /* copy                 */
-  NULL,                 /* data                 */
-  "IPIP"                /* name                 */
+static struct inet_protocol ipip_protocol = 
+{
+	ipip_rcv,             /* IPIP handler          */
+	NULL,                 /* TUNNEL error control    */
+	0,                    /* next                 */
+	IPPROTO_IPIP,         /* protocol ID          */
+	0,                    /* copy                 */
+	NULL,                 /* data                 */
+	"IPIP"                /* name                 */
 };
 
 
 #endif
 #endif
 
-static struct inet_protocol tcp_protocol = {
-  tcp_rcv,		/* TCP handler		*/
-  NULL,			/* No fragment handler (and won't be for a long time) */
-  tcp_err,		/* TCP error control	*/  
+static struct inet_protocol tcp_protocol = 
+{
+	tcp_rcv,		/* TCP handler		*/
+	tcp_err,		/* TCP error control	*/  
 #if defined(CONFIG_NET_IPIP) && defined(CONFIG_IP_FORWARD)
-  &ipip_protocol,
+	&ipip_protocol,
 #else  
-  NULL,			/* next			*/
+	NULL,			/* next			*/
 #endif  
-  IPPROTO_TCP,		/* protocol ID		*/
-  0,			/* copy			*/
-  NULL,			/* data			*/
-  "TCP"			/* name			*/
+	IPPROTO_TCP,		/* protocol ID		*/
+	0,			/* copy			*/
+	NULL,			/* data			*/
+	"TCP"			/* name			*/
 };
 
 
-static struct inet_protocol udp_protocol = {
-  udp_rcv,		/* UDP handler		*/
-  NULL,			/* Will be UDP fraglist handler */
-  udp_err,		/* UDP error control	*/
-  &tcp_protocol,	/* next			*/
-  IPPROTO_UDP,		/* protocol ID		*/
-  0,			/* copy			*/
-  NULL,			/* data			*/
-  "UDP"			/* name			*/
+static struct inet_protocol udp_protocol = 
+{
+	udp_rcv,		/* UDP handler		*/
+	udp_err,		/* UDP error control	*/
+	&tcp_protocol,		/* next			*/
+	IPPROTO_UDP,		/* protocol ID		*/
+	0,			/* copy			*/
+	NULL,			/* data			*/
+	"UDP"			/* name			*/
 };
 
 
-static struct inet_protocol icmp_protocol = {
-  icmp_rcv,		/* ICMP handler		*/
-  NULL,			/* ICMP never fragments anyway */
-  NULL,			/* ICMP error control	*/
-  &udp_protocol,	/* next			*/
-  IPPROTO_ICMP,		/* protocol ID		*/
-  0,			/* copy			*/
-  NULL,			/* data			*/
-  "ICMP"		/* name			*/
+static struct inet_protocol icmp_protocol = 
+{
+	icmp_rcv,		/* ICMP handler		*/
+	NULL,			/* ICMP error control	*/
+	&udp_protocol,		/* next			*/
+	IPPROTO_ICMP,		/* protocol ID		*/
+	0,			/* copy			*/
+	NULL,			/* data			*/
+	"ICMP"			/* name			*/
 };
 
 #ifndef CONFIG_IP_MULTICAST
 struct inet_protocol *inet_protocol_base = &icmp_protocol;
 #else
-static struct inet_protocol igmp_protocol = {
-  igmp_rcv,		/* IGMP handler		*/
-  NULL,			/* IGMP never fragments anyway */
-  NULL,			/* IGMP error control	*/
-  &icmp_protocol,	/* next			*/
-  IPPROTO_IGMP,		/* protocol ID		*/
-  0,			/* copy			*/
-  NULL,			/* data			*/
-  "IGMP"		/* name			*/
+static struct inet_protocol igmp_protocol = 
+{
+	igmp_rcv,		/* IGMP handler		*/
+	NULL,			/* IGMP error control	*/
+	&icmp_protocol,		/* next			*/
+	IPPROTO_IGMP,		/* protocol ID		*/
+	0,			/* copy			*/
+	NULL,			/* data			*/
+	"IGMP"			/* name			*/
 };
 
 struct inet_protocol *inet_protocol_base = &igmp_protocol;
 #endif
 
-struct inet_protocol *inet_protos[MAX_INET_PROTOS] = {
-  NULL
+struct inet_protocol *inet_protos[MAX_INET_PROTOS] = 
+{
+	NULL
 };
 
 
-struct inet_protocol *
-inet_get_protocol(unsigned char prot)
+/*
+ *	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;
+	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);
+	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);
 }
 
+/*
+ *	Add a protocol handler to the hash tables
+ */
 
-void
-inet_add_protocol(struct inet_protocol *prot)
+void inet_add_protocol(struct inet_protocol *prot)
 {
-  unsigned char hash;
-  struct inet_protocol *p2;
+	unsigned char hash;
+	struct inet_protocol *p2;
 
-  hash = prot->protocol & (MAX_INET_PROTOS - 1);
-  prot ->next = inet_protos[hash];
-  inet_protos[hash] = prot;
-  prot->copy = 0;
-
-  /* Set the copy bit if we need to. */
-  p2 = (struct inet_protocol *) prot->next;
-  while(p2 != NULL) {
-	if (p2->protocol == prot->protocol) {
-		prot->copy = 1;
-		break;
+	hash = prot->protocol & (MAX_INET_PROTOS - 1);
+	prot ->next = inet_protos[hash];
+	inet_protos[hash] = prot;
+	prot->copy = 0;
+
+	/*
+	 *	Set the copy bit if we need to. 
+	 */
+	 
+	p2 = (struct inet_protocol *) prot->next;
+	while(p2 != NULL) 
+	{
+		if (p2->protocol == prot->protocol) 
+		{
+			prot->copy = 1;
+			break;
+		}
+		p2 = (struct inet_protocol *) p2->next;
 	}
-	p2 = (struct inet_protocol *) p2->next;
-  }
 }
 
-
-int
-inet_del_protocol(struct inet_protocol *prot)
+/*
+ *	Remove a protocol from the hash tables.
+ */
+ 
+int inet_del_protocol(struct inet_protocol *prot)
 {
-  struct inet_protocol *p;
-  struct inet_protocol *lp = NULL;
-  unsigned char hash;
-
-  hash = prot->protocol & (MAX_INET_PROTOS - 1);
-  if (prot == inet_protos[hash]) {
-	inet_protos[hash] = (struct inet_protocol *) inet_protos[hash]->next;
-	return(0);
-  }
+	struct inet_protocol *p;
+	struct inet_protocol *lp = NULL;
+	unsigned char hash;
+
+	hash = prot->protocol & (MAX_INET_PROTOS - 1);
+	if (prot == inet_protos[hash]) 
+	{
+		inet_protos[hash] = (struct inet_protocol *) inet_protos[hash]->next;
+		return(0);
+	}
 
-  p = (struct inet_protocol *) inet_protos[hash];
-  while(p != NULL) {
-	/*
-	 * We have to worry if the protocol being deleted is
-	 * the last one on the list, then we may need to reset
-	 * someone's copied bit.
-	 */
-	if (p->next != NULL && p->next == prot) {
+	p = (struct inet_protocol *) inet_protos[hash];
+	while(p != NULL) 
+	{
 		/*
-		 * if we are the last one with this protocol and
-		 * there is a previous one, reset its copy bit.
+		 * We have to worry if the protocol being deleted is
+		 * the last one on the list, then we may need to reset
+		 * someone's copied bit.
 		 */
-	     if (p->copy == 0 && lp != NULL) lp->copy = 0;
-	     p->next = prot->next;
-	     return(0);
-	}
+		if (p->next != NULL && p->next == prot) 
+		{
+			/*
+			 * if we are the last one with this protocol and
+			 * there is a previous one, reset its copy bit.
+			 */
+			if (p->copy == 0 && lp != NULL) 
+				lp->copy = 0;
+			p->next = prot->next;
+			return(0);
+		}
+		if (p->next != NULL && p->next->protocol == prot->protocol) 
+			lp = p;
 
-	if (p->next != NULL && p->next->protocol == prot->protocol) {
-		lp = p;
+		p = (struct inet_protocol *) p->next;
 	}
-
-	p = (struct inet_protocol *) p->next;
-  }
-  return(-1);
+	return(-1);
 }

FUNET's LINUX-ADM group, [email protected]
TCL-scripts by Sam Shen, [email protected] with Sam's (original) version
of this