The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/net/if_mib.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*
    2  * Copyright 1996 Massachusetts Institute of Technology
    3  *
    4  * Permission to use, copy, modify, and distribute this software and
    5  * its documentation for any purpose and without fee is hereby
    6  * granted, provided that both the above copyright notice and this
    7  * permission notice appear in all copies, that both the above
    8  * copyright notice and this permission notice appear in all
    9  * supporting documentation, and that the name of M.I.T. not be used
   10  * in advertising or publicity pertaining to distribution of the
   11  * software without specific, written prior permission.  M.I.T. makes
   12  * no representations about the suitability of this software for any
   13  * purpose.  It is provided "as is" without express or implied
   14  * warranty.
   15  * 
   16  * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''.  M.I.T. DISCLAIMS
   17  * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
   18  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
   19  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
   20  * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   23  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   25  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   26  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   27  * SUCH DAMAGE.
   28  *
   29  * $FreeBSD: src/sys/net/if_mib.c,v 1.8.2.1 2000/08/03 00:09:34 ps Exp $
   30  * $DragonFly: src/sys/net/if_mib.c,v 1.7 2005/06/15 19:29:30 joerg Exp $
   31  */
   32 
   33 #include <sys/param.h>
   34 #include <sys/systm.h>
   35 #include <sys/kernel.h>
   36 #include <sys/socket.h>
   37 #include <sys/sysctl.h>
   38 
   39 #include <net/if.h>
   40 #include <net/if_mib.h>
   41 
   42 /*
   43  * A sysctl(3) MIB for generic interface information.  This information
   44  * is exported in the net.link.generic branch, which has the following
   45  * structure:
   46  *
   47  * net.link.generic     .system                 - system-wide control variables
   48  *                                                and statistics (node)
   49  *                      .ifdata.<ifindex>.general
   50  *                                              - what's in `struct ifdata'
   51  *                                                plus some other info
   52  *                      .ifdata.<ifindex>.linkspecific
   53  *                                              - a link-type-specific data
   54  *                                                structure (as might be used
   55  *                                                by an SNMP agent
   56  *
   57  * Perhaps someday we will make addresses accessible via this interface
   58  * as well (then there will be four such...).  The reason that the
   59  * index comes before the last element in the name is because it
   60  * seems more orthogonal that way, particularly with the possibility
   61  * of other per-interface data living down here as well (e.g., integrated
   62  * services stuff).
   63  */
   64 
   65 SYSCTL_DECL(_net_link_generic);
   66 SYSCTL_NODE(_net_link_generic, IFMIB_SYSTEM, system, CTLFLAG_RW, 0,
   67             "Variables global to all interfaces");
   68 SYSCTL_INT(_net_link_generic_system, IFMIB_IFCOUNT, ifcount, CTLFLAG_RD,
   69            &if_index, 0, "Number of configured interfaces");
   70 
   71 static int
   72 sysctl_ifdata(SYSCTL_HANDLER_ARGS) /* XXX bad syntax! */
   73 {
   74         int *name = (int *)arg1;
   75         int error;
   76         u_int namelen = arg2;
   77         struct ifnet *ifp;
   78         struct ifmibdata ifmd;
   79 
   80         if (namelen != 2)
   81                 return EINVAL;
   82 
   83         crit_enter();
   84         if (name[0] <= 0 || name[0] > if_index ||
   85             ifindex2ifnet[name[0]] == NULL) {
   86                 crit_exit();
   87                 return ENOENT;
   88         }
   89 
   90         ifp = ifindex2ifnet[name[0]];
   91         crit_exit();
   92 
   93         switch(name[1]) {
   94         default:
   95                 return ENOENT;
   96 
   97         case IFDATA_GENERAL:
   98                 bzero(&ifmd, sizeof(ifmd));
   99                 strlcpy(ifmd.ifmd_name, ifp->if_xname, sizeof(ifmd.ifmd_name));
  100 
  101 #define COPY(fld) ifmd.ifmd_##fld = ifp->if_##fld
  102                 COPY(pcount);
  103                 COPY(flags);
  104                 COPY(data);
  105 #undef COPY
  106 #define COPY_DATA(name) IFNET_STAT_GET(ifp, name, ifmd.ifmd_data.ifi_##name)
  107                 COPY_DATA(ipackets);
  108                 COPY_DATA(ierrors);
  109                 COPY_DATA(opackets);
  110                 COPY_DATA(oerrors);
  111                 COPY_DATA(collisions);
  112                 COPY_DATA(ibytes);
  113                 COPY_DATA(obytes);
  114                 COPY_DATA(imcasts);
  115                 COPY_DATA(omcasts);
  116                 COPY_DATA(iqdrops);
  117                 COPY_DATA(noproto);
  118 #undef COPY_DATA
  119 
  120                 ifmd.ifmd_snd_maxlen = ifp->if_snd.altq_maxlen;
  121 #ifdef notyet
  122                 ifmd.ifmd_snd_len = ifp->if_snd.ifq_len;
  123                 ifmd.ifmd_snd_drops = ifp->if_snd.ifq_drops;
  124 #endif
  125 
  126                 error = SYSCTL_OUT(req, &ifmd, sizeof ifmd);
  127                 if (error || !req->newptr)
  128                         return error;
  129 
  130                 error = SYSCTL_IN(req, &ifmd, sizeof ifmd);
  131                 if (error)
  132                         return error;
  133 
  134 #define DONTCOPY(fld) ifmd.ifmd_data.ifi_##fld = ifp->if_data.ifi_##fld
  135                 DONTCOPY(type);
  136                 DONTCOPY(physical);
  137                 DONTCOPY(addrlen);
  138                 DONTCOPY(hdrlen);
  139                 DONTCOPY(mtu);
  140                 DONTCOPY(metric);
  141                 DONTCOPY(baudrate);
  142 #undef DONTCOPY
  143 #define COPY(fld) ifp->if_##fld = ifmd.ifmd_##fld
  144                 COPY(data);
  145 #undef COPY
  146 #define COPY_DATA(name) IFNET_STAT_SET(ifp, name, ifmd.ifmd_data.ifi_##name)
  147                 COPY_DATA(ipackets);
  148                 COPY_DATA(ierrors);
  149                 COPY_DATA(opackets);
  150                 COPY_DATA(oerrors);
  151                 COPY_DATA(collisions);
  152                 COPY_DATA(ibytes);
  153                 COPY_DATA(obytes);
  154                 COPY_DATA(imcasts);
  155                 COPY_DATA(omcasts);
  156                 COPY_DATA(iqdrops);
  157                 COPY_DATA(noproto);
  158 #undef COPY_DATA
  159 
  160 #ifdef notyet
  161                 ifp->if_snd.ifq_maxlen = ifmd.ifmd_snd_maxlen;
  162                 ifp->if_snd.ifq_drops = ifmd.ifmd_snd_drops;
  163 #endif
  164                 break;
  165 
  166         case IFDATA_LINKSPECIFIC:
  167                 error = SYSCTL_OUT(req, ifp->if_linkmib, ifp->if_linkmiblen);
  168                 if (error || !req->newptr)
  169                         return error;
  170 
  171                 error = SYSCTL_IN(req, ifp->if_linkmib, ifp->if_linkmiblen);
  172                 if (error)
  173                         return error;
  174                 
  175         }
  176         return 0;
  177 }
  178 
  179 SYSCTL_NODE(_net_link_generic, IFMIB_IFDATA, ifdata, CTLFLAG_RW,
  180             sysctl_ifdata, "Interface table");
  181 

Cache object: 47e76776455b16d4ef0097526bf5cf2d


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.