Bug 301546 - Wrong traffic reported on FreeBSD
Summary: Wrong traffic reported on FreeBSD
Status: RESOLVED UNMAINTAINED
Alias: None
Product: knemo
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: FreeBSD Ports FreeBSD
: NOR major
Target Milestone: ---
Assignee: John Stamp
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-06-10 02:38 UTC by Alberto Villa
Modified: 2018-10-29 22:09 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
Fix to the issue. (2.24 KB, patch)
2012-06-10 02:41 UTC, Alberto Villa
Details
New patch with fix for the multiple IPs bug (3.18 KB, patch)
2012-06-10 21:05 UTC, Alberto Villa
Details
Fix for the "always active" regression (3.19 KB, patch)
2012-06-10 21:33 UTC, Alberto Villa
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alberto Villa 2012-06-10 02:38:56 UTC
Network traffic is reported to send and receive the total sent and received bytes *per second*, e.g.:

Download speed: 501,7 MiB/s
Upload speed: 52,6 MiB/s

This happens because interfaces appear twice in struct ifaddrs, first as AF_LINK and then as AF_INET.

Now, the AF_INET one has a lower amount of sent and received bytes, as shown by the output of a test program I wrote:

interface:              wlan0
level:                  data link
received packets:       547021
sent packets:           430088
received bytes:         509.2 MiB
sent bytes:             58.4 MiB

interface:              wlan0
level:                  network
received packets:       543989
sent packets:           428187
received bytes:         501.7 MiB
sent bytes:             52.6 MiB

Both interfaces call incBytes() with their respective byte values, which triggers incBytes() overflow detection bits.

I'm attaching a patch which solves the issue. Packets and bytes statistics are moved to AF_INET section, while other statistics are kept in the top level as they're reported by the AF_LINK interface (but there's no reason to move them down to its section).

Reproducible: Always




While here, I'm also fixing a wrong assignment (s/==/=/) and a Yoda condition.
Comment 1 Alberto Villa 2012-06-10 02:41:45 UTC
Created attachment 71692 [details]
Fix to the issue.
Comment 2 Alberto Villa 2012-06-10 21:05:54 UTC
Created attachment 71708 [details]
New patch with fix for the multiple IPs bug

The same bug happens when multiple IP addresses are assigned to an interface, as this creates another entry in the list, and overflow check can be triggered:

interface:              wlan0
level:                  network
received packets:       338529
sent packets:           286606
received bytes:         291.2 MiB
sent bytes:             38.7 MiB

interface:              wlan0
level:                  network
received packets:       0
sent packets:           0
received bytes:         0.0 MiB
sent bytes:             0.0 MiB

This new patch fixes this issue by calculating a sum of the bytes and packets of all network-level interfaces and then calling incBytes() after the for() cycle. Overflow of the sum is correctly caught by the incBytes() function.
Comment 3 Alberto Villa 2012-06-10 21:33:52 UTC
Created attachment 71713 [details]
Fix for the "always active" regression

Sorry, the attached patch introduced a regression which resets prevRxPackets and prevTxPackets on every update() call, thus making the interface think to be always receiving and sending data. The attached patch fixes it.
Comment 4 John Stamp 2012-06-11 19:20:53 UTC
Thank you for taking the time to work on this (and bug 301557).  I'll take a look at them and commit soon.
Comment 5 John Stamp 2012-06-12 02:18:10 UTC
SVN commit 1299925 by jstamp:

Fix wrong traffic reported on FreeBSD

Kudos to Alberto Villa for the patch.


 M  +25 -14    bsdbackend.cpp  


WebSVN link: http://websvn.kde.org/?view=rev&revision=1299925
Comment 6 Andrew Crouthamel 2018-10-29 22:09:33 UTC
Hello! Sorry to be the bearer of bad news, but this project has been unmaintained for many years so I will be closing this bug.