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/] [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
//      src/sys/net/raw_usrreq.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) 1980, 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
 *      @(#)raw_usrreq.c        8.1 (Berkeley) 6/10/93
53
 * $FreeBSD: src/sys/net/raw_usrreq.c,v 1.18 1999/08/28 00:48:28 peter Exp $
54
 */
55
 
56
#include <sys/param.h>
57
#include <sys/mbuf.h>
58
#include <sys/protosw.h>
59
#include <sys/socket.h>
60
#include <sys/socketvar.h>
61
 
62
#include <net/raw_cb.h>
63
 
64
/*
65
 * Initialize raw connection block q.
66
 */
67
void
68
raw_init()
69
{
70
        LIST_INIT(&rawcb_list);
71
}
72
 
73
 
74
/*
75
 * Raw protocol input routine.  Find the socket
76
 * associated with the packet(s) and move them over.  If
77
 * nothing exists for this packet, drop it.
78
 */
79
/*
80
 * Raw protocol interface.
81
 */
82
void
83
raw_input(m0, proto, src, dst)
84
        struct mbuf *m0;
85
        register struct sockproto *proto;
86
        struct sockaddr *src, *dst;
87
{
88
        register struct rawcb *rp;
89
        register struct mbuf *m = m0;
90
        register int sockets = 0;
91
        struct socket *last;
92
 
93
        last = 0;
94
        LIST_FOREACH(rp, &rawcb_list, list) {
95
                if (rp->rcb_proto.sp_family != proto->sp_family)
96
                        continue;
97
                if (rp->rcb_proto.sp_protocol  &&
98
                    rp->rcb_proto.sp_protocol != proto->sp_protocol)
99
                        continue;
100
                /*
101
                 * We assume the lower level routines have
102
                 * placed the address in a canonical format
103
                 * suitable for a structure comparison.
104
                 *
105
                 * Note that if the lengths are not the same
106
                 * the comparison will fail at the first byte.
107
                 */
108
#define equal(a1, a2) \
109
  (bcmp((caddr_t)(a1), (caddr_t)(a2), a1->sa_len) == 0)
110
                if (rp->rcb_laddr && !equal(rp->rcb_laddr, dst))
111
                        continue;
112
                if (rp->rcb_faddr && !equal(rp->rcb_faddr, src))
113
                        continue;
114
                if (last) {
115
                        struct mbuf *n;
116
                        n = m_copy(m, 0, (int)M_COPYALL);
117
                        if (n) {
118
                                if (sbappendaddr(&last->so_rcv, src,
119
                                    n, (struct mbuf *)0) == 0)
120
                                        /* should notify about lost packet */
121
                                        m_freem(n);
122
                                else {
123
                                        sorwakeup(last);
124
                                        sockets++;
125
                                }
126
                        }
127
                }
128
                last = rp->rcb_socket;
129
        }
130
        if (last) {
131
                if (sbappendaddr(&last->so_rcv, src,
132
                    m, (struct mbuf *)0) == 0)
133
                        m_freem(m);
134
                else {
135
                        sorwakeup(last);
136
                        sockets++;
137
                }
138
        } else
139
                m_freem(m);
140
}
141
 
142
/*ARGSUSED*/
143
void
144
raw_ctlinput(cmd, arg, dummy)
145
        int cmd;
146
        struct sockaddr *arg;
147
        void *dummy;
148
{
149
 
150
        if (cmd < 0 || cmd > PRC_NCMDS)
151
                return;
152
        /* INCOMPLETE */
153
}
154
 
155
static int
156
raw_uabort(struct socket *so)
157
{
158
        struct rawcb *rp = sotorawcb(so);
159
 
160
        if (rp == 0)
161
                return EINVAL;
162
        raw_disconnect(rp);
163
        sofree(so);
164
        soisdisconnected(so);
165
        return 0;
166
}
167
 
168
/* pru_accept is EOPNOTSUPP */
169
 
170
static int
171
raw_uattach(struct socket *so, int proto, struct proc *p)
172
{
173
        struct rawcb *rp = sotorawcb(so);
174
 
175
        if (rp == 0)
176
                return EINVAL;
177
        return raw_attach(so, proto);
178
}
179
 
180
static int
181
raw_ubind(struct socket *so, struct sockaddr *nam, struct proc *p)
182
{
183
        return EINVAL;
184
}
185
 
186
static int
187
raw_uconnect(struct socket *so, struct sockaddr *nam, struct proc *p)
188
{
189
        return EINVAL;
190
}
191
 
192
/* pru_connect2 is EOPNOTSUPP */
193
/* pru_control is EOPNOTSUPP */
194
 
195
static int
196
raw_udetach(struct socket *so)
197
{
198
        struct rawcb *rp = sotorawcb(so);
199
 
200
        if (rp == 0)
201
                return EINVAL;
202
 
203
        raw_detach(rp);
204
        return 0;
205
}
206
 
207
static int
208
raw_udisconnect(struct socket *so)
209
{
210
        struct rawcb *rp = sotorawcb(so);
211
 
212
        if (rp == 0)
213
                return EINVAL;
214
        if (rp->rcb_faddr == 0) {
215
                return ENOTCONN;
216
        }
217
        raw_disconnect(rp);
218
        soisdisconnected(so);
219
        return 0;
220
}
221
 
222
/* pru_listen is EOPNOTSUPP */
223
 
224
static int
225
raw_upeeraddr(struct socket *so, struct sockaddr **nam)
226
{
227
        struct rawcb *rp = sotorawcb(so);
228
 
229
        if (rp == 0)
230
                return EINVAL;
231
        if (rp->rcb_faddr == 0) {
232
                return ENOTCONN;
233
        }
234
        *nam = dup_sockaddr(rp->rcb_faddr, 1);
235
        return 0;
236
}
237
 
238
/* pru_rcvd is EOPNOTSUPP */
239
/* pru_rcvoob is EOPNOTSUPP */
240
 
241
static int
242
raw_usend(struct socket *so, int flags, struct mbuf *m,
243
          struct sockaddr *nam, struct mbuf *control, struct proc *p)
244
{
245
        int error;
246
        struct rawcb *rp = sotorawcb(so);
247
 
248
        if (rp == 0) {
249
                error = EINVAL;
250
                goto release;
251
        }
252
 
253
        if (flags & PRUS_OOB) {
254
                error = EOPNOTSUPP;
255
                goto release;
256
        }
257
 
258
        if (control && control->m_len) {
259
                error = EOPNOTSUPP;
260
                goto release;
261
        }
262
        if (nam) {
263
                if (rp->rcb_faddr) {
264
                        error = EISCONN;
265
                        goto release;
266
                }
267
                rp->rcb_faddr = nam;
268
        } else if (rp->rcb_faddr == 0) {
269
                error = ENOTCONN;
270
                goto release;
271
        }
272
        error = (*so->so_proto->pr_output)(m, so);
273
        m = NULL;
274
        if (nam)
275
                rp->rcb_faddr = 0;
276
release:
277
        if (m != NULL)
278
                m_freem(m);
279
        return (error);
280
}
281
 
282
/* pru_sense is null */
283
 
284
static int
285
raw_ushutdown(struct socket *so)
286
{
287
        struct rawcb *rp = sotorawcb(so);
288
 
289
        if (rp == 0)
290
                return EINVAL;
291
        socantsendmore(so);
292
        return 0;
293
}
294
 
295
static int
296
raw_usockaddr(struct socket *so, struct sockaddr **nam)
297
{
298
        struct rawcb *rp = sotorawcb(so);
299
 
300
        if (rp == 0)
301
                return EINVAL;
302
        if (rp->rcb_laddr == 0)
303
                return EINVAL;
304
        *nam = dup_sockaddr(rp->rcb_laddr, 1);
305
        return 0;
306
}
307
 
308
struct pr_usrreqs raw_usrreqs = {
309
        raw_uabort, pru_accept_notsupp, raw_uattach, raw_ubind, raw_uconnect,
310
        pru_connect2_notsupp, pru_control_notsupp, raw_udetach,
311
        raw_udisconnect, pru_listen_notsupp, raw_upeeraddr, pru_rcvd_notsupp,
312
        pru_rcvoob_notsupp, raw_usend, pru_sense_null, raw_ushutdown,
313
        raw_usockaddr, sosend, soreceive, sopoll
314
};

powered by: WebSVN 2.1.0

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