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 <linux/inet.h>
33 #include <linux/netdevice.h>
34 #include "ip.h"
35 #include "protocol.h"
36 #include "tcp.h"
37 #include <linux/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 hash = prot & (MAX_INET_PROTOS - 1);
92 for (p = inet_protos[hash] ; p != NULL; p=p->next) {
93 if (p->protocol == prot) return((struct inet_protocol *) p);
94 }
95 return(NULL);
96 }
97
98
99 void
100 inet_add_protocol(struct inet_protocol *prot)
101 {
102 unsigned char hash;
103 struct inet_protocol *p2;
104
105 hash = prot->protocol & (MAX_INET_PROTOS - 1);
106 prot ->next = inet_protos[hash];
107 inet_protos[hash] = prot;
108 prot->copy = 0;
109
110
111 p2 = (struct inet_protocol *) prot->next;
112 while(p2 != NULL) {
113 if (p2->protocol == prot->protocol) {
114 prot->copy = 1;
115 break;
116 }
117 p2 = (struct inet_protocol *) prot->next;
118 }
119 }
120
121
122 int
123 inet_del_protocol(struct inet_protocol *prot)
124 {
125 struct inet_protocol *p;
126 struct inet_protocol *lp = NULL;
127 unsigned char hash;
128
129 hash = prot->protocol & (MAX_INET_PROTOS - 1);
130 if (prot == inet_protos[hash]) {
131 inet_protos[hash] = (struct inet_protocol *) inet_protos[hash]->next;
132 return(0);
133 }
134
135 p = (struct inet_protocol *) inet_protos[hash];
136 while(p != NULL) {
137
138
139
140
141
142 if (p->next != NULL && p->next == prot) {
143
144
145
146
147 if (p->copy == 0 && lp != NULL) lp->copy = 0;
148 p->next = prot->next;
149 return(0);
150 }
151
152 if (p->next != NULL && p->next->protocol == prot->protocol) {
153 lp = p;
154 }
155
156 p = (struct inet_protocol *) p->next;
157 }
158 return(-1);
159 }