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