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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [net/] [tcpip/] [v2_0/] [src/] [sys/] [net/] [raw_usrreq.c] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//      sys/net/raw_usrreq.c
4
//
5
//     
6
//
7
//==========================================================================
8
//####BSDCOPYRIGHTBEGIN####
9
//
10
// -------------------------------------------
11
//
12
// Portions of this software may have been derived from OpenBSD or other sources,
13
// and are covered by the appropriate copyright disclaimers included herein.
14
//
15
// -------------------------------------------
16
//
17
//####BSDCOPYRIGHTEND####
18
//==========================================================================
19
//#####DESCRIPTIONBEGIN####
20
//
21
// Author(s):    gthomas
22
// Contributors: gthomas
23
// Date:         2000-01-10
24
// Purpose:      
25
// Description:  
26
//              
27
//
28
//####DESCRIPTIONEND####
29
//
30
//==========================================================================
31
 
32
 
33
/*      $OpenBSD: raw_usrreq.c,v 1.3 1998/09/17 12:29:55 deraadt Exp $  */
34
/*      $NetBSD: raw_usrreq.c,v 1.11 1996/02/13 22:00:43 christos Exp $ */
35
 
36
/*
37
 * Copyright (c) 1980, 1986, 1993
38
 *      The Regents of the University of California.  All rights reserved.
39
 *
40
 * Redistribution and use in source and binary forms, with or without
41
 * modification, are permitted provided that the following conditions
42
 * are met:
43
 * 1. Redistributions of source code must retain the above copyright
44
 *    notice, this list of conditions and the following disclaimer.
45
 * 2. Redistributions in binary form must reproduce the above copyright
46
 *    notice, this list of conditions and the following disclaimer in the
47
 *    documentation and/or other materials provided with the distribution.
48
 * 3. All advertising materials mentioning features or use of this software
49
 *    must display the following acknowledgement:
50
 *      This product includes software developed by the University of
51
 *      California, Berkeley and its contributors.
52
 * 4. Neither the name of the University nor the names of its contributors
53
 *    may be used to endorse or promote products derived from this software
54
 *    without specific prior written permission.
55
 *
56
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
57
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
58
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
59
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
60
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
61
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
62
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
64
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
65
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
66
 * SUCH DAMAGE.
67
 *
68
 *      @(#)raw_usrreq.c        8.1 (Berkeley) 6/10/93
69
 */
70
 
71
#include <sys/param.h>
72
#include <sys/mbuf.h>
73
#include <sys/domain.h>
74
#include <sys/protosw.h>
75
#include <sys/socket.h>
76
#include <sys/socketvar.h>
77
#include <sys/errno.h>
78
#ifndef __ECOS
79
#include <sys/systm.h>
80
#endif
81
 
82
#include <net/if.h>
83
#include <net/route.h>
84
#include <net/netisr.h>
85
#include <net/raw_cb.h>
86
 
87
#include <machine/stdarg.h>
88
/*
89
 * Initialize raw connection block q.
90
 */
91
void
92
raw_init()
93
{
94
 
95
        LIST_INIT(&rawcb);
96
}
97
 
98
 
99
/*
100
 * Raw protocol input routine.  Find the socket
101
 * associated with the packet(s) and move them over.  If
102
 * nothing exists for this packet, drop it.
103
 */
104
/*
105
 * Raw protocol interface.
106
 */
107
void
108
#if __STDC__
109
raw_input(struct mbuf *m0, ...)
110
#else
111
raw_input(m0, va_alist)
112
        struct mbuf *m0;
113
        va_dcl
114
#endif
115
{
116
        register struct rawcb *rp;
117
        register struct mbuf *m = m0;
118
        register int sockets = 0;
119
        struct socket *last;
120
        va_list ap;
121
        register struct sockproto *proto;
122
        struct sockaddr *src, *dst;
123
 
124
        va_start(ap, m0);
125
        proto = va_arg(ap, struct sockproto *);
126
        src = va_arg(ap, struct sockaddr *);
127
        dst = va_arg(ap, struct sockaddr *);
128
        va_end(ap);
129
 
130
        last = 0;
131
        for (rp = rawcb.lh_first; rp != 0; rp = rp->rcb_list.le_next) {
132
                if (rp->rcb_proto.sp_family != proto->sp_family)
133
                        continue;
134
                if (rp->rcb_proto.sp_protocol  &&
135
                    rp->rcb_proto.sp_protocol != proto->sp_protocol)
136
                        continue;
137
                /*
138
                 * We assume the lower level routines have
139
                 * placed the address in a canonical format
140
                 * suitable for a structure comparison.
141
                 *
142
                 * Note that if the lengths are not the same
143
                 * the comparison will fail at the first byte.
144
                 */
145
#define equal(a1, a2) \
146
  (bcmp((caddr_t)(a1), (caddr_t)(a2), a1->sa_len) == 0)
147
                if (rp->rcb_laddr && !equal(rp->rcb_laddr, dst))
148
                        continue;
149
                if (rp->rcb_faddr && !equal(rp->rcb_faddr, src))
150
                        continue;
151
                if (last) {
152
                        struct mbuf *n;
153
                        if ((n = m_copy(m, 0, (int)M_COPYALL)) != NULL) {
154
                                if (sbappendaddr(&last->so_rcv, src,
155
                                    n, (struct mbuf *)0) == 0)
156
                                        /* should notify about lost packet */
157
                                        m_freem(n);
158
                                else {
159
                                        sorwakeup(last);
160
                                        sockets++;
161
                                }
162
                        }
163
                }
164
                last = rp->rcb_socket;
165
        }
166
        if (last) {
167
                if (sbappendaddr(&last->so_rcv, src,
168
                    m, (struct mbuf *)0) == 0)
169
                        m_freem(m);
170
                else {
171
                        sorwakeup(last);
172
                        sockets++;
173
                }
174
        } else
175
                m_freem(m);
176
}
177
 
178
/*ARGSUSED*/
179
void *
180
raw_ctlinput(cmd, arg, d)
181
        int cmd;
182
        struct sockaddr *arg;
183
        void *d;
184
{
185
 
186
        if (cmd < 0 || cmd > PRC_NCMDS)
187
                return NULL;
188
        return NULL;
189
        /* INCOMPLETE */
190
}
191
 
192
/*ARGSUSED*/
193
int
194
raw_usrreq(so, req, m, nam, control)
195
        struct socket *so;
196
        int req;
197
        struct mbuf *m, *nam, *control;
198
{
199
        register struct rawcb *rp = sotorawcb(so);
200
        register int error = 0;
201
        int len;
202
 
203
        if (req == PRU_CONTROL)
204
                return (EOPNOTSUPP);
205
        if (control && control->m_len) {
206
                error = EOPNOTSUPP;
207
                goto release;
208
        }
209
        if (rp == 0) {
210
                error = EINVAL;
211
                goto release;
212
        }
213
        switch (req) {
214
 
215
        /*
216
         * Allocate a raw control block and fill in the
217
         * necessary info to allow packets to be routed to
218
         * the appropriate raw interface routine.
219
         */
220
        case PRU_ATTACH:
221
#ifndef __ECOS
222
                if ((so->so_state & SS_PRIV) == 0) {
223
                        error = EACCES;
224
                        break;
225
                }
226
#endif
227
                error = raw_attach(so, (int)(long)nam);
228
                break;
229
 
230
        /*
231
         * Destroy state just before socket deallocation.
232
         * Flush data or not depending on the options.
233
         */
234
        case PRU_DETACH:
235
                if (rp == 0) {
236
                        error = ENOTCONN;
237
                        break;
238
                }
239
                raw_detach(rp);
240
                break;
241
 
242
#ifdef notdef
243
        /*
244
         * If a socket isn't bound to a single address,
245
         * the raw input routine will hand it anything
246
         * within that protocol family (assuming there's
247
         * nothing else around it should go to).
248
         */
249
        case PRU_CONNECT:
250
                if (rp->rcb_faddr) {
251
                        error = EISCONN;
252
                        break;
253
                }
254
                nam = m_copym(nam, 0, M_COPYALL, M_WAIT);
255
                rp->rcb_faddr = mtod(nam, struct sockaddr *);
256
                soisconnected(so);
257
                break;
258
 
259
        case PRU_BIND:
260
                if (rp->rcb_laddr) {
261
                        error = EINVAL;                 /* XXX */
262
                        break;
263
                }
264
                error = raw_bind(so, nam);
265
                break;
266
#else
267
        case PRU_CONNECT:
268
        case PRU_BIND:
269
#endif
270
        case PRU_CONNECT2:
271
                error = EOPNOTSUPP;
272
                goto release;
273
 
274
        case PRU_DISCONNECT:
275
                if (rp->rcb_faddr == 0) {
276
                        error = ENOTCONN;
277
                        break;
278
                }
279
                raw_disconnect(rp);
280
                soisdisconnected(so);
281
                break;
282
 
283
        /*
284
         * Mark the connection as being incapable of further input.
285
         */
286
        case PRU_SHUTDOWN:
287
                socantsendmore(so);
288
                break;
289
 
290
        /*
291
         * Ship a packet out.  The appropriate raw output
292
         * routine handles any massaging necessary.
293
         */
294
        case PRU_SEND:
295
                if (nam) {
296
                        if (rp->rcb_faddr) {
297
                                error = EISCONN;
298
                                break;
299
                        }
300
                        rp->rcb_faddr = mtod(nam, struct sockaddr *);
301
                } else if (rp->rcb_faddr == 0) {
302
                        error = ENOTCONN;
303
                        break;
304
                }
305
                error = (*so->so_proto->pr_output)(m, so);
306
                m = NULL;
307
                if (nam)
308
                        rp->rcb_faddr = 0;
309
                break;
310
 
311
        case PRU_ABORT:
312
                raw_disconnect(rp);
313
                sofree(so);
314
                soisdisconnected(so);
315
                break;
316
 
317
        case PRU_SENSE:
318
                /*
319
                 * stat: don't bother with a blocksize.
320
                 */
321
                return (0);
322
 
323
        /*
324
         * Not supported.
325
         */
326
        case PRU_RCVOOB:
327
        case PRU_RCVD:
328
                return(EOPNOTSUPP);
329
 
330
        case PRU_LISTEN:
331
        case PRU_ACCEPT:
332
        case PRU_SENDOOB:
333
                error = EOPNOTSUPP;
334
                break;
335
 
336
        case PRU_SOCKADDR:
337
                if (rp->rcb_laddr == 0) {
338
                        error = EINVAL;
339
                        break;
340
                }
341
                len = rp->rcb_laddr->sa_len;
342
                bcopy((caddr_t)rp->rcb_laddr, mtod(nam, caddr_t), (unsigned)len);
343
                nam->m_len = len;
344
                break;
345
 
346
        case PRU_PEERADDR:
347
                if (rp->rcb_faddr == 0) {
348
                        error = ENOTCONN;
349
                        break;
350
                }
351
                len = rp->rcb_faddr->sa_len;
352
                bcopy((caddr_t)rp->rcb_faddr, mtod(nam, caddr_t), (unsigned)len);
353
                nam->m_len = len;
354
                break;
355
 
356
        default:
357
                panic("raw_usrreq");
358
        }
359
release:
360
        if (m != NULL)
361
                m_freem(m);
362
        return (error);
363
}

powered by: WebSVN 2.1.0

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