From: Alexander Bluhm Subject: route cache counter To: tech@openbsd.org Date: Mon, 5 Feb 2024 20:33:40 +0100 Hi, I would like to improve route caching. For that netstat counter are useful. IPv6 cache is still missing, but add counters for both. ip6s_forward_cache is obsolete and can be reused for route cache. Reorder ip6s_wrongif to keep consistent output. ok? bluhm Index: sys/net/route.c =================================================================== RCS file: /data/mirror/openbsd/cvs/src/sys/net/route.c,v diff -u -p -r1.427 route.c --- sys/net/route.c 31 Jan 2024 14:56:42 -0000 1.427 +++ sys/net/route.c 5 Feb 2024 16:09:20 -0000 @@ -214,9 +214,11 @@ route_cache(struct route *ro, struct in_ ro->ro_tableid == rtableid && ro->ro_dst.sa_family == AF_INET && satosin(&ro->ro_dst)->sin_addr.s_addr == addr.s_addr) { + ipstat_inc(ips_rtcachehit); return; } + ipstat_inc(ips_rtcachemiss); rtfree(ro->ro_rt); ro->ro_rt = NULL; ro->ro_generation = gen; Index: sys/netinet/ip_var.h =================================================================== RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/ip_var.h,v diff -u -p -r1.111 ip_var.h --- sys/netinet/ip_var.h 3 Feb 2024 22:50:09 -0000 1.111 +++ sys/netinet/ip_var.h 5 Feb 2024 16:09:20 -0000 @@ -87,6 +87,8 @@ struct ipstat { u_long ips_inswcsum; /* software checksummed on input */ u_long ips_outswcsum; /* software checksummed on output */ u_long ips_notmember; /* multicasts for unregistered groups */ + u_long ips_rtcachehit; /* valid route found in cache */ + u_long ips_rtcachemiss; /* route cache with new destination */ u_long ips_wrongif; /* packet received on wrong interface */ u_long ips_idropped; /* lost input due to nobufs, etc. */ }; @@ -133,6 +135,8 @@ enum ipstat_counters { ips_inswcsum, /* software checksummed on input */ ips_outswcsum, /* software checksummed on output */ ips_notmember, /* multicasts for unregistered groups */ + ips_rtcachehit, /* valid route to destination found in cache */ + ips_rtcachemiss, /* route cache filled with new destination */ ips_wrongif, /* packet received on wrong interface */ ips_idropped, /* lost input packets due to nobufs, etc. */ Index: sys/netinet6/ip6_var.h =================================================================== RCS file: /data/mirror/openbsd/cvs/src/sys/netinet6/ip6_var.h,v diff -u -p -r1.110 ip6_var.h --- sys/netinet6/ip6_var.h 3 Feb 2024 22:50:09 -0000 1.110 +++ sys/netinet6/ip6_var.h 5 Feb 2024 16:09:20 -0000 @@ -196,8 +196,8 @@ struct ip6stat { /* number of times that an deprecated address is chosen */ u_int64_t ip6s_sources_deprecated[16]; - u_int64_t ip6s_forward_cachehit; - u_int64_t ip6s_forward_cachemiss; + u_int64_t ip6s_rtcachehit; /* valid route found in cache */ + u_int64_t ip6s_rtcachemiss; /* route cache with new destination */ u_int64_t ip6s_wrongif; /* packet received on wrong interface */ u_int64_t ip6s_idropped; /* lost input due to nobufs, etc. */ }; @@ -243,8 +243,8 @@ enum ip6stat_counters { ip6s_sources_samescope = ip6s_sources_otherif + 16, ip6s_sources_otherscope = ip6s_sources_samescope + 16, ip6s_sources_deprecated = ip6s_sources_otherscope + 16, - ip6s_forward_cachehit = ip6s_sources_deprecated + 16, - ip6s_forward_cachemiss, + ip6s_rtcachehit = ip6s_sources_deprecated + 16, + ip6s_rtcachemiss, ip6s_wrongif, ip6s_idropped, Index: usr.bin/netstat/inet.c =================================================================== RCS file: /data/mirror/openbsd/cvs/src/usr.bin/netstat/inet.c,v diff -u -p -r1.179 inet.c --- usr.bin/netstat/inet.c 4 Sep 2023 23:00:36 -0000 1.179 +++ usr.bin/netstat/inet.c 5 Feb 2024 16:19:11 -0000 @@ -621,6 +621,8 @@ ip_stats(char *name) p(ips_inswcsum, "\t%lu input datagram%s software-checksummed\n"); p(ips_outswcsum, "\t%lu output datagram%s software-checksummed\n"); p(ips_notmember, "\t%lu multicast packet%s which we don't join\n"); + p1(ips_rtcachehit, "\t%lu route cache hit\n"); + p1(ips_rtcachemiss, "\t%lu route cache miss\n"); p(ips_wrongif, "\t%lu packet%s received on wrong interface\n"); p(ips_idropped, "\t%lu input packet%s dropped due to no bufs, etc.\n"); #undef p Index: usr.bin/netstat/inet6.c =================================================================== RCS file: /data/mirror/openbsd/cvs/src/usr.bin/netstat/inet6.c,v diff -u -p -r1.56 inet6.c --- usr.bin/netstat/inet6.c 12 Aug 2022 14:49:15 -0000 1.56 +++ usr.bin/netstat/inet6.c 5 Feb 2024 16:02:17 -0000 @@ -371,7 +371,6 @@ ip6_stats(char *name) p(ip6s_cantfrag, "\t%llu datagram%s that can't be fragmented\n"); p(ip6s_badscope, "\t%llu packet%s that violated scope rules\n"); p(ip6s_notmember, "\t%llu multicast packet%s which we don't join\n"); - p(ip6s_wrongif, "\t%llu packet%s received on wrong interface\n"); for (first = 1, i = 0; i < 256; i++) if (ip6stat.ip6s_nxthist[i] != 0) { if (first) { @@ -478,9 +477,9 @@ ip6_stats(char *name) PRINT_SCOPESTAT(ip6s_sources_deprecated[i], i); } } - - p1(ip6s_forward_cachehit, "\t%llu forward cache hit\n"); - p1(ip6s_forward_cachemiss, "\t%llu forward cache miss\n"); + p1(ip6s_rtcachehit, "\t%llu route cache hit\n"); + p1(ip6s_rtcachemiss, "\t%llu route cache miss\n"); + p(ip6s_wrongif, "\t%llu packet%s received on wrong interface\n"); p(ip6s_idropped, "\t%llu input packet%s dropped due to no bufs, etc.\n"); #undef p