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-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
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.13.4.2 2005/05/06 02:50:00 cperciva Exp $
   30  */
   31 
   32 #include <sys/param.h>
   33 #include <sys/systm.h>
   34 #include <sys/kernel.h>
   35 #include <sys/socket.h>
   36 #include <sys/sysctl.h>
   37 
   38 #include <net/if.h>
   39 #include <net/if_mib.h>
   40 
   41 /*
   42  * A sysctl(3) MIB for generic interface information.  This information
   43  * is exported in the net.link.generic branch, which has the following
   44  * structure:
   45  *
   46  * net.link.generic     .system                 - system-wide control variables
   47  *                                                and statistics (node)
   48  *                      .ifdata.<ifindex>.general
   49  *                                              - what's in `struct ifdata'
   50  *                                                plus some other info
   51  *                      .ifdata.<ifindex>.linkspecific
   52  *                                              - a link-type-specific data
   53  *                                                structure (as might be used
   54  *                                                by an SNMP agent
   55  *
   56  * Perhaps someday we will make addresses accessible via this interface
   57  * as well (then there will be four such...).  The reason that the
   58  * index comes before the last element in the name is because it
   59  * seems more orthogonal that way, particularly with the possibility
   60  * of other per-interface data living down here as well (e.g., integrated
   61  * services stuff).
   62  */
   63 
   64 SYSCTL_DECL(_net_link_generic);
   65 SYSCTL_NODE(_net_link_generic, IFMIB_SYSTEM, system, CTLFLAG_RW, 0,
   66             "Variables global to all interfaces");
   67 SYSCTL_INT(_net_link_generic_system, IFMIB_IFCOUNT, ifcount, CTLFLAG_RD,
   68            &if_index, 0, "Number of configured interfaces");
   69 
   70 static int
   71 sysctl_ifdata(SYSCTL_HANDLER_ARGS) /* XXX bad syntax! */
   72 {
   73         int *name = (int *)arg1;
   74         int error;
   75         u_int namelen = arg2;
   76         struct ifnet *ifp;
   77         struct ifmibdata ifmd;
   78 
   79         if (namelen != 2)
   80                 return EINVAL;
   81 
   82         if (name[0] <= 0 || name[0] > if_index ||
   83             ifaddr_byindex(name[0]) == NULL)
   84                 return ENOENT;
   85 
   86         ifp = ifaddr_byindex(name[0])->ifa_ifp;
   87 
   88         switch(name[1]) {
   89         default:
   90                 return ENOENT;
   91 
   92         case IFDATA_GENERAL:
   93                 bzero(&ifmd, sizeof(ifmd));
   94                 strlcpy(ifmd.ifmd_name, ifp->if_xname, sizeof(ifmd.ifmd_name));
   95 
   96 #define COPY(fld) ifmd.ifmd_##fld = ifp->if_##fld
   97                 COPY(pcount);
   98                 COPY(flags);
   99                 COPY(data);
  100 #undef COPY
  101                 ifmd.ifmd_snd_len = ifp->if_snd.ifq_len;
  102                 ifmd.ifmd_snd_maxlen = ifp->if_snd.ifq_maxlen;
  103                 ifmd.ifmd_snd_drops = ifp->if_snd.ifq_drops;
  104 
  105                 error = SYSCTL_OUT(req, &ifmd, sizeof ifmd);
  106                 if (error || !req->newptr)
  107                         return error;
  108 
  109                 error = SYSCTL_IN(req, &ifmd, sizeof ifmd);
  110                 if (error)
  111                         return error;
  112 
  113 #define DONTCOPY(fld) ifmd.ifmd_data.ifi_##fld = ifp->if_data.ifi_##fld
  114                 DONTCOPY(type);
  115                 DONTCOPY(physical);
  116                 DONTCOPY(addrlen);
  117                 DONTCOPY(hdrlen);
  118                 DONTCOPY(mtu);
  119                 DONTCOPY(metric);
  120                 DONTCOPY(baudrate);
  121 #undef DONTCOPY
  122 #define COPY(fld) ifp->if_##fld = ifmd.ifmd_##fld
  123                 COPY(data);
  124                 ifp->if_snd.ifq_maxlen = ifmd.ifmd_snd_maxlen;
  125                 ifp->if_snd.ifq_drops = ifmd.ifmd_snd_drops;
  126 #undef COPY
  127                 break;
  128 
  129         case IFDATA_LINKSPECIFIC:
  130                 error = SYSCTL_OUT(req, ifp->if_linkmib, ifp->if_linkmiblen);
  131                 if (error || !req->newptr)
  132                         return error;
  133 
  134                 error = SYSCTL_IN(req, ifp->if_linkmib, ifp->if_linkmiblen);
  135                 if (error)
  136                         return error;
  137                 
  138         }
  139         return 0;
  140 }
  141 
  142 SYSCTL_NODE(_net_link_generic, IFMIB_IFDATA, ifdata, CTLFLAG_RW,
  143             sysctl_ifdata, "Interface table");
  144 

Cache object: 035e62dfbec07546e882fd8313c95108


[ 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.