Page MenuHomeFreeBSD

Fix netstat -gs with ip_mroute module and/or vnet
ClosedPublic

Authored by karels on Nov 11 2019, 5:38 AM.

Details

Summary

The code for "netstat -gs -f inet" failed if the kernel namelist did not
include the _mrtstat symbol. However, that symbol is not in a standard
kernel even with the ip_mroute module loaded, where the functionality is
available. It is also not in a kernel with MROUTING but also VIMAGE, as
there can be multiple sets of stats. However, when running the command
on a live system, the symbol is not used; a sysctl is used. Go ahead
and try the sysctl in any case, and complain that IPv4 MROUTING is not
present only if the sysctl fails with ENOENT. Also fail if _mrtstat is
not defined when running on a core file; netstat doesn't know about vnets,
so can only work if MROUTING was included, and VIMAGE was not.

Test Plan

tested on amd64 with MROUTING in kernel and not, with and
without ip_mroute loaded.

Diff Detail

Repository
rS FreeBSD src repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

karels created this revision.Nov 11 2019, 5:38 AM
karels updated this revision to Diff 64166.Nov 11 2019, 5:46 AM

Fix parens

cem added a comment.Nov 11 2019, 5:58 AM

So this fixes a single live && MROUTING && VIMAGE case, but leaves the !live && MROUTING && VIMAGE case broken, with the same misleading print, as well as any other !live && VIMAGE code. It seems like a better solution might be teaching it about VIMAGE.

bz accepted this revision.Nov 11 2019, 4:48 PM

libkvm does know about VNETs (see kvm_private.c / kvm_vnet.c) as much as it knows about DPCPU. I seem to remember however it needs something selected, such as a PID or curthread from the dump, as it gets VNET information from there. This is probably something that should be generally fixed for netstat and not just for mrouting, though I am sure I tested that on a core dump back then. People may have broken it or the netstat parts were never merged.

This revision is now accepted and ready to land.Nov 11 2019, 4:48 PM

Conrad: this fixes a current problem with live systems, debugging a multicast problem. I am not aware of any requests to get multicast stats from a kernel core.

This revision was automatically updated to reflect the committed changes.