[PATCH iwinfo] lib: report byte counters as 64 bit values

Thomas Weißschuh thomas at t-8ch.de
Fri Jun 23 09:50:58 PDT 2023


+Cc a few devs that have worked on iwinfo recently.


Hi,

could somebody take a look my patches [0] to fix an overflow of
per-association packet counters after two GiB [1]?

Thanks,
Thomas

[0] https://lists.openwrt.org/pipermail/openwrt-devel/2023-May/041056.html
    https://lists.openwrt.org/pipermail/openwrt-devel/2023-May/041096.html
    https://lists.openwrt.org/pipermail/openwrt-devel/2023-May/041055.html
[1] https://github.com/openwrt/luci/issues/6210

On 2023-05-15 16:54:27+0200, Thomas Weißschuh wrote:
> The 32bit counter can only count to 4GiB before wrapping.
> Switching to the 64bit variant avoids this issue.
> 
> In practice some users are interpreting the counter values as signed
> integer bringing down the usable range for 32bit values down to only
> 2GiB.
> 
> Signed-off-by: Thomas Weißschuh <thomas at t-8ch.de>
> ---
>  include/iwinfo.h |  4 ++--
>  iwinfo_nl80211.c | 12 ++++++++++--
>  2 files changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/include/iwinfo.h b/include/iwinfo.h
> index eae99302704a..b50de69f49ca 100644
> --- a/include/iwinfo.h
> +++ b/include/iwinfo.h
> @@ -240,8 +240,8 @@ struct iwinfo_assoclist_entry {
>  	uint64_t rx_drop_misc;
>  	struct iwinfo_rate_entry rx_rate;
>  	struct iwinfo_rate_entry tx_rate;
> -	uint32_t rx_bytes;
> -	uint32_t tx_bytes;
> +	uint64_t rx_bytes;
> +	uint64_t tx_bytes;
>  	uint32_t tx_retries;
>  	uint32_t tx_failed;
>  	uint64_t t_offset;
> diff --git a/iwinfo_nl80211.c b/iwinfo_nl80211.c
> index 50bb8f03c2fd..1e0a0c77dc39 100644
> --- a/iwinfo_nl80211.c
> +++ b/iwinfo_nl80211.c
> @@ -1554,6 +1554,8 @@ static int nl80211_fill_signal_cb(struct nl_msg *msg, void *arg)
>  		[NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32    },
>  		[NL80211_STA_INFO_RX_BYTES]      = { .type = NLA_U32    },
>  		[NL80211_STA_INFO_TX_BYTES]      = { .type = NLA_U32    },
> +		[NL80211_STA_INFO_RX_BYTES64]    = { .type = NLA_U64    },
> +		[NL80211_STA_INFO_TX_BYTES64]    = { .type = NLA_U64    },
>  		[NL80211_STA_INFO_RX_PACKETS]    = { .type = NLA_U32    },
>  		[NL80211_STA_INFO_TX_PACKETS]    = { .type = NLA_U32    },
>  		[NL80211_STA_INFO_SIGNAL]        = { .type = NLA_U8     },
> @@ -2214,6 +2216,8 @@ static int nl80211_get_assoclist_cb(struct nl_msg *msg, void *arg)
>  		[NL80211_STA_INFO_SIGNAL_AVG]    = { .type = NLA_U8     },
>  		[NL80211_STA_INFO_RX_BYTES]      = { .type = NLA_U32    },
>  		[NL80211_STA_INFO_TX_BYTES]      = { .type = NLA_U32    },
> +		[NL80211_STA_INFO_RX_BYTES64]    = { .type = NLA_U64    },
> +		[NL80211_STA_INFO_TX_BYTES64]    = { .type = NLA_U64    },
>  		[NL80211_STA_INFO_TX_RETRIES]    = { .type = NLA_U32    },
>  		[NL80211_STA_INFO_TX_FAILED]     = { .type = NLA_U32    },
>  		[NL80211_STA_INFO_CONNECTED_TIME]= { .type = NLA_U32    },
> @@ -2277,10 +2281,14 @@ static int nl80211_get_assoclist_cb(struct nl_msg *msg, void *arg)
>  		                      sinfo[NL80211_STA_INFO_TX_BITRATE], rate_policy))
>  			nl80211_parse_rateinfo(rinfo, &e->tx_rate);
>  
> -		if (sinfo[NL80211_STA_INFO_RX_BYTES])
> +		if (sinfo[NL80211_STA_INFO_RX_BYTES64])
> +			e->rx_bytes = nla_get_u64(sinfo[NL80211_STA_INFO_RX_BYTES64]);
> +		else if (sinfo[NL80211_STA_INFO_RX_BYTES])
>  			e->rx_bytes = nla_get_u32(sinfo[NL80211_STA_INFO_RX_BYTES]);
>  
> -		if (sinfo[NL80211_STA_INFO_TX_BYTES])
> +		if (sinfo[NL80211_STA_INFO_TX_BYTES64])
> +			e->tx_bytes = nla_get_u64(sinfo[NL80211_STA_INFO_TX_BYTES64]);
> +		else if (sinfo[NL80211_STA_INFO_TX_BYTES])
>  			e->tx_bytes = nla_get_u32(sinfo[NL80211_STA_INFO_TX_BYTES]);
>  
>  		if (sinfo[NL80211_STA_INFO_TX_RETRIES])
> 
> base-commit: b3888b29535a92584524e14aadf25fcb85e7fed2
> -- 
> 2.40.1
> 



More information about the openwrt-devel mailing list