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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [net/] [tcpip/] [current/] [src/] [sys/] [net/] [raw_usrreq.c] - Blame information for rev 786

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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