xref: /netbsd-src/sys/netinet/raw_ip.c (revision e5548b402ae4c44fb816de42c7bba9581ce23ef5)
1 /*	$NetBSD: raw_ip.c,v 1.88 2005/12/11 12:24:57 christos Exp $	*/
2 
3 /*
4  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
5  * 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  * 3. Neither the name of the project 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 PROJECT 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 PROJECT 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 
32 /*
33  * Copyright (c) 1982, 1986, 1988, 1993
34  *	The Regents of the University of California.  All rights reserved.
35  *
36  * Redistribution and use in source and binary forms, with or without
37  * modification, are permitted provided that the following conditions
38  * are met:
39  * 1. Redistributions of source code must retain the above copyright
40  *    notice, this list of conditions and the following disclaimer.
41  * 2. Redistributions in binary form must reproduce the above copyright
42  *    notice, this list of conditions and the following disclaimer in the
43  *    documentation and/or other materials provided with the distribution.
44  * 3. 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 #include <sys/cdefs.h>
64 __KERNEL_RCSID(0, "$NetBSD: raw_ip.c,v 1.88 2005/12/11 12:24:57 christos Exp $");
65 
66 #include "opt_inet.h"
67 #include "opt_ipsec.h"
68 #include "opt_mrouting.h"
69 
70 #include <sys/param.h>
71 #include <sys/sysctl.h>
72 #include <sys/malloc.h>
73 #include <sys/mbuf.h>
74 #include <sys/socket.h>
75 #include <sys/protosw.h>
76 #include <sys/socketvar.h>
77 #include <sys/errno.h>
78 #include <sys/systm.h>
79 #include <sys/proc.h>
80 
81 #include <net/if.h>
82 #include <net/route.h>
83 
84 #include <netinet/in.h>
85 #include <netinet/in_systm.h>
86 #include <netinet/ip.h>
87 #include <netinet/ip_var.h>
88 #include <netinet/ip_mroute.h>
89 #include <netinet/ip_icmp.h>
90 #include <netinet/in_pcb.h>
91 #include <netinet/in_proto.h>
92 #include <netinet/in_var.h>
93 
94 #include <machine/stdarg.h>
95 
96 #ifdef IPSEC
97 #include <netinet6/ipsec.h>
98 #endif /*IPSEC*/
99 
100 #ifdef FAST_IPSEC
101 #include <netipsec/ipsec.h>
102 #include <netipsec/ipsec_var.h>			/* XXX ipsecstat namespace */
103 #endif	/* FAST_IPSEC*/
104 
105 struct inpcbtable rawcbtable;
106 
107 int	 rip_pcbnotify(struct inpcbtable *, struct in_addr,
108     struct in_addr, int, int, void (*)(struct inpcb *, int));
109 int	 rip_bind(struct inpcb *, struct mbuf *);
110 int	 rip_connect(struct inpcb *, struct mbuf *);
111 void	 rip_disconnect(struct inpcb *);
112 
113 /*
114  * Nominal space allocated to a raw ip socket.
115  */
116 #define	RIPSNDQ		8192
117 #define	RIPRCVQ		8192
118 
119 /*
120  * Raw interface to IP protocol.
121  */
122 
123 /*
124  * Initialize raw connection block q.
125  */
126 void
127 rip_init(void)
128 {
129 
130 	in_pcbinit(&rawcbtable, 1, 1);
131 }
132 
133 /*
134  * Setup generic address and protocol structures
135  * for raw_input routine, then pass them along with
136  * mbuf chain.
137  */
138 void
139 rip_input(struct mbuf *m, ...)
140 {
141 	int proto;
142 	struct ip *ip = mtod(m, struct ip *);
143 	struct inpcb_hdr *inph;
144 	struct inpcb *inp;
145 	struct inpcb *last = 0;
146 	struct mbuf *opts = 0;
147 	struct sockaddr_in ripsrc;
148 	va_list ap;
149 
150 	va_start(ap, m);
151 	(void)va_arg(ap, int);		/* ignore value, advance ap */
152 	proto = va_arg(ap, int);
153 	va_end(ap);
154 
155 	ripsrc.sin_family = AF_INET;
156 	ripsrc.sin_len = sizeof(struct sockaddr_in);
157 	ripsrc.sin_addr = ip->ip_src;
158 	ripsrc.sin_port = 0;
159 	bzero((caddr_t)ripsrc.sin_zero, sizeof(ripsrc.sin_zero));
160 
161 	/*
162 	 * XXX Compatibility: programs using raw IP expect ip_len
163 	 * XXX to have the header length subtracted, and in host order.
164 	 * XXX ip_off is also expected to be host order.
165 	 */
166 	ip->ip_len = ntohs(ip->ip_len) - (ip->ip_hl << 2);
167 	NTOHS(ip->ip_off);
168 
169 	CIRCLEQ_FOREACH(inph, &rawcbtable.inpt_queue, inph_queue) {
170 		inp = (struct inpcb *)inph;
171 		if (inp->inp_af != AF_INET)
172 			continue;
173 		if (inp->inp_ip.ip_p && inp->inp_ip.ip_p != proto)
174 			continue;
175 		if (!in_nullhost(inp->inp_laddr) &&
176 		    !in_hosteq(inp->inp_laddr, ip->ip_dst))
177 			continue;
178 		if (!in_nullhost(inp->inp_faddr) &&
179 		    !in_hosteq(inp->inp_faddr, ip->ip_src))
180 			continue;
181 		if (last) {
182 			struct mbuf *n;
183 
184 #if defined(IPSEC) || defined(FAST_IPSEC)
185 			/* check AH/ESP integrity. */
186 			if (ipsec4_in_reject_so(m, last->inp_socket)) {
187 				ipsecstat.in_polvio++;
188 				/* do not inject data to pcb */
189 			} else
190 #endif /*IPSEC*/
191 			if ((n = m_copy(m, 0, (int)M_COPYALL)) != NULL) {
192 				if (last->inp_flags & INP_CONTROLOPTS ||
193 				    last->inp_socket->so_options & SO_TIMESTAMP)
194 					ip_savecontrol(last, &opts, ip, n);
195 				if (sbappendaddr(&last->inp_socket->so_rcv,
196 				    sintosa(&ripsrc), n, opts) == 0) {
197 					/* should notify about lost packet */
198 					m_freem(n);
199 					if (opts)
200 						m_freem(opts);
201 				} else
202 					sorwakeup(last->inp_socket);
203 				opts = NULL;
204 			}
205 		}
206 		last = inp;
207 	}
208 #if defined(IPSEC) || defined(FAST_IPSEC)
209 	/* check AH/ESP integrity. */
210 	if (last && ipsec4_in_reject_so(m, last->inp_socket)) {
211 		m_freem(m);
212 		ipsecstat.in_polvio++;
213 		ipstat.ips_delivered--;
214 		/* do not inject data to pcb */
215 	} else
216 #endif /*IPSEC*/
217 	if (last) {
218 		if (last->inp_flags & INP_CONTROLOPTS ||
219 		    last->inp_socket->so_options & SO_TIMESTAMP)
220 			ip_savecontrol(last, &opts, ip, m);
221 		if (sbappendaddr(&last->inp_socket->so_rcv,
222 		    sintosa(&ripsrc), m, opts) == 0) {
223 			m_freem(m);
224 			if (opts)
225 				m_freem(opts);
226 		} else
227 			sorwakeup(last->inp_socket);
228 	} else {
229 		if (inetsw[ip_protox[ip->ip_p]].pr_input == rip_input) {
230 			icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_PROTOCOL,
231 			    0, 0);
232 			ipstat.ips_noproto++;
233 			ipstat.ips_delivered--;
234 		} else
235 			m_freem(m);
236 	}
237 	return;
238 }
239 
240 int
241 rip_pcbnotify(struct inpcbtable *table,
242     struct in_addr faddr, struct in_addr laddr, int proto, int errno,
243     void (*notify)(struct inpcb *, int))
244 {
245 	struct inpcb *inp, *ninp;
246 	int nmatch;
247 
248 	nmatch = 0;
249 	for (inp = (struct inpcb *)CIRCLEQ_FIRST(&table->inpt_queue);
250 	    inp != (struct inpcb *)&table->inpt_queue;
251 	    inp = ninp) {
252 		ninp = (struct inpcb *)inp->inp_queue.cqe_next;
253 		if (inp->inp_af != AF_INET)
254 			continue;
255 		if (inp->inp_ip.ip_p && inp->inp_ip.ip_p != proto)
256 			continue;
257 		if (in_hosteq(inp->inp_faddr, faddr) &&
258 		    in_hosteq(inp->inp_laddr, laddr)) {
259 			(*notify)(inp, errno);
260 			nmatch++;
261 		}
262 	}
263 
264 	return nmatch;
265 }
266 
267 void *
268 rip_ctlinput(int cmd, struct sockaddr *sa, void *v)
269 {
270 	struct ip *ip = v;
271 	void (*notify)(struct inpcb *, int) = in_rtchange;
272 	int errno;
273 
274 	if (sa->sa_family != AF_INET ||
275 	    sa->sa_len != sizeof(struct sockaddr_in))
276 		return NULL;
277 	if ((unsigned)cmd >= PRC_NCMDS)
278 		return NULL;
279 	errno = inetctlerrmap[cmd];
280 	if (PRC_IS_REDIRECT(cmd))
281 		notify = in_rtchange, ip = 0;
282 	else if (cmd == PRC_HOSTDEAD)
283 		ip = 0;
284 	else if (errno == 0)
285 		return NULL;
286 	if (ip) {
287 		rip_pcbnotify(&rawcbtable, satosin(sa)->sin_addr,
288 		    ip->ip_src, ip->ip_p, errno, notify);
289 
290 		/* XXX mapped address case */
291 	} else
292 		in_pcbnotifyall(&rawcbtable, satosin(sa)->sin_addr, errno,
293 		    notify);
294 	return NULL;
295 }
296 
297 /*
298  * Generate IP header and pass packet to ip_output.
299  * Tack on options user may have setup with control call.
300  */
301 int
302 rip_output(struct mbuf *m, ...)
303 {
304 	struct inpcb *inp;
305 	struct ip *ip;
306 	struct mbuf *opts;
307 	int flags;
308 	va_list ap;
309 
310 	va_start(ap, m);
311 	inp = va_arg(ap, struct inpcb *);
312 	va_end(ap);
313 
314 	flags =
315 	    (inp->inp_socket->so_options & SO_DONTROUTE) | IP_ALLOWBROADCAST
316 	    | IP_RETURNMTU;
317 
318 	/*
319 	 * If the user handed us a complete IP packet, use it.
320 	 * Otherwise, allocate an mbuf for a header and fill it in.
321 	 */
322 	if ((inp->inp_flags & INP_HDRINCL) == 0) {
323 		if ((m->m_pkthdr.len + sizeof(struct ip)) > IP_MAXPACKET) {
324 			m_freem(m);
325 			return (EMSGSIZE);
326 		}
327 		M_PREPEND(m, sizeof(struct ip), M_DONTWAIT);
328 		if (!m)
329 			return (ENOBUFS);
330 		ip = mtod(m, struct ip *);
331 		ip->ip_tos = 0;
332 		ip->ip_off = htons(0);
333 		ip->ip_p = inp->inp_ip.ip_p;
334 		ip->ip_len = htons(m->m_pkthdr.len);
335 		ip->ip_src = inp->inp_laddr;
336 		ip->ip_dst = inp->inp_faddr;
337 		ip->ip_ttl = MAXTTL;
338 		opts = inp->inp_options;
339 	} else {
340 		if (m->m_pkthdr.len > IP_MAXPACKET) {
341 			m_freem(m);
342 			return (EMSGSIZE);
343 		}
344 		ip = mtod(m, struct ip *);
345 
346 		/*
347 		 * If the mbuf is read-only, we need to allocate
348 		 * a new mbuf for the header, since we need to
349 		 * modify the header.
350 		 */
351 		if (M_READONLY(m)) {
352 			int hlen = ip->ip_hl << 2;
353 
354 			m = m_copyup(m, hlen, (max_linkhdr + 3) & ~3);
355 			if (m == NULL)
356 				return (ENOMEM);	/* XXX */
357 			ip = mtod(m, struct ip *);
358 		}
359 
360 		/* XXX userland passes ip_len and ip_off in host order */
361 		if (m->m_pkthdr.len != ip->ip_len) {
362 			m_freem(m);
363 			return (EINVAL);
364 		}
365 		HTONS(ip->ip_len);
366 		HTONS(ip->ip_off);
367 		if (ip->ip_id == 0)
368 			ip->ip_id = ip_newid();
369 		opts = NULL;
370 		/* XXX prevent ip_output from overwriting header fields */
371 		flags |= IP_RAWOUTPUT;
372 		ipstat.ips_rawout++;
373 	}
374 	return (ip_output(m, opts, &inp->inp_route, flags, inp->inp_moptions,
375 	     inp->inp_socket, &inp->inp_errormtu));
376 }
377 
378 /*
379  * Raw IP socket option processing.
380  */
381 int
382 rip_ctloutput(int op, struct socket *so, int level, int optname,
383     struct mbuf **m)
384 {
385 	struct inpcb *inp = sotoinpcb(so);
386 	int error = 0;
387 
388 	if (level != IPPROTO_IP) {
389 		error = ENOPROTOOPT;
390 		if (op == PRCO_SETOPT && *m != 0)
391 			(void) m_free(*m);
392 	} else switch (op) {
393 
394 	case PRCO_SETOPT:
395 		switch (optname) {
396 		case IP_HDRINCL:
397 			if (*m == 0 || (*m)->m_len < sizeof (int))
398 				error = EINVAL;
399 			else {
400 				if (*mtod(*m, int *))
401 					inp->inp_flags |= INP_HDRINCL;
402 				else
403 					inp->inp_flags &= ~INP_HDRINCL;
404 			}
405 			if (*m != 0)
406 				(void) m_free(*m);
407 			break;
408 
409 #ifdef MROUTING
410 		case MRT_INIT:
411 		case MRT_DONE:
412 		case MRT_ADD_VIF:
413 		case MRT_DEL_VIF:
414 		case MRT_ADD_MFC:
415 		case MRT_DEL_MFC:
416 		case MRT_ASSERT:
417 		case MRT_API_CONFIG:
418 		case MRT_ADD_BW_UPCALL:
419 		case MRT_DEL_BW_UPCALL:
420 			error = ip_mrouter_set(so, optname, m);
421 			break;
422 #endif
423 
424 		default:
425 			error = ip_ctloutput(op, so, level, optname, m);
426 			break;
427 		}
428 		break;
429 
430 	case PRCO_GETOPT:
431 		switch (optname) {
432 		case IP_HDRINCL:
433 			*m = m_get(M_WAIT, MT_SOOPTS);
434 			MCLAIM((*m), so->so_mowner);
435 			(*m)->m_len = sizeof (int);
436 			*mtod(*m, int *) = inp->inp_flags & INP_HDRINCL ? 1 : 0;
437 			break;
438 
439 #ifdef MROUTING
440 		case MRT_VERSION:
441 		case MRT_ASSERT:
442 		case MRT_API_SUPPORT:
443 		case MRT_API_CONFIG:
444 			error = ip_mrouter_get(so, optname, m);
445 			break;
446 #endif
447 
448 		default:
449 			error = ip_ctloutput(op, so, level, optname, m);
450 			break;
451 		}
452 		break;
453 	}
454 	return (error);
455 }
456 
457 int
458 rip_bind(struct inpcb *inp, struct mbuf *nam)
459 {
460 	struct sockaddr_in *addr = mtod(nam, struct sockaddr_in *);
461 
462 	if (nam->m_len != sizeof(*addr))
463 		return (EINVAL);
464 	if (TAILQ_FIRST(&ifnet) == 0)
465 		return (EADDRNOTAVAIL);
466 	if (addr->sin_family != AF_INET &&
467 	    addr->sin_family != AF_IMPLINK)
468 		return (EAFNOSUPPORT);
469 	if (!in_nullhost(addr->sin_addr) &&
470 	    ifa_ifwithaddr(sintosa(addr)) == 0)
471 		return (EADDRNOTAVAIL);
472 	inp->inp_laddr = addr->sin_addr;
473 	return (0);
474 }
475 
476 int
477 rip_connect(struct inpcb *inp, struct mbuf *nam)
478 {
479 	struct sockaddr_in *addr = mtod(nam, struct sockaddr_in *);
480 
481 	if (nam->m_len != sizeof(*addr))
482 		return (EINVAL);
483 	if (TAILQ_FIRST(&ifnet) == 0)
484 		return (EADDRNOTAVAIL);
485 	if (addr->sin_family != AF_INET &&
486 	    addr->sin_family != AF_IMPLINK)
487 		return (EAFNOSUPPORT);
488 	inp->inp_faddr = addr->sin_addr;
489 	return (0);
490 }
491 
492 void
493 rip_disconnect(struct inpcb *inp)
494 {
495 
496 	inp->inp_faddr = zeroin_addr;
497 }
498 
499 u_long	rip_sendspace = RIPSNDQ;
500 u_long	rip_recvspace = RIPRCVQ;
501 
502 /*ARGSUSED*/
503 int
504 rip_usrreq(struct socket *so, int req,
505     struct mbuf *m, struct mbuf *nam, struct mbuf *control, struct lwp *l)
506 {
507 	struct inpcb *inp;
508 	struct proc *p;
509 	int s;
510 	int error = 0;
511 #ifdef MROUTING
512 	extern struct socket *ip_mrouter;
513 #endif
514 
515 	p = l ? l->l_proc : NULL;
516 	if (req == PRU_CONTROL)
517 		return (in_control(so, (long)m, (caddr_t)nam,
518 		    (struct ifnet *)control, p));
519 
520 	if (req == PRU_PURGEIF) {
521 		in_pcbpurgeif0(&rawcbtable, (struct ifnet *)control);
522 		in_purgeif((struct ifnet *)control);
523 		in_pcbpurgeif(&rawcbtable, (struct ifnet *)control);
524 		return (0);
525 	}
526 
527 	s = splsoftnet();
528 	inp = sotoinpcb(so);
529 #ifdef DIAGNOSTIC
530 	if (req != PRU_SEND && req != PRU_SENDOOB && control)
531 		panic("rip_usrreq: unexpected control mbuf");
532 #endif
533 	if (inp == 0 && req != PRU_ATTACH) {
534 		error = EINVAL;
535 		goto release;
536 	}
537 
538 	switch (req) {
539 
540 	case PRU_ATTACH:
541 		if (inp != 0) {
542 			error = EISCONN;
543 			break;
544 		}
545 		if (p == 0 || (error = suser(p->p_ucred, &p->p_acflag))) {
546 			error = EACCES;
547 			break;
548 		}
549 		if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
550 			error = soreserve(so, rip_sendspace, rip_recvspace);
551 			if (error)
552 				break;
553 		}
554 		error = in_pcballoc(so, &rawcbtable);
555 		if (error)
556 			break;
557 		inp = sotoinpcb(so);
558 		inp->inp_ip.ip_p = (long)nam;
559 		break;
560 
561 	case PRU_DETACH:
562 #ifdef MROUTING
563 		if (so == ip_mrouter)
564 			ip_mrouter_done();
565 #endif
566 		in_pcbdetach(inp);
567 		break;
568 
569 	case PRU_BIND:
570 		error = rip_bind(inp, nam);
571 		break;
572 
573 	case PRU_LISTEN:
574 		error = EOPNOTSUPP;
575 		break;
576 
577 	case PRU_CONNECT:
578 		error = rip_connect(inp, nam);
579 		if (error)
580 			break;
581 		soisconnected(so);
582 		break;
583 
584 	case PRU_CONNECT2:
585 		error = EOPNOTSUPP;
586 		break;
587 
588 	case PRU_DISCONNECT:
589 		soisdisconnected(so);
590 		rip_disconnect(inp);
591 		break;
592 
593 	/*
594 	 * Mark the connection as being incapable of further input.
595 	 */
596 	case PRU_SHUTDOWN:
597 		socantsendmore(so);
598 		break;
599 
600 	case PRU_RCVD:
601 		error = EOPNOTSUPP;
602 		break;
603 
604 	/*
605 	 * Ship a packet out.  The appropriate raw output
606 	 * routine handles any massaging necessary.
607 	 */
608 	case PRU_SEND:
609 		if (control && control->m_len) {
610 			m_freem(control);
611 			m_freem(m);
612 			error = EINVAL;
613 			break;
614 		}
615 	{
616 		if (nam) {
617 			if ((so->so_state & SS_ISCONNECTED) != 0) {
618 				error = EISCONN;
619 				goto die;
620 			}
621 			error = rip_connect(inp, nam);
622 			if (error) {
623 			die:
624 				m_freem(m);
625 				break;
626 			}
627 		} else {
628 			if ((so->so_state & SS_ISCONNECTED) == 0) {
629 				error = ENOTCONN;
630 				goto die;
631 			}
632 		}
633 		error = rip_output(m, inp);
634 		if (nam)
635 			rip_disconnect(inp);
636 	}
637 		break;
638 
639 	case PRU_SENSE:
640 		/*
641 		 * stat: don't bother with a blocksize.
642 		 */
643 		splx(s);
644 		return (0);
645 
646 	case PRU_RCVOOB:
647 		error = EOPNOTSUPP;
648 		break;
649 
650 	case PRU_SENDOOB:
651 		m_freem(control);
652 		m_freem(m);
653 		error = EOPNOTSUPP;
654 		break;
655 
656 	case PRU_SOCKADDR:
657 		in_setsockaddr(inp, nam);
658 		break;
659 
660 	case PRU_PEERADDR:
661 		in_setpeeraddr(inp, nam);
662 		break;
663 
664 	default:
665 		panic("rip_usrreq");
666 	}
667 
668 release:
669 	splx(s);
670 	return (error);
671 }
672 
673 SYSCTL_SETUP(sysctl_net_inet_raw_setup, "sysctl net.inet.raw subtree setup")
674 {
675 
676 	sysctl_createv(clog, 0, NULL, NULL,
677 		       CTLFLAG_PERMANENT,
678 		       CTLTYPE_NODE, "net", NULL,
679 		       NULL, 0, NULL, 0,
680 		       CTL_NET, CTL_EOL);
681 	sysctl_createv(clog, 0, NULL, NULL,
682 		       CTLFLAG_PERMANENT,
683 		       CTLTYPE_NODE, "inet", NULL,
684 		       NULL, 0, NULL, 0,
685 		       CTL_NET, PF_INET, CTL_EOL);
686 	sysctl_createv(clog, 0, NULL, NULL,
687 		       CTLFLAG_PERMANENT,
688 		       CTLTYPE_NODE, "raw",
689 		       SYSCTL_DESCR("Raw IPv4 settings"),
690 		       NULL, 0, NULL, 0,
691 		       CTL_NET, PF_INET, IPPROTO_RAW, CTL_EOL);
692 
693 	sysctl_createv(clog, 0, NULL, NULL,
694 		       CTLFLAG_PERMANENT,
695 		       CTLTYPE_STRUCT, "pcblist",
696 		       SYSCTL_DESCR("Raw IPv4 control block list"),
697 		       sysctl_inpcblist, 0, &rawcbtable, 0,
698 		       CTL_NET, PF_INET, IPPROTO_RAW,
699 		       CTL_CREATE, CTL_EOL);
700 }
701