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