2020-03-10 00:20:55 +03:00
|
|
|
/* $NetBSD: rtsock.c,v 1.255 2020/03/09 21:20:55 roy Exp $ */
|
1999-07-01 12:12:45 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
|
|
|
* All rights reserved.
|
2005-02-27 01:45:09 +03:00
|
|
|
*
|
1999-07-01 12:12:45 +04:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the project nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
2005-02-27 01:45:09 +03:00
|
|
|
*
|
1999-07-01 12:12:45 +04:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
1994-06-29 10:29:24 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1994-05-13 10:02:48 +04:00
|
|
|
* Copyright (c) 1988, 1991, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 20:26:28 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1993-03-21 12:45:37 +03:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1998-03-01 05:20:01 +03:00
|
|
|
* @(#)rtsock.c 8.7 (Berkeley) 10/12/95
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
|
2001-11-13 02:49:33 +03:00
|
|
|
#include <sys/cdefs.h>
|
2020-03-10 00:20:55 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.255 2020/03/09 21:20:55 roy Exp $");
|
2001-11-13 02:49:33 +03:00
|
|
|
|
2011-02-01 04:39:19 +03:00
|
|
|
#ifdef _KERNEL_OPT
|
1999-07-10 03:41:16 +04:00
|
|
|
#include "opt_inet.h"
|
2009-01-11 05:45:45 +03:00
|
|
|
#include "opt_compat_netbsd.h"
|
|
|
|
#endif
|
1999-07-10 03:41:16 +04:00
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
|
|
|
#include <sys/domain.h>
|
|
|
|
#include <sys/protosw.h>
|
1996-02-14 00:59:53 +03:00
|
|
|
#include <sys/sysctl.h>
|
2006-05-15 01:19:33 +04:00
|
|
|
#include <sys/kauth.h>
|
2014-05-19 06:51:24 +04:00
|
|
|
#include <sys/kmem.h>
|
2008-03-26 17:53:14 +03:00
|
|
|
#include <sys/intr.h>
|
2018-01-19 08:19:29 +03:00
|
|
|
#include <sys/condvar.h>
|
2019-01-27 05:08:33 +03:00
|
|
|
#include <sys/compat_stub.h>
|
1996-02-14 00:59:53 +03:00
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <net/if.h>
|
2016-04-04 10:37:07 +03:00
|
|
|
#include <net/if_llatbl.h>
|
|
|
|
#include <net/if_types.h>
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <net/route.h>
|
|
|
|
#include <net/raw_cb.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2016-04-04 10:37:07 +03:00
|
|
|
#include <netinet/in_var.h>
|
|
|
|
#include <netinet/if_inarp.h>
|
|
|
|
|
2010-06-26 18:24:27 +04:00
|
|
|
#include <netmpls/mpls.h>
|
|
|
|
|
2019-01-27 05:08:33 +03:00
|
|
|
#include <compat/net/if.h>
|
|
|
|
#include <compat/net/route.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2019-01-27 05:08:33 +03:00
|
|
|
#ifdef COMPAT_RTSOCK
|
|
|
|
#undef COMPAT_RTSOCK
|
2018-04-25 06:49:57 +03:00
|
|
|
#endif
|
2017-04-11 16:55:54 +03:00
|
|
|
|
2019-01-27 05:08:33 +03:00
|
|
|
static int if_addrflags(struct ifaddr *);
|
2017-04-11 16:55:54 +03:00
|
|
|
|
2019-01-27 05:08:33 +03:00
|
|
|
#include <net/rtsock_shared.c>
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2018-04-12 07:38:13 +03:00
|
|
|
/*
|
|
|
|
* XXX avoid using void * once msghdr compat disappears.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
rt_setmetrics(void *in, struct rtentry *out)
|
|
|
|
{
|
|
|
|
const struct rt_xmsghdr *rtm = in;
|
|
|
|
|
|
|
|
_rt_setmetrics(rtm->rtm_inits, rtm, out);
|
|
|
|
}
|
1994-05-13 10:02:48 +04:00
|
|
|
|
2016-04-04 10:37:07 +03:00
|
|
|
int
|
|
|
|
rt_msg3(int type, struct rt_addrinfo *rtinfo, void *cpv, struct rt_walkarg *w,
|
|
|
|
int *lenp)
|
|
|
|
{
|
|
|
|
return rt_msg2(type, rtinfo, cpv, w, lenp);
|
|
|
|
}
|
1994-05-13 10:02:48 +04:00
|
|
|
|
2016-09-21 13:50:22 +03:00
|
|
|
static int
|
|
|
|
if_addrflags(struct ifaddr *ifa)
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (ifa->ifa_addr->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
2020-02-03 23:34:13 +03:00
|
|
|
return ifatoia(ifa)->ia4_flags;
|
2016-09-21 13:50:22 +03:00
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
2020-02-03 23:34:13 +03:00
|
|
|
return ifatoia6(ifa)->ia6_flags;
|
2016-09-21 13:50:22 +03:00
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-22 10:14:51 +04:00
|
|
|
|
2017-06-16 05:24:54 +03:00
|
|
|
/*
|
|
|
|
* Send a routing message as mimicing that a cloned route is added.
|
|
|
|
*/
|
|
|
|
void
|
2020-03-10 00:20:55 +03:00
|
|
|
rt_clonedmsg(int type, const struct sockaddr *src, const struct sockaddr *dst,
|
|
|
|
const uint8_t *lladdr, const struct ifnet *ifp)
|
2017-06-16 05:24:54 +03:00
|
|
|
{
|
|
|
|
struct rt_addrinfo info;
|
|
|
|
/* Mimic flags exactly */
|
|
|
|
#define RTF_LLINFO 0x400
|
|
|
|
#define RTF_CLONED 0x2000
|
2019-09-01 21:54:38 +03:00
|
|
|
int flags = RTF_DONE;
|
2017-06-16 05:24:54 +03:00
|
|
|
union {
|
|
|
|
struct sockaddr sa;
|
|
|
|
struct sockaddr_storage ss;
|
|
|
|
struct sockaddr_dl sdl;
|
|
|
|
} u;
|
|
|
|
|
2019-09-01 21:54:38 +03:00
|
|
|
if (type != RTM_MISS)
|
|
|
|
flags |= RTF_HOST | RTF_CLONED | RTF_LLINFO;
|
|
|
|
if (type == RTM_ADD || type == RTM_CHANGE)
|
2019-08-23 00:14:45 +03:00
|
|
|
flags |= RTF_UP;
|
2017-06-16 05:24:54 +03:00
|
|
|
memset(&info, 0, sizeof(info));
|
2020-03-10 00:20:55 +03:00
|
|
|
info.rti_info[RTAX_AUTHOR] = src;
|
2017-06-16 05:24:54 +03:00
|
|
|
info.rti_info[RTAX_DST] = dst;
|
|
|
|
sockaddr_dl_init(&u.sdl, sizeof(u.ss), ifp->if_index, ifp->if_type,
|
2019-09-01 21:54:38 +03:00
|
|
|
NULL, 0, lladdr, ifp->if_addrlen);
|
2017-06-16 05:24:54 +03:00
|
|
|
info.rti_info[RTAX_GATEWAY] = &u.sa;
|
|
|
|
|
2019-08-23 00:14:45 +03:00
|
|
|
rt_missmsg(type, &info, flags, 0);
|
2017-06-16 05:24:54 +03:00
|
|
|
#undef RTF_LLINFO
|
|
|
|
#undef RTF_CLONED
|
|
|
|
}
|
2019-01-27 05:08:33 +03:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The remaining code implements the routing-table sysctl node. It is
|
|
|
|
* compiled only for the non-COMPAT case.
|
|
|
|
*/
|
2017-06-16 05:24:54 +03:00
|
|
|
|
1994-05-13 10:02:48 +04:00
|
|
|
/*
|
|
|
|
* This is used in dumping the kernel table via sysctl().
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
2000-04-15 21:51:27 +04:00
|
|
|
static int
|
2007-06-09 07:07:21 +04:00
|
|
|
sysctl_dumpentry(struct rtentry *rt, void *v)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2009-01-11 05:45:45 +03:00
|
|
|
struct rt_walkarg *w = v;
|
1994-05-13 10:02:48 +04:00
|
|
|
int error = 0, size;
|
|
|
|
struct rt_addrinfo info;
|
|
|
|
|
|
|
|
if (w->w_op == NET_RT_FLAGS && !(rt->rt_flags & w->w_arg))
|
|
|
|
return 0;
|
2001-07-18 20:43:09 +04:00
|
|
|
memset(&info, 0, sizeof(info));
|
2008-10-28 05:03:06 +03:00
|
|
|
info.rti_info[RTAX_DST] = rt_getkey(rt);
|
|
|
|
info.rti_info[RTAX_GATEWAY] = rt->rt_gateway;
|
|
|
|
info.rti_info[RTAX_NETMASK] = rt_mask(rt);
|
2013-07-24 19:31:04 +04:00
|
|
|
info.rti_info[RTAX_TAG] = rt_gettag(rt);
|
1995-08-19 11:48:14 +04:00
|
|
|
if (rt->rt_ifp) {
|
2006-11-13 22:16:01 +03:00
|
|
|
const struct ifaddr *rtifa;
|
2008-10-28 05:03:06 +03:00
|
|
|
info.rti_info[RTAX_IFP] = rt->rt_ifp->if_dl->ifa_addr;
|
2006-11-13 22:16:01 +03:00
|
|
|
/* rtifa used to be simply rt->rt_ifa. If rt->rt_ifa != NULL,
|
|
|
|
* then rt_get_ifa() != NULL. So this ought to still be safe.
|
|
|
|
* --dyoung
|
|
|
|
*/
|
|
|
|
rtifa = rt_get_ifa(rt);
|
2008-10-28 05:03:06 +03:00
|
|
|
info.rti_info[RTAX_IFA] = rtifa->ifa_addr;
|
1995-08-19 11:48:14 +04:00
|
|
|
if (rt->rt_ifp->if_flags & IFF_POINTOPOINT)
|
2008-10-28 05:03:06 +03:00
|
|
|
info.rti_info[RTAX_BRD] = rtifa->ifa_dstaddr;
|
1995-08-19 11:48:14 +04:00
|
|
|
}
|
1999-04-02 21:22:21 +04:00
|
|
|
if ((error = rt_msg2(RTM_GET, &info, 0, w, &size)))
|
Take steps to hide the radix_node implementation of the forwarding table
from the forwarding table's users:
Introduce rt_walktree() for walking the routing table and
applying a function to each rtentry. Replace most
rn_walktree() calls with it.
Use rt_getkey()/rt_setkey() to get/set a route's destination.
Keep a pointer to the sockaddr key in the rtentry, so that
rtentry users do not have to grovel in the radix_node for
the key.
Add a RTM_GET method to rtrequest. Use that instead of
radix_node lookups in, e.g., carp(4).
Add sys/net/link_proto.c, which supplies sockaddr routines for
link-layer socket addresses (sockaddr_dl).
Cosmetic:
Constify. KNF. Stop open-coding LIST_FOREACH, TAILQ_FOREACH,
et cetera. Use NULL instead of 0 for null pointers. Use
__arraycount(). Reduce gratuitous parenthesization.
Stop using variadic arguments for rip6_output(), it is
unnecessary.
Remove the unnecessary rtentry member rt_genmask and the
code to maintain it, since nothing actually used it.
Make rt_maskedcopy() easier to read by using meaningful variable
names.
Extract a subroutine intern_netmask() for looking up a netmask in
the masks table.
Start converting backslash-ridden IPv6 macros in
sys/netinet6/in6_var.h into inline subroutines that one
can read without special eyeglasses.
One functional change: when the kernel serves an RTM_GET, RTM_LOCK,
or RTM_CHANGE request, it applies the netmask (if supplied) to a
destination before searching for it in the forwarding table.
I have changed sys/netinet/ip_carp.c, carp_setroute(), to remove
the unlawful radix_node knowledge.
Apart from the changes to carp(4), netiso, ATM, and strip(4), I
have run the changes on three nodes in my wireless routing testbed,
which involves IPv4 + IPv6 dynamic routing acrobatics, and it's
working beautifully so far.
2007-07-20 00:48:52 +04:00
|
|
|
return error;
|
1999-04-02 21:22:21 +04:00
|
|
|
if (w->w_where && w->w_tmem && w->w_needed <= 0) {
|
2011-02-01 04:39:19 +03:00
|
|
|
struct rt_xmsghdr *rtm = (struct rt_xmsghdr *)w->w_tmem;
|
1994-05-13 10:02:48 +04:00
|
|
|
|
|
|
|
rtm->rtm_flags = rt->rt_flags;
|
|
|
|
rtm->rtm_use = rt->rt_use;
|
2011-02-01 04:39:19 +03:00
|
|
|
rtm_setmetrics(rt, rtm);
|
2006-04-15 06:14:44 +04:00
|
|
|
KASSERT(rt->rt_ifp != NULL);
|
1994-05-13 10:02:48 +04:00
|
|
|
rtm->rtm_index = rt->rt_ifp->if_index;
|
|
|
|
rtm->rtm_errno = rtm->rtm_pid = rtm->rtm_seq = 0;
|
|
|
|
rtm->rtm_addrs = info.rti_addrs;
|
1996-07-01 05:12:32 +04:00
|
|
|
if ((error = copyout(rtm, w->w_where, size)) != 0)
|
1994-05-13 10:02:48 +04:00
|
|
|
w->w_where = NULL;
|
|
|
|
else
|
2007-03-04 08:59:00 +03:00
|
|
|
w->w_where = (char *)w->w_where + size;
|
1994-05-13 10:02:48 +04:00
|
|
|
}
|
Take steps to hide the radix_node implementation of the forwarding table
from the forwarding table's users:
Introduce rt_walktree() for walking the routing table and
applying a function to each rtentry. Replace most
rn_walktree() calls with it.
Use rt_getkey()/rt_setkey() to get/set a route's destination.
Keep a pointer to the sockaddr key in the rtentry, so that
rtentry users do not have to grovel in the radix_node for
the key.
Add a RTM_GET method to rtrequest. Use that instead of
radix_node lookups in, e.g., carp(4).
Add sys/net/link_proto.c, which supplies sockaddr routines for
link-layer socket addresses (sockaddr_dl).
Cosmetic:
Constify. KNF. Stop open-coding LIST_FOREACH, TAILQ_FOREACH,
et cetera. Use NULL instead of 0 for null pointers. Use
__arraycount(). Reduce gratuitous parenthesization.
Stop using variadic arguments for rip6_output(), it is
unnecessary.
Remove the unnecessary rtentry member rt_genmask and the
code to maintain it, since nothing actually used it.
Make rt_maskedcopy() easier to read by using meaningful variable
names.
Extract a subroutine intern_netmask() for looking up a netmask in
the masks table.
Start converting backslash-ridden IPv6 macros in
sys/netinet6/in6_var.h into inline subroutines that one
can read without special eyeglasses.
One functional change: when the kernel serves an RTM_GET, RTM_LOCK,
or RTM_CHANGE request, it applies the netmask (if supplied) to a
destination before searching for it in the forwarding table.
I have changed sys/netinet/ip_carp.c, carp_setroute(), to remove
the unlawful radix_node knowledge.
Apart from the changes to carp(4), netiso, ATM, and strip(4), I
have run the changes on three nodes in my wireless routing testbed,
which involves IPv4 + IPv6 dynamic routing acrobatics, and it's
working beautifully so far.
2007-07-20 00:48:52 +04:00
|
|
|
return error;
|
1994-05-13 10:02:48 +04:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2016-09-01 22:04:30 +03:00
|
|
|
static int
|
|
|
|
sysctl_iflist_if(struct ifnet *ifp, struct rt_walkarg *w,
|
|
|
|
struct rt_addrinfo *info, size_t len)
|
|
|
|
{
|
|
|
|
struct if_xmsghdr *ifm;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
ifm = (struct if_xmsghdr *)w->w_tmem;
|
|
|
|
ifm->ifm_index = ifp->if_index;
|
|
|
|
ifm->ifm_flags = ifp->if_flags;
|
2020-01-29 07:35:13 +03:00
|
|
|
if_export_if_data(ifp, &ifm->ifm_data, false);
|
2016-09-01 22:04:30 +03:00
|
|
|
ifm->ifm_addrs = info->rti_addrs;
|
|
|
|
if ((error = copyout(ifm, w->w_where, len)) == 0)
|
|
|
|
w->w_where = (char *)w->w_where + len;
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
sysctl_iflist_addr(struct rt_walkarg *w, struct ifaddr *ifa,
|
|
|
|
struct rt_addrinfo *info)
|
|
|
|
{
|
|
|
|
int len, error;
|
|
|
|
|
2016-09-21 13:50:22 +03:00
|
|
|
if ((error = rt_msg2(RTM_XNEWADDR, info, 0, w, &len)))
|
2016-09-01 22:04:30 +03:00
|
|
|
return error;
|
|
|
|
if (w->w_where && w->w_tmem && w->w_needed <= 0) {
|
|
|
|
struct ifa_xmsghdr *ifam;
|
|
|
|
|
|
|
|
ifam = (struct ifa_xmsghdr *)w->w_tmem;
|
|
|
|
ifam->ifam_index = ifa->ifa_ifp->if_index;
|
|
|
|
ifam->ifam_flags = ifa->ifa_flags;
|
|
|
|
ifam->ifam_metric = ifa->ifa_metric;
|
|
|
|
ifam->ifam_addrs = info->rti_addrs;
|
2016-09-21 13:50:22 +03:00
|
|
|
ifam->ifam_pid = 0;
|
|
|
|
ifam->ifam_addrflags = if_addrflags(ifa);
|
2016-09-01 22:04:30 +03:00
|
|
|
if ((error = copyout(w->w_tmem, w->w_where, len)) == 0)
|
|
|
|
w->w_where = (char *)w->w_where + len;
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2000-04-15 21:51:27 +04:00
|
|
|
static int
|
2009-01-11 05:45:45 +03:00
|
|
|
sysctl_iflist(int af, struct rt_walkarg *w, int type)
|
1994-05-13 10:02:48 +04:00
|
|
|
{
|
2000-03-30 13:45:33 +04:00
|
|
|
struct ifnet *ifp;
|
|
|
|
struct ifaddr *ifa;
|
1994-05-13 10:02:48 +04:00
|
|
|
struct rt_addrinfo info;
|
2016-09-01 22:04:30 +03:00
|
|
|
int cmd, len, error = 0;
|
2016-05-12 05:24:16 +03:00
|
|
|
int s;
|
|
|
|
struct psref psref;
|
2017-03-14 11:35:55 +03:00
|
|
|
int bound;
|
1994-05-13 10:02:48 +04:00
|
|
|
|
2016-09-01 22:04:30 +03:00
|
|
|
switch (type) {
|
|
|
|
case NET_RT_IFLIST:
|
|
|
|
cmd = RTM_IFINFO;
|
|
|
|
break;
|
2016-09-21 13:50:22 +03:00
|
|
|
case NET_RT_OOOIFLIST:
|
2016-09-01 22:04:30 +03:00
|
|
|
cmd = RTM_OOIFINFO;
|
|
|
|
break;
|
2016-09-21 13:50:22 +03:00
|
|
|
case NET_RT_OOIFLIST:
|
2016-09-01 22:04:30 +03:00
|
|
|
cmd = RTM_OIFINFO;
|
2016-09-21 13:50:22 +03:00
|
|
|
break;
|
|
|
|
case NET_RT_OIFLIST:
|
|
|
|
cmd = RTM_IFINFO;
|
2016-09-01 22:04:30 +03:00
|
|
|
break;
|
|
|
|
default:
|
2017-03-14 07:23:15 +03:00
|
|
|
#ifdef RTSOCK_DEBUG
|
|
|
|
printf("%s: unsupported IFLIST type %d\n", __func__, type);
|
2016-09-01 22:04:30 +03:00
|
|
|
#endif
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
2001-07-18 20:43:09 +04:00
|
|
|
memset(&info, 0, sizeof(info));
|
2016-05-12 05:24:16 +03:00
|
|
|
|
2017-03-14 11:35:55 +03:00
|
|
|
bound = curlwp_bind();
|
2016-05-12 05:24:16 +03:00
|
|
|
s = pserialize_read_enter();
|
|
|
|
IFNET_READER_FOREACH(ifp) {
|
2017-03-14 11:11:09 +03:00
|
|
|
int _s;
|
1994-05-13 10:02:48 +04:00
|
|
|
if (w->w_arg && w->w_arg != ifp->if_index)
|
|
|
|
continue;
|
2016-07-07 12:32:01 +03:00
|
|
|
if (IFADDR_READER_EMPTY(ifp))
|
2006-02-22 01:01:17 +03:00
|
|
|
continue;
|
2016-05-12 05:24:16 +03:00
|
|
|
|
2017-03-14 12:03:08 +03:00
|
|
|
if_acquire(ifp, &psref);
|
2016-05-12 05:24:16 +03:00
|
|
|
pserialize_read_exit(s);
|
|
|
|
|
2008-10-28 05:03:06 +03:00
|
|
|
info.rti_info[RTAX_IFP] = ifp->if_dl->ifa_addr;
|
2016-09-01 22:04:30 +03:00
|
|
|
if ((error = rt_msg2(cmd, &info, NULL, w, &len)) != 0)
|
2016-05-12 05:24:16 +03:00
|
|
|
goto release_exit;
|
2008-10-28 05:03:06 +03:00
|
|
|
info.rti_info[RTAX_IFP] = NULL;
|
1999-04-02 21:22:21 +04:00
|
|
|
if (w->w_where && w->w_tmem && w->w_needed <= 0) {
|
2019-01-27 05:08:33 +03:00
|
|
|
switch (type) {
|
|
|
|
case NET_RT_OIFLIST: /* old _70 */
|
2019-01-29 12:28:50 +03:00
|
|
|
if (!rtsock_iflist_70_hook.hooked) {
|
2019-01-27 05:08:33 +03:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case NET_RT_IFLIST: /* current */
|
|
|
|
error = sysctl_iflist_if(ifp, w, &info, len);
|
|
|
|
break;
|
|
|
|
case NET_RT_OOIFLIST: /* old _50 */
|
2019-03-01 14:06:55 +03:00
|
|
|
MODULE_HOOK_CALL(rtsock_iflist_50_hook,
|
2019-01-27 05:08:33 +03:00
|
|
|
(ifp, w, &info, len), enosys(), error);
|
|
|
|
break;
|
|
|
|
case NET_RT_OOOIFLIST: /* old _14 */
|
2019-03-01 14:06:55 +03:00
|
|
|
MODULE_HOOK_CALL(rtsock_iflist_14_hook,
|
2019-01-27 05:08:33 +03:00
|
|
|
(ifp, w, &info, len), enosys(), error);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
if (error != 0) {
|
|
|
|
if (error == ENOSYS)
|
|
|
|
error = EINVAL;
|
2016-09-01 22:04:30 +03:00
|
|
|
goto release_exit;
|
2019-01-27 05:08:33 +03:00
|
|
|
}
|
1994-05-13 10:02:48 +04:00
|
|
|
}
|
2017-03-14 11:11:09 +03:00
|
|
|
_s = pserialize_read_enter();
|
2016-07-07 12:32:01 +03:00
|
|
|
IFADDR_READER_FOREACH(ifa, ifp) {
|
2017-03-14 11:11:09 +03:00
|
|
|
struct psref _psref;
|
1994-05-13 10:02:48 +04:00
|
|
|
if (af && af != ifa->ifa_addr->sa_family)
|
|
|
|
continue;
|
2017-03-14 11:11:09 +03:00
|
|
|
ifa_acquire(ifa, &_psref);
|
|
|
|
pserialize_read_exit(_s);
|
|
|
|
|
2008-10-28 05:03:06 +03:00
|
|
|
info.rti_info[RTAX_IFA] = ifa->ifa_addr;
|
|
|
|
info.rti_info[RTAX_NETMASK] = ifa->ifa_netmask;
|
|
|
|
info.rti_info[RTAX_BRD] = ifa->ifa_dstaddr;
|
2019-01-27 05:08:33 +03:00
|
|
|
switch (type) {
|
|
|
|
case NET_RT_IFLIST:
|
|
|
|
error = sysctl_iflist_addr(w, ifa, &info);
|
|
|
|
break;
|
|
|
|
case NET_RT_OIFLIST:
|
|
|
|
case NET_RT_OOIFLIST:
|
|
|
|
case NET_RT_OOOIFLIST:
|
2019-03-01 14:06:55 +03:00
|
|
|
MODULE_HOOK_CALL(rtsock_iflist_70_hook,
|
2019-01-27 05:08:33 +03:00
|
|
|
(w, ifa, &info), enosys(), error);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
2017-03-14 11:11:09 +03:00
|
|
|
|
|
|
|
_s = pserialize_read_enter();
|
|
|
|
ifa_release(ifa, &_psref);
|
2017-03-14 12:39:28 +03:00
|
|
|
if (error != 0) {
|
|
|
|
pserialize_read_exit(_s);
|
2016-05-12 05:24:16 +03:00
|
|
|
goto release_exit;
|
2017-03-14 12:39:28 +03:00
|
|
|
}
|
1994-05-13 10:02:48 +04:00
|
|
|
}
|
2017-03-14 11:11:09 +03:00
|
|
|
pserialize_read_exit(_s);
|
2008-10-28 14:41:23 +03:00
|
|
|
info.rti_info[RTAX_IFA] = info.rti_info[RTAX_NETMASK] =
|
|
|
|
info.rti_info[RTAX_BRD] = NULL;
|
2016-05-12 05:24:16 +03:00
|
|
|
|
|
|
|
s = pserialize_read_enter();
|
2017-03-14 12:03:08 +03:00
|
|
|
if_release(ifp, &psref);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2016-05-12 05:24:16 +03:00
|
|
|
pserialize_read_exit(s);
|
2016-06-16 05:38:40 +03:00
|
|
|
curlwp_bindx(bound);
|
2016-05-12 05:24:16 +03:00
|
|
|
|
Take steps to hide the radix_node implementation of the forwarding table
from the forwarding table's users:
Introduce rt_walktree() for walking the routing table and
applying a function to each rtentry. Replace most
rn_walktree() calls with it.
Use rt_getkey()/rt_setkey() to get/set a route's destination.
Keep a pointer to the sockaddr key in the rtentry, so that
rtentry users do not have to grovel in the radix_node for
the key.
Add a RTM_GET method to rtrequest. Use that instead of
radix_node lookups in, e.g., carp(4).
Add sys/net/link_proto.c, which supplies sockaddr routines for
link-layer socket addresses (sockaddr_dl).
Cosmetic:
Constify. KNF. Stop open-coding LIST_FOREACH, TAILQ_FOREACH,
et cetera. Use NULL instead of 0 for null pointers. Use
__arraycount(). Reduce gratuitous parenthesization.
Stop using variadic arguments for rip6_output(), it is
unnecessary.
Remove the unnecessary rtentry member rt_genmask and the
code to maintain it, since nothing actually used it.
Make rt_maskedcopy() easier to read by using meaningful variable
names.
Extract a subroutine intern_netmask() for looking up a netmask in
the masks table.
Start converting backslash-ridden IPv6 macros in
sys/netinet6/in6_var.h into inline subroutines that one
can read without special eyeglasses.
One functional change: when the kernel serves an RTM_GET, RTM_LOCK,
or RTM_CHANGE request, it applies the netmask (if supplied) to a
destination before searching for it in the forwarding table.
I have changed sys/netinet/ip_carp.c, carp_setroute(), to remove
the unlawful radix_node knowledge.
Apart from the changes to carp(4), netiso, ATM, and strip(4), I
have run the changes on three nodes in my wireless routing testbed,
which involves IPv4 + IPv6 dynamic routing acrobatics, and it's
working beautifully so far.
2007-07-20 00:48:52 +04:00
|
|
|
return 0;
|
2016-05-12 05:24:16 +03:00
|
|
|
|
|
|
|
release_exit:
|
2017-03-14 12:03:08 +03:00
|
|
|
if_release(ifp, &psref);
|
2016-06-16 05:38:40 +03:00
|
|
|
curlwp_bindx(bound);
|
2016-05-12 05:24:16 +03:00
|
|
|
return error;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2000-04-15 21:51:27 +04:00
|
|
|
static int
|
Dynamic sysctl.
Gone are the old kern_sysctl(), cpu_sysctl(), hw_sysctl(),
vfs_sysctl(), etc, routines, along with sysctl_int() et al. Now all
nodes are registered with the tree, and nodes can be added (or
removed) easily, and I/O to and from the tree is handled generically.
Since the nodes are registered with the tree, the mapping from name to
number (and back again) can now be discovered, instead of having to be
hard coded. Adding new nodes to the tree is likewise much simpler --
the new infrastructure handles almost all the work for simple types,
and just about anything else can be done with a small helper function.
All existing nodes are where they were before (numerically speaking),
so all existing consumers of sysctl information should notice no
difference.
PS - I'm sorry, but there's a distinct lack of documentation at the
moment. I'm working on sysctl(3/8/9) right now, and I promise to
watch out for buses.
2003-12-04 22:38:21 +03:00
|
|
|
sysctl_rtable(SYSCTLFN_ARGS)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
Dynamic sysctl.
Gone are the old kern_sysctl(), cpu_sysctl(), hw_sysctl(),
vfs_sysctl(), etc, routines, along with sysctl_int() et al. Now all
nodes are registered with the tree, and nodes can be added (or
removed) easily, and I/O to and from the tree is handled generically.
Since the nodes are registered with the tree, the mapping from name to
number (and back again) can now be discovered, instead of having to be
hard coded. Adding new nodes to the tree is likewise much simpler --
the new infrastructure handles almost all the work for simple types,
and just about anything else can be done with a small helper function.
All existing nodes are where they were before (numerically speaking),
so all existing consumers of sysctl information should notice no
difference.
PS - I'm sorry, but there's a distinct lack of documentation at the
moment. I'm working on sysctl(3/8/9) right now, and I promise to
watch out for buses.
2003-12-04 22:38:21 +03:00
|
|
|
void *where = oldp;
|
|
|
|
size_t *given = oldlenp;
|
1994-05-13 10:02:48 +04:00
|
|
|
int i, s, error = EINVAL;
|
|
|
|
u_char af;
|
2009-01-11 05:45:45 +03:00
|
|
|
struct rt_walkarg w;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2003-12-29 01:36:37 +03:00
|
|
|
if (namelen == 1 && name[0] == CTL_QUERY)
|
Take steps to hide the radix_node implementation of the forwarding table
from the forwarding table's users:
Introduce rt_walktree() for walking the routing table and
applying a function to each rtentry. Replace most
rn_walktree() calls with it.
Use rt_getkey()/rt_setkey() to get/set a route's destination.
Keep a pointer to the sockaddr key in the rtentry, so that
rtentry users do not have to grovel in the radix_node for
the key.
Add a RTM_GET method to rtrequest. Use that instead of
radix_node lookups in, e.g., carp(4).
Add sys/net/link_proto.c, which supplies sockaddr routines for
link-layer socket addresses (sockaddr_dl).
Cosmetic:
Constify. KNF. Stop open-coding LIST_FOREACH, TAILQ_FOREACH,
et cetera. Use NULL instead of 0 for null pointers. Use
__arraycount(). Reduce gratuitous parenthesization.
Stop using variadic arguments for rip6_output(), it is
unnecessary.
Remove the unnecessary rtentry member rt_genmask and the
code to maintain it, since nothing actually used it.
Make rt_maskedcopy() easier to read by using meaningful variable
names.
Extract a subroutine intern_netmask() for looking up a netmask in
the masks table.
Start converting backslash-ridden IPv6 macros in
sys/netinet6/in6_var.h into inline subroutines that one
can read without special eyeglasses.
One functional change: when the kernel serves an RTM_GET, RTM_LOCK,
or RTM_CHANGE request, it applies the netmask (if supplied) to a
destination before searching for it in the forwarding table.
I have changed sys/netinet/ip_carp.c, carp_setroute(), to remove
the unlawful radix_node knowledge.
Apart from the changes to carp(4), netiso, ATM, and strip(4), I
have run the changes on three nodes in my wireless routing testbed,
which involves IPv4 + IPv6 dynamic routing acrobatics, and it's
working beautifully so far.
2007-07-20 00:48:52 +04:00
|
|
|
return sysctl_query(SYSCTLFN_CALL(rnode));
|
2003-12-29 01:36:37 +03:00
|
|
|
|
2014-09-05 10:00:05 +04:00
|
|
|
if (newp)
|
Take steps to hide the radix_node implementation of the forwarding table
from the forwarding table's users:
Introduce rt_walktree() for walking the routing table and
applying a function to each rtentry. Replace most
rn_walktree() calls with it.
Use rt_getkey()/rt_setkey() to get/set a route's destination.
Keep a pointer to the sockaddr key in the rtentry, so that
rtentry users do not have to grovel in the radix_node for
the key.
Add a RTM_GET method to rtrequest. Use that instead of
radix_node lookups in, e.g., carp(4).
Add sys/net/link_proto.c, which supplies sockaddr routines for
link-layer socket addresses (sockaddr_dl).
Cosmetic:
Constify. KNF. Stop open-coding LIST_FOREACH, TAILQ_FOREACH,
et cetera. Use NULL instead of 0 for null pointers. Use
__arraycount(). Reduce gratuitous parenthesization.
Stop using variadic arguments for rip6_output(), it is
unnecessary.
Remove the unnecessary rtentry member rt_genmask and the
code to maintain it, since nothing actually used it.
Make rt_maskedcopy() easier to read by using meaningful variable
names.
Extract a subroutine intern_netmask() for looking up a netmask in
the masks table.
Start converting backslash-ridden IPv6 macros in
sys/netinet6/in6_var.h into inline subroutines that one
can read without special eyeglasses.
One functional change: when the kernel serves an RTM_GET, RTM_LOCK,
or RTM_CHANGE request, it applies the netmask (if supplied) to a
destination before searching for it in the forwarding table.
I have changed sys/netinet/ip_carp.c, carp_setroute(), to remove
the unlawful radix_node knowledge.
Apart from the changes to carp(4), netiso, ATM, and strip(4), I
have run the changes on three nodes in my wireless routing testbed,
which involves IPv4 + IPv6 dynamic routing acrobatics, and it's
working beautifully so far.
2007-07-20 00:48:52 +04:00
|
|
|
return EPERM;
|
1994-05-13 10:02:48 +04:00
|
|
|
if (namelen != 3)
|
Take steps to hide the radix_node implementation of the forwarding table
from the forwarding table's users:
Introduce rt_walktree() for walking the routing table and
applying a function to each rtentry. Replace most
rn_walktree() calls with it.
Use rt_getkey()/rt_setkey() to get/set a route's destination.
Keep a pointer to the sockaddr key in the rtentry, so that
rtentry users do not have to grovel in the radix_node for
the key.
Add a RTM_GET method to rtrequest. Use that instead of
radix_node lookups in, e.g., carp(4).
Add sys/net/link_proto.c, which supplies sockaddr routines for
link-layer socket addresses (sockaddr_dl).
Cosmetic:
Constify. KNF. Stop open-coding LIST_FOREACH, TAILQ_FOREACH,
et cetera. Use NULL instead of 0 for null pointers. Use
__arraycount(). Reduce gratuitous parenthesization.
Stop using variadic arguments for rip6_output(), it is
unnecessary.
Remove the unnecessary rtentry member rt_genmask and the
code to maintain it, since nothing actually used it.
Make rt_maskedcopy() easier to read by using meaningful variable
names.
Extract a subroutine intern_netmask() for looking up a netmask in
the masks table.
Start converting backslash-ridden IPv6 macros in
sys/netinet6/in6_var.h into inline subroutines that one
can read without special eyeglasses.
One functional change: when the kernel serves an RTM_GET, RTM_LOCK,
or RTM_CHANGE request, it applies the netmask (if supplied) to a
destination before searching for it in the forwarding table.
I have changed sys/netinet/ip_carp.c, carp_setroute(), to remove
the unlawful radix_node knowledge.
Apart from the changes to carp(4), netiso, ATM, and strip(4), I
have run the changes on three nodes in my wireless routing testbed,
which involves IPv4 + IPv6 dynamic routing acrobatics, and it's
working beautifully so far.
2007-07-20 00:48:52 +04:00
|
|
|
return EINVAL;
|
1994-05-13 10:02:48 +04:00
|
|
|
af = name[0];
|
1999-04-02 21:22:21 +04:00
|
|
|
w.w_tmemneeded = 0;
|
|
|
|
w.w_tmemsize = 0;
|
|
|
|
w.w_tmem = NULL;
|
|
|
|
again:
|
|
|
|
/* we may return here if a later [re]alloc of the t_mem buffer fails */
|
|
|
|
if (w.w_tmemneeded) {
|
2018-11-13 10:45:43 +03:00
|
|
|
w.w_tmem = kmem_zalloc(w.w_tmemneeded, KM_SLEEP);
|
1999-04-02 21:22:21 +04:00
|
|
|
w.w_tmemsize = w.w_tmemneeded;
|
|
|
|
w.w_tmemneeded = 0;
|
|
|
|
}
|
1994-05-13 10:02:48 +04:00
|
|
|
w.w_op = name[1];
|
|
|
|
w.w_arg = name[2];
|
1999-04-02 21:22:21 +04:00
|
|
|
w.w_given = *given;
|
|
|
|
w.w_needed = 0 - w.w_given;
|
|
|
|
w.w_where = where;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2019-05-27 08:33:48 +03:00
|
|
|
KERNEL_LOCK_UNLESS_NET_MPSAFE();
|
1995-08-13 03:59:09 +04:00
|
|
|
s = splsoftnet();
|
1994-05-13 10:02:48 +04:00
|
|
|
switch (w.w_op) {
|
|
|
|
|
|
|
|
case NET_RT_DUMP:
|
|
|
|
case NET_RT_FLAGS:
|
2017-06-23 08:46:10 +03:00
|
|
|
#if defined(INET) || defined(INET6)
|
2016-04-04 10:37:07 +03:00
|
|
|
/*
|
|
|
|
* take care of llinfo entries, the caller must
|
|
|
|
* specify an AF
|
|
|
|
*/
|
|
|
|
if (w.w_op == NET_RT_FLAGS &&
|
|
|
|
(w.w_arg == 0 || w.w_arg & RTF_LLDATA)) {
|
|
|
|
if (af != 0)
|
2017-06-23 08:46:10 +03:00
|
|
|
error = lltable_sysctl_dump(af, &w);
|
2016-04-04 10:37:07 +03:00
|
|
|
else
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2017-06-23 08:46:10 +03:00
|
|
|
#endif
|
2016-04-04 10:37:07 +03:00
|
|
|
|
2017-06-28 07:14:53 +03:00
|
|
|
for (i = 1; i <= AF_MAX; i++) {
|
|
|
|
if (af == 0 || af == i) {
|
|
|
|
error = rt_walktree(i, sysctl_dumpentry, &w);
|
|
|
|
if (error != 0)
|
|
|
|
break;
|
|
|
|
#if defined(INET) || defined(INET6)
|
|
|
|
/*
|
|
|
|
* Return ARP/NDP entries too for
|
|
|
|
* backward compatibility.
|
|
|
|
*/
|
|
|
|
error = lltable_sysctl_dump(i, &w);
|
|
|
|
if (error != 0)
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
1994-05-13 10:02:48 +04:00
|
|
|
break;
|
|
|
|
|
2019-01-27 05:08:33 +03:00
|
|
|
case NET_RT_OOOIFLIST: /* compat_14 */
|
|
|
|
case NET_RT_OOIFLIST: /* compat_50 */
|
|
|
|
case NET_RT_OIFLIST: /* compat_70 */
|
|
|
|
case NET_RT_IFLIST: /* current */
|
1999-11-19 13:41:41 +03:00
|
|
|
error = sysctl_iflist(af, &w, w.w_op);
|
2011-02-01 04:39:19 +03:00
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-05-13 10:02:48 +04:00
|
|
|
splx(s);
|
2019-05-27 08:33:48 +03:00
|
|
|
KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
|
1999-04-02 21:22:21 +04:00
|
|
|
|
|
|
|
/* check to see if we couldn't allocate memory with NOWAIT */
|
|
|
|
if (error == ENOBUFS && w.w_tmem == 0 && w.w_tmemneeded)
|
|
|
|
goto again;
|
|
|
|
|
1994-05-13 10:02:48 +04:00
|
|
|
if (w.w_tmem)
|
2017-02-21 07:00:01 +03:00
|
|
|
kmem_free(w.w_tmem, w.w_tmemsize);
|
1993-03-21 12:45:37 +03:00
|
|
|
w.w_needed += w.w_given;
|
1994-05-13 10:02:48 +04:00
|
|
|
if (where) {
|
2007-03-04 08:59:00 +03:00
|
|
|
*given = (char *)w.w_where - (char *)where;
|
1994-05-13 10:02:48 +04:00
|
|
|
if (*given < w.w_needed)
|
Take steps to hide the radix_node implementation of the forwarding table
from the forwarding table's users:
Introduce rt_walktree() for walking the routing table and
applying a function to each rtentry. Replace most
rn_walktree() calls with it.
Use rt_getkey()/rt_setkey() to get/set a route's destination.
Keep a pointer to the sockaddr key in the rtentry, so that
rtentry users do not have to grovel in the radix_node for
the key.
Add a RTM_GET method to rtrequest. Use that instead of
radix_node lookups in, e.g., carp(4).
Add sys/net/link_proto.c, which supplies sockaddr routines for
link-layer socket addresses (sockaddr_dl).
Cosmetic:
Constify. KNF. Stop open-coding LIST_FOREACH, TAILQ_FOREACH,
et cetera. Use NULL instead of 0 for null pointers. Use
__arraycount(). Reduce gratuitous parenthesization.
Stop using variadic arguments for rip6_output(), it is
unnecessary.
Remove the unnecessary rtentry member rt_genmask and the
code to maintain it, since nothing actually used it.
Make rt_maskedcopy() easier to read by using meaningful variable
names.
Extract a subroutine intern_netmask() for looking up a netmask in
the masks table.
Start converting backslash-ridden IPv6 macros in
sys/netinet6/in6_var.h into inline subroutines that one
can read without special eyeglasses.
One functional change: when the kernel serves an RTM_GET, RTM_LOCK,
or RTM_CHANGE request, it applies the netmask (if supplied) to a
destination before searching for it in the forwarding table.
I have changed sys/netinet/ip_carp.c, carp_setroute(), to remove
the unlawful radix_node knowledge.
Apart from the changes to carp(4), netiso, ATM, and strip(4), I
have run the changes on three nodes in my wireless routing testbed,
which involves IPv4 + IPv6 dynamic routing acrobatics, and it's
working beautifully so far.
2007-07-20 00:48:52 +04:00
|
|
|
return ENOMEM;
|
1994-05-13 10:02:48 +04:00
|
|
|
} else {
|
|
|
|
*given = (11 * w.w_needed) / 10;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
Take steps to hide the radix_node implementation of the forwarding table
from the forwarding table's users:
Introduce rt_walktree() for walking the routing table and
applying a function to each rtentry. Replace most
rn_walktree() calls with it.
Use rt_getkey()/rt_setkey() to get/set a route's destination.
Keep a pointer to the sockaddr key in the rtentry, so that
rtentry users do not have to grovel in the radix_node for
the key.
Add a RTM_GET method to rtrequest. Use that instead of
radix_node lookups in, e.g., carp(4).
Add sys/net/link_proto.c, which supplies sockaddr routines for
link-layer socket addresses (sockaddr_dl).
Cosmetic:
Constify. KNF. Stop open-coding LIST_FOREACH, TAILQ_FOREACH,
et cetera. Use NULL instead of 0 for null pointers. Use
__arraycount(). Reduce gratuitous parenthesization.
Stop using variadic arguments for rip6_output(), it is
unnecessary.
Remove the unnecessary rtentry member rt_genmask and the
code to maintain it, since nothing actually used it.
Make rt_maskedcopy() easier to read by using meaningful variable
names.
Extract a subroutine intern_netmask() for looking up a netmask in
the masks table.
Start converting backslash-ridden IPv6 macros in
sys/netinet6/in6_var.h into inline subroutines that one
can read without special eyeglasses.
One functional change: when the kernel serves an RTM_GET, RTM_LOCK,
or RTM_CHANGE request, it applies the netmask (if supplied) to a
destination before searching for it in the forwarding table.
I have changed sys/netinet/ip_carp.c, carp_setroute(), to remove
the unlawful radix_node knowledge.
Apart from the changes to carp(4), netiso, ATM, and strip(4), I
have run the changes on three nodes in my wireless routing testbed,
which involves IPv4 + IPv6 dynamic routing acrobatics, and it's
working beautifully so far.
2007-07-20 00:48:52 +04:00
|
|
|
return error;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2019-04-29 08:42:09 +03:00
|
|
|
void
|
|
|
|
sysctl_net_route_setup(struct sysctllog **clog, int pf, const char *name)
|
Dynamic sysctl.
Gone are the old kern_sysctl(), cpu_sysctl(), hw_sysctl(),
vfs_sysctl(), etc, routines, along with sysctl_int() et al. Now all
nodes are registered with the tree, and nodes can be added (or
removed) easily, and I/O to and from the tree is handled generically.
Since the nodes are registered with the tree, the mapping from name to
number (and back again) can now be discovered, instead of having to be
hard coded. Adding new nodes to the tree is likewise much simpler --
the new infrastructure handles almost all the work for simple types,
and just about anything else can be done with a small helper function.
All existing nodes are where they were before (numerically speaking),
so all existing consumers of sysctl information should notice no
difference.
PS - I'm sorry, but there's a distinct lack of documentation at the
moment. I'm working on sysctl(3/8/9) right now, and I promise to
watch out for buses.
2003-12-04 22:38:21 +03:00
|
|
|
{
|
2006-05-28 03:08:11 +04:00
|
|
|
const struct sysctlnode *rnode = NULL;
|
|
|
|
|
|
|
|
sysctl_createv(clog, 0, NULL, &rnode,
|
2004-03-24 18:34:46 +03:00
|
|
|
CTLFLAG_PERMANENT,
|
2019-04-29 08:42:09 +03:00
|
|
|
CTLTYPE_NODE, name,
|
2004-05-25 08:33:59 +04:00
|
|
|
SYSCTL_DESCR("PF_ROUTE information"),
|
Dynamic sysctl.
Gone are the old kern_sysctl(), cpu_sysctl(), hw_sysctl(),
vfs_sysctl(), etc, routines, along with sysctl_int() et al. Now all
nodes are registered with the tree, and nodes can be added (or
removed) easily, and I/O to and from the tree is handled generically.
Since the nodes are registered with the tree, the mapping from name to
number (and back again) can now be discovered, instead of having to be
hard coded. Adding new nodes to the tree is likewise much simpler --
the new infrastructure handles almost all the work for simple types,
and just about anything else can be done with a small helper function.
All existing nodes are where they were before (numerically speaking),
so all existing consumers of sysctl information should notice no
difference.
PS - I'm sorry, but there's a distinct lack of documentation at the
moment. I'm working on sysctl(3/8/9) right now, and I promise to
watch out for buses.
2003-12-04 22:38:21 +03:00
|
|
|
NULL, 0, NULL, 0,
|
2019-04-29 08:42:09 +03:00
|
|
|
CTL_NET, pf, CTL_EOL);
|
2011-02-01 04:39:19 +03:00
|
|
|
|
2004-03-24 18:34:46 +03:00
|
|
|
sysctl_createv(clog, 0, NULL, NULL,
|
|
|
|
CTLFLAG_PERMANENT,
|
2004-05-25 08:33:59 +04:00
|
|
|
CTLTYPE_NODE, "rtable",
|
|
|
|
SYSCTL_DESCR("Routing table information"),
|
Dynamic sysctl.
Gone are the old kern_sysctl(), cpu_sysctl(), hw_sysctl(),
vfs_sysctl(), etc, routines, along with sysctl_int() et al. Now all
nodes are registered with the tree, and nodes can be added (or
removed) easily, and I/O to and from the tree is handled generically.
Since the nodes are registered with the tree, the mapping from name to
number (and back again) can now be discovered, instead of having to be
hard coded. Adding new nodes to the tree is likewise much simpler --
the new infrastructure handles almost all the work for simple types,
and just about anything else can be done with a small helper function.
All existing nodes are where they were before (numerically speaking),
so all existing consumers of sysctl information should notice no
difference.
PS - I'm sorry, but there's a distinct lack of documentation at the
moment. I'm working on sysctl(3/8/9) right now, and I promise to
watch out for buses.
2003-12-04 22:38:21 +03:00
|
|
|
sysctl_rtable, 0, NULL, 0,
|
2019-04-29 08:42:09 +03:00
|
|
|
CTL_NET, pf, 0 /* any protocol */, CTL_EOL);
|
2011-02-01 04:39:19 +03:00
|
|
|
|
2006-05-28 03:08:11 +04:00
|
|
|
sysctl_createv(clog, 0, &rnode, NULL,
|
|
|
|
CTLFLAG_PERMANENT,
|
|
|
|
CTLTYPE_STRUCT, "stats",
|
|
|
|
SYSCTL_DESCR("Routing statistics"),
|
|
|
|
NULL, 0, &rtstat, sizeof(rtstat),
|
|
|
|
CTL_CREATE, CTL_EOL);
|
Dynamic sysctl.
Gone are the old kern_sysctl(), cpu_sysctl(), hw_sysctl(),
vfs_sysctl(), etc, routines, along with sysctl_int() et al. Now all
nodes are registered with the tree, and nodes can be added (or
removed) easily, and I/O to and from the tree is handled generically.
Since the nodes are registered with the tree, the mapping from name to
number (and back again) can now be discovered, instead of having to be
hard coded. Adding new nodes to the tree is likewise much simpler --
the new infrastructure handles almost all the work for simple types,
and just about anything else can be done with a small helper function.
All existing nodes are where they were before (numerically speaking),
so all existing consumers of sysctl information should notice no
difference.
PS - I'm sorry, but there's a distinct lack of documentation at the
moment. I'm working on sysctl(3/8/9) right now, and I promise to
watch out for buses.
2003-12-04 22:38:21 +03:00
|
|
|
}
|