]> git.saurik.com Git - apple/xnu.git/blob - bsd/netinet/raw_ip.c
1f7ccb2275b5789fa97487811661ac884fbef7ae
[apple/xnu.git] / bsd / netinet / raw_ip.c
1 /*
2 * Copyright (c) 2000-2016 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /*
29 * Copyright (c) 1982, 1986, 1988, 1993
30 * The Regents of the University of California. All rights reserved.
31 *
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
34 * are met:
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in the
39 * documentation and/or other materials provided with the distribution.
40 * 3. All advertising materials mentioning features or use of this software
41 * must display the following acknowledgement:
42 * This product includes software developed by the University of
43 * California, Berkeley and its contributors.
44 * 4. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
47 *
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * SUCH DAMAGE.
59 *
60 * @(#)raw_ip.c 8.7 (Berkeley) 5/15/95
61 */
62 /*
63 * NOTICE: This file was modified by SPARTA, Inc. in 2005 to introduce
64 * support for mandatory and extensible security protections. This notice
65 * is included in support of clause 2.2 (b) of the Apple Public License,
66 * Version 2.0.
67 */
68
69 #include <sys/param.h>
70 #include <sys/systm.h>
71 #include <sys/kernel.h>
72 #include <sys/malloc.h>
73 #include <sys/mbuf.h>
74 #include <sys/mcache.h>
75 #include <sys/proc.h>
76 #include <sys/domain.h>
77 #include <sys/protosw.h>
78 #include <sys/socket.h>
79 #include <sys/socketvar.h>
80 #include <sys/sysctl.h>
81 #include <libkern/OSAtomic.h>
82 #include <kern/zalloc.h>
83
84 #include <pexpert/pexpert.h>
85
86 #include <net/if.h>
87 #include <net/route.h>
88
89 #define _IP_VHL
90 #include <netinet/in.h>
91 #include <netinet/in_systm.h>
92 #include <netinet/in_tclass.h>
93 #include <netinet/ip.h>
94 #include <netinet/in_pcb.h>
95 #include <netinet/in_var.h>
96 #include <netinet/ip_var.h>
97
98 #if INET6
99 #include <netinet6/in6_pcb.h>
100 #endif /* INET6 */
101
102 #include <netinet/ip_fw.h>
103
104 #if IPSEC
105 #include <netinet6/ipsec.h>
106 #endif /*IPSEC*/
107
108 #if DUMMYNET
109 #include <netinet/ip_dummynet.h>
110 #endif
111
112 #if CONFIG_MACF_NET
113 #include <security/mac_framework.h>
114 #endif /* MAC_NET */
115
116 int load_ipfw(void);
117 int rip_detach(struct socket *);
118 int rip_abort(struct socket *);
119 int rip_disconnect(struct socket *);
120 int rip_bind(struct socket *, struct sockaddr *, struct proc *);
121 int rip_connect(struct socket *, struct sockaddr *, struct proc *);
122 int rip_shutdown(struct socket *);
123
124 struct inpcbhead ripcb;
125 struct inpcbinfo ripcbinfo;
126
127 /* control hooks for ipfw and dummynet */
128 #if IPFIREWALL
129 ip_fw_ctl_t *ip_fw_ctl_ptr;
130 #endif /* IPFIREWALL */
131 #if DUMMYNET
132 ip_dn_ctl_t *ip_dn_ctl_ptr;
133 #endif /* DUMMYNET */
134
135 /*
136 * Nominal space allocated to a raw ip socket.
137 */
138 #define RIPSNDQ 8192
139 #define RIPRCVQ 8192
140
141 /*
142 * Raw interface to IP protocol.
143 */
144
145 /*
146 * Initialize raw connection block q.
147 */
148 void
149 rip_init(struct protosw *pp, struct domain *dp)
150 {
151 #pragma unused(dp)
152 static int rip_initialized = 0;
153 struct inpcbinfo *pcbinfo;
154
155 VERIFY((pp->pr_flags & (PR_INITIALIZED|PR_ATTACHED)) == PR_ATTACHED);
156
157 if (rip_initialized)
158 return;
159 rip_initialized = 1;
160
161 LIST_INIT(&ripcb);
162 ripcbinfo.ipi_listhead = &ripcb;
163 /*
164 * XXX We don't use the hash list for raw IP, but it's easier
165 * to allocate a one entry hash list than it is to check all
166 * over the place for ipi_hashbase == NULL.
167 */
168 ripcbinfo.ipi_hashbase = hashinit(1, M_PCB, &ripcbinfo.ipi_hashmask);
169 ripcbinfo.ipi_porthashbase = hashinit(1, M_PCB, &ripcbinfo.ipi_porthashmask);
170
171 ripcbinfo.ipi_zone = zinit(sizeof(struct inpcb),
172 (4096 * sizeof(struct inpcb)), 4096, "ripzone");
173
174 pcbinfo = &ripcbinfo;
175 /*
176 * allocate lock group attribute and group for udp pcb mutexes
177 */
178 pcbinfo->ipi_lock_grp_attr = lck_grp_attr_alloc_init();
179 pcbinfo->ipi_lock_grp = lck_grp_alloc_init("ripcb", pcbinfo->ipi_lock_grp_attr);
180
181 /*
182 * allocate the lock attribute for udp pcb mutexes
183 */
184 pcbinfo->ipi_lock_attr = lck_attr_alloc_init();
185 if ((pcbinfo->ipi_lock = lck_rw_alloc_init(pcbinfo->ipi_lock_grp,
186 pcbinfo->ipi_lock_attr)) == NULL) {
187 panic("%s: unable to allocate PCB lock\n", __func__);
188 /* NOTREACHED */
189 }
190
191 in_pcbinfo_attach(&ripcbinfo);
192 }
193
194 static struct sockaddr_in ripsrc = { sizeof(ripsrc), AF_INET , 0, {0}, {0,0,0,0,0,0,0,0,} };
195 /*
196 * Setup generic address and protocol structures
197 * for raw_input routine, then pass them along with
198 * mbuf chain.
199 */
200 void
201 rip_input(struct mbuf *m, int iphlen)
202 {
203 struct ip *ip = mtod(m, struct ip *);
204 struct inpcb *inp;
205 struct inpcb *last = 0;
206 struct mbuf *opts = 0;
207 int skipit = 0, ret = 0;
208 struct ifnet *ifp = m->m_pkthdr.rcvif;
209
210 /* Expect 32-bit aligned data pointer on strict-align platforms */
211 MBUF_STRICT_DATA_ALIGNMENT_CHECK_32(m);
212
213 ripsrc.sin_addr = ip->ip_src;
214 lck_rw_lock_shared(ripcbinfo.ipi_lock);
215 LIST_FOREACH(inp, &ripcb, inp_list) {
216 #if INET6
217 if ((inp->inp_vflag & INP_IPV4) == 0)
218 continue;
219 #endif
220 if (inp->inp_ip_p && (inp->inp_ip_p != ip->ip_p))
221 continue;
222 if (inp->inp_laddr.s_addr &&
223 inp->inp_laddr.s_addr != ip->ip_dst.s_addr)
224 continue;
225 if (inp->inp_faddr.s_addr &&
226 inp->inp_faddr.s_addr != ip->ip_src.s_addr)
227 continue;
228 if (inp_restricted_recv(inp, ifp))
229 continue;
230 if (last) {
231 struct mbuf *n = m_copy(m, 0, (int)M_COPYALL);
232
233 skipit = 0;
234
235 #if NECP
236 if (n && !necp_socket_is_allowed_to_send_recv_v4(last, 0, 0,
237 &ip->ip_dst, &ip->ip_src, ifp, NULL, NULL)) {
238 m_freem(n);
239 /* do not inject data to pcb */
240 skipit = 1;
241 }
242 #endif /* NECP */
243 #if CONFIG_MACF_NET
244 if (n && skipit == 0) {
245 if (mac_inpcb_check_deliver(last, n, AF_INET,
246 SOCK_RAW) != 0) {
247 m_freem(n);
248 skipit = 1;
249 }
250 }
251 #endif
252 if (n && skipit == 0) {
253 int error = 0;
254 if ((last->inp_flags & INP_CONTROLOPTS) != 0 ||
255 (last->inp_socket->so_options & SO_TIMESTAMP) != 0 ||
256 (last->inp_socket->so_options & SO_TIMESTAMP_MONOTONIC) != 0) {
257 ret = ip_savecontrol(last, &opts, ip, n);
258 if (ret != 0) {
259 m_freem(n);
260 m_freem(opts);
261 last = inp;
262 continue;
263 }
264 }
265 if (last->inp_flags & INP_STRIPHDR) {
266 n->m_len -= iphlen;
267 n->m_pkthdr.len -= iphlen;
268 n->m_data += iphlen;
269 }
270 so_recv_data_stat(last->inp_socket, m, 0);
271 if (sbappendaddr(&last->inp_socket->so_rcv,
272 (struct sockaddr *)&ripsrc, n,
273 opts, &error) != 0) {
274 sorwakeup(last->inp_socket);
275 } else {
276 if (error) {
277 /* should notify about lost packet */
278 ipstat.ips_raw_sappend_fail++;
279 }
280 }
281 opts = 0;
282 }
283 }
284 last = inp;
285 }
286
287 skipit = 0;
288 #if NECP
289 if (last && !necp_socket_is_allowed_to_send_recv_v4(last, 0, 0,
290 &ip->ip_dst, &ip->ip_src, ifp, NULL, NULL)) {
291 m_freem(m);
292 OSAddAtomic(1, &ipstat.ips_delivered);
293 /* do not inject data to pcb */
294 skipit = 1;
295 }
296 #endif /* NECP */
297 #if CONFIG_MACF_NET
298 if (last && skipit == 0) {
299 if (mac_inpcb_check_deliver(last, m, AF_INET, SOCK_RAW) != 0) {
300 skipit = 1;
301 m_freem(m);
302 }
303 }
304 #endif
305 if (skipit == 0) {
306 if (last) {
307 if ((last->inp_flags & INP_CONTROLOPTS) != 0 ||
308 (last->inp_socket->so_options & SO_TIMESTAMP) != 0 ||
309 (last->inp_socket->so_options & SO_TIMESTAMP_MONOTONIC) != 0) {
310 ret = ip_savecontrol(last, &opts, ip, m);
311 if (ret != 0) {
312 m_freem(m);
313 m_freem(opts);
314 goto unlock;
315 }
316 }
317 if (last->inp_flags & INP_STRIPHDR) {
318 m->m_len -= iphlen;
319 m->m_pkthdr.len -= iphlen;
320 m->m_data += iphlen;
321 }
322 so_recv_data_stat(last->inp_socket, m, 0);
323 if (sbappendaddr(&last->inp_socket->so_rcv,
324 (struct sockaddr *)&ripsrc, m, opts, NULL) != 0) {
325 sorwakeup(last->inp_socket);
326 } else {
327 ipstat.ips_raw_sappend_fail++;
328 }
329 } else {
330 m_freem(m);
331 OSAddAtomic(1, &ipstat.ips_noproto);
332 OSAddAtomic(-1, &ipstat.ips_delivered);
333 }
334 }
335 unlock:
336 /*
337 * Keep the list locked because socket filter may force the socket lock
338 * to be released when calling sbappendaddr() -- see rdar://7627704
339 */
340 lck_rw_done(ripcbinfo.ipi_lock);
341 }
342
343 /*
344 * Generate IP header and pass packet to ip_output.
345 * Tack on options user may have setup with control call.
346 */
347 int
348 rip_output(
349 struct mbuf *m,
350 struct socket *so,
351 u_int32_t dst,
352 struct mbuf *control)
353 {
354 struct ip *ip;
355 struct inpcb *inp = sotoinpcb(so);
356 int flags = (so->so_options & SO_DONTROUTE) | IP_ALLOWBROADCAST;
357 struct ip_out_args ipoa =
358 { IFSCOPE_NONE, { 0 }, IPOAF_SELECT_SRCIF, 0, 0, 0 };
359 struct ip_moptions *imo;
360 int error = 0;
361 int sotc = SO_TC_UNSPEC;
362 int netsvctype = _NET_SERVICE_TYPE_UNSPEC;
363
364 if (control != NULL) {
365 sotc = so_tc_from_control(control, &netsvctype);
366
367 m_freem(control);
368 control = NULL;
369 }
370 if (sotc == SO_TC_UNSPEC) {
371 sotc = so->so_traffic_class;
372 netsvctype = so->so_netsvctype;
373 }
374
375 if (inp == NULL
376 #if NECP
377 || (necp_socket_should_use_flow_divert(inp))
378 #endif /* NECP */
379 ) {
380 if (m != NULL)
381 m_freem(m);
382 VERIFY(control == NULL);
383 return (inp == NULL ? EINVAL : EPROTOTYPE);
384 }
385
386 flags |= IP_OUTARGS;
387 /* If socket was bound to an ifindex, tell ip_output about it */
388 if (inp->inp_flags & INP_BOUND_IF) {
389 ipoa.ipoa_boundif = inp->inp_boundifp->if_index;
390 ipoa.ipoa_flags |= IPOAF_BOUND_IF;
391 }
392 if (INP_NO_CELLULAR(inp))
393 ipoa.ipoa_flags |= IPOAF_NO_CELLULAR;
394 if (INP_NO_EXPENSIVE(inp))
395 ipoa.ipoa_flags |= IPOAF_NO_EXPENSIVE;
396 if (INP_AWDL_UNRESTRICTED(inp))
397 ipoa.ipoa_flags |= IPOAF_AWDL_UNRESTRICTED;
398 ipoa.ipoa_sotc = sotc;
399 ipoa.ipoa_netsvctype = netsvctype;
400
401 if (inp->inp_flowhash == 0)
402 inp->inp_flowhash = inp_calc_flowhash(inp);
403
404 /*
405 * If the user handed us a complete IP packet, use it.
406 * Otherwise, allocate an mbuf for a header and fill it in.
407 */
408 if ((inp->inp_flags & INP_HDRINCL) == 0) {
409 if (m->m_pkthdr.len + sizeof(struct ip) > IP_MAXPACKET) {
410 m_freem(m);
411 return(EMSGSIZE);
412 }
413 M_PREPEND(m, sizeof(struct ip), M_WAIT, 1);
414 if (m == NULL)
415 return ENOBUFS;
416 ip = mtod(m, struct ip *);
417 ip->ip_tos = inp->inp_ip_tos;
418 ip->ip_off = 0;
419 ip->ip_p = inp->inp_ip_p;
420 ip->ip_len = m->m_pkthdr.len;
421 ip->ip_src = inp->inp_laddr;
422 ip->ip_dst.s_addr = dst;
423 ip->ip_ttl = inp->inp_ip_ttl;
424 } else {
425 if (m->m_pkthdr.len > IP_MAXPACKET) {
426 m_freem(m);
427 return(EMSGSIZE);
428 }
429 ip = mtod(m, struct ip *);
430 /* don't allow both user specified and setsockopt options,
431 and don't allow packet length sizes that will crash */
432 if (((IP_VHL_HL(ip->ip_vhl) != (sizeof (*ip) >> 2))
433 && inp->inp_options)
434 || (ip->ip_len > m->m_pkthdr.len)
435 || (ip->ip_len < (IP_VHL_HL(ip->ip_vhl) << 2))) {
436 m_freem(m);
437 return EINVAL;
438 }
439 if (ip->ip_id == 0)
440 ip->ip_id = ip_randomid();
441 /* XXX prevent ip_output from overwriting header fields */
442 flags |= IP_RAWOUTPUT;
443 OSAddAtomic(1, &ipstat.ips_rawout);
444 }
445
446 if (inp->inp_laddr.s_addr != INADDR_ANY)
447 ipoa.ipoa_flags |= IPOAF_BOUND_SRCADDR;
448
449 #if NECP
450 {
451 necp_kernel_policy_id policy_id;
452 u_int32_t route_rule_id;
453
454 /*
455 * We need a route to perform NECP route rule checks
456 */
457 if (net_qos_policy_restricted != 0 &&
458 ROUTE_UNUSABLE(&inp->inp_route)) {
459 struct sockaddr_in to;
460 struct sockaddr_in from;
461 struct in_addr laddr = ip->ip_src;
462
463 ROUTE_RELEASE(&inp->inp_route);
464
465 bzero(&from, sizeof(struct sockaddr_in));
466 from.sin_family = AF_INET;
467 from.sin_len = sizeof(struct sockaddr_in);
468 from.sin_addr = laddr;
469
470 bzero(&to, sizeof(struct sockaddr_in));
471 to.sin_family = AF_INET;
472 to.sin_len = sizeof(struct sockaddr_in);
473 to.sin_addr.s_addr = ip->ip_dst.s_addr;
474
475 if ((error = in_pcbladdr(inp, (struct sockaddr *)&to,
476 &laddr, ipoa.ipoa_boundif, NULL, 1)) != 0) {
477 printf("%s in_pcbladdr(%p) error %d\n",
478 __func__, inp, error);
479 m_freem(m);
480 return (error);
481 }
482
483 inp_update_necp_policy(inp, (struct sockaddr *)&from,
484 (struct sockaddr *)&to, ipoa.ipoa_boundif);
485 inp->inp_policyresult.results.qos_marking_gencount = 0;
486 }
487
488 if (!necp_socket_is_allowed_to_send_recv_v4(inp, 0, 0,
489 &ip->ip_src, &ip->ip_dst, NULL, &policy_id, &route_rule_id)) {
490 m_freem(m);
491 return(EHOSTUNREACH);
492 }
493
494 necp_mark_packet_from_socket(m, inp, policy_id, route_rule_id);
495
496 if (net_qos_policy_restricted != 0) {
497 struct ifnet *rt_ifp = NULL;
498
499 if (inp->inp_route.ro_rt != NULL)
500 rt_ifp = inp->inp_route.ro_rt->rt_ifp;
501
502 printf("%s inp %p last_pid %u inp_boundifp %d inp_last_outifp %d rt_ifp %d route_rule_id %u\n",
503 __func__, inp,
504 inp->inp_socket != NULL ? inp->inp_socket->last_pid : -1,
505 inp->inp_boundifp != NULL ? inp->inp_boundifp->if_index : -1,
506 inp->inp_last_outifp != NULL ? inp->inp_last_outifp->if_index : -1,
507 rt_ifp != NULL ? rt_ifp->if_index : -1,
508 route_rule_id);
509 necp_socket_update_qos_marking(inp, inp->inp_route.ro_rt,
510 NULL, route_rule_id);
511 }
512 }
513 #endif /* NECP */
514 if ((so->so_flags1 & SOF1_QOSMARKING_ALLOWED))
515 ipoa.ipoa_flags |= IPOAF_QOSMARKING_ALLOWED;
516
517 #if IPSEC
518 if (inp->inp_sp != NULL && ipsec_setsocket(m, so) != 0) {
519 m_freem(m);
520 return ENOBUFS;
521 }
522 #endif /*IPSEC*/
523
524 if (ROUTE_UNUSABLE(&inp->inp_route))
525 ROUTE_RELEASE(&inp->inp_route);
526
527 set_packet_service_class(m, so, sotc, 0);
528 m->m_pkthdr.pkt_flowsrc = FLOWSRC_INPCB;
529 m->m_pkthdr.pkt_flowid = inp->inp_flowhash;
530 m->m_pkthdr.pkt_flags |= (PKTF_FLOW_ID | PKTF_FLOW_LOCALSRC |
531 PKTF_FLOW_RAWSOCK);
532 m->m_pkthdr.pkt_proto = inp->inp_ip_p;
533
534 #if CONFIG_MACF_NET
535 mac_mbuf_label_associate_inpcb(inp, m);
536 #endif
537
538 imo = inp->inp_moptions;
539 if (imo != NULL)
540 IMO_ADDREF(imo);
541 /*
542 * The domain lock is held across ip_output, so it is okay
543 * to pass the PCB cached route pointer directly to IP and
544 * the modules beneath it.
545 */
546 // TODO: PASS DOWN ROUTE RULE ID
547 error = ip_output(m, inp->inp_options, &inp->inp_route, flags,
548 imo, &ipoa);
549
550 if (imo != NULL)
551 IMO_REMREF(imo);
552
553 if (inp->inp_route.ro_rt != NULL) {
554 struct rtentry *rt = inp->inp_route.ro_rt;
555 struct ifnet *outif;
556
557 if ((rt->rt_flags & (RTF_MULTICAST|RTF_BROADCAST)) ||
558 inp->inp_socket == NULL ||
559 !(inp->inp_socket->so_state & SS_ISCONNECTED)) {
560 rt = NULL; /* unusable */
561 }
562 /*
563 * Always discard the cached route for unconnected
564 * socket or if it is a multicast route.
565 */
566 if (rt == NULL)
567 ROUTE_RELEASE(&inp->inp_route);
568
569 /*
570 * If this is a connected socket and the destination
571 * route is unicast, update outif with that of the
572 * route interface used by IP.
573 */
574 if (rt != NULL && (outif = rt->rt_ifp) != inp->inp_last_outifp)
575 inp->inp_last_outifp = outif;
576 } else {
577 ROUTE_RELEASE(&inp->inp_route);
578 }
579
580 /*
581 * If output interface was cellular/expensive, and this socket is
582 * denied access to it, generate an event.
583 */
584 if (error != 0 && (ipoa.ipoa_retflags & IPOARF_IFDENIED) &&
585 (INP_NO_CELLULAR(inp) || INP_NO_EXPENSIVE(inp)))
586 soevent(so, (SO_FILT_HINT_LOCKED|SO_FILT_HINT_IFDENIED));
587
588 return (error);
589 }
590
591 #if IPFIREWALL
592 int
593 load_ipfw(void)
594 {
595 kern_return_t err;
596
597 ipfw_init();
598
599 #if DUMMYNET
600 if (!DUMMYNET_LOADED)
601 ip_dn_init();
602 #endif /* DUMMYNET */
603 err = 0;
604
605 return err == 0 && ip_fw_ctl_ptr == NULL ? -1 : err;
606 }
607 #endif /* IPFIREWALL */
608
609 /*
610 * Raw IP socket option processing.
611 */
612 int
613 rip_ctloutput(struct socket *so, struct sockopt *sopt)
614 {
615 struct inpcb *inp = sotoinpcb(so);
616 int error, optval;
617
618 /* Allow <SOL_SOCKET,SO_FLUSH> at this level */
619 if (sopt->sopt_level != IPPROTO_IP &&
620 !(sopt->sopt_level == SOL_SOCKET && sopt->sopt_name == SO_FLUSH))
621 return (EINVAL);
622
623 error = 0;
624
625 switch (sopt->sopt_dir) {
626 case SOPT_GET:
627 switch (sopt->sopt_name) {
628 case IP_HDRINCL:
629 optval = inp->inp_flags & INP_HDRINCL;
630 error = sooptcopyout(sopt, &optval, sizeof optval);
631 break;
632
633 case IP_STRIPHDR:
634 optval = inp->inp_flags & INP_STRIPHDR;
635 error = sooptcopyout(sopt, &optval, sizeof optval);
636 break;
637
638 #if IPFIREWALL
639 case IP_FW_ADD:
640 case IP_FW_GET:
641 case IP_OLD_FW_ADD:
642 case IP_OLD_FW_GET:
643 if (ip_fw_ctl_ptr == 0)
644 error = load_ipfw();
645 if (ip_fw_ctl_ptr && error == 0)
646 error = ip_fw_ctl_ptr(sopt);
647 else
648 error = ENOPROTOOPT;
649 break;
650 #endif /* IPFIREWALL */
651
652 #if DUMMYNET
653 case IP_DUMMYNET_GET:
654 if (!DUMMYNET_LOADED)
655 ip_dn_init();
656 if (DUMMYNET_LOADED)
657 error = ip_dn_ctl_ptr(sopt);
658 else
659 error = ENOPROTOOPT;
660 break ;
661 #endif /* DUMMYNET */
662
663 default:
664 error = ip_ctloutput(so, sopt);
665 break;
666 }
667 break;
668
669 case SOPT_SET:
670 switch (sopt->sopt_name) {
671 case IP_HDRINCL:
672 error = sooptcopyin(sopt, &optval, sizeof optval,
673 sizeof optval);
674 if (error)
675 break;
676 if (optval)
677 inp->inp_flags |= INP_HDRINCL;
678 else
679 inp->inp_flags &= ~INP_HDRINCL;
680 break;
681
682 case IP_STRIPHDR:
683 error = sooptcopyin(sopt, &optval, sizeof optval,
684 sizeof optval);
685 if (error)
686 break;
687 if (optval)
688 inp->inp_flags |= INP_STRIPHDR;
689 else
690 inp->inp_flags &= ~INP_STRIPHDR;
691 break;
692
693 #if IPFIREWALL
694 case IP_FW_ADD:
695 case IP_FW_DEL:
696 case IP_FW_FLUSH:
697 case IP_FW_ZERO:
698 case IP_FW_RESETLOG:
699 case IP_OLD_FW_ADD:
700 case IP_OLD_FW_DEL:
701 case IP_OLD_FW_FLUSH:
702 case IP_OLD_FW_ZERO:
703 case IP_OLD_FW_RESETLOG:
704 if (ip_fw_ctl_ptr == 0)
705 error = load_ipfw();
706 if (ip_fw_ctl_ptr && error == 0)
707 error = ip_fw_ctl_ptr(sopt);
708 else
709 error = ENOPROTOOPT;
710 break;
711 #endif /* IPFIREWALL */
712
713 #if DUMMYNET
714 case IP_DUMMYNET_CONFIGURE:
715 case IP_DUMMYNET_DEL:
716 case IP_DUMMYNET_FLUSH:
717 if (!DUMMYNET_LOADED)
718 ip_dn_init();
719 if (DUMMYNET_LOADED)
720 error = ip_dn_ctl_ptr(sopt);
721 else
722 error = ENOPROTOOPT ;
723 break ;
724 #endif
725
726 case SO_FLUSH:
727 if ((error = sooptcopyin(sopt, &optval, sizeof (optval),
728 sizeof (optval))) != 0)
729 break;
730
731 error = inp_flush(inp, optval);
732 break;
733
734 default:
735 error = ip_ctloutput(so, sopt);
736 break;
737 }
738 break;
739 }
740
741 return (error);
742 }
743
744 /*
745 * This function exists solely to receive the PRC_IFDOWN messages which
746 * are sent by if_down(). It looks for an ifaddr whose ifa_addr is sa,
747 * and calls in_ifadown() to remove all routes corresponding to that address.
748 * It also receives the PRC_IFUP messages from if_up() and reinstalls the
749 * interface routes.
750 */
751 void
752 rip_ctlinput(
753 int cmd,
754 struct sockaddr *sa,
755 __unused void *vip)
756 {
757 struct in_ifaddr *ia;
758 struct ifnet *ifp;
759 int err;
760 int flags, done = 0;
761
762 switch (cmd) {
763 case PRC_IFDOWN:
764 lck_rw_lock_shared(in_ifaddr_rwlock);
765 for (ia = in_ifaddrhead.tqh_first; ia;
766 ia = ia->ia_link.tqe_next) {
767 IFA_LOCK(&ia->ia_ifa);
768 if (ia->ia_ifa.ifa_addr == sa &&
769 (ia->ia_flags & IFA_ROUTE)) {
770 done = 1;
771 IFA_ADDREF_LOCKED(&ia->ia_ifa);
772 IFA_UNLOCK(&ia->ia_ifa);
773 lck_rw_done(in_ifaddr_rwlock);
774 lck_mtx_lock(rnh_lock);
775 /*
776 * in_ifscrub kills the interface route.
777 */
778 in_ifscrub(ia->ia_ifp, ia, 1);
779 /*
780 * in_ifadown gets rid of all the rest of
781 * the routes. This is not quite the right
782 * thing to do, but at least if we are running
783 * a routing process they will come back.
784 */
785 in_ifadown(&ia->ia_ifa, 1);
786 lck_mtx_unlock(rnh_lock);
787 IFA_REMREF(&ia->ia_ifa);
788 break;
789 }
790 IFA_UNLOCK(&ia->ia_ifa);
791 }
792 if (!done)
793 lck_rw_done(in_ifaddr_rwlock);
794 break;
795
796 case PRC_IFUP:
797 lck_rw_lock_shared(in_ifaddr_rwlock);
798 for (ia = in_ifaddrhead.tqh_first; ia;
799 ia = ia->ia_link.tqe_next) {
800 IFA_LOCK(&ia->ia_ifa);
801 if (ia->ia_ifa.ifa_addr == sa) {
802 /* keep it locked */
803 break;
804 }
805 IFA_UNLOCK(&ia->ia_ifa);
806 }
807 if (ia == NULL || (ia->ia_flags & IFA_ROUTE) ||
808 (ia->ia_ifa.ifa_debug & IFD_NOTREADY)) {
809 if (ia != NULL)
810 IFA_UNLOCK(&ia->ia_ifa);
811 lck_rw_done(in_ifaddr_rwlock);
812 return;
813 }
814 IFA_ADDREF_LOCKED(&ia->ia_ifa);
815 IFA_UNLOCK(&ia->ia_ifa);
816 lck_rw_done(in_ifaddr_rwlock);
817
818 flags = RTF_UP;
819 ifp = ia->ia_ifa.ifa_ifp;
820
821 if ((ifp->if_flags & IFF_LOOPBACK)
822 || (ifp->if_flags & IFF_POINTOPOINT))
823 flags |= RTF_HOST;
824
825 err = rtinit(&ia->ia_ifa, RTM_ADD, flags);
826 if (err == 0) {
827 IFA_LOCK_SPIN(&ia->ia_ifa);
828 ia->ia_flags |= IFA_ROUTE;
829 IFA_UNLOCK(&ia->ia_ifa);
830 }
831 IFA_REMREF(&ia->ia_ifa);
832 break;
833 }
834 }
835
836 u_int32_t rip_sendspace = RIPSNDQ;
837 u_int32_t rip_recvspace = RIPRCVQ;
838
839 SYSCTL_INT(_net_inet_raw, OID_AUTO, maxdgram, CTLFLAG_RW | CTLFLAG_LOCKED,
840 &rip_sendspace, 0, "Maximum outgoing raw IP datagram size");
841 SYSCTL_INT(_net_inet_raw, OID_AUTO, recvspace, CTLFLAG_RW | CTLFLAG_LOCKED,
842 &rip_recvspace, 0, "Maximum incoming raw IP datagram size");
843 SYSCTL_UINT(_net_inet_raw, OID_AUTO, pcbcount, CTLFLAG_RD | CTLFLAG_LOCKED,
844 &ripcbinfo.ipi_count, 0, "Number of active PCBs");
845
846 static int
847 rip_attach(struct socket *so, int proto, struct proc *p)
848 {
849 struct inpcb *inp;
850 int error;
851
852 inp = sotoinpcb(so);
853 if (inp)
854 panic("rip_attach");
855 if ((so->so_state & SS_PRIV) == 0)
856 return (EPERM);
857
858 error = soreserve(so, rip_sendspace, rip_recvspace);
859 if (error)
860 return error;
861 error = in_pcballoc(so, &ripcbinfo, p);
862 if (error)
863 return error;
864 inp = (struct inpcb *)so->so_pcb;
865 inp->inp_vflag |= INP_IPV4;
866 inp->inp_ip_p = proto;
867 inp->inp_ip_ttl = ip_defttl;
868 return 0;
869 }
870
871 __private_extern__ int
872 rip_detach(struct socket *so)
873 {
874 struct inpcb *inp;
875
876 inp = sotoinpcb(so);
877 if (inp == 0)
878 panic("rip_detach");
879 in_pcbdetach(inp);
880 return 0;
881 }
882
883 __private_extern__ int
884 rip_abort(struct socket *so)
885 {
886 soisdisconnected(so);
887 return rip_detach(so);
888 }
889
890 __private_extern__ int
891 rip_disconnect(struct socket *so)
892 {
893 if ((so->so_state & SS_ISCONNECTED) == 0)
894 return ENOTCONN;
895 return rip_abort(so);
896 }
897
898 __private_extern__ int
899 rip_bind(struct socket *so, struct sockaddr *nam, struct proc *p)
900 {
901 #pragma unused(p)
902 struct inpcb *inp = sotoinpcb(so);
903 struct sockaddr_in sin;
904 struct ifaddr *ifa = NULL;
905 struct ifnet *outif = NULL;
906
907 if (inp == NULL
908 #if NECP
909 || (necp_socket_should_use_flow_divert(inp))
910 #endif /* NECP */
911 )
912 return (inp == NULL ? EINVAL : EPROTOTYPE);
913
914 if (nam->sa_len != sizeof (struct sockaddr_in))
915 return (EINVAL);
916
917 /* Sanitized local copy for interface address searches */
918 bzero(&sin, sizeof (sin));
919 sin.sin_family = AF_INET;
920 sin.sin_len = sizeof (struct sockaddr_in);
921 sin.sin_addr.s_addr = SIN(nam)->sin_addr.s_addr;
922
923 if (TAILQ_EMPTY(&ifnet_head) ||
924 (sin.sin_family != AF_INET && sin.sin_family != AF_IMPLINK) ||
925 (sin.sin_addr.s_addr && (ifa = ifa_ifwithaddr(SA(&sin))) == 0)) {
926 return (EADDRNOTAVAIL);
927 } else if (ifa) {
928 /*
929 * Opportunistically determine the outbound
930 * interface that may be used; this may not
931 * hold true if we end up using a route
932 * going over a different interface, e.g.
933 * when sending to a local address. This
934 * will get updated again after sending.
935 */
936 IFA_LOCK(ifa);
937 outif = ifa->ifa_ifp;
938 IFA_UNLOCK(ifa);
939 IFA_REMREF(ifa);
940 }
941 inp->inp_laddr = sin.sin_addr;
942 inp->inp_last_outifp = outif;
943 return (0);
944 }
945
946 __private_extern__ int
947 rip_connect(struct socket *so, struct sockaddr *nam, __unused struct proc *p)
948 {
949 struct inpcb *inp = sotoinpcb(so);
950 struct sockaddr_in *addr = (struct sockaddr_in *)(void *)nam;
951
952 if (inp == NULL
953 #if NECP
954 || (necp_socket_should_use_flow_divert(inp))
955 #endif /* NECP */
956 )
957 return (inp == NULL ? EINVAL : EPROTOTYPE);
958 if (nam->sa_len != sizeof(*addr))
959 return EINVAL;
960 if (TAILQ_EMPTY(&ifnet_head))
961 return EADDRNOTAVAIL;
962 if ((addr->sin_family != AF_INET) &&
963 (addr->sin_family != AF_IMPLINK))
964 return EAFNOSUPPORT;
965 inp->inp_faddr = addr->sin_addr;
966 soisconnected(so);
967
968 return 0;
969 }
970
971 __private_extern__ int
972 rip_shutdown(struct socket *so)
973 {
974 socantsendmore(so);
975 return 0;
976 }
977
978 __private_extern__ int
979 rip_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam,
980 struct mbuf *control, struct proc *p)
981 {
982 #pragma unused(flags, p)
983 struct inpcb *inp = sotoinpcb(so);
984 u_int32_t dst;
985 int error = 0;
986
987 if (inp == NULL
988 #if NECP
989 || (necp_socket_should_use_flow_divert(inp) && (error = EPROTOTYPE))
990 #endif /* NECP */
991 ) {
992 if (inp == NULL)
993 error = EINVAL;
994 else
995 error = EPROTOTYPE;
996 goto bad;
997 }
998
999 if (so->so_state & SS_ISCONNECTED) {
1000 if (nam != NULL) {
1001 error = EISCONN;
1002 goto bad;
1003 }
1004 dst = inp->inp_faddr.s_addr;
1005 } else {
1006 if (nam == NULL) {
1007 error = ENOTCONN;
1008 goto bad;
1009 }
1010 dst = ((struct sockaddr_in *)(void *)nam)->sin_addr.s_addr;
1011 }
1012 return (rip_output(m, so, dst, control));
1013
1014 bad:
1015 VERIFY(error != 0);
1016
1017 if (m != NULL)
1018 m_freem(m);
1019 if (control != NULL)
1020 m_freem(control);
1021
1022 return (error);
1023 }
1024
1025 /* note: rip_unlock is called from different protos instead of the generic socket_unlock,
1026 * it will handle the socket dealloc on last reference
1027 * */
1028 int
1029 rip_unlock(struct socket *so, int refcount, void *debug)
1030 {
1031 void *lr_saved;
1032 struct inpcb *inp = sotoinpcb(so);
1033
1034 if (debug == NULL)
1035 lr_saved = __builtin_return_address(0);
1036 else
1037 lr_saved = debug;
1038
1039 if (refcount) {
1040 if (so->so_usecount <= 0) {
1041 panic("rip_unlock: bad refoucnt so=%p val=%x lrh= %s\n",
1042 so, so->so_usecount, solockhistory_nr(so));
1043 /* NOTREACHED */
1044 }
1045 so->so_usecount--;
1046 if (so->so_usecount == 0 && (inp->inp_wantcnt == WNT_STOPUSING)) {
1047 /* cleanup after last reference */
1048 lck_mtx_unlock(so->so_proto->pr_domain->dom_mtx);
1049 lck_rw_lock_exclusive(ripcbinfo.ipi_lock);
1050 if (inp->inp_state != INPCB_STATE_DEAD) {
1051 #if INET6
1052 if (SOCK_CHECK_DOM(so, PF_INET6))
1053 in6_pcbdetach(inp);
1054 else
1055 #endif /* INET6 */
1056 in_pcbdetach(inp);
1057 }
1058 in_pcbdispose(inp);
1059 lck_rw_done(ripcbinfo.ipi_lock);
1060 return(0);
1061 }
1062 }
1063 so->unlock_lr[so->next_unlock_lr] = lr_saved;
1064 so->next_unlock_lr = (so->next_unlock_lr+1) % SO_LCKDBG_MAX;
1065 lck_mtx_unlock(so->so_proto->pr_domain->dom_mtx);
1066 return(0);
1067 }
1068
1069 static int
1070 rip_pcblist SYSCTL_HANDLER_ARGS
1071 {
1072 #pragma unused(oidp, arg1, arg2)
1073 int error, i, n;
1074 struct inpcb *inp, **inp_list;
1075 inp_gen_t gencnt;
1076 struct xinpgen xig;
1077
1078 /*
1079 * The process of preparing the TCB list is too time-consuming and
1080 * resource-intensive to repeat twice on every request.
1081 */
1082 lck_rw_lock_exclusive(ripcbinfo.ipi_lock);
1083 if (req->oldptr == USER_ADDR_NULL) {
1084 n = ripcbinfo.ipi_count;
1085 req->oldidx = 2 * (sizeof xig)
1086 + (n + n/8) * sizeof(struct xinpcb);
1087 lck_rw_done(ripcbinfo.ipi_lock);
1088 return 0;
1089 }
1090
1091 if (req->newptr != USER_ADDR_NULL) {
1092 lck_rw_done(ripcbinfo.ipi_lock);
1093 return EPERM;
1094 }
1095
1096 /*
1097 * OK, now we're committed to doing something.
1098 */
1099 gencnt = ripcbinfo.ipi_gencnt;
1100 n = ripcbinfo.ipi_count;
1101
1102 bzero(&xig, sizeof(xig));
1103 xig.xig_len = sizeof xig;
1104 xig.xig_count = n;
1105 xig.xig_gen = gencnt;
1106 xig.xig_sogen = so_gencnt;
1107 error = SYSCTL_OUT(req, &xig, sizeof xig);
1108 if (error) {
1109 lck_rw_done(ripcbinfo.ipi_lock);
1110 return error;
1111 }
1112 /*
1113 * We are done if there is no pcb
1114 */
1115 if (n == 0) {
1116 lck_rw_done(ripcbinfo.ipi_lock);
1117 return 0;
1118 }
1119
1120 inp_list = _MALLOC(n * sizeof *inp_list, M_TEMP, M_WAITOK);
1121 if (inp_list == 0) {
1122 lck_rw_done(ripcbinfo.ipi_lock);
1123 return ENOMEM;
1124 }
1125
1126 for (inp = ripcbinfo.ipi_listhead->lh_first, i = 0; inp && i < n;
1127 inp = inp->inp_list.le_next) {
1128 if (inp->inp_gencnt <= gencnt && inp->inp_state != INPCB_STATE_DEAD)
1129 inp_list[i++] = inp;
1130 }
1131 n = i;
1132
1133 error = 0;
1134 for (i = 0; i < n; i++) {
1135 inp = inp_list[i];
1136 if (inp->inp_gencnt <= gencnt && inp->inp_state != INPCB_STATE_DEAD) {
1137 struct xinpcb xi;
1138
1139 bzero(&xi, sizeof(xi));
1140 xi.xi_len = sizeof xi;
1141 /* XXX should avoid extra copy */
1142 inpcb_to_compat(inp, &xi.xi_inp);
1143 if (inp->inp_socket)
1144 sotoxsocket(inp->inp_socket, &xi.xi_socket);
1145 error = SYSCTL_OUT(req, &xi, sizeof xi);
1146 }
1147 }
1148 if (!error) {
1149 /*
1150 * Give the user an updated idea of our state.
1151 * If the generation differs from what we told
1152 * her before, she knows that something happened
1153 * while we were processing this request, and it
1154 * might be necessary to retry.
1155 */
1156 bzero(&xig, sizeof(xig));
1157 xig.xig_len = sizeof xig;
1158 xig.xig_gen = ripcbinfo.ipi_gencnt;
1159 xig.xig_sogen = so_gencnt;
1160 xig.xig_count = ripcbinfo.ipi_count;
1161 error = SYSCTL_OUT(req, &xig, sizeof xig);
1162 }
1163 FREE(inp_list, M_TEMP);
1164 lck_rw_done(ripcbinfo.ipi_lock);
1165 return error;
1166 }
1167
1168 SYSCTL_PROC(_net_inet_raw, OID_AUTO/*XXX*/, pcblist,
1169 CTLTYPE_STRUCT | CTLFLAG_RD | CTLFLAG_LOCKED, 0, 0,
1170 rip_pcblist, "S,xinpcb", "List of active raw IP sockets");
1171
1172
1173 static int
1174 rip_pcblist64 SYSCTL_HANDLER_ARGS
1175 {
1176 #pragma unused(oidp, arg1, arg2)
1177 int error, i, n;
1178 struct inpcb *inp, **inp_list;
1179 inp_gen_t gencnt;
1180 struct xinpgen xig;
1181
1182 /*
1183 * The process of preparing the TCB list is too time-consuming and
1184 * resource-intensive to repeat twice on every request.
1185 */
1186 lck_rw_lock_exclusive(ripcbinfo.ipi_lock);
1187 if (req->oldptr == USER_ADDR_NULL) {
1188 n = ripcbinfo.ipi_count;
1189 req->oldidx = 2 * (sizeof xig)
1190 + (n + n/8) * sizeof(struct xinpcb64);
1191 lck_rw_done(ripcbinfo.ipi_lock);
1192 return 0;
1193 }
1194
1195 if (req->newptr != USER_ADDR_NULL) {
1196 lck_rw_done(ripcbinfo.ipi_lock);
1197 return EPERM;
1198 }
1199
1200 /*
1201 * OK, now we're committed to doing something.
1202 */
1203 gencnt = ripcbinfo.ipi_gencnt;
1204 n = ripcbinfo.ipi_count;
1205
1206 bzero(&xig, sizeof(xig));
1207 xig.xig_len = sizeof xig;
1208 xig.xig_count = n;
1209 xig.xig_gen = gencnt;
1210 xig.xig_sogen = so_gencnt;
1211 error = SYSCTL_OUT(req, &xig, sizeof xig);
1212 if (error) {
1213 lck_rw_done(ripcbinfo.ipi_lock);
1214 return error;
1215 }
1216 /*
1217 * We are done if there is no pcb
1218 */
1219 if (n == 0) {
1220 lck_rw_done(ripcbinfo.ipi_lock);
1221 return 0;
1222 }
1223
1224 inp_list = _MALLOC(n * sizeof *inp_list, M_TEMP, M_WAITOK);
1225 if (inp_list == 0) {
1226 lck_rw_done(ripcbinfo.ipi_lock);
1227 return ENOMEM;
1228 }
1229
1230 for (inp = ripcbinfo.ipi_listhead->lh_first, i = 0; inp && i < n;
1231 inp = inp->inp_list.le_next) {
1232 if (inp->inp_gencnt <= gencnt && inp->inp_state != INPCB_STATE_DEAD)
1233 inp_list[i++] = inp;
1234 }
1235 n = i;
1236
1237 error = 0;
1238 for (i = 0; i < n; i++) {
1239 inp = inp_list[i];
1240 if (inp->inp_gencnt <= gencnt && inp->inp_state != INPCB_STATE_DEAD) {
1241 struct xinpcb64 xi;
1242
1243 bzero(&xi, sizeof(xi));
1244 xi.xi_len = sizeof xi;
1245 inpcb_to_xinpcb64(inp, &xi);
1246 if (inp->inp_socket)
1247 sotoxsocket64(inp->inp_socket, &xi.xi_socket);
1248 error = SYSCTL_OUT(req, &xi, sizeof xi);
1249 }
1250 }
1251 if (!error) {
1252 /*
1253 * Give the user an updated idea of our state.
1254 * If the generation differs from what we told
1255 * her before, she knows that something happened
1256 * while we were processing this request, and it
1257 * might be necessary to retry.
1258 */
1259 bzero(&xig, sizeof(xig));
1260 xig.xig_len = sizeof xig;
1261 xig.xig_gen = ripcbinfo.ipi_gencnt;
1262 xig.xig_sogen = so_gencnt;
1263 xig.xig_count = ripcbinfo.ipi_count;
1264 error = SYSCTL_OUT(req, &xig, sizeof xig);
1265 }
1266 FREE(inp_list, M_TEMP);
1267 lck_rw_done(ripcbinfo.ipi_lock);
1268 return error;
1269 }
1270
1271 SYSCTL_PROC(_net_inet_raw, OID_AUTO, pcblist64,
1272 CTLTYPE_STRUCT | CTLFLAG_RD | CTLFLAG_LOCKED, 0, 0,
1273 rip_pcblist64, "S,xinpcb64", "List of active raw IP sockets");
1274
1275
1276
1277 static int
1278 rip_pcblist_n SYSCTL_HANDLER_ARGS
1279 {
1280 #pragma unused(oidp, arg1, arg2)
1281 int error = 0;
1282
1283 error = get_pcblist_n(IPPROTO_IP, req, &ripcbinfo);
1284
1285 return error;
1286 }
1287
1288 SYSCTL_PROC(_net_inet_raw, OID_AUTO, pcblist_n,
1289 CTLTYPE_STRUCT | CTLFLAG_RD | CTLFLAG_LOCKED, 0, 0,
1290 rip_pcblist_n, "S,xinpcb_n", "List of active raw IP sockets");
1291
1292 struct pr_usrreqs rip_usrreqs = {
1293 .pru_abort = rip_abort,
1294 .pru_attach = rip_attach,
1295 .pru_bind = rip_bind,
1296 .pru_connect = rip_connect,
1297 .pru_control = in_control,
1298 .pru_detach = rip_detach,
1299 .pru_disconnect = rip_disconnect,
1300 .pru_peeraddr = in_getpeeraddr,
1301 .pru_send = rip_send,
1302 .pru_shutdown = rip_shutdown,
1303 .pru_sockaddr = in_getsockaddr,
1304 .pru_sosend = sosend,
1305 .pru_soreceive = soreceive,
1306 };
1307 /* DSEP Review Done pl-20051213-v02 @3253 */