ipv6: snmp: avoid performance issue with RATELIMITHOST
Subsystems (7)
v2 cover ipv6: snmp: avoid performance issue with RATELIMITHOST
Addition of ICMP6_MIB_RATELIMITHOST in commit d0941130c9351 ("icmp: Add counters for rate limits") introduced a performance drop in case of DOS (like receiving UDP packets
to closed ports).
Per netns ICMP6_MIB_RATELIMITHOST tracking uses per-cpu storage and is enough, we do not need per-device and slow tracking for this metric.
In v2 of this series, I completed the removal of SNMP_MIB_SENTINEL in all the kernel for consistency.
v1: had an issue : https://lore.kernel.org/netdev/[email protected]/
Eric Dumazet (9):
ipv6: snmp: remove icmp6type2name[]
ipv6: snmp: do not use SNMP_MIB_SENTINEL anymore
ipv6: snmp: do not track per idev ICMP6_MIB_RATELIMITHOST
ipv4: snmp: do not use SNMP_MIB_SENTINEL anymore
mptcp: snmp: do not use SNMP_MIB_SENTINEL anymore
sctp: snmp: do not use SNMP_MIB_SENTINEL anymore
tls: snmp: do not use SNMP_MIB_SENTINEL anymore
xfrm: snmp: do not use SNMP_MIB_SENTINEL anymore
net: snmp: remove SNMP_MIB_SENTINEL
include/net/ip.h | 9 +++-- include/net/snmp.h | 5 --- net/ipv4/proc.c | 65 +++++++++++++++---------------- net/ipv6/icmp.c | 3 +- net/ipv6/proc.c | 91 ++++++++++++++++++++++++-------------------- net/mptcp/mib.c | 12 +++--- net/sctp/proc.c | 12 +++--- net/tls/tls_proc.c | 10 +++-- net/xfrm/xfrm_proc.c | 12 +++--- 9 files changed, 113 insertions(+), 106 deletions(-)
--
2.51.0.355.g5224444f11-goog
PATCH v2 1/9 ipv6: snmp: remove icmp6type2name[]
This 2KB array can be replaced by a switch() to save space.
Before:
$ size net/ipv6/proc.o text data bss dec hex filename 6410 624 0 7034 1b7a net/ipv6/proc.o
After:
$ size net/ipv6/proc.o text data bss dec hex filename 5516 592 0 6108 17dc net/ipv6/proc.o
--- net/ipv6/proc.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-)
net/ipv6/proc.c +22 -22
@@ -99,26 +99,6 @@ static const struct snmp_mib snmp6_icmp6_list[] = {SNMP_MIB_SENTINEL }; -/* RFC 4293 v6 ICMPMsgStatsTable; named items for RFC 2466 compatibility */ -static const char *const icmp6type2name[256 ] = { - [ICMPV6_DEST_UNREACH ] ="DestUnreachs" , - [ICMPV6_PKT_TOOBIG ] ="PktTooBigs" , - [ICMPV6_TIME_EXCEED ] ="TimeExcds" , - [ICMPV6_PARAMPROB ] ="ParmProblems" , - [ICMPV6_ECHO_REQUEST ] ="Echos" , - [ICMPV6_ECHO_REPLY ] ="EchoReplies" , - [ICMPV6_MGM_QUERY ] ="GroupMembQueries" , - [ICMPV6_MGM_REPORT ] ="GroupMembResponses" , - [ICMPV6_MGM_REDUCTION ] ="GroupMembReductions" , - [ICMPV6_MLD2_REPORT ] ="MLDv2Reports" , - [NDISC_ROUTER_ADVERTISEMENT ] ="RouterAdvertisements" , - [NDISC_ROUTER_SOLICITATION ] ="RouterSolicits" , - [NDISC_NEIGHBOUR_ADVERTISEMENT ] ="NeighborAdvertisements" , - [NDISC_NEIGHBOUR_SOLICITATION ] ="NeighborSolicits" , - [NDISC_REDIRECT ] ="Redirects" , -}; - -static const struct snmp_mib snmp6_udp6_list[] = {SNMP_MIB_ITEM ("Udp6InDatagrams" ,UDP_MIB_INDATAGRAMS ),SNMP_MIB_ITEM ("Udp6NoPorts" ,UDP_MIB_NOPORTS ),
@@ -151,11 +131,31 @@ static void snmp6_seq_show_icmpv6msg(struct seq_file *seq, atomic_long_t *smib)/* print by name -- deprecated items */ for (i =0 ; i <ICMP6MSG_MIB_MAX ; i++) { +const char *p =NULL ;int icmptype; -const char *p; + +#define CASE (TYP ,STR ) case TYP: p = STR; break; icmptype = i &0xff ; - p = icmp6type2name[icmptype]; +switch (icmptype) { +/* RFC 4293 v6 ICMPMsgStatsTable; named items for RFC 2466 compatibility */ + CASE(ICMPV6_DEST_UNREACH, "DestUnreachs") + CASE(ICMPV6_PKT_TOOBIG, "PktTooBigs") + CASE(ICMPV6_TIME_EXCEED, "TimeExcds") + CASE(ICMPV6_PARAMPROB, "ParmProblems") + CASE(ICMPV6_ECHO_REQUEST, "Echos") + CASE(ICMPV6_ECHO_REPLY, "EchoReplies") + CASE(ICMPV6_MGM_QUERY, "GroupMembQueries") + CASE(ICMPV6_MGM_REPORT, "GroupMembResponses") + CASE(ICMPV6_MGM_REDUCTION, "GroupMembReductions") + CASE(ICMPV6_MLD2_REPORT, "MLDv2Reports") + CASE(NDISC_ROUTER_ADVERTISEMENT, "RouterAdvertisements") + CASE(NDISC_ROUTER_SOLICITATION, "RouterSolicits") + CASE(NDISC_NEIGHBOUR_ADVERTISEMENT, "NeighborAdvertisements") + CASE(NDISC_NEIGHBOUR_SOLICITATION, "NeighborSolicits") + CASE(NDISC_REDIRECT, "Redirects") + } +#undef CASEif (!p)/* don't print un-named types here */ continue ; snprintf(name, sizeof(name), "Icmp6%s%s",
Signature · 1 line
2.51.0.355.g5224444f11-goog
Re: [PATCH v2 net-next 1/9] ipv6: snmp: remove icmp6type2name[]
Quoted 8 lines · Eric Dumazet
This 2KB array can be replaced by a
switch()to save space.Before:
$ size net/ipv6/proc.o text data bss dec hex filename 6410 624 0 7034 1b7a net/ipv6/proc.oAfter:
Quoted 8 lines
$ size net/ipv6/proc.o text data bss dec hex filename 5516 592 0 6108 17dc net/ipv6/proc.oSigned-off-by Eric Dumazet <[email protected]>--- net/ipv6/proc.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-)
Signature · 1 line
Sabrina
PATCH v2 2/9 ipv6: snmp: do not use SNMP_MIB_SENTINEL anymore
In reply to Eric DumazetUse ARRAY_SIZE(), so that we know the limit at compile time.
Following patch needs this preliminary change.
--- include/net/ip.h | 24 ++++++++++++++++++++++++ net/ipv6/proc.c | 43 ++++++++++++++++++++++++------------------- 2 files changed, 48 insertions(+), 19 deletions(-)
include/net/ip.h +24 -0
@@ -338,6 +338,19 @@ static inline u64 snmp_fold_field64(void __percpu *mib, int offt, size_t syncp_o } \ } +#define snmp_get_cpu_field64_batch_cnt (buff64, stats_list, cnt, \ + mib_statistic, offset) \ +{ \ + int i, c; \ + for_each_possible_cpu(c) { \ + for (i = 0; i < cnt; i++) \ + buff64[i] += snmp_get_cpu_field64( \ + mib_statistic, \ + c, stats_list[i].entry, \ + offset); \ + } \ +} +#define snmp_get_cpu_field_batch (buff, stats_list, mib_statistic) \ { \ int i, c; \
@@ -349,6 +362,17 @@ static inline u64 snmp_fold_field64(void __percpu *mib, int offt, size_t syncp_o } \ } +#define snmp_get_cpu_field_batch_cnt (buff, stats_list, cnt, mib_statistic) \ +{ \ + int i, c; \ + for_each_possible_cpu(c) { \ + for (i = 0; i < cnt; i++) \ + buff[i] += snmp_get_cpu_field( \ + mib_statistic, \ + c, stats_list[i].entry); \ + } \ +} +static inline void inet_get_local_port_range (const struct net *net,int *low,int *high) {u32 range =READ_ONCE (net->ipv4.ip_local_ports.range);
net/ipv6/proc.c +24 -19
110 lines not on this page · raw message
Signature · 1 line
2.51.0.355.g5224444f11-goog
Re: [PATCH v2 net-next 2/9] ipv6: snmp: do not use SNMP_MIB_SENTINEL anymore
Quoted 9 lines · Eric Dumazet
Use
ARRAY_SIZE(), so that we know the limit at compile time.Following patch needs this preliminary change.
Signed-off-by Eric Dumazet <[email protected]>--- include/net/ip.h | 24 ++++++++++++++++++++++++ net/ipv6/proc.c | 43 ++++++++++++++++++++++++------------------- 2 files changed, 48 insertions(+), 19 deletions(-)
Signature · 1 line
Sabrina
PATCH v2 3/9 ipv6: snmp: do not track per idev ICMP6_MIB_RATELIMITHOST
In reply to Eric DumazetBlamed commit added a critical false sharing on a single atomic_long_t under DOS, like receiving UDP packets to closed ports.
Per netns ICMP6_MIB_RATELIMITHOST tracking uses per-cpu storage and is enough, we do not need per-device and slow tracking.
--- net/ipv6/icmp.c | 3 +-- net/ipv6/proc.c | 6 +++++- 2 files changed, 6 insertions(+), 3 deletions(-)
net/ipv6/icmp.c +1 -2
@@ -230,8 +230,7 @@ static bool icmpv6_xrlim_allow(struct sock *sk, u8 type, }rcu_read_unlock ();if (!res) -__ICMP6_INC_STATS (net,ip6_dst_idev (dst), -ICMP6_MIB_RATELIMITHOST ); +__ICMP6_INC_STATS (net,NULL ,ICMP6_MIB_RATELIMITHOST );else icmp_global_consume (net);dst_release (dst);
net/ipv6/proc.c +5 -1
@@ -94,6 +94,7 @@ static const struct snmp_mib snmp6_icmp6_list[] = {SNMP_MIB_ITEM ("Icmp6OutMsgs" ,ICMP6_MIB_OUTMSGS ),SNMP_MIB_ITEM ("Icmp6OutErrors" ,ICMP6_MIB_OUTERRORS ),SNMP_MIB_ITEM ("Icmp6InCsumErrors" ,ICMP6_MIB_CSUMERRORS ), +/* ICMP6_MIB_RATELIMITHOST needs to be last, see snmp6_dev_seq_show(). */ SNMP_MIB_ITEM("Icmp6OutRateLimitHost", ICMP6_MIB_RATELIMITHOST), };
@@ -242,8 +243,11 @@ static int snmp6_dev_seq_show(struct seq_file *seq, void *v) snmp6_ipstats_list,ARRAY_SIZE (snmp6_ipstats_list), offsetof(struct ipstats_mib, syncp)); + +/* Per idev icmp stats do not have ICMP6_MIB_RATELIMITHOST */ snmp6_seq_show_item (seq,NULL , idev->stats.icmpv6dev->mibs, - snmp6_icmp6_list,ARRAY_SIZE (snmp6_icmp6_list)); + snmp6_icmp6_list,ARRAY_SIZE (snmp6_icmp6_list) -1 ); +snmp6_seq_show_icmpv6msg (seq, idev->stats.icmpv6msgdev->mibs);return 0 ; }
Signature · 1 line
2.51.0.355.g5224444f11-goog
PATCH v2 4/9 ipv4: snmp: do not use SNMP_MIB_SENTINEL anymore
In reply to Eric DumazetUse ARRAY_SIZE(), so that we know the limit at compile time.
--- net/ipv4/proc.c | 65 +++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 32 deletions(-)
net/ipv4/proc.c +33 -32
@@ -95,7 +95,6 @@ static const struct snmp_mib snmp4_ipstats_list[] = {SNMP_MIB_ITEM ("FragFails" ,IPSTATS_MIB_FRAGFAILS ),SNMP_MIB_ITEM ("FragCreates" ,IPSTATS_MIB_FRAGCREATES ), SNMP_MIB_ITEM("OutTransmits", IPSTATS_MIB_OUTPKTS), - SNMP_MIB_SENTINEL };/* Following items are displayed in /proc/net/netstat */
@@ -119,7 +118,6 @@ static const struct snmp_mib snmp4_ipextstats_list[] = {SNMP_MIB_ITEM ("InECT0Pkts" ,IPSTATS_MIB_ECT0PKTS ),SNMP_MIB_ITEM ("InCEPkts" ,IPSTATS_MIB_CEPKTS ), SNMP_MIB_ITEM("ReasmOverlaps", IPSTATS_MIB_REASM_OVERLAPS), -SNMP_MIB_SENTINEL }; static const struct {
@@ -157,7 +155,6 @@ static const struct snmp_mib snmp4_tcp_list[] = {SNMP_MIB_ITEM ("InErrs" ,TCP_MIB_INERRS ),SNMP_MIB_ITEM ("OutRsts" ,TCP_MIB_OUTRSTS ), SNMP_MIB_ITEM("InCsumErrors", TCP_MIB_CSUMERRORS), -SNMP_MIB_SENTINEL }; static const struct snmp_mib snmp4_udp_list[] = {
@@ -170,7 +167,6 @@ static const struct snmp_mib snmp4_udp_list[] = {SNMP_MIB_ITEM ("InCsumErrors" ,UDP_MIB_CSUMERRORS ),SNMP_MIB_ITEM ("IgnoredMulti" ,UDP_MIB_IGNOREDMULTI ), SNMP_MIB_ITEM("MemErrors", UDP_MIB_MEMERRORS), -SNMP_MIB_SENTINEL }; static const struct snmp_mib snmp4_net_list[] = {
@@ -309,7 +305,6 @@ static const struct snmp_mib snmp4_net_list[] = {SNMP_MIB_ITEM ("TCPAOKeyNotFound" ,LINUX_MIB_TCPAOKEYNOTFOUND ),SNMP_MIB_ITEM ("TCPAOGood" ,LINUX_MIB_TCPAOGOOD ), SNMP_MIB_ITEM("TCPAODroppedIcmps", LINUX_MIB_TCPAODROPPEDICMPS), -SNMP_MIB_SENTINEL }; static void icmpmsg_put_line(struct seq_file *seq, unsigned long *vals,
@@ -389,14 +384,15 @@ static void icmp_put(struct seq_file *seq)*/ static int snmp_seq_show_ipstats (struct seq_file *seq,void *v) { +const int cnt =ARRAY_SIZE (snmp4_ipstats_list); +u64 buff64[ARRAY_SIZE (snmp4_ipstats_list)];struct net *net = seq->private; -u64 buff64[IPSTATS_MIB_MAX ];int i; -memset (buff64,0 ,IPSTATS_MIB_MAX *sizeof (u64)); +memset (buff64,0 ,sizeof (buff64));seq_puts (seq,"Ip: Forwarding DefaultTTL" ); -for (i =0 ; snmp4_ipstats_list[i].name; i++) +for (i =0 ; i < cnt; i++)seq_printf (seq," %s" , snmp4_ipstats_list[i].name); seq_printf(seq, "\nIp: %d %d",
@@ -404,10 +400,10 @@ static int snmp_seq_show_ipstats(struct seq_file *seq, void *v) READ_ONCE(net->ipv4.sysctl_ip_default_ttl));BUILD_BUG_ON (offsetof(struct ipstats_mib , mibs) !=0 ); -snmp_get_cpu_field64_batch (buff64, snmp4_ipstats_list, - net->mib.ip_statistics, - offsetof(struct ipstats_mib , syncp)); -for (i =0 ; snmp4_ipstats_list[i].name; i++) +snmp_get_cpu_field64_batch_cnt (buff64, snmp4_ipstats_list, cnt, + net->mib.ip_statistics, + offsetof(struct ipstats_mib , syncp)); +for (i =0 ; i < cnt; i++)seq_printf (seq," %llu" , buff64[i]);return 0 ;
@@ -415,20 +411,23 @@ static int snmp_seq_show_ipstats(struct seq_file *seq, void *v)static int snmp_seq_show_tcp_udp (struct seq_file *seq,void *v) { +const int udp_cnt =ARRAY_SIZE (snmp4_udp_list); +const int tcp_cnt =ARRAY_SIZE (snmp4_tcp_list);unsigned long buff[TCPUDP_MIB_MAX ];struct net *net = seq->private;int i; -memset (buff,0 ,TCPUDP_MIB_MAX *sizeof (unsigned long )); +memset (buff,0 , tcp_cnt *sizeof (unsigned long ));seq_puts (seq,"\nTcp:" ); -for (i =0 ; snmp4_tcp_list[i].name; i++) +for (i =0 ; i < tcp_cnt; i++)seq_printf (seq," %s" , snmp4_tcp_list[i].name);seq_puts (seq,"\nTcp:" ); -snmp_get_cpu_field_batch (buff, snmp4_tcp_list, - net->mib.tcp_statistics); -for (i =0 ; snmp4_tcp_list[i].name; i++) { +snmp_get_cpu_field_batch_cnt (buff, snmp4_tcp_list, + tcp_cnt, + net->mib.tcp_statistics); +for (i =0 ; i < tcp_cnt; i++) {/* MaxConn field is signed, RFC 2012 */ if (snmp4_tcp_list[i].entry ==TCP_MIB_MAXCONN )seq_printf (seq," %ld" , buff[i]);
@@ -436,27 +435,29 @@ static int snmp_seq_show_tcp_udp(struct seq_file *seq, void *v)seq_printf (seq," %lu" , buff[i]); } -memset (buff,0 ,TCPUDP_MIB_MAX *sizeof (unsigned long )); +memset (buff,0 , udp_cnt *sizeof (unsigned long )); -snmp_get_cpu_field_batch (buff, snmp4_udp_list, - net->mib.udp_statistics); +snmp_get_cpu_field_batch_cnt (buff, snmp4_udp_list, + udp_cnt, + net->mib.udp_statistics);seq_puts (seq,"\nUdp:" ); -for (i =0 ; snmp4_udp_list[i].name; i++) +for (i =0 ; i < udp_cnt; i++)seq_printf (seq," %s" , snmp4_udp_list[i].name);seq_puts (seq,"\nUdp:" ); -for (i =0 ; snmp4_udp_list[i].name; i++) +for (i =0 ; i < udp_cnt; i++)seq_printf (seq," %lu" , buff[i]); -memset (buff,0 ,TCPUDP_MIB_MAX *sizeof (unsigned long )); +memset (buff,0 , udp_cnt *sizeof (unsigned long ));/* the UDP and UDP-Lite MIBs are the same */ seq_puts (seq,"\nUdpLite:" ); -snmp_get_cpu_field_batch (buff, snmp4_udp_list, - net->mib.udplite_statistics); -for (i =0 ; snmp4_udp_list[i].name; i++) +snmp_get_cpu_field_batch_cnt (buff, snmp4_udp_list, + udp_cnt, + net->mib.udplite_statistics); +for (i =0 ; i < udp_cnt; i++)seq_printf (seq," %s" , snmp4_udp_list[i].name);seq_puts (seq,"\nUdpLite:" ); -for (i =0 ; snmp4_udp_list[i].name; i++) +for (i =0 ; i < udp_cnt; i++)seq_printf (seq," %lu" , buff[i]);seq_putc (seq,'\n' );
@@ -480,8 +481,8 @@ static int snmp_seq_show(struct seq_file *seq, void *v)*/ static int netstat_seq_show (struct seq_file *seq,void *v) { -const int ip_cnt =ARRAY_SIZE (snmp4_ipextstats_list) -1 ; -const int tcp_cnt =ARRAY_SIZE (snmp4_net_list) -1 ; +const int ip_cnt =ARRAY_SIZE (snmp4_ipextstats_list); +const int tcp_cnt =ARRAY_SIZE (snmp4_net_list);struct net *net = seq->private;unsigned long *buff;int i;
@@ -494,8 +495,8 @@ static int netstat_seq_show(struct seq_file *seq, void *v) buff =kzalloc (max (tcp_cnt *sizeof (long ), ip_cnt *sizeof (u64)),GFP_KERNEL );if (buff) { -snmp_get_cpu_field_batch (buff, snmp4_net_list, - net->mib.net_statistics); +snmp_get_cpu_field_batch_cnt (buff, snmp4_net_list, tcp_cnt, + net->mib.net_statistics);for (i =0 ; i < tcp_cnt; i++)seq_printf (seq," %lu" , buff[i]); }else {
@@ -513,7 +514,7 @@ static int netstat_seq_show(struct seq_file *seq, void *v)u64 *buff64 = (u64 *)buff;memset (buff64,0 , ip_cnt *sizeof (u64)); -snmp_get_cpu_field64_batch (buff64, snmp4_ipextstats_list, +snmp_get_cpu_field64_batch_cnt (buff64, snmp4_ipextstats_list, ip_cnt, net->mib.ip_statistics, offsetof(struct ipstats_mib , syncp));for (i =0 ; i < ip_cnt; i++)
Signature · 1 line
2.51.0.355.g5224444f11-goog
Re: [PATCH v2 net-next 4/9] ipv4: snmp: do not use SNMP_MIB_SENTINEL anymore
Quoted 6 lines · Eric Dumazet
Use
ARRAY_SIZE(), so that we know the limit at compile time.Signed-off-by Eric Dumazet <[email protected]>--- net/ipv4/proc.c | 65 +++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 32 deletions(-)
Signature · 1 line
Sabrina
PATCH v2 5/9 mptcp: snmp: do not use SNMP_MIB_SENTINEL anymore
In reply to Eric DumazetUse ARRAY_SIZE(), so that we know the limit at compile time.
--- net/mptcp/mib.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
net/mptcp/mib.c +6 -6
@@ -85,7 +85,6 @@ static const struct snmp_mib mptcp_snmp_list[] = {SNMP_MIB_ITEM ("DssFallback" ,MPTCP_MIB_DSSFALLBACK ),SNMP_MIB_ITEM ("SimultConnectFallback" ,MPTCP_MIB_SIMULTCONNFALLBACK ), SNMP_MIB_ITEM("FallbackFailed", MPTCP_MIB_FALLBACKFAILED), - SNMP_MIB_SENTINEL };/* mptcp_mib_alloc - allocate percpu mib counters
@@ -108,22 +107,23 @@ bool mptcp_mib_alloc(struct net *net)void mptcp_seq_show (struct seq_file *seq) { -unsigned long sum[ARRAY_SIZE (mptcp_snmp_list) -1 ]; +unsigned long sum[ARRAY_SIZE (mptcp_snmp_list)]; +const int cnt =ARRAY_SIZE (mptcp_snmp_list);struct net *net = seq->private;int i;seq_puts (seq,"MPTcpExt:" ); -for (i =0 ; mptcp_snmp_list[i].name; i++) +for (i =0 ; i < cnt; i++)seq_printf (seq," %s" , mptcp_snmp_list[i].name);seq_puts (seq,"\nMPTcpExt:" );memset (sum,0 ,sizeof (sum));if (net->mib.mptcp_statistics) -snmp_get_cpu_field_batch (sum, mptcp_snmp_list, - net->mib.mptcp_statistics); +snmp_get_cpu_field_batch_cnt (sum, mptcp_snmp_list, cnt, + net->mib.mptcp_statistics); -for (i =0 ; mptcp_snmp_list[i].name; i++) +for (i =0 ; i < cnt; i++)seq_printf (seq," %lu" , sum[i]);seq_putc (seq,'\n' );
Signature · 1 line
2.51.0.355.g5224444f11-goog
Re: [PATCH v2 net-next 5/9] mptcp: snmp: do not use SNMP_MIB_SENTINEL anymore
Hi Eric,
Quoted 1 line · Eric Dumazet
Use
ARRAY_SIZE(), so that we know the limit at compile time.
Thank you for having done this modification in MPTCP as well!
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
PATCH v2 6/9 sctp: snmp: do not use SNMP_MIB_SENTINEL anymore
In reply to Eric DumazetUse ARRAY_SIZE(), so that we know the limit at compile time.
--- net/sctp/proc.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
net/sctp/proc.c +6 -6
@@ -52,21 +52,21 @@ static const struct snmp_mib sctp_snmp_list[] = {SNMP_MIB_ITEM ("SctpInPktBacklog" ,SCTP_MIB_IN_PKT_BACKLOG ),SNMP_MIB_ITEM ("SctpInPktDiscards" ,SCTP_MIB_IN_PKT_DISCARDS ), SNMP_MIB_ITEM("SctpInDataChunkDiscards", SCTP_MIB_IN_DATA_CHUNK_DISCARDS), - SNMP_MIB_SENTINEL };/* Display sctp snmp mib statistics(/proc/net/sctp/snmp). */ static int sctp_snmp_seq_show (struct seq_file *seq,void *v) { -unsigned long buff[SCTP_MIB_MAX ]; +unsigned long buff[ARRAY_SIZE (sctp_snmp_list)]; +const int cnt =ARRAY_SIZE (sctp_snmp_list);struct net *net = seq->private;int i; -memset (buff,0 ,sizeof (unsigned long ) *SCTP_MIB_MAX ); +memset (buff,0 ,sizeof (buff)); -snmp_get_cpu_field_batch (buff, sctp_snmp_list, - net->sctp.sctp_statistics); -for (i =0 ; sctp_snmp_list[i].name; i++) +snmp_get_cpu_field_batch_cnt (buff, sctp_snmp_list, cnt, + net->sctp.sctp_statistics); +for (i =0 ; i < cnt; i++)seq_printf (seq,"%-32s\t%ld\n" , sctp_snmp_list[i].name, buff[i]);
Signature · 1 line
2.51.0.355.g5224444f11-goog
Re: [PATCH v2 net-next 6/9] sctp: snmp: do not use SNMP_MIB_SENTINEL anymore
Quoted 8 lines · Eric Dumazet
Use
ARRAY_SIZE(), so that we know the limit at compile time.Signed-off-by Eric Dumazet <[email protected]>Cc Marcelo Ricardo Leitner <[email protected]>Cc Xin Long <[email protected]>--- net/sctp/proc.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
Signature · 1 line
Sabrina
Re: [PATCH v2 net-next 6/9] sctp: snmp: do not use SNMP_MIB_SENTINEL anymore
In reply to Eric DumazetQuoted 6 lines · Eric Dumazet
Use
ARRAY_SIZE(), so that we know the limit at compile time.Signed-off-by Eric Dumazet <[email protected]>Cc Marcelo Ricardo Leitner <[email protected]>Cc Xin Long <[email protected]>
PATCH v2 7/9 tls: snmp: do not use SNMP_MIB_SENTINEL anymore
In reply to Eric DumazetUse ARRAY_SIZE(), so that we know the limit at compile time.
--- net/tls/tls_proc.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
net/tls/tls_proc.c +6 -4
@@ -27,17 +27,19 @@ static const struct snmp_mib tls_mib_list[] = {SNMP_MIB_ITEM ("TlsTxRekeyOk" ,LINUX_MIB_TLSTXREKEYOK ),SNMP_MIB_ITEM ("TlsTxRekeyError" ,LINUX_MIB_TLSTXREKEYERROR ), SNMP_MIB_ITEM("TlsRxRekeyReceived", LINUX_MIB_TLSRXREKEYRECEIVED), - SNMP_MIB_SENTINEL };static int tls_statistics_seq_show (struct seq_file *seq,void *v) { -unsigned long buf[LINUX_MIB_TLSMAX ] = {}; +unsigned long buf[ARRAY_SIZE (tls_mib_list)]; +const int cnt =ARRAY_SIZE (tls_mib_list);struct net *net = seq->private;int i; -snmp_get_cpu_field_batch (buf, tls_mib_list, net->mib.tls_statistics); -for (i =0 ; tls_mib_list[i].name; i++) +memset (buf,0 ,sizeof (buf)); +snmp_get_cpu_field_batch_cnt (buf, tls_mib_list, cnt, + net->mib.tls_statistics); +for (i =0 ; i < cnt; i++)seq_printf (seq,"%-32s\t%lu\n" , tls_mib_list[i].name, buf[i]);return 0 ;
Signature · 1 line
2.51.0.355.g5224444f11-goog
Re: [PATCH v2 net-next 7/9] tls: snmp: do not use SNMP_MIB_SENTINEL anymore
Quoted 8 lines · Eric Dumazet
Use
ARRAY_SIZE(), so that we know the limit at compile time.Signed-off-by Eric Dumazet <[email protected]>Cc John Fastabend <[email protected]>Cc Sabrina Dubroca <[email protected]>--- net/tls/tls_proc.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
Signature · 1 line
Sabrina
PATCH v2 8/9 xfrm: snmp: do not use SNMP_MIB_SENTINEL anymore
In reply to Eric DumazetUse ARRAY_SIZE(), so that we know the limit at compile time.
--- net/xfrm/xfrm_proc.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
net/xfrm/xfrm_proc.c +6 -6
@@ -45,21 +45,21 @@ static const struct snmp_mib xfrm_mib_list[] = {SNMP_MIB_ITEM ("XfrmInStateDirError" ,LINUX_MIB_XFRMINSTATEDIRERROR ),SNMP_MIB_ITEM ("XfrmInIptfsError" ,LINUX_MIB_XFRMINIPTFSERROR ), SNMP_MIB_ITEM("XfrmOutNoQueueSpace", LINUX_MIB_XFRMOUTNOQSPACE), - SNMP_MIB_SENTINEL };static int xfrm_statistics_seq_show (struct seq_file *seq,void *v) { -unsigned long buff[LINUX_MIB_XFRMMAX ]; +unsigned long buff[ARRAY_SIZE (xfrm_mib_list)]; +const int cnt =ARRAY_SIZE (xfrm_mib_list);struct net *net = seq->private;int i; -memset (buff,0 ,sizeof (unsigned long ) *LINUX_MIB_XFRMMAX ); +memset (buff,0 ,sizeof (buff));xfrm_state_update_stats (net); -snmp_get_cpu_field_batch (buff, xfrm_mib_list, - net->mib.xfrm_statistics); -for (i =0 ; xfrm_mib_list[i].name; i++) +snmp_get_cpu_field_batch_cnt (buff, xfrm_mib_list, cnt, + net->mib.xfrm_statistics); +for (i =0 ; i < cnt; i++)seq_printf (seq,"%-24s\t%lu\n" , xfrm_mib_list[i].name, buff[i]);
Signature · 1 line
2.51.0.355.g5224444f11-goog
Re: [PATCH v2 net-next 8/9] xfrm: snmp: do not use SNMP_MIB_SENTINEL anymore
Quoted 7 lines · Eric Dumazet
Use
ARRAY_SIZE(), so that we know the limit at compile time.Signed-off-by Eric Dumazet <[email protected]>Cc Steffen Klassert <[email protected]>--- net/xfrm/xfrm_proc.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
Signature · 1 line
Sabrina
PATCH v2 9/9 net: snmp: remove SNMP_MIB_SENTINEL
In reply to Eric DumazetNo more user of SNMP_MIB_SENTINEL, we can remove it.
Also remove snmp_get_cpu_field[64]_batch() helpers.
--- include/net/ip.h | 23 ----------------------- include/net/snmp.h | 5 ----- 2 files changed, 28 deletions(-)
include/net/ip.h +0 -23
@@ -326,18 +326,6 @@ static inline u64 snmp_fold_field64(void __percpu *mib, int offt, size_t syncp_o }#endif -#define snmp_get_cpu_field64_batch (buff64, stats_list, mib_statistic, offset) \ -{ \ - int i, c; \ - for_each_possible_cpu(c) { \ - for (i = 0; stats_list[i].name; i++) \ - buff64[i] += snmp_get_cpu_field64( \ - mib_statistic, \ - c, stats_list[i].entry, \ - offset); \ - } \ -} -#define snmp_get_cpu_field64_batch_cnt (buff64, stats_list, cnt, \ mib_statistic, offset) \ { \
@@ -351,17 +339,6 @@ static inline u64 snmp_fold_field64(void __percpu *mib, int offt, size_t syncp_o } \ } -#define snmp_get_cpu_field_batch (buff, stats_list, mib_statistic) \ -{ \ - int i, c; \ - for_each_possible_cpu(c) { \ - for (i = 0; stats_list[i].name; i++) \ - buff[i] += snmp_get_cpu_field( \ - mib_statistic, \ - c, stats_list[i].entry); \ - } \ -} -#define snmp_get_cpu_field_batch_cnt (buff, stats_list, cnt, mib_statistic) \ { \ int i, c; \
include/net/snmp.h +0 -5
@@ -36,11 +36,6 @@ struct snmp_mib { .entry = _entry, \ } -#define SNMP_MIB_SENTINEL { \ - .name = NULL, \ - .entry = 0, \ -} -/* * We use unsigned longs for most mibs but u64 for ipstats. */
Signature · 1 line
2.51.0.355.g5224444f11-goog
Re: [PATCH v2 net-next 9/9] net: snmp: remove SNMP_MIB_SENTINEL
Quoted 9 lines · Eric Dumazet
No more user of
SNMP_MIB_SENTINEL, we can remove it.Also remove snmp_get_cpu_field[64]_batch() helpers.
Signed-off-by Eric Dumazet <[email protected]>--- include/net/ip.h | 23 ----------------------- include/net/snmp.h | 5 ----- 2 files changed, 28 deletions(-)
Signature · 1 line
Sabrina
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Fri, 5 Sep 2025 16:58:04 +0000 you wrote:
Addition of
ICMP6_MIB_RATELIMITHOSTin commitd0941130c9351("icmp: Add counters for rate limits") introduced a performance drop in case of DOS (like receiving UDP packets
to closed ports).Per netns
ICMP6_MIB_RATELIMITHOSTtracking uses per-cpu storage and is enough, we do not need per-device and slow tracking for this metric.[...]
Here is the summary with links:
- [v2,net-next,1/9] ipv6: snmp: remove icmp6type2name[]
https://git.kernel.org/netdev/net-next/c/b7fe8c1be776 - [v2,net-next,2/9] ipv6: snmp: do not use SNMP_MIB_SENTINEL anymore https://git.kernel.org/netdev/net-next/c/ceac1fb2290d - [v2,net-next,3/9] ipv6: snmp: do not track per idev ICMP6_MIB_RATELIMITHOST https://git.kernel.org/netdev/net-next/c/2fab94bcf313 - [v2,net-next,4/9] ipv4: snmp: do not use SNMP_MIB_SENTINEL anymore https://git.kernel.org/netdev/net-next/c/b7b74953f834 - [v2,net-next,5/9] mptcp: snmp: do not use SNMP_MIB_SENTINEL anymore https://git.kernel.org/netdev/net-next/c/35cb2da0abaf - [v2,net-next,6/9] sctp: snmp: do not use SNMP_MIB_SENTINEL anymore https://git.kernel.org/netdev/net-next/c/52a33cae6a6f - [v2,net-next,7/9] tls: snmp: do not use SNMP_MIB_SENTINEL anymore https://git.kernel.org/netdev/net-next/c/3a951f95202c - [v2,net-next,8/9] xfrm: snmp: do not use SNMP_MIB_SENTINEL anymore https://git.kernel.org/netdev/net-next/c/c73d583e7008 - [v2,net-next,9/9] net: snmp: remove SNMP_MIB_SENTINEL https://git.kernel.org/netdev/net-next/c/20d3d2681544
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html