xref: /dragonfly/sys/netinet/raw_ip.c (revision 19fe1c42)
1 /*
2  * Copyright (c) 1982, 1986, 1988, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *	This product includes software developed by the University of
16  *	California, Berkeley and its contributors.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  *	@(#)raw_ip.c	8.7 (Berkeley) 5/15/95
34  * $FreeBSD: src/sys/netinet/raw_ip.c,v 1.64.2.16 2003/08/24 08:24:38 hsu Exp $
35  * $DragonFly: src/sys/netinet/raw_ip.c,v 1.33 2008/10/28 03:07:28 sephe Exp $
36  */
37 
38 #include "opt_inet6.h"
39 #include "opt_ipsec.h"
40 
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/kernel.h>
44 #include <sys/jail.h>
45 #include <sys/malloc.h>
46 #include <sys/mbuf.h>
47 #include <sys/proc.h>
48 #include <sys/priv.h>
49 #include <sys/protosw.h>
50 #include <sys/socket.h>
51 #include <sys/socketvar.h>
52 #include <sys/sysctl.h>
53 #include <sys/thread2.h>
54 
55 #include <machine/stdarg.h>
56 
57 #include <vm/vm_zone.h>
58 
59 #include <net/if.h>
60 #include <net/route.h>
61 
62 #define _IP_VHL
63 #include <netinet/in.h>
64 #include <netinet/in_systm.h>
65 #include <netinet/ip.h>
66 #include <netinet/in_pcb.h>
67 #include <netinet/in_var.h>
68 #include <netinet/ip_var.h>
69 
70 #include <net/ip_mroute/ip_mroute.h>
71 #include <net/ipfw/ip_fw.h>
72 #include <net/dummynet/ip_dummynet.h>
73 
74 #ifdef FAST_IPSEC
75 #include <netproto/ipsec/ipsec.h>
76 #endif /*FAST_IPSEC*/
77 
78 #ifdef IPSEC
79 #include <netinet6/ipsec.h>
80 #endif /*IPSEC*/
81 
82 struct	inpcbinfo ripcbinfo;
83 
84 /* control hooks for ipfw and dummynet */
85 ip_fw_ctl_t *ip_fw_ctl_ptr;
86 ip_dn_ctl_t *ip_dn_ctl_ptr;
87 
88 /*
89  * hooks for multicast routing. They all default to NULL,
90  * so leave them not initialized and rely on BSS being set to 0.
91  */
92 
93 /* The socket used to communicate with the multicast routing daemon.  */
94 struct socket  *ip_mrouter;
95 
96 /* The various mrouter and rsvp functions */
97 int (*ip_mrouter_set)(struct socket *, struct sockopt *);
98 int (*ip_mrouter_get)(struct socket *, struct sockopt *);
99 int (*ip_mrouter_done)(void);
100 int (*ip_mforward)(struct ip *, struct ifnet *, struct mbuf *,
101 		struct ip_moptions *);
102 int (*mrt_ioctl)(int, caddr_t);
103 int (*legal_vif_num)(int);
104 u_long (*ip_mcast_src)(int);
105 
106 void (*rsvp_input_p)(struct mbuf *m, ...);
107 int (*ip_rsvp_vif)(struct socket *, struct sockopt *);
108 void (*ip_rsvp_force_done)(struct socket *);
109 
110 /*
111  * Nominal space allocated to a raw ip socket.
112  */
113 #define	RIPSNDQ		8192
114 #define	RIPRCVQ		8192
115 
116 /*
117  * Raw interface to IP protocol.
118  */
119 
120 /*
121  * Initialize raw connection block queue.
122  */
123 void
124 rip_init(void)
125 {
126 	in_pcbinfo_init(&ripcbinfo);
127 	/*
128 	 * XXX We don't use the hash list for raw IP, but it's easier
129 	 * to allocate a one entry hash list than it is to check all
130 	 * over the place for hashbase == NULL.
131 	 */
132 	ripcbinfo.hashbase = hashinit(1, M_PCB, &ripcbinfo.hashmask);
133 	ripcbinfo.porthashbase = hashinit(1, M_PCB, &ripcbinfo.porthashmask);
134 	ripcbinfo.wildcardhashbase = hashinit(1, M_PCB,
135 					      &ripcbinfo.wildcardhashmask);
136 	ripcbinfo.ipi_zone = zinit("ripcb", sizeof(struct inpcb),
137 				   maxsockets, ZONE_INTERRUPT, 0);
138 }
139 
140 /*
141  * Setup generic address and protocol structures
142  * for raw_input routine, then pass them along with
143  * mbuf chain.
144  */
145 void
146 rip_input(struct mbuf *m, ...)
147 {
148 	struct sockaddr_in ripsrc = { sizeof ripsrc, AF_INET };
149 	struct ip *ip = mtod(m, struct ip *);
150 	struct inpcb *inp;
151 	struct inpcb *last = NULL;
152 	struct mbuf *opts = NULL;
153 	int off, proto;
154 	__va_list ap;
155 
156 	__va_start(ap, m);
157 	off = __va_arg(ap, int);
158 	proto = __va_arg(ap, int);
159 	__va_end(ap);
160 
161 	ripsrc.sin_addr = ip->ip_src;
162 	LIST_FOREACH(inp, &ripcbinfo.pcblisthead, inp_list) {
163 		if (inp->inp_flags & INP_PLACEMARKER)
164 			continue;
165 #ifdef INET6
166 		if ((inp->inp_vflag & INP_IPV4) == 0)
167 			continue;
168 #endif
169 		if (inp->inp_ip_p && inp->inp_ip_p != proto)
170 			continue;
171 		if (inp->inp_laddr.s_addr != INADDR_ANY &&
172 		    inp->inp_laddr.s_addr != ip->ip_dst.s_addr)
173 			continue;
174 		if (inp->inp_faddr.s_addr != INADDR_ANY &&
175 		    inp->inp_faddr.s_addr != ip->ip_src.s_addr)
176 			continue;
177 		if (last) {
178 			struct mbuf *n = m_copypacket(m, MB_DONTWAIT);
179 
180 #ifdef IPSEC
181 			/* check AH/ESP integrity. */
182 			if (n && ipsec4_in_reject_so(n, last->inp_socket)) {
183 				m_freem(n);
184 				ipsecstat.in_polvio++;
185 				/* do not inject data to pcb */
186 			} else
187 #endif /*IPSEC*/
188 #ifdef FAST_IPSEC
189 			/* check AH/ESP integrity. */
190 			if (ipsec4_in_reject(n, last)) {
191 				m_freem(n);
192 				/* do not inject data to pcb */
193 			} else
194 #endif /*FAST_IPSEC*/
195 			if (n) {
196 				if (last->inp_flags & INP_CONTROLOPTS ||
197 				    last->inp_socket->so_options & SO_TIMESTAMP)
198 				    ip_savecontrol(last, &opts, ip, n);
199 				if (ssb_appendaddr(&last->inp_socket->so_rcv,
200 				    (struct sockaddr *)&ripsrc, n,
201 				    opts) == 0) {
202 					/* should notify about lost packet */
203 					m_freem(n);
204 					if (opts)
205 					    m_freem(opts);
206 				} else
207 					sorwakeup(last->inp_socket);
208 				opts = 0;
209 			}
210 		}
211 		last = inp;
212 	}
213 #ifdef IPSEC
214 	/* check AH/ESP integrity. */
215 	if (last && ipsec4_in_reject_so(m, last->inp_socket)) {
216 		m_freem(m);
217 		ipsecstat.in_polvio++;
218 		ipstat.ips_delivered--;
219 		/* do not inject data to pcb */
220 	} else
221 #endif /*IPSEC*/
222 #ifdef FAST_IPSEC
223 	/* check AH/ESP integrity. */
224 	if (last && ipsec4_in_reject(m, last)) {
225 		m_freem(m);
226 		ipstat.ips_delivered--;
227 		/* do not inject data to pcb */
228 	} else
229 #endif /*FAST_IPSEC*/
230 	/* Check the minimum TTL for socket. */
231 	if (last && ip->ip_ttl < last->inp_ip_minttl) {
232 		m_freem(opts);
233 		ipstat.ips_delivered--;
234 	} else if (last) {
235 		if (last->inp_flags & INP_CONTROLOPTS ||
236 		    last->inp_socket->so_options & SO_TIMESTAMP)
237 			ip_savecontrol(last, &opts, ip, m);
238 		if (ssb_appendaddr(&last->inp_socket->so_rcv,
239 		    (struct sockaddr *)&ripsrc, m, opts) == 0) {
240 			m_freem(m);
241 			if (opts)
242 			    m_freem(opts);
243 		} else
244 			sorwakeup(last->inp_socket);
245 	} else {
246 		m_freem(m);
247 		ipstat.ips_noproto++;
248 		ipstat.ips_delivered--;
249 	}
250 }
251 
252 /*
253  * Generate IP header and pass packet to ip_output.
254  * Tack on options user may have setup with control call.
255  */
256 int
257 rip_output(struct mbuf *m, struct socket *so, ...)
258 {
259 	struct ip *ip;
260 	struct inpcb *inp = so->so_pcb;
261 	__va_list ap;
262 	int flags = (so->so_options & SO_DONTROUTE) | IP_ALLOWBROADCAST;
263 	u_long dst;
264 
265 	__va_start(ap, so);
266 	dst = __va_arg(ap, u_long);
267 	__va_end(ap);
268 
269 	/*
270 	 * If the user handed us a complete IP packet, use it.
271 	 * Otherwise, allocate an mbuf for a header and fill it in.
272 	 */
273 	if ((inp->inp_flags & INP_HDRINCL) == 0) {
274 		if (m->m_pkthdr.len + sizeof(struct ip) > IP_MAXPACKET) {
275 			m_freem(m);
276 			return(EMSGSIZE);
277 		}
278 		M_PREPEND(m, sizeof(struct ip), MB_WAIT);
279 		if (m == NULL)
280 			return(ENOBUFS);
281 		ip = mtod(m, struct ip *);
282 		ip->ip_tos = inp->inp_ip_tos;
283 		ip->ip_off = 0;
284 		ip->ip_p = inp->inp_ip_p;
285 		ip->ip_len = m->m_pkthdr.len;
286 		ip->ip_src = inp->inp_laddr;
287 		ip->ip_dst.s_addr = dst;
288 		ip->ip_ttl = inp->inp_ip_ttl;
289 	} else {
290 		int hlen;
291 
292 		if (m->m_pkthdr.len > IP_MAXPACKET) {
293 			m_freem(m);
294 			return(EMSGSIZE);
295 		}
296 		if (m->m_len < sizeof(struct ip)) {
297 			m = m_pullup(m, sizeof(struct ip));
298 			if (m == NULL)
299 				return ENOBUFS;
300 		}
301 		ip = mtod(m, struct ip *);
302 		hlen = IP_VHL_HL(ip->ip_vhl) << 2;
303 
304 		/* Don't allow header length less than the minimum. */
305 		if (hlen < sizeof(struct ip)) {
306 			m_freem(m);
307 			return EINVAL;
308 		}
309 
310 		/*
311 		 * Don't allow both user specified and setsockopt options.
312 		 * Don't allow packet length sizes that will crash.
313 		 */
314 		if ((hlen != sizeof(struct ip) && inp->inp_options) ||
315 		    ip->ip_len > m->m_pkthdr.len || ip->ip_len < hlen) {
316 			m_freem(m);
317 			return EINVAL;
318 		}
319 		if (ip->ip_id == 0)
320 			ip->ip_id = ip_newid();
321 
322 		/* Prevent ip_output from overwriting header fields */
323 		flags |= IP_RAWOUTPUT;
324 		ipstat.ips_rawout++;
325 	}
326 
327 	return ip_output(m, inp->inp_options, &inp->inp_route, flags,
328 			 inp->inp_moptions, inp);
329 }
330 
331 /*
332  * Raw IP socket option processing.
333  */
334 int
335 rip_ctloutput(struct socket *so, struct sockopt *sopt)
336 {
337 	struct	inpcb *inp = so->so_pcb;
338 	int	error, optval;
339 
340 	if (sopt->sopt_level != IPPROTO_IP)
341 		return (EINVAL);
342 
343 	error = 0;
344 
345 	switch (sopt->sopt_dir) {
346 	case SOPT_GET:
347 		switch (sopt->sopt_name) {
348 		case IP_HDRINCL:
349 			optval = inp->inp_flags & INP_HDRINCL;
350 			soopt_from_kbuf(sopt, &optval, sizeof optval);
351 			break;
352 
353 		case IP_FW_ADD: /* ADD actually returns the body... */
354 		case IP_FW_GET:
355 			if (IPFW_LOADED)
356 				error = ip_fw_sockopt(sopt);
357 			else
358 				error = ENOPROTOOPT;
359 			break;
360 
361 		case IP_DUMMYNET_GET:
362 			error = ip_dn_sockopt(sopt);
363 			break ;
364 
365 		case MRT_INIT:
366 		case MRT_DONE:
367 		case MRT_ADD_VIF:
368 		case MRT_DEL_VIF:
369 		case MRT_ADD_MFC:
370 		case MRT_DEL_MFC:
371 		case MRT_VERSION:
372 		case MRT_ASSERT:
373 		case MRT_API_SUPPORT:
374 		case MRT_API_CONFIG:
375 		case MRT_ADD_BW_UPCALL:
376 		case MRT_DEL_BW_UPCALL:
377 			error = ip_mrouter_get ? ip_mrouter_get(so, sopt) :
378 				EOPNOTSUPP;
379 			break;
380 
381 		default:
382 			error = ip_ctloutput(so, sopt);
383 			break;
384 		}
385 		break;
386 
387 	case SOPT_SET:
388 		switch (sopt->sopt_name) {
389 		case IP_HDRINCL:
390 			error = soopt_to_kbuf(sopt, &optval, sizeof optval,
391 					      sizeof optval);
392 			if (error)
393 				break;
394 			if (optval)
395 				inp->inp_flags |= INP_HDRINCL;
396 			else
397 				inp->inp_flags &= ~INP_HDRINCL;
398 			break;
399 
400 		case IP_FW_ADD:
401 		case IP_FW_DEL:
402 		case IP_FW_FLUSH:
403 		case IP_FW_ZERO:
404 		case IP_FW_RESETLOG:
405 			if (IPFW_LOADED)
406 				error = ip_fw_ctl_ptr(sopt);
407 			else
408 				error = ENOPROTOOPT;
409 			break;
410 
411 		case IP_DUMMYNET_CONFIGURE:
412 		case IP_DUMMYNET_DEL:
413 		case IP_DUMMYNET_FLUSH:
414 			error = ip_dn_sockopt(sopt);
415 			break ;
416 
417 		case IP_RSVP_ON:
418 			error = ip_rsvp_init(so);
419 			break;
420 
421 		case IP_RSVP_OFF:
422 			error = ip_rsvp_done();
423 			break;
424 
425 		case IP_RSVP_VIF_ON:
426 		case IP_RSVP_VIF_OFF:
427 			error = ip_rsvp_vif ?
428 				ip_rsvp_vif(so, sopt) : EINVAL;
429 			break;
430 
431 		case MRT_INIT:
432 		case MRT_DONE:
433 		case MRT_ADD_VIF:
434 		case MRT_DEL_VIF:
435 		case MRT_ADD_MFC:
436 		case MRT_DEL_MFC:
437 		case MRT_VERSION:
438 		case MRT_ASSERT:
439 		case MRT_API_SUPPORT:
440 		case MRT_API_CONFIG:
441 		case MRT_ADD_BW_UPCALL:
442 		case MRT_DEL_BW_UPCALL:
443 			error = ip_mrouter_set ? ip_mrouter_set(so, sopt) :
444 					EOPNOTSUPP;
445 			break;
446 
447 		default:
448 			error = ip_ctloutput(so, sopt);
449 			break;
450 		}
451 		break;
452 	}
453 
454 	return (error);
455 }
456 
457 /*
458  * This function exists solely to receive the PRC_IFDOWN messages which
459  * are sent by if_down().  It looks for an ifaddr whose ifa_addr is sa,
460  * and calls in_ifadown() to remove all routes corresponding to that address.
461  * It also receives the PRC_IFUP messages from if_up() and reinstalls the
462  * interface routes.
463  */
464 void
465 rip_ctlinput(int cmd, struct sockaddr *sa, void *vip)
466 {
467 	struct in_ifaddr *ia;
468 	struct in_ifaddr_container *iac;
469 	struct ifnet *ifp;
470 	int err;
471 	int flags;
472 
473 	switch (cmd) {
474 	case PRC_IFDOWN:
475 		TAILQ_FOREACH(iac, &in_ifaddrheads[mycpuid], ia_link) {
476 			ia = iac->ia;
477 
478 			if (ia->ia_ifa.ifa_addr == sa &&
479 			    (ia->ia_flags & IFA_ROUTE)) {
480 				/*
481 				 * in_ifscrub kills the interface route.
482 				 */
483 				in_ifscrub(ia->ia_ifp, ia);
484 				/*
485 				 * in_ifadown gets rid of all the rest of
486 				 * the routes.  This is not quite the right
487 				 * thing to do, but at least if we are running
488 				 * a routing process they will come back.
489 				 */
490 				in_ifadown(&ia->ia_ifa, 0);
491 				break;
492 			}
493 		}
494 		break;
495 
496 	case PRC_IFUP:
497 		ia = NULL;
498 		TAILQ_FOREACH(iac, &in_ifaddrheads[mycpuid], ia_link) {
499 			if (iac->ia->ia_ifa.ifa_addr == sa) {
500 				ia = iac->ia;
501 				break;
502 			}
503 		}
504 		if (ia == NULL || (ia->ia_flags & IFA_ROUTE))
505 			return;
506 		flags = RTF_UP;
507 		ifp = ia->ia_ifa.ifa_ifp;
508 
509 		if ((ifp->if_flags & IFF_LOOPBACK) ||
510 		    (ifp->if_flags & IFF_POINTOPOINT))
511 			flags |= RTF_HOST;
512 
513 		err = rtinit(&ia->ia_ifa, RTM_ADD, flags);
514 		if (err == 0)
515 			ia->ia_flags |= IFA_ROUTE;
516 		break;
517 	}
518 }
519 
520 u_long	rip_sendspace = RIPSNDQ;
521 u_long	rip_recvspace = RIPRCVQ;
522 
523 SYSCTL_INT(_net_inet_raw, OID_AUTO, maxdgram, CTLFLAG_RW,
524     &rip_sendspace, 0, "Maximum outgoing raw IP datagram size");
525 SYSCTL_INT(_net_inet_raw, OID_AUTO, recvspace, CTLFLAG_RW,
526     &rip_recvspace, 0, "Maximum incoming raw IP datagram size");
527 
528 static int
529 rip_attach(struct socket *so, int proto, struct pru_attach_info *ai)
530 {
531 	struct inpcb *inp;
532 	int error;
533 	int flag;
534 
535 	if (jailed(ai->p_ucred) && jail_allow_raw_sockets)
536 		flag = NULL_CRED_OKAY | PRISON_ROOT;
537 	else
538 		flag = NULL_CRED_OKAY;
539 
540 	inp = so->so_pcb;
541 	if (inp)
542 		panic("rip_attach");
543 	if ((error = priv_check_cred(ai->p_ucred, PRIV_ROOT, flag)) != 0)
544 		return error;
545 
546 	error = soreserve(so, rip_sendspace, rip_recvspace, ai->sb_rlimit);
547 	if (error)
548 		return error;
549 	crit_enter();
550 	error = in_pcballoc(so, &ripcbinfo);
551 	crit_exit();
552 	if (error)
553 		return error;
554 	inp = (struct inpcb *)so->so_pcb;
555 	inp->inp_vflag |= INP_IPV4;
556 	inp->inp_ip_p = proto;
557 	inp->inp_ip_ttl = ip_defttl;
558 	return 0;
559 }
560 
561 static int
562 rip_detach(struct socket *so)
563 {
564 	struct inpcb *inp;
565 
566 	inp = so->so_pcb;
567 	if (inp == 0)
568 		panic("rip_detach");
569 	if (so == ip_mrouter && ip_mrouter_done)
570 		ip_mrouter_done();
571 	if (ip_rsvp_force_done)
572 		ip_rsvp_force_done(so);
573 	if (so == ip_rsvpd)
574 		ip_rsvp_done();
575 	in_pcbdetach(inp);
576 	return 0;
577 }
578 
579 static int
580 rip_abort(struct socket *so)
581 {
582 	soisdisconnected(so);
583 	if (so->so_state & SS_NOFDREF)
584 		return rip_detach(so);
585 	return 0;
586 }
587 
588 static int
589 rip_disconnect(struct socket *so)
590 {
591 	if ((so->so_state & SS_ISCONNECTED) == 0)
592 		return ENOTCONN;
593 	return rip_abort(so);
594 }
595 
596 static int
597 rip_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
598 {
599 	struct inpcb *inp = so->so_pcb;
600 	struct sockaddr_in *addr = (struct sockaddr_in *)nam;
601 
602 	if (nam->sa_len != sizeof(*addr))
603 		return EINVAL;
604 
605 	if (TAILQ_EMPTY(&ifnet) || ((addr->sin_family != AF_INET) &&
606 				    (addr->sin_family != AF_IMPLINK)) ||
607 	    (addr->sin_addr.s_addr != INADDR_ANY &&
608 	     ifa_ifwithaddr((struct sockaddr *)addr) == 0))
609 		return EADDRNOTAVAIL;
610 	inp->inp_laddr = addr->sin_addr;
611 	return 0;
612 }
613 
614 static int
615 rip_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
616 {
617 	struct inpcb *inp = so->so_pcb;
618 	struct sockaddr_in *addr = (struct sockaddr_in *)nam;
619 
620 	if (nam->sa_len != sizeof(*addr))
621 		return EINVAL;
622 	if (TAILQ_EMPTY(&ifnet))
623 		return EADDRNOTAVAIL;
624 	if ((addr->sin_family != AF_INET) &&
625 	    (addr->sin_family != AF_IMPLINK))
626 		return EAFNOSUPPORT;
627 	inp->inp_faddr = addr->sin_addr;
628 	soisconnected(so);
629 	return 0;
630 }
631 
632 static int
633 rip_shutdown(struct socket *so)
634 {
635 	socantsendmore(so);
636 	return 0;
637 }
638 
639 static int
640 rip_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam,
641 	 struct mbuf *control, struct thread *td)
642 {
643 	struct inpcb *inp = so->so_pcb;
644 	u_long dst;
645 
646 	if (so->so_state & SS_ISCONNECTED) {
647 		if (nam) {
648 			m_freem(m);
649 			return EISCONN;
650 		}
651 		dst = inp->inp_faddr.s_addr;
652 	} else {
653 		if (nam == NULL) {
654 			m_freem(m);
655 			return ENOTCONN;
656 		}
657 		dst = ((struct sockaddr_in *)nam)->sin_addr.s_addr;
658 	}
659 	return rip_output(m, so, dst);
660 }
661 
662 SYSCTL_PROC(_net_inet_raw, OID_AUTO/*XXX*/, pcblist, CTLFLAG_RD, &ripcbinfo, 0,
663 	    in_pcblist_global, "S,xinpcb", "List of active raw IP sockets");
664 
665 struct pr_usrreqs rip_usrreqs = {
666 	.pru_abort = rip_abort,
667 	.pru_accept = pru_accept_notsupp,
668 	.pru_attach = rip_attach,
669 	.pru_bind = rip_bind,
670 	.pru_connect = rip_connect,
671 	.pru_connect2 = pru_connect2_notsupp,
672 	.pru_control = in_control,
673 	.pru_detach = rip_detach,
674 	.pru_disconnect = rip_disconnect,
675 	.pru_listen = pru_listen_notsupp,
676 	.pru_peeraddr = in_setpeeraddr,
677 	.pru_rcvd = pru_rcvd_notsupp,
678 	.pru_rcvoob = pru_rcvoob_notsupp,
679 	.pru_send = rip_send,
680 	.pru_sense = pru_sense_null,
681 	.pru_shutdown = rip_shutdown,
682 	.pru_sockaddr = in_setsockaddr,
683 	.pru_sosend = sosend,
684 	.pru_soreceive = soreceive,
685 	.pru_sopoll = sopoll
686 };
687