Home | History | Annotate | Line # | Download | only in net
rtsock.c revision 1.238.2.24
      1 /*	$NetBSD: rtsock.c,v 1.238.2.24 2019/01/21 06:49:28 pgoyette 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) 1988, 1991, 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  *	@(#)rtsock.c	8.7 (Berkeley) 10/12/95
     61  */
     62 
     63 #include <sys/cdefs.h>
     64 __KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.238.2.24 2019/01/21 06:49:28 pgoyette Exp $");
     65 
     66 #ifdef _KERNEL_OPT
     67 #include "opt_inet.h"
     68 #include "opt_compat_netbsd.h"
     69 #endif
     70 
     71 #include <sys/param.h>
     72 #include <sys/systm.h>
     73 #include <sys/proc.h>
     74 #include <sys/socket.h>
     75 #include <sys/socketvar.h>
     76 #include <sys/domain.h>
     77 #include <sys/protosw.h>
     78 #include <sys/sysctl.h>
     79 #include <sys/kauth.h>
     80 #include <sys/kmem.h>
     81 #include <sys/intr.h>
     82 #include <sys/condvar.h>
     83 #include <sys/compat_stub.h>
     84 
     85 #include <net/if.h>
     86 #include <net/if_llatbl.h>
     87 #include <net/if_types.h>
     88 #include <net/route.h>
     89 #include <net/raw_cb.h>
     90 
     91 #include <netinet/in_var.h>
     92 #include <netinet/if_inarp.h>
     93 
     94 #include <netmpls/mpls.h>
     95 
     96 #include <compat/net/if.h>
     97 #include <compat/net/route.h>
     98 
     99 #ifdef COMPAT_RTSOCK
    100 #undef COMPAT_RTSOCK
    101 #endif
    102 
    103 static int if_addrflags(struct ifaddr *);
    104 static void sysctl_net_route_setup(struct sysctllog **);
    105 
    106 #include <net/rtsock_shared.c>
    107 
    108 /*
    109  * XXX avoid using void * once msghdr compat disappears.
    110  */
    111 void
    112 rt_setmetrics(void *in, struct rtentry *out)
    113 {
    114 	const struct rt_xmsghdr *rtm = in;
    115 
    116 	_rt_setmetrics(rtm->rtm_inits, rtm, out);
    117 }
    118 
    119 int
    120 rt_msg3(int type, struct rt_addrinfo *rtinfo, void *cpv, struct rt_walkarg *w,
    121 	int *lenp)
    122 {
    123 	return rt_msg2(type, rtinfo, cpv, w, lenp);
    124 }
    125 
    126 /*
    127  * MODULE_HOOK glue for rtsock_14_oifmsg and rtsock_14_iflist
    128  */
    129 MODULE_CALL_HOOK_DECL(rtsock_14_oifmsg_hook, void, (struct ifnet *ifp));
    130 MODULE_CALL_VOID_HOOK(rtsock_14_oifmsg_hook, (struct ifnet *ifp), (ifp),
    131     __nothing);
    132 
    133 MODULE_CALL_HOOK_DECL(rtsock_14_iflist_hook, int,
    134     (struct ifnet *ifp, struct rt_walkarg *w, struct rt_addrinfo *info,
    135      size_t len));
    136 MODULE_CALL_HOOK(rtsock_14_iflist_hook, int,
    137     (struct ifnet *ifp, struct rt_walkarg *w, struct rt_addrinfo *info,
    138      size_t len),
    139     (ifp, w, info, len),
    140     enosys());
    141 
    142 /*
    143  * MODULE_HOOK glue for rtsock_50 ifaddr_list and various message routines
    144  */
    145 MODULE_CALL_HOOK_DECL(rtsock_50_iflist_hook, int,
    146     (struct ifnet *ifp, struct rt_walkarg *w, struct rt_addrinfo *info,
    147      size_t len));
    148 MODULE_CALL_HOOK(rtsock_50_iflist_hook,  int,
    149     (struct ifnet *ifp, struct rt_walkarg *w, struct rt_addrinfo *info,
    150      size_t len),
    151     (ifp, w, info, len),
    152     enosys());
    153 
    154 MODULE_CALL_HOOK_DECL(rtsock_50_rt_missmsg_hook, void,
    155     (int, const struct rt_addrinfo *, int, int));
    156 MODULE_CALL_VOID_HOOK(rtsock_50_rt_missmsg_hook,
    157     (int type, const struct rt_addrinfo *rtinfo, int flags, int error),
    158     (type, rtinfo, flags, error), __nothing);
    159 
    160 MODULE_CALL_HOOK_DECL(rtsock_50_rt_ifmsg_hook, void, (struct ifnet *));
    161 MODULE_CALL_VOID_HOOK(rtsock_50_rt_ifmsg_hook, (struct ifnet *ifp), (ifp),
    162     __nothing);
    163 
    164 MODULE_CALL_HOOK_DECL(rtsock_50_rt_newaddrmsg_hook, void,
    165     (int, struct ifaddr *, int, struct rtentry *));
    166 MODULE_CALL_VOID_HOOK(rtsock_50_rt_newaddrmsg_hook,
    167     (int cmd, struct ifaddr *ifa, int error, struct rtentry *rt),
    168     (cmd, ifa, error, rt), __nothing);
    169 
    170 MODULE_CALL_HOOK_DECL(rtsock_50_rt_ifannouncemsg_hook, void,
    171     (struct ifnet *, int what));
    172 MODULE_CALL_VOID_HOOK(rtsock_50_rt_ifannouncemsg_hook,
    173     (struct ifnet *ifp, int what), (ifp, what), __nothing);
    174 
    175 MODULE_CALL_HOOK_DECL(rtsock_50_rt_ieee80211msg_hook, void,
    176     (struct ifnet *, int, void *, size_t));
    177 MODULE_CALL_VOID_HOOK(rtsock_50_rt_ieee80211msg_hook,
    178     (struct ifnet *ifp, int what, void *data, size_t data_len),
    179     (ifp, what, data, data_len), __nothing);
    180 
    181 MODULE_CALL_HOOK_DECL(rtsock_50_oifmsg_hook, void, (struct ifnet *ifp));
    182 MODULE_CALL_VOID_HOOK(rtsock_50_oifmsg_hook, (struct ifnet *ifp), (ifp),
    183     __nothing);
    184 
    185 /*
    186  * MODULE_HOOK glue for rtsock70_newaddrmsg1, rtsock70_ifaddr_listaddr,
    187  * and rtsock70_ifaddr_listif
    188  */
    189 MODULE_CALL_HOOK_DECL(rtsock_70_newaddr_hook, void, (int, struct ifaddr *));
    190 MODULE_CALL_VOID_HOOK(rtsock_70_newaddr_hook, (int cmd, struct ifaddr *ifa),
    191     (cmd, ifa), __nothing);
    192 
    193 MODULE_CALL_HOOK_DECL(rtsock_70_iflist_hook, int,
    194     (struct rt_walkarg *, struct ifaddr *, struct rt_addrinfo *));
    195 MODULE_CALL_HOOK(rtsock_70_iflist_hook, int,
    196     (struct rt_walkarg *w, struct ifaddr *ifa, struct rt_addrinfo *info),
    197     (w, ifa, info),
    198     enosys());
    199 
    200 
    201 static int
    202 if_addrflags(struct ifaddr *ifa)
    203 {
    204 
    205 	switch (ifa->ifa_addr->sa_family) {
    206 #ifdef INET
    207 	case AF_INET:
    208 		return ((struct in_ifaddr *)ifa)->ia4_flags;
    209 #endif
    210 #ifdef INET6
    211 	case AF_INET6:
    212 		return ((struct in6_ifaddr *)ifa)->ia6_flags;
    213 #endif
    214 	default:
    215 		return 0;
    216 	}
    217 }
    218 
    219 
    220 /*
    221  * Send a routing message as mimicing that a cloned route is added.
    222  */
    223 void
    224 rt_clonedmsg(const struct sockaddr *dst, const struct ifnet *ifp,
    225     const struct rtentry *rt)
    226 {
    227 	struct rt_addrinfo info;
    228 	/* Mimic flags exactly */
    229 #define RTF_LLINFO	0x400
    230 #define RTF_CLONED	0x2000
    231 	int flags = RTF_UP | RTF_HOST | RTF_DONE | RTF_LLINFO | RTF_CLONED;
    232 	union {
    233 		struct sockaddr sa;
    234 		struct sockaddr_storage ss;
    235 		struct sockaddr_dl sdl;
    236 	} u;
    237 	uint8_t namelen = strlen(ifp->if_xname);
    238 	uint8_t addrlen = ifp->if_addrlen;
    239 
    240 	if (rt == NULL)
    241 		return; /* XXX */
    242 
    243 	memset(&info, 0, sizeof(info));
    244 	info.rti_info[RTAX_DST] = dst;
    245 	sockaddr_dl_init(&u.sdl, sizeof(u.ss), ifp->if_index, ifp->if_type,
    246 	    NULL, namelen, NULL, addrlen);
    247 	info.rti_info[RTAX_GATEWAY] = &u.sa;
    248 
    249 	rt_missmsg(RTM_ADD, &info, flags, 0);
    250 #undef RTF_LLINFO
    251 #undef RTF_CLONED
    252 }
    253 
    254 
    255 /*
    256  * The remaining code implements the routing-table sysctl node.  It is
    257  * compiled only for the non-COMPAT case.
    258  */
    259 
    260 /*
    261  * This is used in dumping the kernel table via sysctl().
    262  */
    263 static int
    264 sysctl_dumpentry(struct rtentry *rt, void *v)
    265 {
    266 	struct rt_walkarg *w = v;
    267 	int error = 0, size;
    268 	struct rt_addrinfo info;
    269 
    270 	if (w->w_op == NET_RT_FLAGS && !(rt->rt_flags & w->w_arg))
    271 		return 0;
    272 	memset(&info, 0, sizeof(info));
    273 	info.rti_info[RTAX_DST] = rt_getkey(rt);
    274 	info.rti_info[RTAX_GATEWAY] = rt->rt_gateway;
    275 	info.rti_info[RTAX_NETMASK] = rt_mask(rt);
    276 	info.rti_info[RTAX_TAG] = rt_gettag(rt);
    277 	if (rt->rt_ifp) {
    278 		const struct ifaddr *rtifa;
    279 		info.rti_info[RTAX_IFP] = rt->rt_ifp->if_dl->ifa_addr;
    280 		/* rtifa used to be simply rt->rt_ifa.  If rt->rt_ifa != NULL,
    281 		 * then rt_get_ifa() != NULL.  So this ought to still be safe.
    282 		 * --dyoung
    283 		 */
    284 		rtifa = rt_get_ifa(rt);
    285 		info.rti_info[RTAX_IFA] = rtifa->ifa_addr;
    286 		if (rt->rt_ifp->if_flags & IFF_POINTOPOINT)
    287 			info.rti_info[RTAX_BRD] = rtifa->ifa_dstaddr;
    288 	}
    289 	if ((error = rt_msg2(RTM_GET, &info, 0, w, &size)))
    290 		return error;
    291 	if (w->w_where && w->w_tmem && w->w_needed <= 0) {
    292 		struct rt_xmsghdr *rtm = (struct rt_xmsghdr *)w->w_tmem;
    293 
    294 		rtm->rtm_flags = rt->rt_flags;
    295 		rtm->rtm_use = rt->rt_use;
    296 		rtm_setmetrics(rt, rtm);
    297 		KASSERT(rt->rt_ifp != NULL);
    298 		rtm->rtm_index = rt->rt_ifp->if_index;
    299 		rtm->rtm_errno = rtm->rtm_pid = rtm->rtm_seq = 0;
    300 		rtm->rtm_addrs = info.rti_addrs;
    301 		if ((error = copyout(rtm, w->w_where, size)) != 0)
    302 			w->w_where = NULL;
    303 		else
    304 			w->w_where = (char *)w->w_where + size;
    305 	}
    306 	return error;
    307 }
    308 
    309 static int
    310 sysctl_iflist_if(struct ifnet *ifp, struct rt_walkarg *w,
    311     struct rt_addrinfo *info, size_t len)
    312 {
    313 	struct if_xmsghdr *ifm;
    314 	int error;
    315 
    316 	ifm = (struct if_xmsghdr *)w->w_tmem;
    317 	ifm->ifm_index = ifp->if_index;
    318 	ifm->ifm_flags = ifp->if_flags;
    319 	ifm->ifm_data = ifp->if_data;
    320 	ifm->ifm_addrs = info->rti_addrs;
    321 	if ((error = copyout(ifm, w->w_where, len)) == 0)
    322 		w->w_where = (char *)w->w_where + len;
    323 	return error;
    324 }
    325 
    326 static int
    327 sysctl_iflist_addr(struct rt_walkarg *w, struct ifaddr *ifa,
    328      struct rt_addrinfo *info)
    329 {
    330 	int len, error;
    331 
    332 	if ((error = rt_msg2(RTM_XNEWADDR, info, 0, w, &len)))
    333 		return error;
    334 	if (w->w_where && w->w_tmem && w->w_needed <= 0) {
    335 		struct ifa_xmsghdr *ifam;
    336 
    337 		ifam = (struct ifa_xmsghdr *)w->w_tmem;
    338 		ifam->ifam_index = ifa->ifa_ifp->if_index;
    339 		ifam->ifam_flags = ifa->ifa_flags;
    340 		ifam->ifam_metric = ifa->ifa_metric;
    341 		ifam->ifam_addrs = info->rti_addrs;
    342 		ifam->ifam_pid = 0;
    343 		ifam->ifam_addrflags = if_addrflags(ifa);
    344 		if ((error = copyout(w->w_tmem, w->w_where, len)) == 0)
    345 			w->w_where = (char *)w->w_where + len;
    346 	}
    347 	return error;
    348 }
    349 
    350 static int
    351 sysctl_iflist(int af, struct rt_walkarg *w, int type)
    352 {
    353 	struct ifnet *ifp;
    354 	struct ifaddr *ifa;
    355 	struct	rt_addrinfo info;
    356 	int	cmd, len, error = 0;
    357 	int s;
    358 	struct psref psref;
    359 	int bound;
    360 
    361 	switch (type) {
    362 	case NET_RT_IFLIST:
    363 		cmd = RTM_IFINFO;
    364 		break;
    365 	case NET_RT_OOOIFLIST:
    366 		cmd = RTM_OOIFINFO;
    367 		break;
    368 	case NET_RT_OOIFLIST:
    369 		cmd = RTM_OIFINFO;
    370 		break;
    371 	case NET_RT_OIFLIST:
    372 		cmd = RTM_IFINFO;
    373 		break;
    374 	default:
    375 #ifdef RTSOCK_DEBUG
    376 		printf("%s: unsupported IFLIST type %d\n", __func__, type);
    377 #endif
    378 		return EINVAL;
    379 	}
    380 
    381 	memset(&info, 0, sizeof(info));
    382 
    383 	bound = curlwp_bind();
    384 	s = pserialize_read_enter();
    385 	IFNET_READER_FOREACH(ifp) {
    386 		int _s;
    387 		if (w->w_arg && w->w_arg != ifp->if_index)
    388 			continue;
    389 		if (IFADDR_READER_EMPTY(ifp))
    390 			continue;
    391 
    392 		if_acquire(ifp, &psref);
    393 		pserialize_read_exit(s);
    394 
    395 		info.rti_info[RTAX_IFP] = ifp->if_dl->ifa_addr;
    396 		if ((error = rt_msg2(cmd, &info, NULL, w, &len)) != 0)
    397 			goto release_exit;
    398 		info.rti_info[RTAX_IFP] = NULL;
    399 		if (w->w_where && w->w_tmem && w->w_needed <= 0) {
    400 			switch (type) {
    401 			case NET_RT_OIFLIST: /* old _70 */
    402 				if (!rtsock_70_iflist_hook.hooked) {
    403 					error = EINVAL;
    404 					break;
    405 				}
    406 				/* FALLTHROUGH */
    407 			case NET_RT_IFLIST: /* current */
    408 				error = sysctl_iflist_if(ifp, w, &info, len);
    409 				break;
    410 			case NET_RT_OOIFLIST: /* old _50 */
    411 				error = rtsock_50_iflist_hook_call(ifp, w, &info,
    412 				    len);
    413 				break;
    414 			case NET_RT_OOOIFLIST: /* old _14 */
    415 				error = rtsock_14_iflist_hook_call(ifp, w,
    416 				    &info, len);
    417 				break;
    418 			default:
    419 				error = EINVAL;
    420 			}
    421 			if (error != 0) {
    422 				if (error == ENOSYS)
    423 					error = EINVAL;
    424 				goto release_exit;
    425 			}
    426 		}
    427 		_s = pserialize_read_enter();
    428 		IFADDR_READER_FOREACH(ifa, ifp) {
    429 			struct psref _psref;
    430 			if (af && af != ifa->ifa_addr->sa_family)
    431 				continue;
    432 			ifa_acquire(ifa, &_psref);
    433 			pserialize_read_exit(_s);
    434 
    435 			info.rti_info[RTAX_IFA] = ifa->ifa_addr;
    436 			info.rti_info[RTAX_NETMASK] = ifa->ifa_netmask;
    437 			info.rti_info[RTAX_BRD] = ifa->ifa_dstaddr;
    438 			switch (type) {
    439 			case NET_RT_IFLIST:
    440 				error = sysctl_iflist_addr(w, ifa, &info);
    441 				break;
    442 			case NET_RT_OIFLIST:
    443 			case NET_RT_OOIFLIST:
    444 			case NET_RT_OOOIFLIST:
    445 				error = rtsock_70_iflist_hook_call(w, ifa,
    446 				    &info);
    447 				break;
    448 			default:
    449 				error = EINVAL;
    450 			}
    451 
    452 			_s = pserialize_read_enter();
    453 			ifa_release(ifa, &_psref);
    454 			if (error != 0) {
    455 				pserialize_read_exit(_s);
    456 				goto release_exit;
    457 			}
    458 		}
    459 		pserialize_read_exit(_s);
    460 		info.rti_info[RTAX_IFA] = info.rti_info[RTAX_NETMASK] =
    461 		    info.rti_info[RTAX_BRD] = NULL;
    462 
    463 		s = pserialize_read_enter();
    464 		if_release(ifp, &psref);
    465 	}
    466 	pserialize_read_exit(s);
    467 	curlwp_bindx(bound);
    468 
    469 	return 0;
    470 
    471 release_exit:
    472 	if_release(ifp, &psref);
    473 	curlwp_bindx(bound);
    474 	return error;
    475 }
    476 
    477 static int
    478 sysctl_rtable(SYSCTLFN_ARGS)
    479 {
    480 	void 	*where = oldp;
    481 	size_t	*given = oldlenp;
    482 	int	i, s, error = EINVAL;
    483 	u_char  af;
    484 	struct	rt_walkarg w;
    485 
    486 	if (namelen == 1 && name[0] == CTL_QUERY)
    487 		return sysctl_query(SYSCTLFN_CALL(rnode));
    488 
    489 	if (newp)
    490 		return EPERM;
    491 	if (namelen != 3)
    492 		return EINVAL;
    493 	af = name[0];
    494 	w.w_tmemneeded = 0;
    495 	w.w_tmemsize = 0;
    496 	w.w_tmem = NULL;
    497 again:
    498 	/* we may return here if a later [re]alloc of the t_mem buffer fails */
    499 	if (w.w_tmemneeded) {
    500 		w.w_tmem = kmem_zalloc(w.w_tmemneeded, KM_SLEEP);
    501 		w.w_tmemsize = w.w_tmemneeded;
    502 		w.w_tmemneeded = 0;
    503 	}
    504 	w.w_op = name[1];
    505 	w.w_arg = name[2];
    506 	w.w_given = *given;
    507 	w.w_needed = 0 - w.w_given;
    508 	w.w_where = where;
    509 
    510 	s = splsoftnet();
    511 	switch (w.w_op) {
    512 
    513 	case NET_RT_DUMP:
    514 	case NET_RT_FLAGS:
    515 #if defined(INET) || defined(INET6)
    516 		/*
    517 		 * take care of llinfo entries, the caller must
    518 		 * specify an AF
    519 		 */
    520 		if (w.w_op == NET_RT_FLAGS &&
    521 		    (w.w_arg == 0 || w.w_arg & RTF_LLDATA)) {
    522 			if (af != 0)
    523 				error = lltable_sysctl_dump(af, &w);
    524 			else
    525 				error = EINVAL;
    526 			break;
    527 		}
    528 #endif
    529 
    530 		for (i = 1; i <= AF_MAX; i++) {
    531 			if (af == 0 || af == i) {
    532 				error = rt_walktree(i, sysctl_dumpentry, &w);
    533 				if (error != 0)
    534 					break;
    535 #if defined(INET) || defined(INET6)
    536 				/*
    537 				 * Return ARP/NDP entries too for
    538 				 * backward compatibility.
    539 				 */
    540 				error = lltable_sysctl_dump(i, &w);
    541 				if (error != 0)
    542 					break;
    543 #endif
    544 			}
    545 		}
    546 		break;
    547 
    548 	case NET_RT_OOOIFLIST:		/* compat_14 */
    549 	case NET_RT_OOIFLIST:		/* compat_50 */
    550 	case NET_RT_OIFLIST:		/* compat_70 */
    551 	case NET_RT_IFLIST:		/* current */
    552 		error = sysctl_iflist(af, &w, w.w_op);
    553 		break;
    554 	}
    555 	splx(s);
    556 
    557 	/* check to see if we couldn't allocate memory with NOWAIT */
    558 	if (error == ENOBUFS && w.w_tmem == 0 && w.w_tmemneeded)
    559 		goto again;
    560 
    561 	if (w.w_tmem)
    562 		kmem_free(w.w_tmem, w.w_tmemsize);
    563 	w.w_needed += w.w_given;
    564 	if (where) {
    565 		*given = (char *)w.w_where - (char *)where;
    566 		if (*given < w.w_needed)
    567 			return ENOMEM;
    568 	} else {
    569 		*given = (11 * w.w_needed) / 10;
    570 	}
    571 	return error;
    572 }
    573 
    574 static void
    575 sysctl_net_route_setup(struct sysctllog **clog)
    576 {
    577 	const struct sysctlnode *rnode = NULL;
    578 
    579 	sysctl_createv(clog, 0, NULL, &rnode,
    580 		       CTLFLAG_PERMANENT,
    581 		       CTLTYPE_NODE, DOMAINNAME,
    582 		       SYSCTL_DESCR("PF_ROUTE information"),
    583 		       NULL, 0, NULL, 0,
    584 		       CTL_NET, PF_XROUTE, CTL_EOL);
    585 
    586 	sysctl_createv(clog, 0, NULL, NULL,
    587 		       CTLFLAG_PERMANENT,
    588 		       CTLTYPE_NODE, "rtable",
    589 		       SYSCTL_DESCR("Routing table information"),
    590 		       sysctl_rtable, 0, NULL, 0,
    591 		       CTL_NET, PF_XROUTE, 0 /* any protocol */, CTL_EOL);
    592 
    593 	sysctl_createv(clog, 0, &rnode, NULL,
    594 		       CTLFLAG_PERMANENT,
    595 		       CTLTYPE_STRUCT, "stats",
    596 		       SYSCTL_DESCR("Routing statistics"),
    597 		       NULL, 0, &rtstat, sizeof(rtstat),
    598 		       CTL_CREATE, CTL_EOL);
    599 }
    600