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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [net/] [bsd_tcpip/] [current/] [src/] [sys/] [kern/] [uipc_domain.c] - Blame information for rev 838

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

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      src/sys/kern/uipc_domain.c
4
//
5
//==========================================================================
6
// ####BSDCOPYRIGHTBEGIN####                                    
7
// -------------------------------------------                  
8
// This file is part of eCos, the Embedded Configurable Operating System.
9
//
10
// Portions of this software may have been derived from FreeBSD 
11
// or other sources, and if so are covered by the appropriate copyright
12
// and license included herein.                                 
13
//
14
// Portions created by the Free Software Foundation are         
15
// Copyright (C) 2002 Free Software Foundation, Inc.            
16
// -------------------------------------------                  
17
// ####BSDCOPYRIGHTEND####                                      
18
//==========================================================================
19
 
20
/*
21
 * Copyright (c) 1982, 1986, 1993
22
 *      The Regents of the University of California.  All rights reserved.
23
 *
24
 * Redistribution and use in source and binary forms, with or without
25
 * modification, are permitted provided that the following conditions
26
 * are met:
27
 * 1. Redistributions of source code must retain the above copyright
28
 *    notice, this list of conditions and the following disclaimer.
29
 * 2. Redistributions in binary form must reproduce the above copyright
30
 *    notice, this list of conditions and the following disclaimer in the
31
 *    documentation and/or other materials provided with the distribution.
32
 * 3. All advertising materials mentioning features or use of this software
33
 *    must display the following acknowledgement:
34
 *      This product includes software developed by the University of
35
 *      California, Berkeley and its contributors.
36
 * 4. Neither the name of the University nor the names of its contributors
37
 *    may be used to endorse or promote products derived from this software
38
 *    without specific prior written permission.
39
 *
40
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
41
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
44
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50
 * SUCH DAMAGE.
51
 *
52
 *      @(#)uipc_domain.c       8.2 (Berkeley) 10/18/93
53
 * $FreeBSD: src/sys/kern/uipc_domain.c,v 1.22.2.1 2001/07/03 11:01:37 ume Exp $
54
 */
55
 
56
#include <sys/param.h>
57
#include <sys/socket.h>
58
#include <sys/protosw.h>
59
#include <sys/domain.h>
60
#include <sys/mbuf.h>
61
#include <sys/socketvar.h>
62
 
63
/*
64
 * System initialization
65
 *
66
 * Note: domain initialization wants to take place on a per domain basis
67
 * as a result of traversing a linker set.  Most likely, each domain
68
 * want to call a registration function rather than being handled here
69
 * in domaininit().  Probably this will look like:
70
 *
71
 * SYSINIT(unique, SI_SUB_PROTO_DOMAIN, SI_ORDER_ANY, domain_add, xxx)
72
 *
73
 * Where 'xxx' is replaced by the address of a parameter struct to be
74
 * passed to the doamin_add() function.
75
 */
76
 
77
static void domaininit __P((void *));
78
SYSINIT(domain, SI_SUB_PROTO_DOMAIN, SI_ORDER_FIRST, domaininit, NULL)
79
 
80
static void     pffasttimo __P((void *));
81
static void     pfslowtimo __P((void *));
82
 
83
struct domain *domains;
84
 
85
/*
86
 * Add a new protocol domain to the list of supported domains
87
 * Note: you cant unload it again because  a socket may be using it.
88
 * XXX can't fail at this time.
89
 */
90
static void
91
net_init_domain(struct domain *dp)
92
{
93
        register struct protosw *pr;
94
        int     s;
95
 
96
        s = splnet();
97
        log(LOG_INIT, "New domain %s at %p\n", dp->dom_name, dp->dom_init);
98
        if (dp->dom_init)
99
                (*dp->dom_init)();
100
        for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++){
101
                if (pr->pr_usrreqs == 0)
102
                        panic("domaininit: %ssw[%d] has no usrreqs!",
103
                              dp->dom_name,
104
                              (int)(pr - dp->dom_protosw));
105
                if (pr->pr_init)
106
                        (*pr->pr_init)();
107
        }
108
        /*
109
         * update global informatio about maximums
110
         */
111
        max_hdr = max_linkhdr + max_protohdr;
112
        max_datalen = MHLEN - max_hdr;
113
        splx(s);
114
}
115
 
116
/*
117
 * Add a new protocol domain to the list of supported domains
118
 * Note: you cant unload it again because  a socket may be using it.
119
 * XXX can't fail at this time.
120
 */
121
void
122
net_add_domain(void *data)
123
{
124
        int     s;
125
        struct domain *dp;
126
 
127
        dp = (struct domain *)data;
128
        s = splnet();
129
        dp->dom_next = domains;
130
        domains = dp;
131
        splx(s);
132
        net_init_domain(dp);
133
}
134
 
135
/* ARGSUSED*/
136
static void
137
domaininit(void *dummy)
138
{
139
        /*
140
         * Before we do any setup, make sure to initialize the
141
         * zone allocator we get struct sockets from.  The obvious
142
         * maximum number of sockets is `maxfiles', but it is possible
143
         * to have a socket without an open file (e.g., a connection waiting
144
         * to be accept(2)ed).  Rather than think up and define a
145
         * better value, we just use nmbclusters, since that's what people
146
         * are told to increase first when the network runs out of memory.
147
         * Perhaps we should have two pools, one of unlimited size
148
         * for use during socreate(), and one ZONE_INTERRUPT pool for
149
         * use in sonewconn().
150
         */
151
        socket_zone = zinit("socket", sizeof(struct socket), maxsockets,
152
                            ZONE_INTERRUPT, 0);
153
 
154
        if (max_linkhdr < 16)           /* XXX */
155
                max_linkhdr = 16;
156
 
157
        timeout(pffasttimo, (void *)0, 1);
158
        timeout(pfslowtimo, (void *)0, 1);
159
}
160
 
161
 
162
struct protosw *
163
pffindtype(family, type)
164
        int family;
165
        int type;
166
{
167
        register struct domain *dp;
168
        register struct protosw *pr;
169
 
170
        for (dp = domains; dp; dp = dp->dom_next)
171
                if (dp->dom_family == family)
172
                        goto found;
173
        return (0);
174
found:
175
        for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
176
                if (pr->pr_type && pr->pr_type == type)
177
                        return (pr);
178
        return (0);
179
}
180
 
181
struct protosw *
182
pffindproto(family, protocol, type)
183
        int family;
184
        int protocol;
185
        int type;
186
{
187
        register struct domain *dp;
188
        register struct protosw *pr;
189
        struct protosw *maybe = 0;
190
 
191
        if (family == 0)
192
                return (0);
193
        for (dp = domains; dp; dp = dp->dom_next)
194
                if (dp->dom_family == family)
195
                        goto found;
196
        return (0);
197
found:
198
        for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
199
                if ((pr->pr_protocol == protocol) && (pr->pr_type == type))
200
                        return (pr);
201
 
202
                if (type == SOCK_RAW && pr->pr_type == SOCK_RAW &&
203
                    pr->pr_protocol == 0 && maybe == (struct protosw *)0)
204
                        maybe = pr;
205
        }
206
        return (maybe);
207
}
208
 
209
void
210
pfctlinput(cmd, sa)
211
        int cmd;
212
        struct sockaddr *sa;
213
{
214
        register struct domain *dp;
215
        register struct protosw *pr;
216
 
217
        for (dp = domains; dp; dp = dp->dom_next)
218
                for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
219
                        if (pr->pr_ctlinput)
220
                                (*pr->pr_ctlinput)(cmd, sa, (void *)0);
221
}
222
 
223
void
224
pfctlinput2(cmd, sa, ctlparam)
225
        int cmd;
226
        struct sockaddr *sa;
227
        void *ctlparam;
228
{
229
        struct domain *dp;
230
        struct protosw *pr;
231
 
232
        if (!sa)
233
                return;
234
        for (dp = domains; dp; dp = dp->dom_next) {
235
                /*
236
                 * the check must be made by xx_ctlinput() anyways, to
237
                 * make sure we use data item pointed to by ctlparam in
238
                 * correct way.  the following check is made just for safety.
239
                 */
240
                if (dp->dom_family != sa->sa_family)
241
                        continue;
242
 
243
                for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
244
                        if (pr->pr_ctlinput)
245
                                (*pr->pr_ctlinput)(cmd, sa, ctlparam);
246
        }
247
}
248
 
249
static void
250
pfslowtimo(arg)
251
        void *arg;
252
{
253
        register struct domain *dp;
254
        register struct protosw *pr;
255
 
256
        for (dp = domains; dp; dp = dp->dom_next)
257
                for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
258
                        if (pr->pr_slowtimo)
259
                                (*pr->pr_slowtimo)();
260
        timeout(pfslowtimo, (void *)0, hz/2);
261
}
262
 
263
static void
264
pffasttimo(arg)
265
        void *arg;
266
{
267
        register struct domain *dp;
268
        register struct protosw *pr;
269
 
270
        for (dp = domains; dp; dp = dp->dom_next)
271
                for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
272
                        if (pr->pr_fasttimo)
273
                                (*pr->pr_fasttimo)();
274
        timeout(pffasttimo, (void *)0, hz/5);
275
}

powered by: WebSVN 2.1.0

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