Changeset View
Changeset View
Standalone View
Standalone View
usr.bin/netstat/route.c
Show First 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | struct bits rt_bits[] = { | ||||
{ RTF_BLACKHOLE,'B', "blackhole" }, | { RTF_BLACKHOLE,'B', "blackhole" }, | ||||
{ RTF_BROADCAST,'b', "broadcast" }, | { RTF_BROADCAST,'b', "broadcast" }, | ||||
#ifdef RTF_LLINFO | #ifdef RTF_LLINFO | ||||
{ RTF_LLINFO, 'L', "llinfo" }, | { RTF_LLINFO, 'L', "llinfo" }, | ||||
#endif | #endif | ||||
{ 0 , 0, NULL } | { 0 , 0, NULL } | ||||
}; | }; | ||||
#ifdef WITHOUT_NETLINK | |||||
static struct ifmap_entry *ifmap; | static struct ifmap_entry *ifmap; | ||||
static size_t ifmap_size; | static size_t ifmap_size; | ||||
#endif | |||||
static struct timespec uptime; | static struct timespec uptime; | ||||
static const char *netname4(in_addr_t, in_addr_t); | static const char *netname4(in_addr_t, in_addr_t); | ||||
#ifdef INET6 | #ifdef INET6 | ||||
static const char *netname6(struct sockaddr_in6 *, struct sockaddr_in6 *); | static const char *netname6(struct sockaddr_in6 *, struct sockaddr_in6 *); | ||||
#endif | #endif | ||||
#ifdef WITHOUT_NETLINK | |||||
static void p_rtable_sysctl(int, int); | static void p_rtable_sysctl(int, int); | ||||
static void p_rtentry_sysctl(const char *name, struct rt_msghdr *); | static void p_rtentry_sysctl(const char *name, struct rt_msghdr *); | ||||
#endif | |||||
static void domask(char *, size_t, u_long); | static void domask(char *, size_t, u_long); | ||||
const uint32_t rt_default_weight = RT_DEFAULT_WEIGHT; | const uint32_t rt_default_weight = RT_DEFAULT_WEIGHT; | ||||
/* | /* | ||||
* Print routing tables. | * Print routing tables. | ||||
*/ | */ | ||||
void | void | ||||
Show All 21 Lines | routepr(int fibnum, int af) | ||||
if (clock_gettime(CLOCK_UPTIME, &uptime) < 0) | if (clock_gettime(CLOCK_UPTIME, &uptime) < 0) | ||||
err(EX_OSERR, "clock_gettime() failed"); | err(EX_OSERR, "clock_gettime() failed"); | ||||
xo_open_container("route-information"); | xo_open_container("route-information"); | ||||
xo_emit("{T:Routing tables}"); | xo_emit("{T:Routing tables}"); | ||||
if (fibnum) | if (fibnum) | ||||
xo_emit(" ({L:fib}: {:fib/%d})", fibnum); | xo_emit(" ({L:fib}: {:fib/%d})", fibnum); | ||||
xo_emit("\n"); | xo_emit("\n"); | ||||
if (!p_rtable_netlink(fibnum, af)) | #ifdef WITHOUT_NETLINK | ||||
p_rtable_sysctl(fibnum, af); | p_rtable_sysctl(fibnum, af); | ||||
#else | |||||
p_rtable_netlink(fibnum, af); | |||||
#endif | |||||
xo_close_container("route-information"); | xo_close_container("route-information"); | ||||
} | } | ||||
/* | /* | ||||
* Print address family header before a section of the routing table. | * Print address family header before a section of the routing table. | ||||
*/ | */ | ||||
void | void | ||||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | set_wid(int fam) | ||||
wid.gw = WID_GW_DEFAULT(fam); | wid.gw = WID_GW_DEFAULT(fam); | ||||
wid.flags = 6; | wid.flags = 6; | ||||
wid.pksent = 8; | wid.pksent = 8; | ||||
wid.mtu = 6; | wid.mtu = 6; | ||||
wid.iface = WID_IF_DEFAULT(fam); | wid.iface = WID_IF_DEFAULT(fam); | ||||
wid.expire = 6; | wid.expire = 6; | ||||
} | } | ||||
#ifdef WITHOUT_NETLINK | |||||
static void | static void | ||||
p_rtable_sysctl(int fibnum, int af) | p_rtable_sysctl(int fibnum, int af) | ||||
{ | { | ||||
size_t needed; | size_t needed; | ||||
int mib[7]; | int mib[7]; | ||||
char *buf, *next, *lim; | char *buf, *next, *lim; | ||||
struct rt_msghdr *rtm; | struct rt_msghdr *rtm; | ||||
struct sockaddr *sa; | struct sockaddr *sa; | ||||
▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | if (rtm->rtm_rmx.rmx_expire) { | ||||
if ((expire_time = rtm->rtm_rmx.rmx_expire - uptime.tv_sec) > 0) | if ((expire_time = rtm->rtm_rmx.rmx_expire - uptime.tv_sec) > 0) | ||||
xo_emit(" {:expire-time/%*d}", wid.expire, | xo_emit(" {:expire-time/%*d}", wid.expire, | ||||
(int)expire_time); | (int)expire_time); | ||||
} | } | ||||
xo_emit("\n"); | xo_emit("\n"); | ||||
xo_close_instance(name); | xo_close_instance(name); | ||||
} | } | ||||
#endif | |||||
int | int | ||||
p_sockaddr(const char *name, struct sockaddr *sa, struct sockaddr *mask, | p_sockaddr(const char *name, struct sockaddr *sa, struct sockaddr *mask, | ||||
int flags, int width) | int flags, int width) | ||||
{ | { | ||||
const char *cp; | const char *cp; | ||||
char buf[128]; | char buf[128]; | ||||
int protrusion; | int protrusion; | ||||
▲ Show 20 Lines • Show All 352 Lines • Show Last 20 Lines |