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