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