|
|
1.1 root 1: /*
2: * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
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.
11: *
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
14: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
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: *
50: */
51:
52: #include <sys/param.h>
53: #include <sys/systm.h>
54: #include <sys/kernel.h>
55: #include <sys/socket.h>
56: #include <sys/sysctl.h>
57:
58: #include <net/if.h>
59: #include <net/if_mib.h>
60:
61: #if NETMIBS
62:
63: /*
64: * A sysctl(3) MIB for generic interface information. This information
65: * is exported in the net.link.generic branch, which has the following
66: * structure:
67: *
68: * net.link.generic .system - system-wide control variables
69: * and statistics (node)
70: * .ifdata.<ifindex>.general
71: * - what's in `struct ifdata'
72: * plus some other info
73: * .ifdata.<ifindex>.linkspecific
74: * - a link-type-specific data
75: * structure (as might be used
76: * by an SNMP agent
77: *
78: * Perhaps someday we will make addresses accessible via this interface
79: * as well (then there will be four such...). The reason that the
80: * index comes before the last element in the name is because it
81: * seems more orthogonal that way, particularly with the possibility
82: * of other per-interface data living down here as well (e.g., integrated
83: * services stuff).
84: */
85:
86: SYSCTL_DECL(_net_link_generic);
87: SYSCTL_NODE(_net_link_generic, IFMIB_SYSTEM, system, CTLFLAG_RW, 0,
88: "Variables global to all interfaces");
89: SYSCTL_INT(_net_link_generic_system, IFMIB_IFCOUNT, ifcount, CTLFLAG_RD,
90: &if_index, 0, "Number of configured interfaces");
91:
92: static int
93: sysctl_ifdata SYSCTL_HANDLER_ARGS /* XXX bad syntax! */
94: {
95: int *name = (int *)arg1;
96: int error, ifnlen;
97: u_int namelen = arg2;
98: struct ifnet *ifp;
99: char workbuf[64];
100: struct ifmibdata ifmd;
101:
102: if (namelen != 2)
103: return EINVAL;
104:
105: if (name[0] <= 0 || name[0] > if_index)
106: return ENOENT;
107:
108: ifp = ifnet_addrs[name[0] - 1]->ifa_ifp;
109:
110: switch(name[1]) {
111: default:
112: return ENOENT;
113:
114: case IFDATA_GENERAL:
115: /*
116: ifnlen = snprintf(workbuf, sizeof(workbuf),
117: "%s%d", ifp->if_name, ifp->if_unit);
118: if(ifnlen + 1 > sizeof ifmd.ifmd_name) {
119: return ENAMETOOLONG;
120: } else {
121: strcpy(ifmd.ifmd_name, workbuf);
122: }
123: */
124:
125: #define COPY(fld) ifmd.ifmd_##fld = ifp->if_##fld
126: COPY(pcount);
127: COPY(flags);
128: COPY(data);
129: #undef COPY
130: ifmd.ifmd_snd_len = ifp->if_snd.ifq_len;
131: ifmd.ifmd_snd_maxlen = ifp->if_snd.ifq_maxlen;
132: ifmd.ifmd_snd_drops = ifp->if_snd.ifq_drops;
133:
134: error = SYSCTL_OUT(req, &ifmd, sizeof ifmd);
135: if (error || !req->newptr)
136: return error;
137:
138: error = SYSCTL_IN(req, &ifmd, sizeof ifmd);
139: if (error)
140: return error;
141:
142: #define DONTCOPY(fld) ifmd.ifmd_data.ifi_##fld = ifp->if_data.ifi_##fld
143: DONTCOPY(type);
144: DONTCOPY(physical);
145: DONTCOPY(addrlen);
146: DONTCOPY(hdrlen);
147: DONTCOPY(mtu);
148: DONTCOPY(metric);
149: DONTCOPY(baudrate);
150: #undef DONTCOPY
151: #define COPY(fld) ifp->if_##fld = ifmd.ifmd_##fld
152: COPY(data);
153: ifp->if_snd.ifq_maxlen = ifmd.ifmd_snd_maxlen;
154: ifp->if_snd.ifq_drops = ifmd.ifmd_snd_drops;
155: #undef COPY
156: break;
157:
158: case IFDATA_LINKSPECIFIC:
159: error = SYSCTL_OUT(req, ifp->if_linkmib, ifp->if_linkmiblen);
160: if (error || !req->newptr)
161: return error;
162:
163: error = SYSCTL_IN(req, ifp->if_linkmib, ifp->if_linkmiblen);
164: if (error)
165: return error;
166:
167: }
168: return 0;
169: }
170:
171: SYSCTL_NODE(_net_link_generic, IFMIB_IFDATA, ifdata, CTLFLAG_RW,
172: sysctl_ifdata, "Interface table");
173:
174: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.