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/socket.h>
32 #include <linux/in.h>
33 #include "inet.h"
34 #include "devinet.h"
35 #include "ip.h"
36 #include "protocol.h"
37 #include "tcp.h"
38 #include "socket/skbuff.h"
39 #include "sockinet.h"
40 #include "icmp.h"
41 #include "udp.h"
42
43
44 static struct inet_protocol tcp_protocol =
45 {
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 {
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 {
72 icmp_rcv,
73 NULL,
74 NULL,
75 &udp_protocol,
76 IPPROTO_ICMP,
77 0,
78 NULL,
79 "ICMP"
80 };
81
82
83 struct inet_protocol *inet_protocol_base = &icmp_protocol;
84
85 struct inet_protocol *inet_protos[MAX_INET_PROTOS] =
86 {
87 NULL
88 };
89
90
91 struct inet_protocol *inet_get_protocol(unsigned char prot)
92 {
93 unsigned char hash;
94 struct inet_protocol *p;
95
96 DPRINTF((DBG_PROTO, "get_protocol (%d)\n ", prot));
97 hash = prot & (MAX_INET_PROTOS - 1);
98 for (p = inet_protos[hash] ; p != NULL; p=p->next)
99 {
100 DPRINTF((DBG_PROTO, "trying protocol %d\n", p->protocol));
101 if (p->protocol == prot)
102 return((struct inet_protocol *) p);
103 }
104 return(NULL);
105 }
106
107
108 void inet_add_protocol(struct inet_protocol *prot)
109 {
110 unsigned char hash;
111 struct inet_protocol *p2;
112
113 hash = prot->protocol & (MAX_INET_PROTOS - 1);
114 prot ->next = inet_protos[hash];
115 inet_protos[hash] = prot;
116 prot->copy = 0;
117
118
119 p2 = (struct inet_protocol *) prot->next;
120 while(p2 != NULL)
121 {
122 if (p2->protocol == prot->protocol)
123 {
124 prot->copy = 1;
125 break;
126 }
127 p2 = (struct inet_protocol *) prot->next;
128 }
129 }
130
131
132 int inet_del_protocol(struct inet_protocol *prot)
133 {
134 struct inet_protocol *p;
135 struct inet_protocol *lp = NULL;
136 unsigned char hash;
137
138 hash = prot->protocol & (MAX_INET_PROTOS - 1);
139 if (prot == inet_protos[hash])
140 {
141 inet_protos[hash] = (struct inet_protocol *) inet_protos[hash]->next;
142 return(0);
143 }
144
145 p = (struct inet_protocol *) inet_protos[hash];
146 while(p != NULL)
147 {
148
149
150
151
152
153 if (p->next != NULL && p->next == prot)
154 {
155
156
157
158
159 if (p->copy == 0 && lp != NULL)
160 lp->copy = 0;
161 p->next = prot->next;
162 return(0);
163 }
164
165 if (p->next != NULL && p->next->protocol == prot->protocol)
166 {
167 lp = p;
168 }
169
170 p = (struct inet_protocol *) p->next;
171 }
172 return(-1);
173 }