]>
git.saurik.com Git - apple/xnu.git/blob - bsd/net/raw_usrreq.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
26 * Copyright (c) 1980, 1986, 1993
27 * The Regents of the University of California. All rights reserved.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
32 * 1. Redistributions of source code must retain the above copyright
33 * notice, this list of conditions and the following disclaimer.
34 * 2. Redistributions in binary form must reproduce the above copyright
35 * notice, this list of conditions and the following disclaimer in the
36 * documentation and/or other materials provided with the distribution.
37 * 3. All advertising materials mentioning features or use of this software
38 * must display the following acknowledgement:
39 * This product includes software developed by the University of
40 * California, Berkeley and its contributors.
41 * 4. Neither the name of the University nor the names of its contributors
42 * may be used to endorse or promote products derived from this software
43 * without specific prior written permission.
45 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
46 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
49 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 * @(#)raw_usrreq.c 8.1 (Berkeley) 6/10/93
58 * $FreeBSD: src/sys/net/raw_usrreq.c,v 1.18 1999/08/28 00:48:28 peter Exp $
61 #include <sys/param.h>
62 #include <sys/systm.h>
65 #include <sys/protosw.h>
66 #include <sys/socket.h>
67 #include <sys/socketvar.h>
69 #include <net/raw_cb.h>
72 * Initialize raw connection block q.
77 LIST_INIT(&rawcb_list
);
82 * Raw protocol input routine. Find the socket
83 * associated with the packet(s) and move them over. If
84 * nothing exists for this packet, drop it.
87 * Raw protocol interface.
90 raw_input(m0
, proto
, src
, dst
)
92 register struct sockproto
*proto
;
93 struct sockaddr
*src
, *dst
;
95 register struct rawcb
*rp
;
96 register struct mbuf
*m
= m0
;
97 register int sockets
= 0;
101 LIST_FOREACH(rp
, &rawcb_list
, list
) {
102 if (rp
->rcb_proto
.sp_family
!= proto
->sp_family
)
104 if (rp
->rcb_proto
.sp_protocol
&&
105 rp
->rcb_proto
.sp_protocol
!= proto
->sp_protocol
)
108 * We assume the lower level routines have
109 * placed the address in a canonical format
110 * suitable for a structure comparison.
112 * Note that if the lengths are not the same
113 * the comparison will fail at the first byte.
115 #define equal(a1, a2) \
116 (bcmp((caddr_t)(a1), (caddr_t)(a2), a1->sa_len) == 0)
117 if (rp
->rcb_laddr
&& !equal(rp
->rcb_laddr
, dst
))
119 if (rp
->rcb_faddr
&& !equal(rp
->rcb_faddr
, src
))
123 n
= m_copy(m
, 0, (int)M_COPYALL
);
125 if (sbappendaddr(&last
->so_rcv
, src
,
126 n
, (struct mbuf
*)0) == 0)
127 /* should notify about lost packet */
135 last
= rp
->rcb_socket
;
138 if (sbappendaddr(&last
->so_rcv
, src
,
139 m
, (struct mbuf
*)0) == 0)
151 raw_ctlinput(cmd
, arg
, dummy
)
153 struct sockaddr
*arg
;
157 if (cmd
< 0 || cmd
> PRC_NCMDS
)
163 raw_uabort(struct socket
*so
)
165 struct rawcb
*rp
= sotorawcb(so
);
171 soisdisconnected(so
);
175 /* pru_accept is EOPNOTSUPP */
178 raw_uattach(struct socket
*so
, int proto
, struct proc
*p
)
180 struct rawcb
*rp
= sotorawcb(so
);
186 if ((so
->so_state
& SS_PRIV
) == 0)
189 if (p
&& (error
= suser(p
)) != 0)
192 return raw_attach(so
, proto
);
196 raw_ubind(struct socket
*so
, struct sockaddr
*nam
, struct proc
*p
)
202 raw_uconnect(struct socket
*so
, struct sockaddr
*nam
, struct proc
*p
)
207 /* pru_connect2 is EOPNOTSUPP */
208 /* pru_control is EOPNOTSUPP */
211 raw_udetach(struct socket
*so
)
213 struct rawcb
*rp
= sotorawcb(so
);
223 raw_udisconnect(struct socket
*so
)
225 struct rawcb
*rp
= sotorawcb(so
);
229 if (rp
->rcb_faddr
== 0) {
233 soisdisconnected(so
);
237 /* pru_listen is EOPNOTSUPP */
240 raw_upeeraddr(struct socket
*so
, struct sockaddr
**nam
)
242 struct rawcb
*rp
= sotorawcb(so
);
246 if (rp
->rcb_faddr
== 0) {
249 *nam
= dup_sockaddr(rp
->rcb_faddr
, 1);
253 /* pru_rcvd is EOPNOTSUPP */
254 /* pru_rcvoob is EOPNOTSUPP */
257 raw_usend(struct socket
*so
, int flags
, struct mbuf
*m
,
258 struct sockaddr
*nam
, struct mbuf
*control
, struct proc
*p
)
261 struct rawcb
*rp
= sotorawcb(so
);
268 if (flags
& PRUS_OOB
) {
273 if (control
&& control
->m_len
) {
283 } else if (rp
->rcb_faddr
== 0) {
287 error
= (*so
->so_proto
->pr_output
)(m
, so
);
297 /* pru_sense is null */
300 raw_ushutdown(struct socket
*so
)
302 struct rawcb
*rp
= sotorawcb(so
);
311 raw_usockaddr(struct socket
*so
, struct sockaddr
**nam
)
313 struct rawcb
*rp
= sotorawcb(so
);
317 if (rp
->rcb_laddr
== 0)
319 *nam
= dup_sockaddr(rp
->rcb_laddr
, 1);
323 struct pr_usrreqs raw_usrreqs
= {
324 raw_uabort
, pru_accept_notsupp
, raw_uattach
, raw_ubind
, raw_uconnect
,
325 pru_connect2_notsupp
, pru_control_notsupp
, raw_udetach
,
326 raw_udisconnect
, pru_listen_notsupp
, raw_upeeraddr
, pru_rcvd_notsupp
,
327 pru_rcvoob_notsupp
, raw_usend
, pru_sense_null
, raw_ushutdown
,
328 raw_usockaddr
, sosend
, soreceive
, sopoll