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