[Iftop-users] Patches to fix some bugs with 10gbit cards

Hans Fugal hans at fugal.net
Fri, 07 Mar 2014 13:36:01 -0800


This is a multi-part message in MIME format.
--------------080504060404020809090308
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

[PATCH 1/3] Avoid 32-bit overflow for rates when calculating bar length

Avoid 32-bit overflow by using double instead of int. uint64_t would be
another option but these are only ever used in conjunction with floats.
(float was also an option)
---
 ui.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/ui.c b/ui.c
index 57ca6c0..8a3b9d0 100644
--- a/ui.c
+++ b/ui.c
@@ -71,7 +71,8 @@ int dontshowdisplay = 0;

 /* Barchart scales. */
 static struct {
-    int max, interval;
+    double max;
+    int interval;
 } scale[] = {
         {      64000,     10 },     /* 64 kbit/s */
         {     128000,     10 },
@@ -105,7 +106,7 @@ static float get_max_bandwidth() {
 }

 /* rate in bits */
-static int get_bar_length(const int rate) {
+static int get_bar_length(const double rate) {
     float l;
     if (rate <= 0)
         return 0;


[PATCH 2/3] scale[] up to tbit

Extend the scale[] array up to terabit. 10gbit is not uncommon,
100gbit 40 and 100 gbit are coming, 400 gbit and terabit are future
possibilities.
---
 ui.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/ui.c b/ui.c
index 8a3b9d0..d1500ad 100644
--- a/ui.c
+++ b/ui.c
@@ -74,13 +74,16 @@ static struct {
     double max;
     int interval;
 } scale[] = {
-        {      64000,     10 },     /* 64 kbit/s */
-        {     128000,     10 },
-        {     256000,     10 },
-        {    1000000,     10 },     /* 1 Mbit/s */
-        {   10000000,     10 },
-        {  100000000,    100 },
-        { 1000000000,    100 }      /* 1 Gbit/s */
+        {         64000,     10 },     /* 64 kbit/s */
+        {        128000,     10 },
+        {        256000,     10 },
+        {       1000000,     10 },     /* 1 Mbit/s */
+        {      10000000,     10 },
+        {     100000000,    100 },
+        {    1000000000,    100 },     /* 1 Gbit/s */
+        {   10000000000,    100 },
+        {  100000000000,    100 },
+        { 1000000000000,    100 },     /* 1 Tbit/s */
     };
 static int rateidx = 0, wantbiggerrate;


[PATCH 3/3] rateidx_init fix

When calculating the first rateidx, we were overshooting to the next
scale. Fix that.
---
 ui.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/ui.c b/ui.c
index d1500ad..15624bf 100644
--- a/ui.c
+++ b/ui.c
@@ -116,7 +116,8 @@ static int get_bar_length(const double rate) {
     if (rate > scale[rateidx].max) {
       wantbiggerrate = 1;
       if(! rateidx_init) {
-	while(rate > scale[rateidx_init++].max) {
+	while(rate > scale[rateidx_init].max) {
+          rateidx_init++;
 	}
 	rateidx = rateidx_init;
       }

--------------080504060404020809090308
Content-Type: text/plain; charset=UTF-8; x-mac-type="0"; x-mac-creator="0";
 name="0001-Avoid-32-bit-overflow-for-rates-when-calculating-bar.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename*0="0001-Avoid-32-bit-overflow-for-rates-when-calculating-bar.pa";
 filename*1="tch"

From: Hans Fugal <hans@fugal.net>
Date: Fri, 7 Mar 2014 13:22:04 -0800
Subject: [PATCH 1/3] Avoid 32-bit overflow for rates when calculating bar
 length

Avoid 32-bit overflow by using double instead of int. uint64_t would be
another option but these are only ever used in conjunction with floats.
(float was also an option)
---
 ui.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/ui.c b/ui.c
index 57ca6c0..8a3b9d0 100644
--- a/ui.c
+++ b/ui.c
@@ -71,7 +71,8 @@ int dontshowdisplay = 0;
 
 /* Barchart scales. */
 static struct {
-    int max, interval;
+    double max;
+    int interval;
 } scale[] = {
         {      64000,     10 },     /* 64 kbit/s */
         {     128000,     10 },
@@ -105,7 +106,7 @@ static float get_max_bandwidth() {
 }
 
 /* rate in bits */
-static int get_bar_length(const int rate) {
+static int get_bar_length(const double rate) {
     float l;
     if (rate <= 0)
         return 0;
-- 
1.8.1


--------------080504060404020809090308
Content-Type: text/plain; charset=UTF-8; x-mac-type="0"; x-mac-creator="0";
 name="0002-scale-up-to-tbit.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="0002-scale-up-to-tbit.patch"

From: Hans Fugal <hans@fugal.net>
Date: Fri, 7 Mar 2014 13:22:18 -0800
Subject: [PATCH 2/3] scale[] up to tbit

Extend the scale[] array up to terabit. 10gbit is not uncommon,
100gbit 40 and 100 gbit are coming, 400 gbit and terabit are future
possibilities.
---
 ui.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/ui.c b/ui.c
index 8a3b9d0..d1500ad 100644
--- a/ui.c
+++ b/ui.c
@@ -74,13 +74,16 @@ static struct {
     double max;
     int interval;
 } scale[] = {
-        {      64000,     10 },     /* 64 kbit/s */
-        {     128000,     10 },
-        {     256000,     10 },
-        {    1000000,     10 },     /* 1 Mbit/s */
-        {   10000000,     10 },     
-        {  100000000,    100 },
-        { 1000000000,    100 }      /* 1 Gbit/s */
+        {         64000,     10 },     /* 64 kbit/s */
+        {        128000,     10 },
+        {        256000,     10 },
+        {       1000000,     10 },     /* 1 Mbit/s */
+        {      10000000,     10 },
+        {     100000000,    100 },
+        {    1000000000,    100 },     /* 1 Gbit/s */
+        {   10000000000,    100 },
+        {  100000000000,    100 },
+        { 1000000000000,    100 },     /* 1 Tbit/s */
     };
 static int rateidx = 0, wantbiggerrate;
 
-- 
1.8.1


--------------080504060404020809090308
Content-Type: text/plain; charset=UTF-8; x-mac-type="0"; x-mac-creator="0";
 name="0003-rateidx_init-fix.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="0003-rateidx_init-fix.patch"

From: Hans Fugal <hans@fugal.net>
Date: Fri, 7 Mar 2014 13:23:14 -0800
Subject: [PATCH 3/3] rateidx_init fix

When calculating the first rateidx, we were overshooting to the next
scale. Fix that.
---
 ui.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/ui.c b/ui.c
index d1500ad..15624bf 100644
--- a/ui.c
+++ b/ui.c
@@ -116,7 +116,8 @@ static int get_bar_length(const double rate) {
     if (rate > scale[rateidx].max) {
       wantbiggerrate = 1;
       if(! rateidx_init) {
-	while(rate > scale[rateidx_init++].max) {
+	while(rate > scale[rateidx_init].max) {
+          rateidx_init++;
 	}
 	rateidx = rateidx_init;
       }
-- 
1.8.1


--------------080504060404020809090308--