Author: glebius
Date: Mon Apr  6 22:12:18 2015
New Revision: 281172
URL: https://svnweb.freebsd.org/changeset/base/281172
Log:
  o Make net.inet6.ip6.mif6table return special API structure, that doesn't
    contain kernel pointers, and instead has interface index.
    Bump __FreeBSD_version for that change.
  o Now, netstat/mroute6.c no longer needs to kvm_read(3) struct ifnet, and
    no longer needs to include if_var.h
  
  Note that this change is far from being a complete move of IPv6 multicast
  routing to a proper API. Other structures are still dumped into their
  sysctls as is, requiring userland application to #define _KERNEL when
  including ip6_mroute.h and then call kvm_read(3) to gather all bits and
  pieces. But fixing this is out of scope of the opaque ifnet project.
  
  Sponsored by: Nginx, Inc.
  Sponsored by: Netflix

Modified:
  head/sys/netinet6/ip6_mroute.c
  head/sys/netinet6/ip6_mroute.h
  head/sys/sys/param.h
  head/usr.bin/netstat/mroute6.c
  head/usr.bin/netstat/netstat.1

Modified: head/sys/netinet6/ip6_mroute.c
==============================================================================
--- head/sys/netinet6/ip6_mroute.c      Mon Apr  6 21:51:55 2015        
(r281171)
+++ head/sys/netinet6/ip6_mroute.c      Mon Apr  6 22:12:18 2015        
(r281172)
@@ -196,9 +196,34 @@ static struct mtx mfc6_mtx;
 static u_char n6expire[MF6CTBLSIZ];
 
 static struct mif6 mif6table[MAXMIFS];
-SYSCTL_OPAQUE(_net_inet6_ip6, OID_AUTO, mif6table, CTLFLAG_RD,
-    &mif6table, sizeof(mif6table), "S,mif6[MAXMIFS]",
-    "IPv6 Multicast Interfaces (struct mif6[MAXMIFS], netinet6/ip6_mroute.h)");
+static int
+sysctl_mif6table(SYSCTL_HANDLER_ARGS)
+{
+       struct mif6_sctl *out;
+       int error;
+
+       out = malloc(sizeof(struct mif6_sctl) * MAXMIFS, M_TEMP, M_WAITOK);
+       for (int i = 0; i < MAXMIFS; i++) {
+               out[i].m6_flags         = mif6table[i].m6_flags;
+               out[i].m6_rate_limit    = mif6table[i].m6_rate_limit;
+               out[i].m6_lcl_addr      = mif6table[i].m6_lcl_addr;
+               if (mif6table[i].m6_ifp != NULL)
+                       out[i].m6_ifp   = mif6table[i].m6_ifp->if_index;
+               else
+                       out[i].m6_ifp   = 0;
+               out[i].m6_pkt_in        = mif6table[i].m6_pkt_in;
+               out[i].m6_pkt_out       = mif6table[i].m6_pkt_out;
+               out[i].m6_bytes_in      = mif6table[i].m6_bytes_in;
+               out[i].m6_bytes_out     = mif6table[i].m6_bytes_out;
+       }
+       error = SYSCTL_OUT(req, out, sizeof(struct mif6_sctl) * MAXMIFS);
+       free(out, M_TEMP);
+       return (error);
+}
+SYSCTL_PROC(_net_inet6_ip6, OID_AUTO, mif6table, CTLTYPE_OPAQUE | CTLFLAG_RD,
+    NULL, 0, sysctl_mif6table, "S,mif6_sctl[MAXMIFS]",
+    "IPv6 Multicast Interfaces (struct mif6_sctl[MAXMIFS], "
+    "netinet6/ip6_mroute.h)");
 
 static struct mtx mif6_mtx;
 #define        MIF6_LOCK()             mtx_lock(&mif6_mtx)

Modified: head/sys/netinet6/ip6_mroute.h
==============================================================================
--- head/sys/netinet6/ip6_mroute.h      Mon Apr  6 21:51:55 2015        
(r281171)
+++ head/sys/netinet6/ip6_mroute.h      Mon Apr  6 22:12:18 2015        
(r281172)
@@ -194,6 +194,20 @@ struct sioc_mif_req6 {
        u_quad_t obytes;        /* Output byte count on mif             */
 };
 
+/*
+ * Structure to export 'struct mif6' to userland via sysctl.
+ */
+struct mif6_sctl {
+       u_char          m6_flags;       /* MIFF_ flags defined above         */
+       u_int           m6_rate_limit;  /* max rate                          */
+       struct in6_addr m6_lcl_addr;    /* local interface address           */
+       uint32_t        m6_ifp;         /* interface index                   */
+       u_quad_t        m6_pkt_in;      /* # pkts in on interface            */
+       u_quad_t        m6_pkt_out;     /* # pkts out on interface           */
+       u_quad_t        m6_bytes_in;    /* # bytes in on interface           */
+       u_quad_t        m6_bytes_out;   /* # bytes out on interface          */
+};
+
 #if defined(_KERNEL) || defined(KERNEL)
 /*
  * The kernel's multicast-interface structure.

Modified: head/sys/sys/param.h
==============================================================================
--- head/sys/sys/param.h        Mon Apr  6 21:51:55 2015        (r281171)
+++ head/sys/sys/param.h        Mon Apr  6 22:12:18 2015        (r281172)
@@ -58,7 +58,7 @@
  *             in the range 5 to 9.
  */
 #undef __FreeBSD_version
-#define __FreeBSD_version 1100067      /* Master, propagated to newvers */
+#define __FreeBSD_version 1100068      /* Master, propagated to newvers */
 
 /*
  * __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,

Modified: head/usr.bin/netstat/mroute6.c
==============================================================================
--- head/usr.bin/netstat/mroute6.c      Mon Apr  6 21:51:55 2015        
(r281171)
+++ head/usr.bin/netstat/mroute6.c      Mon Apr  6 22:12:18 2015        
(r281172)
@@ -79,13 +79,11 @@ __FBSDID("$FreeBSD$");
 #include <sys/time.h>
 
 #include <net/if.h>
-#include <net/if_var.h>
 #include <net/route.h>
 
 #include <netinet/in.h>
 
 #include <err.h>
-#include <nlist.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -98,20 +96,6 @@ __FBSDID("$FreeBSD$");
 
 #include "netstat.h"
 
-/*
- * kvm(3) bindings for every needed symbol
- */
-static struct nlist mrl[] = {
-#define        N_MF6CTABLE     0
-       { .n_name = "_mf6ctable" },
-#define        N_MIF6TABLE     1
-       { .n_name = "_mif6table" },
-#define        N_MRT6STAT      2
-       { .n_name = "_mrt6stat" },
-       { .n_name = NULL },
-};
-
-
 #define        WID_ORG (Wflag ? 39 : (numeric_addr ? 29 : 18)) /* width of 
origin column */
 #define        WID_GRP (Wflag ? 18 : (numeric_addr ? 16 : 18)) /* width of 
group column */
 
@@ -119,11 +103,10 @@ void
 mroute6pr()
 {
        struct mf6c *mf6ctable[MF6CTBLSIZ], *mfcp;
-       struct mif6 mif6table[MAXMIFS];
+       struct mif6_sctl mif6table[MAXMIFS];
        struct mf6c mfc;
        struct rtdetq rte, *rtep;
-       struct mif6 *mifp;
-       u_long mfcaddr, mifaddr;
+       struct mif6_sctl *mifp;
        mifi_t mifi;
        int i;
        int banner_printed;
@@ -132,39 +115,26 @@ mroute6pr()
        long int waitings;
        size_t len;
 
-       kresolve_list(mrl);
-       mfcaddr = mrl[N_MF6CTABLE].n_value;
-       mifaddr = mrl[N_MIF6TABLE].n_value;
-
-       if (mfcaddr == 0 || mifaddr == 0) {
-               fprintf(stderr, "No IPv6 MROUTING kernel support.\n");
+       if (live == 0)
                return;
-       }
 
        len = sizeof(mif6table);
-       if (live) {
-               if (sysctlbyname("net.inet6.ip6.mif6table", mif6table, &len,
-                   NULL, 0) < 0) {
-                       xo_warn("sysctl: net.inet6.ip6.mif6table");
-                       return;
-               }
-       } else
-               kread(mifaddr, (char *)mif6table, sizeof(mif6table));
+       if (sysctlbyname("net.inet6.ip6.mif6table", mif6table, &len, NULL, 0) <
+           0) {
+               xo_warn("sysctl: net.inet6.ip6.mif6table");
+               return;
+       }
 
        saved_numeric_addr = numeric_addr;
        numeric_addr = 1;
        banner_printed = 0;
 
        for (mifi = 0, mifp = mif6table; mifi < MAXMIFS; ++mifi, ++mifp) {
-               struct ifnet ifnet;
                char ifname[IFNAMSIZ];
 
-               if (mifp->m6_ifp == NULL)
+               if (mifp->m6_ifp == 0)
                        continue;
 
-               /* XXX KVM */
-               kread((u_long)mifp->m6_ifp, (char *)&ifnet, sizeof(ifnet));
-
                maxmif = mifi;
                if (!banner_printed) {
                        xo_open_list("multicast-interface");
@@ -177,7 +147,7 @@ mroute6pr()
                xo_emit("  {:mif/%2u}   {:rate-limit/%4d}",
                    mifi, mifp->m6_rate_limit);
                xo_emit("   {:ifname/%5s}", (mifp->m6_flags & MIFF_REGISTER) ?
-                   "reg0" : if_indextoname(ifnet.if_index, ifname));
+                   "reg0" : if_indextoname(mifp->m6_ifp, ifname));
 
                xo_emit(" {:received-packets/%9ju}  {:sent-packets/%9ju}\n",
                    (uintmax_t)mifp->m6_pkt_in,
@@ -190,14 +160,11 @@ mroute6pr()
                xo_emit("\n{T:IPv6 Multicast Interface Table is empty}\n");
 
        len = sizeof(mf6ctable);
-       if (live) {
-               if (sysctlbyname("net.inet6.ip6.mf6ctable", mf6ctable, &len,
-                   NULL, 0) < 0) {
-                       xo_warn("sysctl: net.inet6.ip6.mf6ctable");
-                       return;
-               }
-       } else
-               kread(mfcaddr, (char *)mf6ctable, sizeof(mf6ctable));
+       if (sysctlbyname("net.inet6.ip6.mf6ctable", mf6ctable, &len, NULL, 0) <
+           0) {
+               xo_warn("sysctl: net.inet6.ip6.mf6ctable");
+               return;
+       }
 
        banner_printed = 0;
 
@@ -262,26 +229,14 @@ void
 mrt6_stats()
 {
        struct mrt6stat mrtstat;
-       u_long mstaddr;
        size_t len = sizeof mrtstat;
 
-       kresolve_list(mrl);
-       mstaddr = mrl[N_MRT6STAT].n_value;
-
-       if (mstaddr == 0) {
-               fprintf(stderr, "No IPv6 MROUTING kernel support.\n");
+       if (sysctlbyname("net.inet6.ip6.mrt6stat", &mrtstat, &len, NULL, 0) <
+           0) {
+               xo_warn("sysctl: net.inet6.ip6.mrt6stat");
                return;
        }
 
-       if (live) {
-               if (sysctlbyname("net.inet6.ip6.mrt6stat", &mrtstat, &len,
-                   NULL, 0) < 0) {
-                       xo_warn("sysctl: net.inet6.ip6.mrt6stat");
-                       return;
-               }
-       } else
-               kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat));
-
        xo_open_container("multicast-statistics");
        xo_emit("{T:IPv6 multicast forwarding}:\n");
 

Modified: head/usr.bin/netstat/netstat.1
==============================================================================
--- head/usr.bin/netstat/netstat.1      Mon Apr  6 21:51:55 2015        
(r281171)
+++ head/usr.bin/netstat/netstat.1      Mon Apr  6 22:12:18 2015        
(r281172)
@@ -28,7 +28,7 @@
 .\"    @(#)netstat.1   8.8 (Berkeley) 4/18/94
 .\" $FreeBSD$
 .\"
-.Dd February 21, 2015
+.Dd April 7, 2015
 .Dt NETSTAT 1
 .Os
 .Sh NAME
@@ -92,8 +92,6 @@
 .Op Fl -libxo
 .Op Fl 46W
 .Op Fl f Ar address_family
-.Op Fl M Ar core
-.Op Fl N Ar system
 .It Nm Fl gs
 .Op Fl -libxo
 .Op Fl 46s
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to