git: 64dfea86515e - main - netlink: add NETLINK/NETLINK_SUPPORT userland options.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 26 Mar 2023 09:00:20 UTC
The branch main has been updated by melifaro:
URL: https://cgit.FreeBSD.org/src/commit/?id=64dfea86515e71af254cf90d6d5ceb689b8fbf5a
commit 64dfea86515e71af254cf90d6d5ceb689b8fbf5a
Author: Alexander V. Chernikov <melifaro@FreeBSD.org>
AuthorDate: 2023-03-26 08:56:49 +0000
Commit: Alexander V. Chernikov <melifaro@FreeBSD.org>
CommitDate: 2023-03-26 08:59:58 +0000
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
---
share/mk/src.opts.mk | 2 ++
tools/build/options/WITHOUT_NETLINK_SUPPORT | 5 +++++
usr.bin/netstat/Makefile | 7 ++++++-
usr.bin/netstat/route.c | 13 +++++++++++--
4 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/share/mk/src.opts.mk b/share/mk/src.opts.mk
index 880f1139843c..7c73e66aba18 100644
--- a/share/mk/src.opts.mk
+++ b/share/mk/src.opts.mk
@@ -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
diff --git a/tools/build/options/WITHOUT_NETLINK_SUPPORT b/tools/build/options/WITHOUT_NETLINK_SUPPORT
new file mode 100644
index 000000000000..4a72d3f1e4d1
--- /dev/null
+++ b/tools/build/options/WITHOUT_NETLINK_SUPPORT
@@ -0,0 +1,5 @@
+.\" $FreeBSD$
+Make libraries and programs use rtsock and
+.Xr sysctl 3
+interfaces instead of
+.Xr snl 3 .
diff --git a/usr.bin/netstat/Makefile b/usr.bin/netstat/Makefile
index e2c9ca09eea5..92f8aa9c30fa 100644
--- a/usr.bin/netstat/Makefile
+++ b/usr.bin/netstat/Makefile
@@ -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>
diff --git a/usr.bin/netstat/route.c b/usr.bin/netstat/route.c
index 5de683ebfe7a..c597f3632fa6 100644
--- a/usr.bin/netstat/route.c
+++ b/usr.bin/netstat/route.c
@@ -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,