raw_ip.c revision 46381
155682Smarkm/*
2233294Sstas * Copyright (c) 1982, 1986, 1988, 1993
3233294Sstas *	The Regents of the University of California.  All rights reserved.
4233294Sstas *
555682Smarkm * Redistribution and use in source and binary forms, with or without
6233294Sstas * modification, are permitted provided that the following conditions
7233294Sstas * are met:
8233294Sstas * 1. Redistributions of source code must retain the above copyright
955682Smarkm *    notice, this list of conditions and the following disclaimer.
10233294Sstas * 2. Redistributions in binary form must reproduce the above copyright
11233294Sstas *    notice, this list of conditions and the following disclaimer in the
1255682Smarkm *    documentation and/or other materials provided with the distribution.
13233294Sstas * 3. All advertising materials mentioning features or use of this software
14233294Sstas *    must display the following acknowledgement:
15233294Sstas *	This product includes software developed by the University of
1655682Smarkm *	California, Berkeley and its contributors.
17233294Sstas * 4. Neither the name of the University nor the names of its contributors
18233294Sstas *    may be used to endorse or promote products derived from this software
19233294Sstas *    without specific prior written permission.
2055682Smarkm *
21233294Sstas * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22233294Sstas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23233294Sstas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24233294Sstas * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25233294Sstas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26233294Sstas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27233294Sstas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28233294Sstas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29233294Sstas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30233294Sstas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31233294Sstas * SUCH DAMAGE.
3255682Smarkm *
3355682Smarkm *	@(#)raw_ip.c	8.7 (Berkeley) 5/15/95
3455682Smarkm *	$Id: raw_ip.c,v 1.58 1999/04/27 11:17:36 phk Exp $
3555682Smarkm */
36233294Sstas
3755682Smarkm#include <sys/param.h>
3855682Smarkm#include <sys/systm.h>
3955682Smarkm#include <sys/kernel.h>
4055682Smarkm#include <sys/malloc.h>
4155682Smarkm#include <sys/mbuf.h>
42233294Sstas#include <sys/proc.h>
4355682Smarkm#include <sys/protosw.h>
4455682Smarkm#include <sys/socket.h>
4555682Smarkm#include <sys/socketvar.h>
4655682Smarkm#include <sys/sysctl.h>
4755682Smarkm
4855682Smarkm#include <vm/vm_zone.h>
4955682Smarkm
5055682Smarkm#include <net/if.h>
5155682Smarkm#include <net/route.h>
5255682Smarkm
5355682Smarkm#define _IP_VHL
5455682Smarkm#include <netinet/in.h>
5555682Smarkm#include <netinet/in_systm.h>
5655682Smarkm#include <netinet/ip.h>
5755682Smarkm#include <netinet/in_pcb.h>
5855682Smarkm#include <netinet/in_var.h>
59102644Snectar#include <netinet/ip_var.h>
6055682Smarkm#include <netinet/ip_mroute.h>
6155682Smarkm
6255682Smarkm#include <netinet/ip_fw.h>
6355682Smarkm
6455682Smarkm#include "opt_ipdn.h"
6555682Smarkm#ifdef DUMMYNET
6655682Smarkm#include <netinet/ip_dummynet.h>
6755682Smarkm#endif
6855682Smarkm
6955682Smarkmstatic struct inpcbhead ripcb;
70233294Sstasstatic struct inpcbinfo ripcbinfo;
7155682Smarkm
7255682Smarkm/*
7355682Smarkm * Nominal space allocated to a raw ip socket.
7455682Smarkm */
7555682Smarkm#define	RIPSNDQ		8192
7655682Smarkm#define	RIPRCVQ		8192
7755682Smarkm
7855682Smarkm/*
7955682Smarkm * Raw interface to IP protocol.
8078527Sassar */
8155682Smarkm
8255682Smarkm/*
8355682Smarkm * Initialize raw connection block q.
8455682Smarkm */
8555682Smarkmvoid
8655682Smarkmrip_init()
8755682Smarkm{
8855682Smarkm	LIST_INIT(&ripcb);
8955682Smarkm	ripcbinfo.listhead = &ripcb;
9055682Smarkm	/*
9178527Sassar	 * XXX We don't use the hash list for raw IP, but it's easier
9278527Sassar	 * to allocate a one entry hash list than it is to check all
93233294Sstas	 * over the place for hashbase == NULL.
94233294Sstas	 */
9578527Sassar	ripcbinfo.hashbase = hashinit(1, M_PCB, &ripcbinfo.hashmask);
9678527Sassar	ripcbinfo.porthashbase = hashinit(1, M_PCB, &ripcbinfo.porthashmask);
9755682Smarkm	ripcbinfo.ipi_zone = zinit("ripcb", sizeof(struct inpcb),
9855682Smarkm				   maxsockets, ZONE_INTERRUPT, 0);
9955682Smarkm}
10055682Smarkm
10155682Smarkmstatic struct	sockaddr_in ripsrc = { sizeof(ripsrc), AF_INET };
10255682Smarkm/*
10355682Smarkm * Setup generic address and protocol structures
10455682Smarkm * for raw_input routine, then pass them along with
10555682Smarkm * mbuf chain.
10655682Smarkm */
10755682Smarkmvoid
10855682Smarkmrip_input(m, iphlen)
10955682Smarkm	struct mbuf *m;
11055682Smarkm	int iphlen;
11155682Smarkm{
11255682Smarkm	register struct ip *ip = mtod(m, struct ip *);
11355682Smarkm	register struct inpcb *inp;
11455682Smarkm	struct inpcb *last = 0;
11555682Smarkm	struct mbuf *opts = 0;
11655682Smarkm
11755682Smarkm	ripsrc.sin_addr = ip->ip_src;
118233294Sstas	for (inp = ripcb.lh_first; inp != NULL; inp = inp->inp_list.le_next) {
119233294Sstas		if (inp->inp_ip_p && inp->inp_ip_p != ip->ip_p)
12055682Smarkm			continue;
12155682Smarkm		if (inp->inp_laddr.s_addr &&
12255682Smarkm                  inp->inp_laddr.s_addr != ip->ip_dst.s_addr)
12355682Smarkm			continue;
12455682Smarkm		if (inp->inp_faddr.s_addr &&
12555682Smarkm                  inp->inp_faddr.s_addr != ip->ip_src.s_addr)
12655682Smarkm			continue;
12755682Smarkm		if (last) {
12855682Smarkm			struct mbuf *n = m_copy(m, 0, (int)M_COPYALL);
12955682Smarkm			if (n) {
13055682Smarkm				if (last->inp_flags & INP_CONTROLOPTS ||
13155682Smarkm				    last->inp_socket->so_options & SO_TIMESTAMP)
13255682Smarkm				    ip_savecontrol(last, &opts, ip, n);
13355682Smarkm				if (sbappendaddr(&last->inp_socket->so_rcv,
13455682Smarkm				    (struct sockaddr *)&ripsrc, n,
13555682Smarkm				    opts) == 0) {
13655682Smarkm					/* should notify about lost packet */
13755682Smarkm					m_freem(n);
13855682Smarkm					if (opts)
13955682Smarkm					    m_freem(opts);
14055682Smarkm				} else
14155682Smarkm					sorwakeup(last->inp_socket);
14255682Smarkm				opts = 0;
14355682Smarkm			}
14455682Smarkm		}
14555682Smarkm		last = inp;
14655682Smarkm	}
14755682Smarkm	if (last) {
14855682Smarkm		if (last->inp_flags & INP_CONTROLOPTS ||
14955682Smarkm		    last->inp_socket->so_options & SO_TIMESTAMP)
15055682Smarkm			ip_savecontrol(last, &opts, ip, m);
15155682Smarkm		if (sbappendaddr(&last->inp_socket->so_rcv,
15257416Smarkm		    (struct sockaddr *)&ripsrc, m, opts) == 0) {
15357416Smarkm			m_freem(m);
15455682Smarkm			if (opts)
15555682Smarkm			    m_freem(opts);
15655682Smarkm		} else
15755682Smarkm			sorwakeup(last->inp_socket);
15855682Smarkm	} else {
15957416Smarkm		m_freem(m);
16055682Smarkm              ipstat.ips_noproto++;
161233294Sstas              ipstat.ips_delivered--;
16255682Smarkm      }
16355682Smarkm}
16455682Smarkm
16555682Smarkm/*
16655682Smarkm * Generate IP header and pass packet to ip_output.
16755682Smarkm * Tack on options user may have setup with control call.
16855682Smarkm */
16955682Smarkmint
17055682Smarkmrip_output(m, so, dst)
17155682Smarkm	register struct mbuf *m;
17255682Smarkm	struct socket *so;
17355682Smarkm	u_long dst;
17455682Smarkm{
17555682Smarkm	register struct ip *ip;
17655682Smarkm	register struct inpcb *inp = sotoinpcb(so);
17755682Smarkm	int flags = (so->so_options & SO_DONTROUTE) | IP_ALLOWBROADCAST;
17855682Smarkm
17955682Smarkm	/*
18055682Smarkm	 * If the user handed us a complete IP packet, use it.
18155682Smarkm	 * Otherwise, allocate an mbuf for a header and fill it in.
18257416Smarkm	 */
18355682Smarkm	if ((inp->inp_flags & INP_HDRINCL) == 0) {
18455682Smarkm		if (m->m_pkthdr.len + sizeof(struct ip) > IP_MAXPACKET) {
18555682Smarkm			m_freem(m);
18655682Smarkm			return(EMSGSIZE);
18755682Smarkm		}
18878527Sassar		M_PREPEND(m, sizeof(struct ip), M_WAIT);
18978527Sassar		ip = mtod(m, struct ip *);
19078527Sassar		ip->ip_tos = 0;
19178527Sassar		ip->ip_off = 0;
19255682Smarkm		ip->ip_p = inp->inp_ip_p;
19355682Smarkm		ip->ip_len = m->m_pkthdr.len;
19455682Smarkm		ip->ip_src = inp->inp_laddr;
19555682Smarkm		ip->ip_dst.s_addr = dst;
19655682Smarkm		ip->ip_ttl = MAXTTL;
19755682Smarkm	} else {
19855682Smarkm		if (m->m_pkthdr.len > IP_MAXPACKET) {
199233294Sstas			m_freem(m);
200233294Sstas			return(EMSGSIZE);
201233294Sstas		}
202233294Sstas		ip = mtod(m, struct ip *);
203233294Sstas		/* don't allow both user specified and setsockopt options,
204233294Sstas		   and don't allow packet length sizes that will crash */
205233294Sstas		if (((IP_VHL_HL(ip->ip_vhl) != (sizeof (*ip) >> 2))
206233294Sstas		     && inp->inp_options)
207233294Sstas		    || (ip->ip_len > m->m_pkthdr.len)
208233294Sstas		    || (ip->ip_len < (IP_VHL_HL(ip->ip_vhl) << 2))) {
209233294Sstas			m_freem(m);
210233294Sstas			return EINVAL;
211233294Sstas		}
212233294Sstas		if (ip->ip_id == 0)
213233294Sstas			ip->ip_id = htons(ip_id++);
214233294Sstas		/* XXX prevent ip_output from overwriting header fields */
215233294Sstas		flags |= IP_RAWOUTPUT;
216233294Sstas		ipstat.ips_rawout++;
217233294Sstas	}
218233294Sstas	return (ip_output(m, inp->inp_options, &inp->inp_route, flags,
219233294Sstas			  inp->inp_moptions));
220233294Sstas}
221233294Sstas
222233294Sstas/*
223233294Sstas * Raw IP socket option processing.
224233294Sstas */
225233294Sstasint
226233294Sstasrip_ctloutput(so, sopt)
227233294Sstas	struct socket *so;
228233294Sstas	struct sockopt *sopt;
229233294Sstas{
230233294Sstas	struct	inpcb *inp = sotoinpcb(so);
231233294Sstas	int	error, optval;
232233294Sstas
233233294Sstas	if (sopt->sopt_level != IPPROTO_IP)
234233294Sstas		return (EINVAL);
235233294Sstas
236233294Sstas	error = 0;
237233294Sstas
238233294Sstas	switch (sopt->sopt_dir) {
239233294Sstas	case SOPT_GET:
240233294Sstas		switch (sopt->sopt_name) {
241233294Sstas		case IP_HDRINCL:
242233294Sstas			optval = inp->inp_flags & INP_HDRINCL;
243233294Sstas			error = sooptcopyout(sopt, &optval, sizeof optval);
244			break;
245
246		case IP_FW_GET:
247			if (ip_fw_ctl_ptr == 0)
248				error = ENOPROTOOPT;
249			else
250				error = ip_fw_ctl_ptr(sopt);
251			break;
252
253#ifdef DUMMYNET
254		case IP_DUMMYNET_GET:
255			if (ip_dn_ctl_ptr == NULL)
256				error = ENOPROTOOPT ;
257			else
258				error = ip_dn_ctl_ptr(sopt);
259			break ;
260#endif /* DUMMYNET */
261
262		case MRT_INIT:
263		case MRT_DONE:
264		case MRT_ADD_VIF:
265		case MRT_DEL_VIF:
266		case MRT_ADD_MFC:
267		case MRT_DEL_MFC:
268		case MRT_VERSION:
269		case MRT_ASSERT:
270			error = ip_mrouter_get(so, sopt);
271			break;
272
273		default:
274			error = ip_ctloutput(so, sopt);
275			break;
276		}
277		break;
278
279	case SOPT_SET:
280		switch (sopt->sopt_name) {
281		case IP_HDRINCL:
282			error = sooptcopyin(sopt, &optval, sizeof optval,
283					    sizeof optval);
284			if (error)
285				break;
286			if (optval)
287				inp->inp_flags |= INP_HDRINCL;
288			else
289				inp->inp_flags &= ~INP_HDRINCL;
290			break;
291
292		case IP_FW_ADD:
293		case IP_FW_DEL:
294		case IP_FW_FLUSH:
295		case IP_FW_ZERO:
296			if (ip_fw_ctl_ptr == 0)
297				error = ENOPROTOOPT;
298			else
299				error = ip_fw_ctl_ptr(sopt);
300			break;
301
302#ifdef DUMMYNET
303		case IP_DUMMYNET_CONFIGURE:
304		case IP_DUMMYNET_DEL:
305		case IP_DUMMYNET_FLUSH:
306			if (ip_dn_ctl_ptr == NULL)
307				error = ENOPROTOOPT ;
308			else
309				error = ip_dn_ctl_ptr(sopt);
310			break ;
311#endif
312
313		case IP_RSVP_ON:
314			error = ip_rsvp_init(so);
315			break;
316
317		case IP_RSVP_OFF:
318			error = ip_rsvp_done();
319			break;
320
321			/* XXX - should be combined */
322		case IP_RSVP_VIF_ON:
323			error = ip_rsvp_vif_init(so, sopt);
324			break;
325
326		case IP_RSVP_VIF_OFF:
327			error = ip_rsvp_vif_done(so, sopt);
328			break;
329
330		case MRT_INIT:
331		case MRT_DONE:
332		case MRT_ADD_VIF:
333		case MRT_DEL_VIF:
334		case MRT_ADD_MFC:
335		case MRT_DEL_MFC:
336		case MRT_VERSION:
337		case MRT_ASSERT:
338			error = ip_mrouter_set(so, sopt);
339			break;
340
341		default:
342			error = ip_ctloutput(so, sopt);
343			break;
344		}
345		break;
346	}
347
348	return (error);
349}
350
351/*
352 * This function exists solely to receive the PRC_IFDOWN messages which
353 * are sent by if_down().  It looks for an ifaddr whose ifa_addr is sa,
354 * and calls in_ifadown() to remove all routes corresponding to that address.
355 * It also receives the PRC_IFUP messages from if_up() and reinstalls the
356 * interface routes.
357 */
358void
359rip_ctlinput(cmd, sa, vip)
360	int cmd;
361	struct sockaddr *sa;
362	void *vip;
363{
364	struct in_ifaddr *ia;
365	struct ifnet *ifp;
366	int err;
367	int flags;
368
369	switch (cmd) {
370	case PRC_IFDOWN:
371		for (ia = in_ifaddrhead.tqh_first; ia;
372		     ia = ia->ia_link.tqe_next) {
373			if (ia->ia_ifa.ifa_addr == sa
374			    && (ia->ia_flags & IFA_ROUTE)) {
375				/*
376				 * in_ifscrub kills the interface route.
377				 */
378				in_ifscrub(ia->ia_ifp, ia);
379				/*
380				 * in_ifadown gets rid of all the rest of
381				 * the routes.  This is not quite the right
382				 * thing to do, but at least if we are running
383				 * a routing process they will come back.
384				 */
385				in_ifadown(&ia->ia_ifa);
386				break;
387			}
388		}
389		break;
390
391	case PRC_IFUP:
392		for (ia = in_ifaddrhead.tqh_first; ia;
393		     ia = ia->ia_link.tqe_next) {
394			if (ia->ia_ifa.ifa_addr == sa)
395				break;
396		}
397		if (ia == 0 || (ia->ia_flags & IFA_ROUTE))
398			return;
399		flags = RTF_UP;
400		ifp = ia->ia_ifa.ifa_ifp;
401
402		if ((ifp->if_flags & IFF_LOOPBACK)
403		    || (ifp->if_flags & IFF_POINTOPOINT))
404			flags |= RTF_HOST;
405
406		err = rtinit(&ia->ia_ifa, RTM_ADD, flags);
407		if (err == 0)
408			ia->ia_flags |= IFA_ROUTE;
409		break;
410	}
411}
412
413static u_long	rip_sendspace = RIPSNDQ;
414static u_long	rip_recvspace = RIPRCVQ;
415
416SYSCTL_INT(_net_inet_raw, OID_AUTO, maxdgram, CTLFLAG_RW,
417    &rip_sendspace, 0, "Maximum outgoing raw IP datagram size");
418SYSCTL_INT(_net_inet_raw, OID_AUTO, recvspace, CTLFLAG_RW,
419    &rip_recvspace, 0, "Maximum incoming raw IP datagram size");
420
421static int
422rip_attach(struct socket *so, int proto, struct proc *p)
423{
424	struct inpcb *inp;
425	int error, s;
426
427	inp = sotoinpcb(so);
428	if (inp)
429		panic("rip_attach");
430	if (p && (error = suser(p)) != 0)
431		return error;
432
433	s = splnet();
434	error = in_pcballoc(so, &ripcbinfo, p);
435	splx(s);
436	if (error)
437		return error;
438	error = soreserve(so, rip_sendspace, rip_recvspace);
439	if (error)
440		return error;
441	inp = (struct inpcb *)so->so_pcb;
442	inp->inp_ip_p = proto;
443	return 0;
444}
445
446static int
447rip_detach(struct socket *so)
448{
449	struct inpcb *inp;
450
451	inp = sotoinpcb(so);
452	if (inp == 0)
453		panic("rip_detach");
454	if (so == ip_mrouter)
455		ip_mrouter_done();
456	ip_rsvp_force_done(so);
457	if (so == ip_rsvpd)
458		ip_rsvp_done();
459	in_pcbdetach(inp);
460	return 0;
461}
462
463static int
464rip_abort(struct socket *so)
465{
466	soisdisconnected(so);
467	return rip_detach(so);
468}
469
470static int
471rip_disconnect(struct socket *so)
472{
473	if ((so->so_state & SS_ISCONNECTED) == 0)
474		return ENOTCONN;
475	return rip_abort(so);
476}
477
478static int
479rip_bind(struct socket *so, struct sockaddr *nam, struct proc *p)
480{
481	struct inpcb *inp = sotoinpcb(so);
482	struct sockaddr_in *addr = (struct sockaddr_in *)nam;
483
484	if (nam->sa_len != sizeof(*addr))
485		return EINVAL;
486
487	if (TAILQ_EMPTY(&ifnet) || ((addr->sin_family != AF_INET) &&
488				    (addr->sin_family != AF_IMPLINK)) ||
489	    (addr->sin_addr.s_addr &&
490	     ifa_ifwithaddr((struct sockaddr *)addr) == 0))
491		return EADDRNOTAVAIL;
492	inp->inp_laddr = addr->sin_addr;
493	return 0;
494}
495
496static int
497rip_connect(struct socket *so, struct sockaddr *nam, struct proc *p)
498{
499	struct inpcb *inp = sotoinpcb(so);
500	struct sockaddr_in *addr = (struct sockaddr_in *)nam;
501
502	if (nam->sa_len != sizeof(*addr))
503		return EINVAL;
504	if (TAILQ_EMPTY(&ifnet))
505		return EADDRNOTAVAIL;
506	if ((addr->sin_family != AF_INET) &&
507	    (addr->sin_family != AF_IMPLINK))
508		return EAFNOSUPPORT;
509	inp->inp_faddr = addr->sin_addr;
510	soisconnected(so);
511	return 0;
512}
513
514static int
515rip_shutdown(struct socket *so)
516{
517	socantsendmore(so);
518	return 0;
519}
520
521static int
522rip_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam,
523	 struct mbuf *control, struct proc *p)
524{
525	struct inpcb *inp = sotoinpcb(so);
526	register u_long dst;
527
528	if (so->so_state & SS_ISCONNECTED) {
529		if (nam) {
530			m_freem(m);
531			return EISCONN;
532		}
533		dst = inp->inp_faddr.s_addr;
534	} else {
535		if (nam == NULL) {
536			m_freem(m);
537			return ENOTCONN;
538		}
539		dst = ((struct sockaddr_in *)nam)->sin_addr.s_addr;
540	}
541	return rip_output(m, so, dst);
542}
543
544static int
545rip_pcblist SYSCTL_HANDLER_ARGS
546{
547	int error, i, n, s;
548	struct inpcb *inp, **inp_list;
549	inp_gen_t gencnt;
550	struct xinpgen xig;
551
552	/*
553	 * The process of preparing the TCB list is too time-consuming and
554	 * resource-intensive to repeat twice on every request.
555	 */
556	if (req->oldptr == 0) {
557		n = ripcbinfo.ipi_count;
558		req->oldidx = 2 * (sizeof xig)
559			+ (n + n/8) * sizeof(struct xinpcb);
560		return 0;
561	}
562
563	if (req->newptr != 0)
564		return EPERM;
565
566	/*
567	 * OK, now we're committed to doing something.
568	 */
569	s = splnet();
570	gencnt = ripcbinfo.ipi_gencnt;
571	n = ripcbinfo.ipi_count;
572	splx(s);
573
574	xig.xig_len = sizeof xig;
575	xig.xig_count = n;
576	xig.xig_gen = gencnt;
577	xig.xig_sogen = so_gencnt;
578	error = SYSCTL_OUT(req, &xig, sizeof xig);
579	if (error)
580		return error;
581
582	inp_list = malloc(n * sizeof *inp_list, M_TEMP, M_WAITOK);
583	if (inp_list == 0)
584		return ENOMEM;
585
586	s = splnet();
587	for (inp = ripcbinfo.listhead->lh_first, i = 0; inp && i < n;
588	     inp = inp->inp_list.le_next) {
589		if (inp->inp_gencnt <= gencnt)
590			inp_list[i++] = inp;
591	}
592	splx(s);
593	n = i;
594
595	error = 0;
596	for (i = 0; i < n; i++) {
597		inp = inp_list[i];
598		if (inp->inp_gencnt <= gencnt) {
599			struct xinpcb xi;
600			xi.xi_len = sizeof xi;
601			/* XXX should avoid extra copy */
602			bcopy(inp, &xi.xi_inp, sizeof *inp);
603			if (inp->inp_socket)
604				sotoxsocket(inp->inp_socket, &xi.xi_socket);
605			error = SYSCTL_OUT(req, &xi, sizeof xi);
606		}
607	}
608	if (!error) {
609		/*
610		 * Give the user an updated idea of our state.
611		 * If the generation differs from what we told
612		 * her before, she knows that something happened
613		 * while we were processing this request, and it
614		 * might be necessary to retry.
615		 */
616		s = splnet();
617		xig.xig_gen = ripcbinfo.ipi_gencnt;
618		xig.xig_sogen = so_gencnt;
619		xig.xig_count = ripcbinfo.ipi_count;
620		splx(s);
621		error = SYSCTL_OUT(req, &xig, sizeof xig);
622	}
623	free(inp_list, M_TEMP);
624	return error;
625}
626
627SYSCTL_PROC(_net_inet_raw, OID_AUTO/*XXX*/, pcblist, CTLFLAG_RD, 0, 0,
628	    rip_pcblist, "S,xinpcb", "List of active raw IP sockets");
629
630struct pr_usrreqs rip_usrreqs = {
631	rip_abort, pru_accept_notsupp, rip_attach, rip_bind, rip_connect,
632	pru_connect2_notsupp, in_control, rip_detach, rip_disconnect,
633	pru_listen_notsupp, in_setpeeraddr, pru_rcvd_notsupp,
634	pru_rcvoob_notsupp, rip_send, pru_sense_null, rip_shutdown,
635	in_setsockaddr, sosend, soreceive, sopoll
636};
637