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

Subversion Repositories openrisc

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

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

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//      src/sys/net/raw_usrreq.c
4
//
5
//==========================================================================
6
//####BSDCOPYRIGHTBEGIN####
7
//
8
// -------------------------------------------
9
//
10
// Portions of this software may have been derived from OpenBSD, 
11
// FreeBSD or other sources, and are covered by the appropriate
12
// copyright disclaimers included herein.
13
//
14
// Portions created by Red Hat are
15
// Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
16
//
17
// -------------------------------------------
18
//
19
//####BSDCOPYRIGHTEND####
20
//==========================================================================
21
 
22
/*
23
 * Copyright (c) 1980, 1986, 1993
24
 *      The Regents of the University of California.  All rights reserved.
25
 *
26
 * Redistribution and use in source and binary forms, with or without
27
 * modification, are permitted provided that the following conditions
28
 * are met:
29
 * 1. Redistributions of source code must retain the above copyright
30
 *    notice, this list of conditions and the following disclaimer.
31
 * 2. Redistributions in binary form must reproduce the above copyright
32
 *    notice, this list of conditions and the following disclaimer in the
33
 *    documentation and/or other materials provided with the distribution.
34
 * 3. All advertising materials mentioning features or use of this software
35
 *    must display the following acknowledgement:
36
 *      This product includes software developed by the University of
37
 *      California, Berkeley and its contributors.
38
 * 4. Neither the name of the University nor the names of its contributors
39
 *    may be used to endorse or promote products derived from this software
40
 *    without specific prior written permission.
41
 *
42
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
43
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
46
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
48
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
50
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
51
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52
 * SUCH DAMAGE.
53
 *
54
 *      @(#)raw_usrreq.c        8.1 (Berkeley) 6/10/93
55
 * $FreeBSD: src/sys/net/raw_usrreq.c,v 1.18 1999/08/28 00:48:28 peter Exp $
56
 */
57
 
58
#include <sys/param.h>
59
#include <sys/mbuf.h>
60
#include <sys/protosw.h>
61
#include <sys/socket.h>
62
#include <sys/socketvar.h>
63
 
64
#include <net/raw_cb.h>
65
 
66
/*
67
 * Initialize raw connection block q.
68
 */
69
void
70
raw_init()
71
{
72
        LIST_INIT(&rawcb_list);
73
}
74
 
75
 
76
/*
77
 * Raw protocol input routine.  Find the socket
78
 * associated with the packet(s) and move them over.  If
79
 * nothing exists for this packet, drop it.
80
 */
81
/*
82
 * Raw protocol interface.
83
 */
84
void
85
raw_input(m0, proto, src, dst)
86
        struct mbuf *m0;
87
        register struct sockproto *proto;
88
        struct sockaddr *src, *dst;
89
{
90
        register struct rawcb *rp;
91
        register struct mbuf *m = m0;
92
        register int sockets = 0;
93
        struct socket *last;
94
 
95
        last = 0;
96
        LIST_FOREACH(rp, &rawcb_list, list) {
97
                if (rp->rcb_proto.sp_family != proto->sp_family)
98
                        continue;
99
                if (rp->rcb_proto.sp_protocol  &&
100
                    rp->rcb_proto.sp_protocol != proto->sp_protocol)
101
                        continue;
102
                /*
103
                 * We assume the lower level routines have
104
                 * placed the address in a canonical format
105
                 * suitable for a structure comparison.
106
                 *
107
                 * Note that if the lengths are not the same
108
                 * the comparison will fail at the first byte.
109
                 */
110
#define equal(a1, a2) \
111
  (bcmp((caddr_t)(a1), (caddr_t)(a2), a1->sa_len) == 0)
112
                if (rp->rcb_laddr && !equal(rp->rcb_laddr, dst))
113
                        continue;
114
                if (rp->rcb_faddr && !equal(rp->rcb_faddr, src))
115
                        continue;
116
                if (last) {
117
                        struct mbuf *n;
118
                        n = m_copy(m, 0, (int)M_COPYALL);
119
                        if (n) {
120
                                if (sbappendaddr(&last->so_rcv, src,
121
                                    n, (struct mbuf *)0) == 0)
122
                                        /* should notify about lost packet */
123
                                        m_freem(n);
124
                                else {
125
                                        sorwakeup(last);
126
                                        sockets++;
127
                                }
128
                        }
129
                }
130
                last = rp->rcb_socket;
131
        }
132
        if (last) {
133
                if (sbappendaddr(&last->so_rcv, src,
134
                    m, (struct mbuf *)0) == 0)
135
                        m_freem(m);
136
                else {
137
                        sorwakeup(last);
138
                        sockets++;
139
                }
140
        } else
141
                m_freem(m);
142
}
143
 
144
/*ARGSUSED*/
145
void
146
raw_ctlinput(cmd, arg, dummy)
147
        int cmd;
148
        struct sockaddr *arg;
149
        void *dummy;
150
{
151
 
152
        if (cmd < 0 || cmd > PRC_NCMDS)
153
                return;
154
        /* INCOMPLETE */
155
}
156
 
157
static int
158
raw_uabort(struct socket *so)
159
{
160
        struct rawcb *rp = sotorawcb(so);
161
 
162
        if (rp == 0)
163
                return EINVAL;
164
        raw_disconnect(rp);
165
        sofree(so);
166
        soisdisconnected(so);
167
        return 0;
168
}
169
 
170
/* pru_accept is EOPNOTSUPP */
171
 
172
static int
173
raw_uattach(struct socket *so, int proto, struct proc *p)
174
{
175
        struct rawcb *rp = sotorawcb(so);
176
 
177
        if (rp == 0)
178
                return EINVAL;
179
        return raw_attach(so, proto);
180
}
181
 
182
static int
183
raw_ubind(struct socket *so, struct sockaddr *nam, struct proc *p)
184
{
185
        return EINVAL;
186
}
187
 
188
static int
189
raw_uconnect(struct socket *so, struct sockaddr *nam, struct proc *p)
190
{
191
        return EINVAL;
192
}
193
 
194
/* pru_connect2 is EOPNOTSUPP */
195
/* pru_control is EOPNOTSUPP */
196
 
197
static int
198
raw_udetach(struct socket *so)
199
{
200
        struct rawcb *rp = sotorawcb(so);
201
 
202
        if (rp == 0)
203
                return EINVAL;
204
 
205
        raw_detach(rp);
206
        return 0;
207
}
208
 
209
static int
210
raw_udisconnect(struct socket *so)
211
{
212
        struct rawcb *rp = sotorawcb(so);
213
 
214
        if (rp == 0)
215
                return EINVAL;
216
        if (rp->rcb_faddr == 0) {
217
                return ENOTCONN;
218
        }
219
        raw_disconnect(rp);
220
        soisdisconnected(so);
221
        return 0;
222
}
223
 
224
/* pru_listen is EOPNOTSUPP */
225
 
226
static int
227
raw_upeeraddr(struct socket *so, struct sockaddr **nam)
228
{
229
        struct rawcb *rp = sotorawcb(so);
230
 
231
        if (rp == 0)
232
                return EINVAL;
233
        if (rp->rcb_faddr == 0) {
234
                return ENOTCONN;
235
        }
236
        *nam = dup_sockaddr(rp->rcb_faddr, 1);
237
        return 0;
238
}
239
 
240
/* pru_rcvd is EOPNOTSUPP */
241
/* pru_rcvoob is EOPNOTSUPP */
242
 
243
static int
244
raw_usend(struct socket *so, int flags, struct mbuf *m,
245
          struct sockaddr *nam, struct mbuf *control, struct proc *p)
246
{
247
        int error;
248
        struct rawcb *rp = sotorawcb(so);
249
 
250
        if (rp == 0) {
251
                error = EINVAL;
252
                goto release;
253
        }
254
 
255
        if (flags & PRUS_OOB) {
256
                error = EOPNOTSUPP;
257
                goto release;
258
        }
259
 
260
        if (control && control->m_len) {
261
                error = EOPNOTSUPP;
262
                goto release;
263
        }
264
        if (nam) {
265
                if (rp->rcb_faddr) {
266
                        error = EISCONN;
267
                        goto release;
268
                }
269
                rp->rcb_faddr = nam;
270
        } else if (rp->rcb_faddr == 0) {
271
                error = ENOTCONN;
272
                goto release;
273
        }
274
        error = (*so->so_proto->pr_output)(m, so);
275
        m = NULL;
276
        if (nam)
277
                rp->rcb_faddr = 0;
278
release:
279
        if (m != NULL)
280
                m_freem(m);
281
        return (error);
282
}
283
 
284
/* pru_sense is null */
285
 
286
static int
287
raw_ushutdown(struct socket *so)
288
{
289
        struct rawcb *rp = sotorawcb(so);
290
 
291
        if (rp == 0)
292
                return EINVAL;
293
        socantsendmore(so);
294
        return 0;
295
}
296
 
297
static int
298
raw_usockaddr(struct socket *so, struct sockaddr **nam)
299
{
300
        struct rawcb *rp = sotorawcb(so);
301
 
302
        if (rp == 0)
303
                return EINVAL;
304
        if (rp->rcb_laddr == 0)
305
                return EINVAL;
306
        *nam = dup_sockaddr(rp->rcb_laddr, 1);
307
        return 0;
308
}
309
 
310
struct pr_usrreqs raw_usrreqs = {
311
        raw_uabort, pru_accept_notsupp, raw_uattach, raw_ubind, raw_uconnect,
312
        pru_connect2_notsupp, pru_control_notsupp, raw_udetach,
313
        raw_udisconnect, pru_listen_notsupp, raw_upeeraddr, pru_rcvd_notsupp,
314
        pru_rcvoob_notsupp, raw_usend, pru_sense_null, raw_ushutdown,
315
        raw_usockaddr, sosend, soreceive, sopoll
316
};

powered by: WebSVN 2.1.0

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