0001-Add-Linux-6.7-compatibility-parsing-proc-net-snmp.patch 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. From 8350fd9e9c8bd97f587809265516f61aa7fe8aa0 Mon Sep 17 00:00:00 2001
  2. From: Philippe Troin <phil+github-commits@fifi.org>
  3. Date: Sat, 3 Feb 2024 10:30:30 -0800
  4. Subject: [PATCH] Add Linux 6.7 compatibility parsing /proc/net/snmp
  5. Linux 6.7 adds a new OutTransmits field to Ip in /proc/net/snmp.
  6. This breaks the hard-coded assumptions about the Ip line length.
  7. Add compatibility to parse Linux 6.7 Ip header while keep support
  8. for previous versions.
  9. Upstream: https://github.com/net-snmp/net-snmp/commit/49d60ba57f4b462df7dc5fd5b38b4425dab0982c
  10. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
  11. ---
  12. .../ip-mib/data_access/systemstats_linux.c | 46 +++++++++++++++----
  13. 1 file changed, 37 insertions(+), 9 deletions(-)
  14. diff --git a/agent/mibgroup/ip-mib/data_access/systemstats_linux.c b/agent/mibgroup/ip-mib/data_access/systemstats_linux.c
  15. index a0fbdd9ffa..8eb40742b4 100644
  16. --- a/agent/mibgroup/ip-mib/data_access/systemstats_linux.c
  17. +++ b/agent/mibgroup/ip-mib/data_access/systemstats_linux.c
  18. @@ -36,7 +36,7 @@ netsnmp_access_systemstats_arch_init(void)
  19. }
  20. /*
  21. - /proc/net/snmp
  22. + /proc/net/snmp - Linux 6.6 and lower
  23. Ip: Forwarding DefaultTTL InReceives InHdrErrors InAddrErrors ForwDatagrams InUnknownProtos InDiscards InDelivers OutRequests OutDiscards OutNoRoutes ReasmTimeout ReasmReqds ReasmOKs ReasmFails FragOKs FragFails FragCreates
  24. Ip: 2 64 7083534 0 0 0 0 0 6860233 6548963 0 0 1 286623 63322 1 259920 0 0
  25. @@ -49,6 +49,26 @@ netsnmp_access_systemstats_arch_init(void)
  26. Udp: InDatagrams NoPorts InErrors OutDatagrams
  27. Udp: 1491094 122 0 1466178
  28. +*
  29. + /proc/net/snmp - Linux 6.7 and higher
  30. +
  31. + Ip: Forwarding DefaultTTL InReceives InHdrErrors InAddrErrors ForwDatagrams InUnknownProtos InDiscards InDelivers OutRequests OutDiscards OutNoRoutes ReasmTimeout ReasmReqds ReasmOKs ReasmFails FragOKs FragFails FragCreates OutTransmits
  32. + Ip: 1 64 50859058 496 0 37470604 0 0 20472980 7515791 1756 0 0 7264 3632 0 3548 0 7096 44961424
  33. +
  34. + Icmp: InMsgs InErrors InCsumErrors InDestUnreachs InTimeExcds InParmProbs InSrcQuenchs InRedirects InEchos InEchoReps InTimestamps InTimestampReps InAddrMasks InAddrMaskReps OutMsgs OutErrors OutRateLimitGlobal OutRateLimitHost OutDestUnreachs OutTimeExcds OutParmProbs OutSrcQuenchs OutRedirects OutEchos OutEchoReps OutTimestamps OutTimestampReps OutAddrMasks OutAddrMaskReps
  35. + Icmp: 114447 2655 0 17589 0 0 0 0 66905 29953 0 0 0 0 143956 0 0 572 16610 484 0 0 0 59957 66905 0 0 0 0
  36. +
  37. + IcmpMsg: InType0 InType3 InType8 OutType0 OutType3 OutType8 OutType11
  38. + IcmpMsg: 29953 17589 66905 66905 16610 59957 484
  39. +
  40. + Tcp: RtoAlgorithm RtoMin RtoMax MaxConn ActiveOpens PassiveOpens AttemptFails EstabResets CurrEstab InSegs OutSegs RetransSegs InErrs OutRsts InCsumErrors
  41. + Tcp: 1 200 120000 -1 17744 13525 307 3783 6 18093137 9277788 3499 8 7442 0
  42. +
  43. + Udp: InDatagrams NoPorts InErrors OutDatagrams RcvbufErrors SndbufErrors InCsumErrors IgnoredMulti MemErrors
  44. + Udp: 2257832 1422 0 2252835 0 0 0 84 0
  45. +
  46. + UdpLite: InDatagrams NoPorts InErrors OutDatagrams RcvbufErrors SndbufErrors InCsumErrors IgnoredMulti MemErrors
  47. + UdpLite: 0 0 0 0 0 0 0 0 0
  48. */
  49. @@ -101,10 +121,10 @@ _systemstats_v4(netsnmp_container* container, u_int load_flags)
  50. FILE *devin;
  51. char line[1024];
  52. netsnmp_systemstats_entry *entry = NULL;
  53. - int scan_count;
  54. + int scan_count, expected_scan_count;
  55. char *stats, *start = line;
  56. int len;
  57. - unsigned long long scan_vals[19];
  58. + unsigned long long scan_vals[20];
  59. DEBUGMSGTL(("access:systemstats:container:arch", "load v4 (flags %x)\n",
  60. load_flags));
  61. @@ -126,10 +146,17 @@ _systemstats_v4(netsnmp_container* container, u_int load_flags)
  62. */
  63. NETSNMP_IGNORE_RESULT(fgets(line, sizeof(line), devin));
  64. len = strlen(line);
  65. - if (224 != len) {
  66. + switch (len) {
  67. + case 224:
  68. + expected_scan_count = 19;
  69. + break;
  70. + case 237:
  71. + expected_scan_count = 20;
  72. + break;
  73. + default:
  74. fclose(devin);
  75. snmp_log(LOG_ERR, "systemstats_linux: unexpected header length in /proc/net/snmp."
  76. - " %d != 224\n", len);
  77. + " %d not in { 224, 237 } \n", len);
  78. return -4;
  79. }
  80. @@ -178,20 +205,20 @@ _systemstats_v4(netsnmp_container* container, u_int load_flags)
  81. memset(scan_vals, 0x0, sizeof(scan_vals));
  82. scan_count = sscanf(stats,
  83. "%llu %llu %llu %llu %llu %llu %llu %llu %llu %llu"
  84. - "%llu %llu %llu %llu %llu %llu %llu %llu %llu",
  85. + "%llu %llu %llu %llu %llu %llu %llu %llu %llu %llu",
  86. &scan_vals[0],&scan_vals[1],&scan_vals[2],
  87. &scan_vals[3],&scan_vals[4],&scan_vals[5],
  88. &scan_vals[6],&scan_vals[7],&scan_vals[8],
  89. &scan_vals[9],&scan_vals[10],&scan_vals[11],
  90. &scan_vals[12],&scan_vals[13],&scan_vals[14],
  91. &scan_vals[15],&scan_vals[16],&scan_vals[17],
  92. - &scan_vals[18]);
  93. + &scan_vals[18],&scan_vals[19]);
  94. DEBUGMSGTL(("access:systemstats", " read %d values\n", scan_count));
  95. - if(scan_count != 19) {
  96. + if(scan_count != expected_scan_count) {
  97. snmp_log(LOG_ERR,
  98. "error scanning systemstats data (expected %d, got %d)\n",
  99. - 19, scan_count);
  100. + expected_scan_count, scan_count);
  101. netsnmp_access_systemstats_entry_free(entry);
  102. return -4;
  103. }
  104. @@ -223,6 +250,7 @@ _systemstats_v4(netsnmp_container* container, u_int load_flags)
  105. entry->stats.HCOutFragFails.high = scan_vals[17] >> 32;
  106. entry->stats.HCOutFragCreates.low = scan_vals[18] & 0xffffffff;
  107. entry->stats.HCOutFragCreates.high = scan_vals[18] >> 32;
  108. + /* entry->stats. = scan_vals[19]; / * OutTransmits */
  109. entry->stats.columnAvail[IPSYSTEMSTATSTABLE_HCINRECEIVES] = 1;
  110. entry->stats.columnAvail[IPSYSTEMSTATSTABLE_INHDRERRORS] = 1;
  111. --
  112. 2.49.0