Changeset View
Changeset View
Standalone View
Standalone View
usr.bin/netstat/nhgrp.c
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
#include <arpa/inet.h> | #include <arpa/inet.h> | ||||
#include <libutil.h> | #include <libutil.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <stdbool.h> | #include <stdbool.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <sysexits.h> | #include <sysexits.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <err.h> | |||||
#include <libxo/xo.h> | #include <libxo/xo.h> | ||||
#include "netstat.h" | #include "netstat.h" | ||||
#include "common.h" | #include "common.h" | ||||
#define WID_GW_DEFAULT(af) (((af) == AF_INET6) ? 40 : 18) | #define WID_GW_DEFAULT(af) (((af) == AF_INET6) ? 40 : 18) | ||||
static int wid_gw; | static int wid_gw; | ||||
static int wid_if = 10; | static int wid_if = 10; | ||||
▲ Show 20 Lines • Show All 147 Lines • ▼ Show 20 Lines | dump_nhgrp_sysctl(int fibnum, int af, struct nhops_dump *nd) | ||||
mib[0] = CTL_NET; | mib[0] = CTL_NET; | ||||
mib[1] = PF_ROUTE; | mib[1] = PF_ROUTE; | ||||
mib[2] = 0; | mib[2] = 0; | ||||
mib[3] = af; | mib[3] = af; | ||||
mib[4] = NET_RT_NHGRP; | mib[4] = NET_RT_NHGRP; | ||||
mib[5] = 0; | mib[5] = 0; | ||||
mib[6] = fibnum; | mib[6] = fibnum; | ||||
if (sysctl(mib, nitems(mib), NULL, &needed, NULL, 0) < 0) | if (sysctl(mib, nitems(mib), NULL, &needed, NULL, 0) < 0) | ||||
err(EX_OSERR, "sysctl: net.route.0.%d.nhgrpdump.%d estimate", | xo_err(EX_OSERR, "sysctl: net.route.0.%d.nhgrpdump.%d estimate", | ||||
af, fibnum); | af, fibnum); | ||||
if ((buf = malloc(needed)) == NULL) | if ((buf = malloc(needed)) == NULL) | ||||
errx(2, "malloc(%lu)", (unsigned long)needed); | xo_errx(EX_OSERR, "malloc(%lu)", (unsigned long)needed); | ||||
des: `EX_OSERR` | |||||
if (sysctl(mib, nitems(mib), buf, &needed, NULL, 0) < 0) | if (sysctl(mib, nitems(mib), buf, &needed, NULL, 0) < 0) | ||||
err(1, "sysctl: net.route.0.%d.nhgrpdump.%d", af, fibnum); | xo_err(EX_OSERR, "sysctl: net.route.0.%d.nhgrpdump.%d", af, fibnum); | ||||
Not Done Inline ActionsEX_OSERR des: `EX_OSERR` | |||||
lim = buf + needed; | lim = buf + needed; | ||||
/* | /* | ||||
* nexhops groups are received unsorted. Collect everything first, | * nexhops groups are received unsorted. Collect everything first, | ||||
* and sort prior displaying. | * and sort prior displaying. | ||||
*/ | */ | ||||
nhg_count = 0; | nhg_count = 0; | ||||
nhg_size = 16; | nhg_size = 16; | ||||
▲ Show 20 Lines • Show All 106 Lines • ▼ Show 20 Lines | nhgrp_print(int fibnum, int af) | ||||
intsize = sizeof(int); | intsize = sizeof(int); | ||||
if (fibnum == -1 && | if (fibnum == -1 && | ||||
sysctlbyname("net.my_fibnum", &fibnum, &intsize, NULL, 0) == -1) | sysctlbyname("net.my_fibnum", &fibnum, &intsize, NULL, 0) == -1) | ||||
fibnum = 0; | fibnum = 0; | ||||
if (sysctlbyname("net.fibs", &numfibs, &intsize, NULL, 0) == -1) | if (sysctlbyname("net.fibs", &numfibs, &intsize, NULL, 0) == -1) | ||||
numfibs = 1; | numfibs = 1; | ||||
if (fibnum < 0 || fibnum > numfibs - 1) | if (fibnum < 0 || fibnum > numfibs - 1) | ||||
errx(EX_USAGE, "%d: invalid fib", fibnum); | xo_errx(EX_USAGE, "%d: invalid fib", fibnum); | ||||
ifmap = prepare_ifmap(&ifmap_size); | ifmap = prepare_ifmap(&ifmap_size); | ||||
prepare_nh_map(fibnum, af); | prepare_nh_map(fibnum, af); | ||||
xo_open_container("route-nhgrp-information"); | xo_open_container("route-nhgrp-information"); | ||||
xo_emit("{T:Nexthop groups data}"); | xo_emit("{T:Nexthop groups data}"); | ||||
if (fibnum) | if (fibnum) | ||||
xo_emit(" ({L:fib}: {:fib/%d})", fibnum); | xo_emit(" ({L:fib}: {:fib/%d})", fibnum); | ||||
xo_emit("\n"); | xo_emit("\n"); | ||||
print_nhgrp_sysctl(fibnum, af); | print_nhgrp_sysctl(fibnum, af); | ||||
xo_close_container("route-nhgrp-information"); | xo_close_container("route-nhgrp-information"); | ||||
} | } | ||||
EX_OSERR