xref: /netbsd-src/sys/netinet/raw_ip.c (revision df0caa2637da0538ecdf6b878c4d08e684b43d8f)
1 /*	$NetBSD: raw_ip.c,v 1.87 2005/04/29 10:39:09 yamt 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.87 2005/04/29 10:39:09 yamt 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 proc *p)
506 {
507 	struct inpcb *inp;
508 	int s;
509 	int error = 0;
510 #ifdef MROUTING
511 	extern struct socket *ip_mrouter;
512 #endif
513 
514 	if (req == PRU_CONTROL)
515 		return (in_control(so, (long)m, (caddr_t)nam,
516 		    (struct ifnet *)control, p));
517 
518 	if (req == PRU_PURGEIF) {
519 		in_pcbpurgeif0(&rawcbtable, (struct ifnet *)control);
520 		in_purgeif((struct ifnet *)control);
521 		in_pcbpurgeif(&rawcbtable, (struct ifnet *)control);
522 		return (0);
523 	}
524 
525 	s = splsoftnet();
526 	inp = sotoinpcb(so);
527 #ifdef DIAGNOSTIC
528 	if (req != PRU_SEND && req != PRU_SENDOOB && control)
529 		panic("rip_usrreq: unexpected control mbuf");
530 #endif
531 	if (inp == 0 && req != PRU_ATTACH) {
532 		error = EINVAL;
533 		goto release;
534 	}
535 
536 	switch (req) {
537 
538 	case PRU_ATTACH:
539 		if (inp != 0) {
540 			error = EISCONN;
541 			break;
542 		}
543 		if (p == 0 || (error = suser(p->p_ucred, &p->p_acflag))) {
544 			error = EACCES;
545 			break;
546 		}
547 		if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
548 			error = soreserve(so, rip_sendspace, rip_recvspace);
549 			if (error)
550 				break;
551 		}
552 		error = in_pcballoc(so, &rawcbtable);
553 		if (error)
554 			break;
555 		inp = sotoinpcb(so);
556 		inp->inp_ip.ip_p = (long)nam;
557 		break;
558 
559 	case PRU_DETACH:
560 #ifdef MROUTING
561 		if (so == ip_mrouter)
562 			ip_mrouter_done();
563 #endif
564 		in_pcbdetach(inp);
565 		break;
566 
567 	case PRU_BIND:
568 		error = rip_bind(inp, nam);
569 		break;
570 
571 	case PRU_LISTEN:
572 		error = EOPNOTSUPP;
573 		break;
574 
575 	case PRU_CONNECT:
576 		error = rip_connect(inp, nam);
577 		if (error)
578 			break;
579 		soisconnected(so);
580 		break;
581 
582 	case PRU_CONNECT2:
583 		error = EOPNOTSUPP;
584 		break;
585 
586 	case PRU_DISCONNECT:
587 		soisdisconnected(so);
588 		rip_disconnect(inp);
589 		break;
590 
591 	/*
592 	 * Mark the connection as being incapable of further input.
593 	 */
594 	case PRU_SHUTDOWN:
595 		socantsendmore(so);
596 		break;
597 
598 	case PRU_RCVD:
599 		error = EOPNOTSUPP;
600 		break;
601 
602 	/*
603 	 * Ship a packet out.  The appropriate raw output
604 	 * routine handles any massaging necessary.
605 	 */
606 	case PRU_SEND:
607 		if (control && control->m_len) {
608 			m_freem(control);
609 			m_freem(m);
610 			error = EINVAL;
611 			break;
612 		}
613 	{
614 		if (nam) {
615 			if ((so->so_state & SS_ISCONNECTED) != 0) {
616 				error = EISCONN;
617 				goto die;
618 			}
619 			error = rip_connect(inp, nam);
620 			if (error) {
621 			die:
622 				m_freem(m);
623 				break;
624 			}
625 		} else {
626 			if ((so->so_state & SS_ISCONNECTED) == 0) {
627 				error = ENOTCONN;
628 				goto die;
629 			}
630 		}
631 		error = rip_output(m, inp);
632 		if (nam)
633 			rip_disconnect(inp);
634 	}
635 		break;
636 
637 	case PRU_SENSE:
638 		/*
639 		 * stat: don't bother with a blocksize.
640 		 */
641 		splx(s);
642 		return (0);
643 
644 	case PRU_RCVOOB:
645 		error = EOPNOTSUPP;
646 		break;
647 
648 	case PRU_SENDOOB:
649 		m_freem(control);
650 		m_freem(m);
651 		error = EOPNOTSUPP;
652 		break;
653 
654 	case PRU_SOCKADDR:
655 		in_setsockaddr(inp, nam);
656 		break;
657 
658 	case PRU_PEERADDR:
659 		in_setpeeraddr(inp, nam);
660 		break;
661 
662 	default:
663 		panic("rip_usrreq");
664 	}
665 
666 release:
667 	splx(s);
668 	return (error);
669 }
670 
671 SYSCTL_SETUP(sysctl_net_inet_raw_setup, "sysctl net.inet.raw subtree setup")
672 {
673 
674 	sysctl_createv(clog, 0, NULL, NULL,
675 		       CTLFLAG_PERMANENT,
676 		       CTLTYPE_NODE, "net", NULL,
677 		       NULL, 0, NULL, 0,
678 		       CTL_NET, CTL_EOL);
679 	sysctl_createv(clog, 0, NULL, NULL,
680 		       CTLFLAG_PERMANENT,
681 		       CTLTYPE_NODE, "inet", NULL,
682 		       NULL, 0, NULL, 0,
683 		       CTL_NET, PF_INET, CTL_EOL);
684 	sysctl_createv(clog, 0, NULL, NULL,
685 		       CTLFLAG_PERMANENT,
686 		       CTLTYPE_NODE, "raw",
687 		       SYSCTL_DESCR("Raw IPv4 settings"),
688 		       NULL, 0, NULL, 0,
689 		       CTL_NET, PF_INET, IPPROTO_RAW, CTL_EOL);
690 
691 	sysctl_createv(clog, 0, NULL, NULL,
692 		       CTLFLAG_PERMANENT,
693 		       CTLTYPE_STRUCT, "pcblist",
694 		       SYSCTL_DESCR("Raw IPv4 control block list"),
695 		       sysctl_inpcblist, 0, &rawcbtable, 0,
696 		       CTL_NET, PF_INET, IPPROTO_RAW,
697 		       CTL_CREATE, CTL_EOL);
698 }
699