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