OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [net/] [ipv4/] [protocol.c] - Blame information for rev 1772

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1629 jcastillo
/*
2
 * INET         An implementation of the TCP/IP protocol suite for the LINUX
3
 *              operating system.  INET is implemented using the  BSD Socket
4
 *              interface as the means of communication with the user level.
5
 *
6
 *              INET protocol dispatch tables.
7
 *
8
 * Version:     @(#)protocol.c  1.0.5   05/25/93
9
 *
10
 * Authors:     Ross Biro, <bir7@leland.Stanford.Edu>
11
 *              Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
12
 *
13
 * Fixes:
14
 *              Alan Cox        : Ahah! udp icmp errors don't work because
15
 *                                udp_err is never called!
16
 *              Alan Cox        : Added new fields for init and ready for
17
 *                                proper fragmentation (_NO_ 4K limits!)
18
 *              Richard Colella : Hang on hash collision
19
 *
20
 *              This program is free software; you can redistribute it and/or
21
 *              modify it under the terms of the GNU General Public License
22
 *              as published by the Free Software Foundation; either version
23
 *              2 of the License, or (at your option) any later version.
24
 */
25
 
26
#include <asm/segment.h>
27
#include <asm/system.h>
28
#include <linux/types.h>
29
#include <linux/kernel.h>
30
#include <linux/sched.h>
31
#include <linux/string.h>
32
#include <linux/config.h>
33
#include <linux/socket.h>
34
#include <linux/in.h>
35
#include <linux/inet.h>
36
#include <linux/netdevice.h>
37
#include <linux/timer.h>
38
#include <net/ip.h>
39
#include <net/protocol.h>
40
#include <net/tcp.h>
41
#include <linux/skbuff.h>
42
#include <net/sock.h>
43
#include <net/icmp.h>
44
#include <net/udp.h>
45
#include <net/ipip.h>
46
#include <linux/igmp.h>
47
 
48
 
49
#ifdef CONFIG_NET_IPIP
50
 
51
static struct inet_protocol ipip_protocol =
52
{
53
        ipip_rcv,             /* IPIP handler          */
54
        NULL,                 /* TUNNEL error control    */
55
        0,                    /* next                 */
56
        IPPROTO_IPIP,         /* protocol ID          */
57
        0,                    /* copy                 */
58
        NULL,                 /* data                 */
59
        "IPIP"                /* name                 */
60
};
61
 
62
 
63
#endif
64
 
65
static struct inet_protocol tcp_protocol =
66
{
67
        tcp_rcv,                /* TCP handler          */
68
        tcp_err,                /* TCP error control    */
69
#if defined(CONFIG_NET_IPIP)
70
        &ipip_protocol,
71
#else  
72
        NULL,                   /* next                 */
73
#endif  
74
        IPPROTO_TCP,            /* protocol ID          */
75
        0,                       /* copy                 */
76
        NULL,                   /* data                 */
77
        "TCP"                   /* name                 */
78
};
79
 
80
 
81
static struct inet_protocol udp_protocol =
82
{
83
        udp_rcv,                /* UDP handler          */
84
        udp_err,                /* UDP error control    */
85
        &tcp_protocol,          /* next                 */
86
        IPPROTO_UDP,            /* protocol ID          */
87
        0,                       /* copy                 */
88
        NULL,                   /* data                 */
89
        "UDP"                   /* name                 */
90
};
91
 
92
 
93
static struct inet_protocol icmp_protocol =
94
{
95
        icmp_rcv,               /* ICMP handler         */
96
        NULL,                   /* ICMP error control   */
97
        &udp_protocol,          /* next                 */
98
        IPPROTO_ICMP,           /* protocol ID          */
99
        0,                       /* copy                 */
100
        NULL,                   /* data                 */
101
        "ICMP"                  /* name                 */
102
};
103
 
104
#ifndef CONFIG_IP_MULTICAST
105
struct inet_protocol *inet_protocol_base = &icmp_protocol;
106
#else
107
static struct inet_protocol igmp_protocol =
108
{
109
        igmp_rcv,               /* IGMP handler         */
110
        NULL,                   /* IGMP error control   */
111
        &icmp_protocol,         /* next                 */
112
        IPPROTO_IGMP,           /* protocol ID          */
113
        0,                       /* copy                 */
114
        NULL,                   /* data                 */
115
        "IGMP"                  /* name                 */
116
};
117
 
118
struct inet_protocol *inet_protocol_base = &igmp_protocol;
119
#endif
120
 
121
struct inet_protocol *inet_protos[MAX_INET_PROTOS] =
122
{
123
        NULL
124
};
125
 
126
 
127
/*
128
 *      Find a protocol in the protocol tables given its
129
 *      IP type.
130
 */
131
 
132
struct inet_protocol *inet_get_protocol(unsigned char prot)
133
{
134
        unsigned char hash;
135
        struct inet_protocol *p;
136
 
137
        hash = prot & (MAX_INET_PROTOS - 1);
138
        for (p = inet_protos[hash] ; p != NULL; p=p->next)
139
        {
140
                if (p->protocol == prot)
141
                        return((struct inet_protocol *) p);
142
        }
143
        return(NULL);
144
}
145
 
146
/*
147
 *      Add a protocol handler to the hash tables
148
 */
149
 
150
void inet_add_protocol(struct inet_protocol *prot)
151
{
152
        unsigned char hash;
153
        struct inet_protocol *p2;
154
 
155
        hash = prot->protocol & (MAX_INET_PROTOS - 1);
156
        prot ->next = inet_protos[hash];
157
        inet_protos[hash] = prot;
158
        prot->copy = 0;
159
 
160
        /*
161
         *      Set the copy bit if we need to.
162
         */
163
 
164
        p2 = (struct inet_protocol *) prot->next;
165
        while(p2 != NULL)
166
        {
167
                if (p2->protocol == prot->protocol)
168
                {
169
                        prot->copy = 1;
170
                        break;
171
                }
172
                p2 = (struct inet_protocol *) p2->next;
173
        }
174
}
175
 
176
/*
177
 *      Remove a protocol from the hash tables.
178
 */
179
 
180
int inet_del_protocol(struct inet_protocol *prot)
181
{
182
        struct inet_protocol *p;
183
        struct inet_protocol *lp = NULL;
184
        unsigned char hash;
185
 
186
        hash = prot->protocol & (MAX_INET_PROTOS - 1);
187
        if (prot == inet_protos[hash])
188
        {
189
                inet_protos[hash] = (struct inet_protocol *) inet_protos[hash]->next;
190
                return(0);
191
        }
192
 
193
        p = (struct inet_protocol *) inet_protos[hash];
194
        while(p != NULL)
195
        {
196
                /*
197
                 * We have to worry if the protocol being deleted is
198
                 * the last one on the list, then we may need to reset
199
                 * someone's copied bit.
200
                 */
201
                if (p->next != NULL && p->next == prot)
202
                {
203
                        /*
204
                         * if we are the last one with this protocol and
205
                         * there is a previous one, reset its copy bit.
206
                         */
207
                        if (p->copy == 0 && lp != NULL)
208
                                lp->copy = 0;
209
                        p->next = prot->next;
210
                        return(0);
211
                }
212
                if (p->next != NULL && p->next->protocol == prot->protocol)
213
                        lp = p;
214
 
215
                p = (struct inet_protocol *) p->next;
216
        }
217
        return(-1);
218
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.