summaryrefslogtreecommitdiffstats
path: root/usr.bin/netstat
diff options
context:
space:
mode:
authorbms <bms@FreeBSD.org>2007-02-24 21:58:30 +0000
committerbms <bms@FreeBSD.org>2007-02-24 21:58:30 +0000
commit79da54db6260784340c97d4f6f8f1ba325cfe3df (patch)
tree53e9b09a92cfbfea75ddc658e17f0fcf24c6d1a3 /usr.bin/netstat
parent03b57a9ea62a2cc2130505ef43db5283e2385515 (diff)
downloadFreeBSD-src-79da54db6260784340c97d4f6f8f1ba325cfe3df.zip
FreeBSD-src-79da54db6260784340c97d4f6f8f1ba325cfe3df.tar.gz
Use sysctl(2), not kvm(3), to read IPv6 multicast information from
the running system. Use the name 'IPv6 Forwarding Table', not 'IPv6 Routing Table', to be consistent with what the code actually does and is.
Diffstat (limited to 'usr.bin/netstat')
-rw-r--r--usr.bin/netstat/inet6.c15
-rw-r--r--usr.bin/netstat/mroute6.c66
2 files changed, 60 insertions, 21 deletions
diff --git a/usr.bin/netstat/inet6.c b/usr.bin/netstat/inet6.c
index f652697..7b4f54d 100644
--- a/usr.bin/netstat/inet6.c
+++ b/usr.bin/netstat/inet6.c
@@ -66,6 +66,7 @@ __FBSDID("$FreeBSD$");
#include <arpa/inet.h>
#include <netdb.h>
+#include <err.h>
#include <stdint.h>
#include <stdio.h>
#include <errno.h>
@@ -995,12 +996,18 @@ icmp6_ifstats(char *ifname)
void
pim6_stats(u_long off __unused, const char *name, int af1 __unused)
{
- struct pim6stat pim6stat;
+ struct pim6stat pim6stat, zerostat;
+ size_t len = sizeof pim6stat;
- if (off == 0)
- return;
- if (kread(off, (char *)&pim6stat, sizeof(pim6stat)))
+ /* TODO put back the KVM functionality for -M switch ie coredumps. */
+ if (zflag)
+ memset(&zerostat, 0, len);
+ if (sysctlbyname("net.inet6.pim.stats", &pim6stat, &len,
+ zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
+ if (errno != ENOENT)
+ warn("sysctl: net.inet6.pim.stats");
return;
+ }
printf("%s:\n", name);
#define p(f, m) if (pim6stat.f || sflag <= 1) \
diff --git a/usr.bin/netstat/mroute6.c b/usr.bin/netstat/mroute6.c
index d23ba97..f071b5b 100644
--- a/usr.bin/netstat/mroute6.c
+++ b/usr.bin/netstat/mroute6.c
@@ -74,7 +74,10 @@ __FBSDID("$FreeBSD$");
#include <sys/queue.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
+#include <sys/sysctl.h>
#include <sys/protosw.h>
+#include <sys/mbuf.h>
+#include <sys/time.h>
#include <net/if.h>
#include <net/if_var.h>
@@ -82,8 +85,10 @@ __FBSDID("$FreeBSD$");
#include <netinet/in.h>
+#include <err.h>
#include <stdint.h>
#include <stdio.h>
+#include <stdlib.h>
#define KERNEL 1
#include <netinet6/ip6_mroute.h>
@@ -108,19 +113,24 @@ mroute6pr(u_long mfcaddr, u_long mifaddr)
int saved_numeric_addr;
mifi_t maxmif = 0;
long int waitings;
+ size_t len;
- /* XXX: sysctl not yet implemented for mif6table. */
- if (mfcaddr == 0 || mifaddr == 0) {
- printf("No IPv6 multicast forwarding configured in the "
- "running system.\n");
- return;
+ len = sizeof(mif6table);
+ if (sysctlbyname("net.inet6.ip6.mif6table", mif6table, &len,
+ NULL, 0) < 0) {
+ warn("sysctl: net.inet6.ip6.mif6table");
+ if (mifaddr == 0) {
+ printf("No IPv6 multicast forwarding configured in "
+ "the running system.\n");
+ return;
+ }
+ kread(mifaddr, (char *)mif6table, sizeof(mif6table));
}
saved_numeric_addr = numeric_addr;
numeric_addr = 1;
-
- kread(mifaddr, (char *)&mif6table, sizeof(mif6table));
banner_printed = 0;
+
for (mifi = 0, mifp = mif6table; mifi < MAXMIFS; ++mifi, ++mifp) {
struct ifnet ifnet;
char ifname[IFNAMSIZ];
@@ -128,7 +138,9 @@ mroute6pr(u_long mfcaddr, u_long mifaddr)
if (mifp->m6_ifp == NULL)
continue;
+ /* XXX KVM */
kread((u_long)mifp->m6_ifp, (char *)&ifnet, sizeof(ifnet));
+
maxmif = mifi;
if (!banner_printed) {
printf("\nIPv6 Multicast Interface Table\n"
@@ -148,9 +160,25 @@ mroute6pr(u_long mfcaddr, u_long mifaddr)
if (!banner_printed)
printf("\nIPv6 Multicast Interface Table is empty\n");
- /* XXX: sysctl not yet implemented for mf6ctable. */
- kread(mfcaddr, (char *)&mf6ctable, sizeof(mf6ctable));
+ len = sizeof(mf6ctable);
+ if (sysctlbyname("net.inet6.ip6.mf6ctable", mf6ctable, &len,
+ NULL, 0) < 0) {
+ warn("sysctl: net.inet6.ip6.mf6ctable");
+ if (mfcaddr == 0) {
+ printf("No IPv6 multicast forwarding configured in "
+ "the running system.\n");
+ return;
+ }
+ /*
+ * XXX: Try KVM if the module is neither compiled nor loaded.
+ * The correct behaviour would be to always use KVM if
+ * the -M option is specified to netstat(1).
+ */
+ kread(mfcaddr, (char *)mf6ctable, sizeof(mf6ctable));
+ }
+
banner_printed = 0;
+
for (i = 0; i < MF6CTBLSIZ; ++i) {
mfcp = mf6ctable[i];
while(mfcp) {
@@ -172,6 +200,7 @@ mroute6pr(u_long mfcaddr, u_long mifaddr)
for (waitings = 0, rtep = mfc.mf6c_stall; rtep; ) {
waitings++;
+ /* XXX KVM */
kread((u_long)rtep, (char *)&rte, sizeof(rte));
rtep = rte.next;
}
@@ -191,7 +220,7 @@ mroute6pr(u_long mfcaddr, u_long mifaddr)
}
}
if (!banner_printed)
- printf("\nIPv6 Multicast Routing Table is empty\n");
+ printf("\nIPv6 Multicast Forwarding Table is empty\n");
printf("\n");
numeric_addr = saved_numeric_addr;
@@ -201,15 +230,18 @@ void
mrt6_stats(u_long mstaddr)
{
struct mrt6stat mrtstat;
+ size_t len = sizeof mrtstat;
- /* XXX: sysctl not yet implemented for mrt6stat. */
- if (mstaddr == 0) {
- printf("No IPv6 multicast forwarding configured in the "
- "running system.\n");
- return;
+ if (sysctlbyname("net.inet6.ip6.mrt6stat", &mrtstat, &len,
+ NULL, 0) < 0) {
+ warn("sysctl: net.inet6.ip6.mrt6stat");
+ if (mstaddr == 0) {
+ printf("No IPv6 multicast forwarding configured in the "
+ "running system.\n");
+ return;
+ }
+ kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat));
}
-
- kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat));
printf("IPv6 multicast forwarding:\n");
#define p(f, m) if (mrtstat.f || sflag <= 1) \
OpenPOWER on IntegriCloud