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