My net-snmp patch to fix Debian sid (Sparc64) 64 bit problem

Place to discuss Debian Linux and Debian based distributions
Post Reply
User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

My net-snmp patch to fix Debian sid (Sparc64) 64 bit problem

Post by Void Main »

net-snmp inoctet network interface counters on Debian Sparc64 stop counting at ~4 gig (unsigned 32 bit max). I had found a patch on the net that changed the variables and scanf format strings from "unsigned long" to "unsigned long long" to accept the 64 bit interface counters from the kernel (cat /proc/net/dev). Problem is, on a 64 bit machine an "unsigned long" is 64 bit and an "unsigned int" is 32. The snmp variables are supposed to be "counter32" so I cast the output to "unsigned int" so the vars wrap back to 0 properly after reaching 0xFFFFFFFF. I was monitoring (graphing in Cacti) the interfaces on an UltraSparc running Debian Linux with an interface that receives a steady 40Mbps. The counter maxes out in like 10-15 minutes at that rate and my graphs weren't working, now they do. This patch is for net-snmp v5.1.1-2 which is the current release for Debian SID for Sparc. It should work for other versions around that version:

http://voidmain.is-a-geek.net/files/pat ... t-vm.patch

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main »

Duh, I thought about it after posting the patch and realized that since both unsigned long and unsigned long long are the same size on Sparc64 then there was no reason to change the integer types and scanfs. The only thing necessary was to cast the output to unsigned int. Here's a shorter patch:

Code: Select all

--- net-snmp-5.1.1/agent/mibgroup/mibII/interfaces.c.bak        2004-04-23 14:48:40.000000000 -0500
+++ net-snmp-5.1.1/agent/mibgroup/mibII/interfaces.c    2004-04-28 08:46:32.000000000 -0500
@@ -1658,19 +1658,19 @@
         if (!strcmp(ifname_buf, "lo") && rec_pkt > 0 && !snd_pkt)
             snd_pkt = rec_pkt;
 
-        nnew->if_ipackets = rec_pkt;
-        nnew->if_ierrors = rec_err;
-        nnew->if_opackets = snd_pkt;
-        nnew->if_oerrors = snd_err;
+        nnew->if_ipackets = (unsigned int)rec_pkt;
+        nnew->if_ierrors = (unsigned int)rec_err;
+        nnew->if_opackets = (unsigned int)snd_pkt;
+        nnew->if_oerrors = (unsigned int)snd_err;
         nnew->if_collisions = coll;
         if (scan_line_to_use == scan_line_2_2) {
-            nnew->if_ibytes = rec_oct;
-            nnew->if_obytes = snd_oct;
-            nnew->if_iqdrops = rec_drop;
-            nnew->if_snd.ifq_drops = snd_drop;
+            nnew->if_ibytes = (unsigned int)rec_oct;
+            nnew->if_obytes = (unsigned int)snd_oct;
+            nnew->if_iqdrops = (unsigned int)rec_drop;
+            nnew->if_snd.ifq_drops = (unsigned int)snd_drop;
         } else {
-            nnew->if_ibytes = rec_pkt * 308;
-            nnew->if_obytes = snd_pkt * 308;
+            nnew->if_ibytes = (unsigned int)(rec_pkt * 308);
+            nnew->if_obytes = (unsigned int)(snd_pkt * 308);
         }
 
         /*
It works just the same but fewer changes. I will update the file that the first link points to this evening.

Post Reply