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