This source file includes following definitions.
- inet_get_protocol
- inet_add_protocol
- inet_del_protocol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 #include <asm/segment.h>
26 #include <asm/system.h>
27 #include <linux/types.h>
28 #include <linux/kernel.h>
29 #include <linux/sched.h>
30 #include <linux/string.h>
31 #include <linux/config.h>
32 #include <linux/socket.h>
33 #include <linux/in.h>
34 #include <linux/inet.h>
35 #include <linux/netdevice.h>
36 #include <linux/timer.h>
37 #include <net/ip.h>
38 #include <net/protocol.h>
39 #include <net/tcp.h>
40 #include <linux/skbuff.h>
41 #include <net/sock.h>
42 #include <net/icmp.h>
43 #include <net/udp.h>
44 #include <net/ipip.h>
45 #include <linux/igmp.h>
46
47
48 #ifdef CONFIG_IP_FORWARD
49 #ifdef CONFIG_NET_IPIP
50
51 static struct inet_protocol ipip_protocol = {
52 ipip_rcv,
53 NULL,
54 NULL,
55 0,
56 IPPROTO_IPIP,
57 0,
58 NULL,
59 "IPIP"
60 };
61
62
63 #endif
64 #endif
65
66 static struct inet_protocol tcp_protocol = {
67 tcp_rcv,
68 NULL,
69 tcp_err,
70 #if defined(CONFIG_NET_IPIP) && defined(CONFIG_IP_FORWARD)
71 &ipip_protocol,
72 #else
73 NULL,
74 #endif
75 IPPROTO_TCP,
76 0,
77 NULL,
78 "TCP"
79 };
80
81
82 static struct inet_protocol udp_protocol = {
83 udp_rcv,
84 NULL,
85 udp_err,
86 &tcp_protocol,
87 IPPROTO_UDP,
88 0,
89 NULL,
90 "UDP"
91 };
92
93
94 static struct inet_protocol icmp_protocol = {
95 icmp_rcv,
96 NULL,
97 NULL,
98 &udp_protocol,
99 IPPROTO_ICMP,
100 0,
101 NULL,
102 "ICMP"
103 };
104
105 #ifndef CONFIG_IP_MULTICAST
106 struct inet_protocol *inet_protocol_base = &icmp_protocol;
107 #else
108 static struct inet_protocol igmp_protocol = {
109 igmp_rcv,
110 NULL,
111 NULL,
112 &icmp_protocol,
113 IPPROTO_IGMP,
114 0,
115 NULL,
116 "IGMP"
117 };
118
119 struct inet_protocol *inet_protocol_base = &igmp_protocol;
120 #endif
121
122 struct inet_protocol *inet_protos[MAX_INET_PROTOS] = {
123 NULL
124 };
125
126
127 struct inet_protocol *
128 inet_get_protocol(unsigned char prot)
129 {
130 unsigned char hash;
131 struct inet_protocol *p;
132
133 hash = prot & (MAX_INET_PROTOS - 1);
134 for (p = inet_protos[hash] ; p != NULL; p=p->next) {
135 if (p->protocol == prot) return((struct inet_protocol *) p);
136 }
137 return(NULL);
138 }
139
140
141 void
142 inet_add_protocol(struct inet_protocol *prot)
143 {
144 unsigned char hash;
145 struct inet_protocol *p2;
146
147 hash = prot->protocol & (MAX_INET_PROTOS - 1);
148 prot ->next = inet_protos[hash];
149 inet_protos[hash] = prot;
150 prot->copy = 0;
151
152
153 p2 = (struct inet_protocol *) prot->next;
154 while(p2 != NULL) {
155 if (p2->protocol == prot->protocol) {
156 prot->copy = 1;
157 break;
158 }
159 p2 = (struct inet_protocol *) p2->next;
160 }
161 }
162
163
164 int
165 inet_del_protocol(struct inet_protocol *prot)
166 {
167 struct inet_protocol *p;
168 struct inet_protocol *lp = NULL;
169 unsigned char hash;
170
171 hash = prot->protocol & (MAX_INET_PROTOS - 1);
172 if (prot == inet_protos[hash]) {
173 inet_protos[hash] = (struct inet_protocol *) inet_protos[hash]->next;
174 return(0);
175 }
176
177 p = (struct inet_protocol *) inet_protos[hash];
178 while(p != NULL) {
179
180
181
182
183
184 if (p->next != NULL && p->next == prot) {
185
186
187
188
189 if (p->copy == 0 && lp != NULL) lp->copy = 0;
190 p->next = prot->next;
191 return(0);
192 }
193
194 if (p->next != NULL && p->next->protocol == prot->protocol) {
195 lp = p;
196 }
197
198 p = (struct inet_protocol *) p->next;
199 }
200 return(-1);
201 }