wifidog / wifidog-gateway

Repository for the wifidog-gateway captive portal designed for embedded systems
GNU General Public License v2.0
760 stars 320 forks source link

Delta traffic stats #192

Open t123yh opened 9 years ago

t123yh commented 9 years ago

I'm creating a hotspot that charges by the user's traffic. I've been writting a web authentication system based on ASP.NET MVC, but I've found that I cannot stat the traffic on each /auth/ action because the incoming and outgoing values won't be resetted to zero on each report. Could you please tell me where can I modify the code that it can let the traffic statistic be automatically reseted to zero? Or could you please add a section to the configuration file that controls it? Thanks a lot!

acv commented 9 years ago

In a way, that'd be unfair because if there's no traffic, the gateway will create some (it pings the user.)

That said, if you keep track of the previous value sent in the connection, you can sub from it from new values and get only the delta.

Adding delta stats is possible, the gateway keeps around most of the required information. The code that sends the stats is in src/firewall.c at:

https://github.com/wifidog/wifidog-gateway/blob/master/src/firewall.c#L287-L290

You would need to add two new counters to the t_counters type (https://github.com/wifidog/wifidog-gateway/blob/master/src/client_list.h#L36-L42) and also change the counters update code in:

https://github.com/wifidog/wifidog-gateway/blob/master/src/fw_iptables.c#L628-L725

acv commented 9 years ago

A patch would be considered for merging if it did that only optionally based on a config file directive.

t123yh commented 9 years ago

Awesome! Many thanks.