summaryrefslogtreecommitdiffstats
path: root/usr.bin/netstat/sctp.c
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2007-07-16 17:15:55 +0000
committerjhb <jhb@FreeBSD.org>2007-07-16 17:15:55 +0000
commit27187e7f6bd04a94e9ada0ca994e7c828abb4514 (patch)
tree165174828db97bceab2299030940226f1b6620cf /usr.bin/netstat/sctp.c
parent5a67dd7c20118e6593c9e3904b775b2274c2757b (diff)
downloadFreeBSD-src-27187e7f6bd04a94e9ada0ca994e7c828abb4514.zip
FreeBSD-src-27187e7f6bd04a94e9ada0ca994e7c828abb4514.tar.gz
Restore netstat -M functionality for most statistics on core dumps. In
general, when support was added to netstat for fetching data using sysctl, no provision was left for fetching equivalent data from a core dump, and in fact, netstat would _always_ fetch data from the live kernel using sysctl even when -M was specified resulting in the user believing they were getting data from coredumps when they actually weren't. Some specific changes: - Add a global 'live' variable that is true if netstat is running against the live kernel and false if -M has been specified. - Stop abusing the sysctl flag in the protocol tables to hold the protocol number. Instead, the protocol is now its own field in the tables, and it is passed as a separate parameter to the PCB and stat routines rather than overloading the KVM offset parameter. - Don't run PCB or stats functions who don't have a namelist offset if we are being run against a crash dump (!live). - For the inet and unix PCB routines, we generate the same buffer from KVM that the sysctl usually generates complete with the header and trailer. - Don't run bpf stats for !live (before it would just silently always run live). - kread() no longer trashes memory when opening the buffer if there is an error on open and the passed in buffer is smaller than _POSIX2_LINE_MAX. - The multicast routing code doesn't fallback to kvm on live kernels if the sysctl fails. Keeping this made the code rather hairy, and netstat is already tied to the kernel ABI anyway (even when using sysctl's since things like xinpcb contain an inpcb) so any kernels this is run against that have the multicast routing stuff should have the sysctls. - Don't try to dig around in the kernel linker in the netgraph PCB routine for core dumps. Other notes: - sctp's PCB routine only works on live kernels, it looked rather complicated to generate all the same stuff via KVM. Someone can always add it later if desired though. - Fix the ipsec removal bug where N_xxx for IPSEC stats weren't renumbered. - Use sysctlbyname() everywhere rather than hardcoded mib values. MFC after: 1 week Approved by: re (rwatson)
Diffstat (limited to 'usr.bin/netstat/sctp.c')
-rw-r--r--usr.bin/netstat/sctp.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/usr.bin/netstat/sctp.c b/usr.bin/netstat/sctp.c
index b3038d3..feb9a25 100644
--- a/usr.bin/netstat/sctp.c
+++ b/usr.bin/netstat/sctp.c
@@ -432,8 +432,8 @@ sctp_process_inpcb(struct xsctp_inpcb *xinpcb, const char *name,
* protocol.
*/
void
-sctp_protopr(u_long proto,
- const char *name, int af1)
+sctp_protopr(u_long off __unused,
+ const char *name, int af1, int proto)
{
char *buf;
const char *mibvar = "net.inet.sctp.assoclist";
@@ -511,18 +511,21 @@ sctp_statesprint(uint32_t state)
* Dump SCTP statistics structure.
*/
void
-sctp_stats(u_long off __unused, const char *name, int af1 __unused)
+sctp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
{
struct sctpstat sctpstat, zerostat;
size_t len = sizeof(sctpstat);
- if (zflag)
- memset(&zerostat, 0, len);
- if (sysctlbyname("net.inet.sctp.stats", &sctpstat, &len,
- zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
- warn("sysctl: net.inet.sctp.stats");
- return;
- }
+ if (live) {
+ if (zflag)
+ memset(&zerostat, 0, len);
+ if (sysctlbyname("net.inet.sctp.stats", &sctpstat, &len,
+ zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
+ warn("sysctl: net.inet.sctp.stats");
+ return;
+ }
+ } else
+ kread(off, &sctpstat, len);
printf ("%s:\n", name);
OpenPOWER on IntegriCloud