source: rtems/cpukit/libnetworking/net/raw_usrreq.c @ cb68253

5
Last change on this file since cb68253 was cb68253, checked in by Sebastian Huber <sebastian.huber@…>, on 09/07/18 at 04:19:02

network: Use kernel/user space header files

Add and use <machine/rtems-bsd-kernel-space.h> and
<machine/rtems-bsd-user-space.h> similar to the libbsd to avoid command
line defines and defines scattered throught the code base.

Simplify cpukit/libnetworking/Makefile.am.

Update #3375.

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