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