2 * INET An implementation of the TCP/IP protocol suite for the LINUX
3 * operating system. INET is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
6 * INET protocol dispatch tables.
8 * Version: $Id: protocol.c,v 1.14 2001/05/18 02:25:49 davem Exp $
10 * Authors: Ross Biro, <bir7@leland.Stanford.Edu>
11 * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
14 * Alan Cox : Ahah! udp icmp errors don't work because
15 * udp_err is never called!
16 * Alan Cox : Added new fields for init and ready for
17 * proper fragmentation (_NO_ 4K limits!)
18 * Richard Colella : Hang on hash collision
19 * Vince Laviano : Modified inet_del_protocol() to correctly
22 * This program is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU General Public License
24 * as published by the Free Software Foundation; either version
25 * 2 of the License, or (at your option) any later version.
28 #include <asm/uaccess.h>
29 #include <asm/system.h>
30 #include <linux/types.h>
31 #include <linux/kernel.h>
32 #include <linux/sched.h>
33 #include <linux/string.h>
34 #include <linux/config.h>
35 #include <linux/socket.h>
37 #include <linux/inet.h>
38 #include <linux/netdevice.h>
39 #include <linux/timer.h>
40 #include <linux/brlock.h>
42 #include <net/protocol.h>
44 #include <linux/skbuff.h>
49 #include <linux/igmp.h>
51 #define IPPROTO_PREVIOUS NULL
53 #ifdef CONFIG_IP_MULTICAST
55 static struct inet_protocol igmp_protocol = {
57 next: IPPROTO_PREVIOUS,
58 protocol: IPPROTO_IGMP,
62 #undef IPPROTO_PREVIOUS
63 #define IPPROTO_PREVIOUS &igmp_protocol
67 static struct inet_protocol tcp_protocol = {
69 err_handler: tcp_v4_err,
70 next: IPPROTO_PREVIOUS,
71 protocol: IPPROTO_TCP,
75 #undef IPPROTO_PREVIOUS
76 #define IPPROTO_PREVIOUS &tcp_protocol
78 static struct inet_protocol udp_protocol = {
81 next: IPPROTO_PREVIOUS,
82 protocol: IPPROTO_UDP,
86 #undef IPPROTO_PREVIOUS
87 #define IPPROTO_PREVIOUS &udp_protocol
89 static struct inet_protocol icmp_protocol = {
91 next: IPPROTO_PREVIOUS,
92 protocol: IPPROTO_ICMP,
96 #undef IPPROTO_PREVIOUS
97 #define IPPROTO_PREVIOUS &icmp_protocol
100 struct inet_protocol *inet_protocol_base = IPPROTO_PREVIOUS;
102 struct inet_protocol *inet_protos[MAX_INET_PROTOS];
105 * Add a protocol handler to the hash tables
108 void inet_add_protocol(struct inet_protocol *prot)
111 struct inet_protocol *p2;
113 hash = prot->protocol & (MAX_INET_PROTOS - 1);
114 br_write_lock_bh(BR_NETPROTO_LOCK);
115 prot ->next = inet_protos[hash];
116 inet_protos[hash] = prot;
120 * Set the copy bit if we need to.
123 p2 = (struct inet_protocol *) prot->next;
125 if (p2->protocol == prot->protocol) {
129 p2 = (struct inet_protocol *) p2->next;
131 br_write_unlock_bh(BR_NETPROTO_LOCK);
135 * Remove a protocol from the hash tables.
138 int inet_del_protocol(struct inet_protocol *prot)
140 struct inet_protocol *p;
141 struct inet_protocol *lp = NULL;
144 hash = prot->protocol & (MAX_INET_PROTOS - 1);
145 br_write_lock_bh(BR_NETPROTO_LOCK);
146 if (prot == inet_protos[hash]) {
147 inet_protos[hash] = (struct inet_protocol *) inet_protos[hash]->next;
148 br_write_unlock_bh(BR_NETPROTO_LOCK);
152 p = (struct inet_protocol *) inet_protos[hash];
154 if (p != NULL && p->protocol == prot->protocol)
159 * We have to worry if the protocol being deleted is
160 * the last one on the list, then we may need to reset
161 * someone's copied bit.
163 if (p->next && p->next == prot) {
165 * if we are the last one with this protocol and
166 * there is a previous one, reset its copy bit.
168 if (prot->copy == 0 && lp != NULL)
170 p->next = prot->next;
171 br_write_unlock_bh(BR_NETPROTO_LOCK);
174 if (p->next != NULL && p->next->protocol == prot->protocol)
177 p = (struct inet_protocol *) p->next;
179 br_write_unlock_bh(BR_NETPROTO_LOCK);