dankamongmen / libnetstack

Small library around rtnetlink to track networking stack elements
https://nick-black.com/dankwiki/index.php/Libnetstack
Apache License 2.0
10 stars 0 forks source link

stats aren't getting updated with call to refresh #55

Open dankamongmen opened 1 year ago

dankamongmen commented 1 year ago

despite calling netstack_refresh_stats(), subsequent calls to netstack_iface_stats() always return the same stats we got when we initialized.

dankamongmen commented 1 year ago

watching strace(), it does seem that we fire off the RTM_GETLINK message and even get IFLA_STATS64 in response. i bet the issue is that we drop messages for known ifaces, which would have all kinds of problems (won't pick up new MTU, etc.)

dankamongmen commented 1 year ago

it looks like iface_create() just whips up a new iface for every NEW message it sees...seriously? indeed, the iface_count stat goes up by a constant amount each iteration. oy vey!

dankamongmen commented 1 year ago

it looks like in iface_cb() we replace the existing entry in the nametrie, but we never remove the item from the iface_hash. we always insert the new iface at the head of the hash chain, so all lookups find the new one. we're of course holding a local reference to the netstack_iface. so i think what we need do is check for an existing item when we go to add into the name trie, and update that item rather than replacing it? and then free the new item.

we can't just replace the old with the new, because someone might have a handle on it. though how do we handle locking in that case?