summaryrefslogtreecommitdiffstats
path: root/usr.bin/netstat/mroute.c
diff options
context:
space:
mode:
authorglebius <glebius@FreeBSD.org>2014-03-19 09:36:29 +0000
committerglebius <glebius@FreeBSD.org>2014-03-19 09:36:29 +0000
commit78bde6490528c198cd485385ecb997b6031f1bdb (patch)
tree6a605ad66fc5de0ab09fc2d971e094c397efb352 /usr.bin/netstat/mroute.c
parent73a339242daca126752a08f5390d85b17a8f0436 (diff)
downloadFreeBSD-src-78bde6490528c198cd485385ecb997b6031f1bdb.zip
FreeBSD-src-78bde6490528c198cd485385ecb997b6031f1bdb.tar.gz
Merge r259562,r259566,r259638,r259645,r260124 by melifaro:
Switch netstat -rn to use standard API for retrieving list of routes instead of peeking inside in-kernel radix via kget.
Diffstat (limited to 'usr.bin/netstat/mroute.c')
-rw-r--r--usr.bin/netstat/mroute.c43
1 files changed, 39 insertions, 4 deletions
diff --git a/usr.bin/netstat/mroute.c b/usr.bin/netstat/mroute.c
index 7cade4e..3766415 100644
--- a/usr.bin/netstat/mroute.c
+++ b/usr.bin/netstat/mroute.c
@@ -65,11 +65,26 @@ __FBSDID("$FreeBSD$");
#undef _KERNEL
#include <err.h>
+#include <nlist.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "netstat.h"
+/*
+ * kvm(3) bindings for every needed symbol
+ */
+static struct nlist mrl[] = {
+#define N_MRTSTAT 0
+ { .n_name = "_mrtstat" },
+#define N_MFCHASHTBL 1
+ { .n_name = "_mfchashtbl" },
+#define N_VIFTABLE 2
+ { .n_name = "_viftable" },
+#define N_MFCTABLESIZE 3
+ { .n_name = "_mfctablesize" },
+ { .n_name = NULL },
+};
static void print_bw_meter(struct bw_meter *, int *);
static void print_mfc(struct mfc *, int, int *);
@@ -193,11 +208,12 @@ print_mfc(struct mfc *m, int maxvif, int *banner_printed)
}
void
-mroutepr(u_long pmfchashtbl, u_long pmfctablesize, u_long pviftbl)
+mroutepr()
{
struct vif viftable[MAXVIFS];
struct vif *v;
struct mfc *m;
+ u_long pmfchashtbl, pmfctablesize, pviftbl;
int banner_printed;
int saved_numeric_addr;
size_t len;
@@ -221,6 +237,16 @@ mroutepr(u_long pmfchashtbl, u_long pmfctablesize, u_long pviftbl)
*/
maxvif = 0;
+ kresolve_list(mrl);
+ pmfchashtbl = mrl[N_MFCHASHTBL].n_value;
+ pmfctablesize = mrl[N_MFCTABLESIZE].n_value;
+ pviftbl = mrl[N_VIFTABLE].n_value;
+
+ if (pmfchashtbl == 0 || pmfctablesize == 0 || pviftbl == 0) {
+ fprintf(stderr, "No IPv4 MROUTING kernel support.\n");
+ return;
+ }
+
len = sizeof(viftable);
if (live) {
if (sysctlbyname("net.inet.ip.viftable", viftable, &len, NULL,
@@ -338,15 +364,24 @@ mroutepr(u_long pmfchashtbl, u_long pmfctablesize, u_long pviftbl)
}
void
-mrt_stats(u_long mstaddr)
+mrt_stats()
{
struct mrtstat mrtstat;
- size_t len = sizeof mrtstat;
+ u_long mstaddr;
+ size_t len = sizeof(mrtstat);
+
+ kresolve_list(mrl);
+ mstaddr = mrl[N_MRTSTAT].n_value;
+
+ if (mstaddr == 0) {
+ fprintf(stderr, "No IPv4 MROUTING kernel support.\n");
+ return;
+ }
if (live) {
if (sysctlbyname("net.inet.ip.mrtstat", &mrtstat, &len, NULL,
0) < 0) {
- warn("sysctl: net.inet.ip.mrtstat");
+ warn("sysctl: net.inet.ip.mrtstat failed.");
return;
}
} else
OpenPOWER on IntegriCloud