1 | #include <machine/rtems-bsd-kernel-space.h> |
---|
2 | |
---|
3 | /*- |
---|
4 | * Copyright 1996 Massachusetts Institute of Technology |
---|
5 | * |
---|
6 | * Permission to use, copy, modify, and distribute this software and |
---|
7 | * its documentation for any purpose and without fee is hereby |
---|
8 | * granted, provided that both the above copyright notice and this |
---|
9 | * permission notice appear in all copies, that both the above |
---|
10 | * copyright notice and this permission notice appear in all |
---|
11 | * supporting documentation, and that the name of M.I.T. not be used |
---|
12 | * in advertising or publicity pertaining to distribution of the |
---|
13 | * software without specific, written prior permission. M.I.T. makes |
---|
14 | * no representations about the suitability of this software for any |
---|
15 | * purpose. It is provided "as is" without express or implied |
---|
16 | * warranty. |
---|
17 | * |
---|
18 | * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS |
---|
19 | * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, |
---|
20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
---|
21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT |
---|
22 | * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
---|
23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
---|
24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
---|
25 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
---|
26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
---|
27 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
---|
28 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
---|
29 | * SUCH DAMAGE. |
---|
30 | * |
---|
31 | * $FreeBSD$ |
---|
32 | */ |
---|
33 | |
---|
34 | #include <sys/param.h> |
---|
35 | #include <sys/systm.h> |
---|
36 | #include <sys/kernel.h> |
---|
37 | #include <sys/malloc.h> |
---|
38 | #include <sys/socket.h> |
---|
39 | #include <sys/sysctl.h> |
---|
40 | |
---|
41 | #include <net/if.h> |
---|
42 | #include <net/if_var.h> |
---|
43 | #include <net/if_mib.h> |
---|
44 | #include <net/vnet.h> |
---|
45 | |
---|
46 | /* |
---|
47 | * A sysctl(3) MIB for generic interface information. This information |
---|
48 | * is exported in the net.link.generic branch, which has the following |
---|
49 | * structure: |
---|
50 | * |
---|
51 | * net.link.generic .system - system-wide control variables |
---|
52 | * and statistics (node) |
---|
53 | * .ifdata.<ifindex>.general |
---|
54 | * - what's in `struct ifdata' |
---|
55 | * plus some other info |
---|
56 | * .ifdata.<ifindex>.linkspecific |
---|
57 | * - a link-type-specific data |
---|
58 | * structure (as might be used |
---|
59 | * by an SNMP agent |
---|
60 | * |
---|
61 | * Perhaps someday we will make addresses accessible via this interface |
---|
62 | * as well (then there will be four such...). The reason that the |
---|
63 | * index comes before the last element in the name is because it |
---|
64 | * seems more orthogonal that way, particularly with the possibility |
---|
65 | * of other per-interface data living down here as well (e.g., integrated |
---|
66 | * services stuff). |
---|
67 | */ |
---|
68 | |
---|
69 | SYSCTL_DECL(_net_link_generic); |
---|
70 | static SYSCTL_NODE(_net_link_generic, IFMIB_SYSTEM, system, CTLFLAG_RW, 0, |
---|
71 | "Variables global to all interfaces"); |
---|
72 | |
---|
73 | SYSCTL_INT(_net_link_generic_system, IFMIB_IFCOUNT, ifcount, |
---|
74 | CTLFLAG_VNET | CTLFLAG_RD, &VNET_NAME(if_index), 0, |
---|
75 | "Number of configured interfaces"); |
---|
76 | |
---|
77 | static int |
---|
78 | sysctl_ifdata(SYSCTL_HANDLER_ARGS) /* XXX bad syntax! */ |
---|
79 | { |
---|
80 | int *name = (int *)arg1; |
---|
81 | int error; |
---|
82 | u_int namelen = arg2; |
---|
83 | struct ifnet *ifp; |
---|
84 | struct ifmibdata ifmd; |
---|
85 | size_t dlen; |
---|
86 | char *dbuf; |
---|
87 | |
---|
88 | if (namelen != 2) |
---|
89 | return EINVAL; |
---|
90 | if (name[0] <= 0) |
---|
91 | return (ENOENT); |
---|
92 | ifp = ifnet_byindex_ref(name[0]); |
---|
93 | if (ifp == NULL) |
---|
94 | return (ENOENT); |
---|
95 | |
---|
96 | switch(name[1]) { |
---|
97 | default: |
---|
98 | error = ENOENT; |
---|
99 | goto out; |
---|
100 | |
---|
101 | case IFDATA_GENERAL: |
---|
102 | bzero(&ifmd, sizeof(ifmd)); |
---|
103 | strlcpy(ifmd.ifmd_name, ifp->if_xname, sizeof(ifmd.ifmd_name)); |
---|
104 | |
---|
105 | ifmd.ifmd_pcount = ifp->if_pcount; |
---|
106 | if_data_copy(ifp, &ifmd.ifmd_data); |
---|
107 | |
---|
108 | ifmd.ifmd_flags = ifp->if_flags | ifp->if_drv_flags; |
---|
109 | ifmd.ifmd_snd_len = ifp->if_snd.ifq_len; |
---|
110 | ifmd.ifmd_snd_maxlen = ifp->if_snd.ifq_maxlen; |
---|
111 | ifmd.ifmd_snd_drops = |
---|
112 | ifp->if_get_counter(ifp, IFCOUNTER_OQDROPS); |
---|
113 | |
---|
114 | error = SYSCTL_OUT(req, &ifmd, sizeof ifmd); |
---|
115 | if (error) |
---|
116 | goto out; |
---|
117 | break; |
---|
118 | |
---|
119 | case IFDATA_LINKSPECIFIC: |
---|
120 | error = SYSCTL_OUT(req, ifp->if_linkmib, ifp->if_linkmiblen); |
---|
121 | if (error || !req->newptr) |
---|
122 | goto out; |
---|
123 | |
---|
124 | error = SYSCTL_IN(req, ifp->if_linkmib, ifp->if_linkmiblen); |
---|
125 | if (error) |
---|
126 | goto out; |
---|
127 | break; |
---|
128 | |
---|
129 | case IFDATA_DRIVERNAME: |
---|
130 | /* 20 is enough for 64bit ints */ |
---|
131 | dlen = strlen(ifp->if_dname) + 20 + 1; |
---|
132 | if ((dbuf = malloc(dlen, M_TEMP, M_NOWAIT)) == NULL) { |
---|
133 | error = ENOMEM; |
---|
134 | goto out; |
---|
135 | } |
---|
136 | if (ifp->if_dunit == IF_DUNIT_NONE) |
---|
137 | strcpy(dbuf, ifp->if_dname); |
---|
138 | else |
---|
139 | sprintf(dbuf, "%s%d", ifp->if_dname, ifp->if_dunit); |
---|
140 | |
---|
141 | error = SYSCTL_OUT(req, dbuf, strlen(dbuf) + 1); |
---|
142 | if (error == 0 && req->newptr != NULL) |
---|
143 | error = EPERM; |
---|
144 | free(dbuf, M_TEMP); |
---|
145 | goto out; |
---|
146 | } |
---|
147 | out: |
---|
148 | if_rele(ifp); |
---|
149 | return error; |
---|
150 | } |
---|
151 | |
---|
152 | static SYSCTL_NODE(_net_link_generic, IFMIB_IFDATA, ifdata, CTLFLAG_RW, |
---|
153 | sysctl_ifdata, "Interface table"); |
---|
154 | |
---|