Index: sys/net/route.h =================================================================== --- sys/net/route.h +++ sys/net/route.h @@ -238,12 +238,27 @@ * Routing statistics. */ struct rtstat { - short rts_badredirect; /* bogus redirect calls */ - short rts_dynamic; /* routes created by redirects */ - short rts_newgateway; /* routes modified by redirects */ - short rts_unreach; /* lookups which failed */ - short rts_wildcard; /* lookups satisfied by a wildcard */ + uint64_t rts_badredirect; /* bogus redirect calls */ + uint64_t rts_dynamic; /* routes created by redirects */ + uint64_t rts_newgateway; /* routes modified by redirects */ + uint64_t rts_unreach; /* lookups which failed */ + uint64_t rts_wildcard; /* lookups satisfied by a wildcard */ }; + +#ifdef _KERNEL + +VNET_PCPUSTAT_DECLARE(struct rtstat, rtstat); + /* + * In-kernel consumers can use these accessor macros directly to update + * stats. + */ +#define RTSTAT_ADD(name, val) \ + VNET_PCPUSTAT_ADD(struct rtstat, rtstat, name, (val)) +#define RTSTAT_SUB(name, val) RTSTAT_ADD(name, -(val)) +#define RTSTAT_INC(name) RTSTAT_ADD(name, 1) +#define RTSTAT_DEC(name) RTSTAT_SUB(name, 1) +#endif /* _KERNEL */ + /* * Structures for routing messages. */ Index: sys/net/route.c =================================================================== --- sys/net/route.c +++ sys/net/route.c @@ -108,9 +108,13 @@ SYSCTL_UINT(_net, OID_AUTO, add_addr_allfibs, CTLFLAG_RWTUN | CTLFLAG_VNET, &VNET_NAME(rt_add_addr_allfibs), 0, ""); -VNET_DEFINE(struct rtstat, rtstat); -#define V_rtstat VNET(rtstat) +VNET_PCPUSTAT_DEFINE(struct rtstat, rtstat); +VNET_PCPUSTAT_SYSINIT(rtstat); +#ifdef VIMAGE +VNET_PCPUSTAT_SYSUNINIT(rtstat); +#endif /* VIMAGE */ + VNET_DEFINE(struct rib_head *, rt_tables); #define V_rt_tables VNET(rt_tables) @@ -476,7 +480,7 @@ * which basically means: "cannot get there from here". */ miss: - V_rtstat.rts_unreach++; + RTSTAT_INC(rts_unreach); if (report) { /* @@ -587,7 +591,6 @@ { struct rtentry *rt; int error = 0; - short *stat = NULL; struct rt_addrinfo info; struct ifaddr *ifa; struct rib_head *rnh; @@ -662,7 +665,7 @@ flags = rt->rt_flags; } - stat = &V_rtstat.rts_dynamic; + RTSTAT_INC(rts_dynamic); } else { /* @@ -673,7 +676,7 @@ rt->rt_flags &= ~RTF_GATEWAY; rt->rt_flags |= RTF_MODIFIED; flags |= RTF_MODIFIED; - stat = &V_rtstat.rts_newgateway; + RTSTAT_INC(rts_newgateway); /* * add the key and gateway (in one malloc'd chunk). */ @@ -690,9 +693,7 @@ RTFREE_LOCKED(rt); out: if (error) - V_rtstat.rts_badredirect++; - else if (stat != NULL) - (*stat)++; + RTSTAT_INC(rts_badredirect); bzero((caddr_t)&info, sizeof(info)); info.rti_info[RTAX_DST] = dst; info.rti_info[RTAX_GATEWAY] = gateway; Index: usr.bin/netstat/route.c =================================================================== --- usr.bin/netstat/route.c +++ usr.bin/netstat/route.c @@ -776,22 +776,22 @@ xo_emit("{W:rttrash: symbol not in namelist}\n"); return; } - kread(rtsaddr, (char *)&rtstat, sizeof (rtstat)); + kread_counters(rtsaddr, (char *)&rtstat, sizeof (rtstat)); kread(rttaddr, (char *)&rttrash, sizeof (rttrash)); xo_emit("{T:routing}:\n"); #define p(f, m) if (rtstat.f || sflag <= 1) \ xo_emit(m, rtstat.f, plural(rtstat.f)) - p(rts_badredirect, "\t{:bad-redirects/%hu} " + p(rts_badredirect, "\t{:bad-redirects/%ju} " "{N:/bad routing redirect%s}\n"); - p(rts_dynamic, "\t{:dynamically-created/%hu} " + p(rts_dynamic, "\t{:dynamically-created/%ju} " "{N:/dynamically created route%s}\n"); - p(rts_newgateway, "\t{:new-gateways/%hu} " + p(rts_newgateway, "\t{:new-gateways/%ju} " "{N:/new gateway%s due to redirects}\n"); - p(rts_unreach, "\t{:unreachable-destination/%hu} " + p(rts_unreach, "\t{:unreachable-destination/%ju} " "{N:/destination%s found unreachable}\n"); - p(rts_wildcard, "\t{:wildcard-uses/%hu} " + p(rts_wildcard, "\t{:wildcard-uses/%ju} " "{N:/use%s of a wildcard route}\n"); #undef p