2 * Copyright (c) 2000-2010 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Copyright 1996 Massachusetts Institute of Technology
31 * Permission to use, copy, modify, and distribute this software and
32 * its documentation for any purpose and without fee is hereby
33 * granted, provided that both the above copyright notice and this
34 * permission notice appear in all copies, that both the above
35 * copyright notice and this permission notice appear in all
36 * supporting documentation, and that the name of M.I.T. not be used
37 * in advertising or publicity pertaining to distribution of the
38 * software without specific, written prior permission. M.I.T. makes
39 * no representations about the suitability of this software for any
40 * purpose. It is provided "as is" without express or implied
43 * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS
44 * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
45 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
46 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
47 * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
49 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
50 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
51 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
52 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
53 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 * $FreeBSD: src/sys/net/if_mib.c,v 1.8.2.1 2000/08/03 00:09:34 ps Exp $
59 #include <sys/param.h>
60 #include <sys/systm.h>
61 #include <sys/kernel.h>
62 #include <sys/socket.h>
63 #include <sys/sysctl.h>
64 #include <sys/systm.h>
67 #include <net/if_mib.h>
68 #include <net/if_var.h>
73 * A sysctl(3) MIB for generic interface information. This information
74 * is exported in the net.link.generic branch, which has the following
77 * net.link.generic .system - system-wide control variables
78 * and statistics (node)
79 * .ifdata.<ifindex>.general
80 * - what's in `struct ifdata'
81 * plus some other info
82 * .ifdata.<ifindex>.linkspecific
83 * - a link-type-specific data
84 * structure (as might be used
87 * Perhaps someday we will make addresses accessible via this interface
88 * as well (then there will be four such...). The reason that the
89 * index comes before the last element in the name is because it
90 * seems more orthogonal that way, particularly with the possibility
91 * of other per-interface data living down here as well (e.g., integrated
95 SYSCTL_DECL(_net_link_generic
);
97 SYSCTL_NODE(_net_link_generic
, IFMIB_SYSTEM
, system
, CTLFLAG_RD
|CTLFLAG_LOCKED
, 0,
98 "Variables global to all interfaces");
100 SYSCTL_INT(_net_link_generic_system
, IFMIB_IFCOUNT
, ifcount
, CTLFLAG_RD
,
101 &if_index
, 0, "Number of configured interfaces");
103 static int sysctl_ifdata SYSCTL_HANDLER_ARGS
;
104 SYSCTL_NODE(_net_link_generic
, IFMIB_IFDATA
, ifdata
, CTLFLAG_RD
,
105 sysctl_ifdata
, "Interface table");
107 static int sysctl_ifalldata SYSCTL_HANDLER_ARGS
;
108 SYSCTL_NODE(_net_link_generic
, IFMIB_IFALLDATA
, ifalldata
, CTLFLAG_RD
,
109 sysctl_ifalldata
, "Interface table");
111 extern int dlil_multithreaded_input
;
112 SYSCTL_INT(_net_link_generic_system
, OID_AUTO
, multi_threaded_input
, CTLFLAG_RW
,
113 &dlil_multithreaded_input
, 0, "Uses multiple input thread for DLIL input");
114 #ifdef IFNET_INPUT_SANITY_CHK
115 extern int dlil_input_sanity_check
;
116 SYSCTL_INT(_net_link_generic_system
, OID_AUTO
, dlil_input_sanity_check
, CTLFLAG_RW
,
117 &dlil_input_sanity_check
, 0, "Turn on sanity checking in DLIL input");
120 extern int dlil_verbose
;
121 SYSCTL_INT(_net_link_generic_system
, OID_AUTO
, dlil_verbose
, CTLFLAG_RW
,
122 &dlil_verbose
, 0, "Log DLIL error messages");
125 static int make_ifmibdata(struct ifnet
*, int *, struct sysctl_req
*);
128 make_ifmibdata(struct ifnet
*ifp
, int *name
, struct sysctl_req
*req
)
130 struct ifmibdata ifmd
;
139 bzero(&ifmd
, sizeof(ifmd
));
141 * Make sure the interface is in use
143 if (ifp
->if_refcnt
> 0) {
144 snprintf(ifmd
.ifmd_name
, sizeof(ifmd
.ifmd_name
), "%s%d",
145 ifp
->if_name
, ifp
->if_unit
);
147 #define COPY(fld) ifmd.ifmd_##fld = ifp->if_##fld
150 if_data_internal_to_if_data64(ifp
, &ifp
->if_data
, &ifmd
.ifmd_data
);
152 ifmd
.ifmd_snd_len
= ifp
->if_snd
.ifq_len
;
153 ifmd
.ifmd_snd_maxlen
= ifp
->if_snd
.ifq_maxlen
;
154 ifmd
.ifmd_snd_drops
= ifp
->if_snd
.ifq_drops
;
156 error
= SYSCTL_OUT(req
, &ifmd
, sizeof ifmd
);
157 if (error
|| !req
->newptr
)
161 error
= SYSCTL_IN(req
, &ifmd
, sizeof ifmd
);
165 #define DONTCOPY(fld) ifmd.ifmd_data.ifi_##fld = ifp->if_data.ifi_##fld
174 #define COPY(fld) ifp->if_##fld = ifmd.ifmd_##fld
176 ifp
->if_snd
.ifq_maxlen
= ifmd
.ifmd_snd_maxlen
;
177 ifp
->if_snd
.ifq_drops
= ifmd
.ifmd_snd_drops
;
179 #endif /* IF_MIB_WR */
182 case IFDATA_LINKSPECIFIC
:
183 error
= SYSCTL_OUT(req
, ifp
->if_linkmib
, ifp
->if_linkmiblen
);
184 if (error
|| !req
->newptr
)
188 error
= SYSCTL_IN(req
, ifp
->if_linkmib
, ifp
->if_linkmiblen
);
191 #endif /* IF_MIB_WR */
195 case IFDATA_SUPPLEMENTAL
:
196 error
= SYSCTL_OUT(req
, &ifp
->if_tc
, sizeof(struct if_traffic_class
));
198 #endif /* PKT_PRIORITY */
205 sysctl_ifdata SYSCTL_HANDLER_ARGS
/* XXX bad syntax! */
208 int *name
= (int *)arg1
;
210 u_int namelen
= arg2
;
215 ifnet_head_lock_shared();
216 if (name
[0] <= 0 || name
[0] > if_index
||
217 (ifp
= ifindex2ifnet
[name
[0]]) == NULL
||
218 ifp
->if_refcnt
== 0) {
224 ifnet_lock_shared(ifp
);
226 error
= make_ifmibdata(ifp
, name
, req
);
228 ifnet_lock_done(ifp
);
234 sysctl_ifalldata SYSCTL_HANDLER_ARGS
/* XXX bad syntax! */
237 int *name
= (int *)arg1
;
239 u_int namelen
= arg2
;
245 ifnet_head_lock_shared();
246 TAILQ_FOREACH(ifp
, &ifnet_head
, if_link
) {
247 ifnet_lock_shared(ifp
);
249 error
= make_ifmibdata(ifp
, name
, req
);
251 ifnet_lock_done(ifp
);