On Tue 15 Nov 2005, Paul Slootman wrote: > Hmm, hold off on any action here, it looks like something may still need > to be tweaked.
I had missed one place where /proc/net/dev is read, namely agent/mibgroup/if-mib/data_access/interface_linux.c . Attached is the revised patch. Paul Slootman
diff -ru net-snmp-5.2.1.2/agent/mibgroup/if-mib/data_access/interface_linux.c net-snmp-5.2.1.2.fix/agent/mibgroup/if-mib/data_access/interface_linux.c --- net-snmp-5.2.1.2/agent/mibgroup/if-mib/data_access/interface_linux.c 2004-10-18 05:49:50.000000000 +0200 +++ net-snmp-5.2.1.2.fix/agent/mibgroup/if-mib/data_access/interface_linux.c 2005-11-15 14:45:33.000000000 +0100 @@ -59,6 +59,7 @@ u_int load_flags) { FILE *devin; + char proc_net_dev_buf[51200]; char line[256]; /* * scanline_2_2: @@ -107,6 +108,11 @@ snmp_log(LOG_ERR, "cannot open /proc/net/dev ...\n"); return -2; } + /* + * default stdio buffer of 10k is not enough with > 85 interfaces, + * the contents change between reads and this causes data format errors. + */ + setvbuf(devin, proc_net_dev_buf, _IOFBF, sizeof(proc_net_dev_buf)); /* * create socket for ioctls diff -ru net-snmp-5.2.1.2/agent/mibgroup/mibII/ifTable.c net-snmp-5.2.1.2.fix/agent/mibgroup/mibII/ifTable.c --- net-snmp-5.2.1.2/agent/mibgroup/mibII/ifTable.c 2004-07-07 19:41:15.000000000 +0200 +++ net-snmp-5.2.1.2.fix/agent/mibgroup/mibII/ifTable.c 2005-11-15 13:16:16.000000000 +0100 @@ -738,6 +738,7 @@ ifTable_load(netsnmp_cache * cache, void *vmagic) { FILE *devin; + char proc_net_dev_buf[51200]; char line[256]; const char *scan_line_2_2 = "%llu %llu %llu %llu %*llu %*llu %*llu %*llu %llu %llu %llu %llu %*llu %llu"; @@ -768,6 +769,11 @@ snmp_log(LOG_ERR, "snmpd: cannot open /proc/net/dev ...\n"); return -1; } + /* + * default stdio buffer of 10k is not enough with > 85 interfaces, + * the contents change between reads and this causes data format errors. + */ + setvbuf(devin, proc_net_dev_buf, _IOFBF, sizeof(proc_net_dev_buf)); /* * Read the first two lines of the file, containing the header @@ -821,7 +827,8 @@ } if ((scan_line_to_use == scan_line_2_2) && ((stats - line) < 6)) { snmp_log(LOG_ERR, - "/proc/net/dev data format error, line ==|%s|", line); + "/proc/net/dev data format error; line ==|%s|", line); + continue; } *stats = 0; entry = ifTable_ifentry_get_by_name(cache, ifstart, 1); diff -ru net-snmp-5.2.1.2/agent/mibgroup/mibII/interfaces.c net-snmp-5.2.1.2.fix/agent/mibgroup/mibII/interfaces.c --- net-snmp-5.2.1.2/agent/mibgroup/mibII/interfaces.c 2005-01-03 16:51:32.000000000 +0100 +++ net-snmp-5.2.1.2.fix/agent/mibgroup/mibII/interfaces.c 2005-11-15 14:55:59.000000000 +0100 @@ -1383,6 +1383,7 @@ Interface_Scan_Init(void) { #ifdef linux + char proc_net_dev_buf[51200]; char line[256], ifname_buf[64], *ifname, *ptr; struct ifreq ifrq; struct ifnet **ifnetaddr_ptr; @@ -1468,6 +1469,11 @@ snmp_log(LOG_ERR, "cannot open /proc/net/dev - continuing...\n"); return; /** exit (1); **/ } + /* + * default stdio buffer of 10k is not enough with > 85 interfaces, + * the contents change between reads and this causes data format errors. + */ + setvbuf(devin, proc_net_dev_buf, _IOFBF, sizeof(proc_net_dev_buf)); i = 0; @@ -1507,7 +1513,8 @@ } if ((scan_line_to_use == scan_line_2_2) && ((stats - line) < 6)) { snmp_log(LOG_ERR, - "/proc/net/dev data format error, line ==|%s|", line); + "/proc/net/dev data format error; line ==|%s|", line); + continue; } *stats = 0; diff -ru net-snmp-5.2.1.2/debian/changelog net-snmp-5.2.1.2.fix/debian/changelog --- net-snmp-5.2.1.2/debian/changelog 2005-11-15 13:40:41.000000000 +0100 +++ net-snmp-5.2.1.2.fix/debian/changelog 2005-11-15 13:17:43.000000000 +0100 @@ -1,3 +1,11 @@ +net-snmp (5.2.1.2-4.fix) unstable; urgency=low + + * use large buffer for /proc/net/dev, to prevent data format errors when the + data is more than 10k and changes between reads (>85 interfaces, 2.4 + kernel) + + -- Paul Slootman <[EMAIL PROTECTED]> Tue, 15 Nov 2005 13:16:31 +0100 + net-snmp (5.2.1.2-4) unstable; urgency=low * Version builddep on libssl-dev and rebuild, for openssl transition