2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
26 * Copyright 1996 Massachusetts Institute of Technology
28 * Permission to use, copy, modify, and distribute this software and
29 * its documentation for any purpose and without fee is hereby
30 * granted, provided that both the above copyright notice and this
31 * permission notice appear in all copies, that both the above
32 * copyright notice and this permission notice appear in all
33 * supporting documentation, and that the name of M.I.T. not be used
34 * in advertising or publicity pertaining to distribution of the
35 * software without specific, written prior permission. M.I.T. makes
36 * no representations about the suitability of this software for any
37 * purpose. It is provided "as is" without express or implied
40 * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS
41 * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
42 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
43 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
44 * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
46 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
47 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
48 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
49 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
50 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53 * $FreeBSD: src/sys/net/if_mib.c,v 1.8.2.1 2000/08/03 00:09:34 ps Exp $
56 #include <sys/param.h>
57 #include <sys/systm.h>
58 #include <sys/kernel.h>
59 #include <sys/socket.h>
60 #include <sys/sysctl.h>
63 #include <net/if_mib.h>
68 * A sysctl(3) MIB for generic interface information. This information
69 * is exported in the net.link.generic branch, which has the following
72 * net.link.generic .system - system-wide control variables
73 * and statistics (node)
74 * .ifdata.<ifindex>.general
75 * - what's in `struct ifdata'
76 * plus some other info
77 * .ifdata.<ifindex>.linkspecific
78 * - a link-type-specific data
79 * structure (as might be used
82 * Perhaps someday we will make addresses accessible via this interface
83 * as well (then there will be four such...). The reason that the
84 * index comes before the last element in the name is because it
85 * seems more orthogonal that way, particularly with the possibility
86 * of other per-interface data living down here as well (e.g., integrated
90 SYSCTL_DECL(_net_link_generic
);
91 SYSCTL_NODE(_net_link_generic
, IFMIB_SYSTEM
, system
, CTLFLAG_RW
, 0,
92 "Variables global to all interfaces");
93 SYSCTL_INT(_net_link_generic_system
, IFMIB_IFCOUNT
, ifcount
, CTLFLAG_RD
,
94 &if_index
, 0, "Number of configured interfaces");
97 sysctl_ifdata SYSCTL_HANDLER_ARGS
/* XXX bad syntax! */
99 int *name
= (int *)arg1
;
101 u_int namelen
= arg2
;
104 struct ifmibdata ifmd
;
109 if (name
[0] <= 0 || name
[0] > if_index
)
112 ifp
= ifnet_addrs
[name
[0] - 1]->ifa_ifp
;
120 ifnlen = snprintf(workbuf, sizeof(workbuf),
121 "%s%d", ifp->if_name, ifp->if_unit);
122 if(ifnlen + 1 > sizeof ifmd.ifmd_name) {
125 strcpy(ifmd.ifmd_name, workbuf);
129 #define COPY(fld) ifmd.ifmd_##fld = ifp->if_##fld
134 ifmd
.ifmd_snd_len
= ifp
->if_snd
.ifq_len
;
135 ifmd
.ifmd_snd_maxlen
= ifp
->if_snd
.ifq_maxlen
;
136 ifmd
.ifmd_snd_drops
= ifp
->if_snd
.ifq_drops
;
138 error
= SYSCTL_OUT(req
, &ifmd
, sizeof ifmd
);
139 if (error
|| !req
->newptr
)
142 error
= SYSCTL_IN(req
, &ifmd
, sizeof ifmd
);
146 #define DONTCOPY(fld) ifmd.ifmd_data.ifi_##fld = ifp->if_data.ifi_##fld
155 #define COPY(fld) ifp->if_##fld = ifmd.ifmd_##fld
157 ifp
->if_snd
.ifq_maxlen
= ifmd
.ifmd_snd_maxlen
;
158 ifp
->if_snd
.ifq_drops
= ifmd
.ifmd_snd_drops
;
162 case IFDATA_LINKSPECIFIC
:
163 error
= SYSCTL_OUT(req
, ifp
->if_linkmib
, ifp
->if_linkmiblen
);
164 if (error
|| !req
->newptr
)
167 error
= SYSCTL_IN(req
, ifp
->if_linkmib
, ifp
->if_linkmiblen
);
175 SYSCTL_NODE(_net_link_generic
, IFMIB_IFDATA
, ifdata
, CTLFLAG_RW
,
176 sysctl_ifdata
, "Interface table");