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