]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
43866e37 | 6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. |
1c79356b | 7 | * |
43866e37 A |
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 | |
13 | * file. | |
14 | * | |
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 | |
1c79356b A |
17 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
18 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
43866e37 A |
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. | |
1c79356b A |
22 | * |
23 | * @APPLE_LICENSE_HEADER_END@ | |
24 | */ | |
25 | /* | |
26 | * Copyright 1996 Massachusetts Institute of Technology | |
27 | * | |
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 | |
38 | * warranty. | |
39 | * | |
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 | |
51 | * SUCH DAMAGE. | |
52 | * | |
9bccf70c | 53 | * $FreeBSD: src/sys/net/if_mib.c,v 1.8.2.1 2000/08/03 00:09:34 ps Exp $ |
1c79356b A |
54 | */ |
55 | ||
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> | |
61 | ||
62 | #include <net/if.h> | |
63 | #include <net/if_mib.h> | |
64 | ||
65 | #if NETMIBS | |
66 | ||
67 | /* | |
68 | * A sysctl(3) MIB for generic interface information. This information | |
69 | * is exported in the net.link.generic branch, which has the following | |
70 | * structure: | |
71 | * | |
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 | |
80 | * by an SNMP agent | |
81 | * | |
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 | |
87 | * services stuff). | |
88 | */ | |
89 | ||
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"); | |
95 | ||
96 | static int | |
97 | sysctl_ifdata SYSCTL_HANDLER_ARGS /* XXX bad syntax! */ | |
98 | { | |
99 | int *name = (int *)arg1; | |
100 | int error, ifnlen; | |
101 | u_int namelen = arg2; | |
102 | struct ifnet *ifp; | |
103 | char workbuf[64]; | |
104 | struct ifmibdata ifmd; | |
105 | ||
106 | if (namelen != 2) | |
107 | return EINVAL; | |
108 | ||
109 | if (name[0] <= 0 || name[0] > if_index) | |
110 | return ENOENT; | |
111 | ||
112 | ifp = ifnet_addrs[name[0] - 1]->ifa_ifp; | |
113 | ||
114 | switch(name[1]) { | |
115 | default: | |
116 | return ENOENT; | |
117 | ||
118 | case IFDATA_GENERAL: | |
119 | /* | |
120 | ifnlen = snprintf(workbuf, sizeof(workbuf), | |
121 | "%s%d", ifp->if_name, ifp->if_unit); | |
122 | if(ifnlen + 1 > sizeof ifmd.ifmd_name) { | |
123 | return ENAMETOOLONG; | |
124 | } else { | |
125 | strcpy(ifmd.ifmd_name, workbuf); | |
126 | } | |
127 | */ | |
128 | ||
129 | #define COPY(fld) ifmd.ifmd_##fld = ifp->if_##fld | |
130 | COPY(pcount); | |
131 | COPY(flags); | |
132 | COPY(data); | |
133 | #undef COPY | |
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; | |
137 | ||
138 | error = SYSCTL_OUT(req, &ifmd, sizeof ifmd); | |
139 | if (error || !req->newptr) | |
140 | return error; | |
141 | ||
142 | error = SYSCTL_IN(req, &ifmd, sizeof ifmd); | |
143 | if (error) | |
144 | return error; | |
145 | ||
146 | #define DONTCOPY(fld) ifmd.ifmd_data.ifi_##fld = ifp->if_data.ifi_##fld | |
147 | DONTCOPY(type); | |
148 | DONTCOPY(physical); | |
149 | DONTCOPY(addrlen); | |
150 | DONTCOPY(hdrlen); | |
151 | DONTCOPY(mtu); | |
152 | DONTCOPY(metric); | |
153 | DONTCOPY(baudrate); | |
154 | #undef DONTCOPY | |
155 | #define COPY(fld) ifp->if_##fld = ifmd.ifmd_##fld | |
156 | COPY(data); | |
157 | ifp->if_snd.ifq_maxlen = ifmd.ifmd_snd_maxlen; | |
158 | ifp->if_snd.ifq_drops = ifmd.ifmd_snd_drops; | |
159 | #undef COPY | |
160 | break; | |
161 | ||
162 | case IFDATA_LINKSPECIFIC: | |
163 | error = SYSCTL_OUT(req, ifp->if_linkmib, ifp->if_linkmiblen); | |
164 | if (error || !req->newptr) | |
165 | return error; | |
166 | ||
167 | error = SYSCTL_IN(req, ifp->if_linkmib, ifp->if_linkmiblen); | |
168 | if (error) | |
169 | return error; | |
170 | ||
171 | } | |
172 | return 0; | |
173 | } | |
174 | ||
175 | SYSCTL_NODE(_net_link_generic, IFMIB_IFDATA, ifdata, CTLFLAG_RW, | |
176 | sysctl_ifdata, "Interface table"); | |
177 | ||
178 | #endif |