netlink: add NETLINK/NETLINK_SUPPORT userland options.

Make userland tools such as netstat, route, arp and ndp use
 either netlink or rtsock interfaces based on the NETLINK_SUPPORT
 options.
Both NETLINK and NETLINK_SUPPORT options are turned on by default.

Reviewed By: eugen
Differential Revision: https://reviews.freebsd.org/D39148
This commit is contained in:
Alexander V. Chernikov 2023-03-26 08:56:49 +00:00
parent 04f75b9802
commit 64dfea8651
4 changed files with 24 additions and 3 deletions

View File

@ -145,6 +145,7 @@ __DEFAULT_YES_OPTIONS = \
MLX5TOOL \
NETCAT \
NETGRAPH \
NETLINK \
NLS_CATALOGS \
NS_CACHING \
NTP \
@ -233,6 +234,7 @@ __DEFAULT_DEPENDENT_OPTIONS= \
KERBEROS \
KVM \
NETGRAPH \
NETLINK \
PAM \
TESTS \
WIRELESS

View File

@ -0,0 +1,5 @@
.\" $FreeBSD$
Make libraries and programs use rtsock and
.Xr sysctl 3
interfaces instead of
.Xr snl 3 .

View File

@ -6,7 +6,6 @@
PROG= netstat
SRCS= if.c inet.c main.c mbuf.c mroute.c netisr.c nl_symbols.c route.c \
unix.c mroute6.c ipsec.c bpf.c pfkey.c sctp.c common.c nhops.c nhgrp.c \
route_netlink.c \
nl_defs.h
nl_symbols.c: nlist_symbols
@ -64,4 +63,10 @@ LIBADD+= netgraph
CFLAGS+=-DNETGRAPH
.endif
.if ${MK_NETLINK_SUPPORT} != "no"
SRCS+= route_netlink.c
.else
CFLAGS+=-DWITHOUT_NETLINK
.endif
.include <bsd.prog.mk>

View File

@ -96,16 +96,20 @@ struct bits rt_bits[] = {
{ 0 , 0, NULL }
};
#ifdef WITHOUT_NETLINK
static struct ifmap_entry *ifmap;
static size_t ifmap_size;
#endif
static struct timespec uptime;
static const char *netname4(in_addr_t, in_addr_t);
#ifdef INET6
static const char *netname6(struct sockaddr_in6 *, struct sockaddr_in6 *);
#endif
#ifdef WITHOUT_NETLINK
static void p_rtable_sysctl(int, int);
static void p_rtentry_sysctl(const char *name, struct rt_msghdr *);
#endif
static void domask(char *, size_t, u_long);
const uint32_t rt_default_weight = RT_DEFAULT_WEIGHT;
@ -143,8 +147,11 @@ routepr(int fibnum, int af)
if (fibnum)
xo_emit(" ({L:fib}: {:fib/%d})", fibnum);
xo_emit("\n");
if (!p_rtable_netlink(fibnum, af))
p_rtable_sysctl(fibnum, af);
#ifdef WITHOUT_NETLINK
p_rtable_sysctl(fibnum, af);
#else
p_rtable_netlink(fibnum, af);
#endif
xo_close_container("route-information");
}
@ -240,6 +247,7 @@ set_wid(int fam)
wid.expire = 6;
}
#ifdef WITHOUT_NETLINK
static void
p_rtable_sysctl(int fibnum, int af)
{
@ -365,6 +373,7 @@ p_rtentry_sysctl(const char *name, struct rt_msghdr *rtm)
xo_emit("\n");
xo_close_instance(name);
}
#endif
int
p_sockaddr(const char *name, struct sockaddr *sa, struct sockaddr *mask,