2 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
3 * Copyright (c) 1996-2017 The strace developers.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "print_fields.h"
32 #include <sys/socket.h>
33 #if defined ALPHA || defined SH || defined SH64
34 # include <linux/ioctl.h>
36 #include <linux/sockios.h>
37 #include <arpa/inet.h>
40 #include DEF_MPERS_TYPE(struct_ifconf)
41 #include DEF_MPERS_TYPE(struct_ifreq)
43 typedef struct ifconf struct_ifconf;
44 typedef struct ifreq struct_ifreq;
48 #include "xlat/iffflags.h"
50 #define XLAT_MACROS_ONLY
51 # include "xlat/arp_hardware_types.h"
52 #undef XLAT_MACROS_ONLY
55 print_ifname(const char *ifname)
57 print_quoted_string(ifname, IFNAMSIZ + 1, QUOTE_0_TERMINATED);
61 print_ifreq(struct tcb *const tcp, const unsigned int code,
62 const kernel_ulong_t arg, const struct_ifreq *const ifr)
67 PRINT_FIELD_SOCKADDR("", *ifr, ifr_addr);
71 PRINT_FIELD_SOCKADDR("", *ifr, ifr_dstaddr);
75 PRINT_FIELD_SOCKADDR("", *ifr, ifr_broadaddr);
79 PRINT_FIELD_SOCKADDR("", *ifr, ifr_netmask);
83 static uint8_t hwaddr_sizes[] = {
84 [0 ... ARPHRD_IEEE802_TR] = 255,
86 [ARPHRD_NETROM] = 7 /* AX25_ADDR_LEN */,
87 [ARPHRD_ETHER] = 6 /* ETH_ALEN */,
88 /* ARPHRD_EETHER - no actual devices in Linux */
89 [ARPHRD_AX25] = 7 /* AX25_ADDR_LEN */,
90 /* ARPHRD_PRONET - no actual devices in Linux */
91 /* ARPHRD_CHAOS - no actual devices in Linux */
92 [ARPHRD_IEEE802] = 6 /* FC_ALEN */,
93 [ARPHRD_ARCNET] = 1 /* ARCNET_ALEN */,
94 /* ARPHRD_APPLETLK - no actual devices in Linux */
95 [ARPHRD_DLCI] = sizeof(short),
96 /* ARPHRD_ATM - no explicit setting */
97 /* ARPHRD_METRICOM - no actual devices in Linux */
98 [ARPHRD_IEEE1394] = 16 /* FWNET_ALEN */,
99 [ARPHRD_EUI64] = 8 /* EUI64_ADDR_LEN */,
100 [ARPHRD_INFINIBAND] = 20 /* INFINIBAND_ALEN */,
102 /* ARPHRD_CSLIP - no actual devices in Linux */
103 /* ARPHRD_SLIP6 - no actual devices in Linux */
104 /* ARPHRD_CSLIP6 - no actual devices in Linux */
105 /* ARPHRD_RSRVD - no actual devices in Linux */
106 /* ARPHRD_ADAPT - no actual devices in Linux */
107 [ARPHRD_ROSE] = 5 /* ROSE_ADDR_LEN */,
109 /* ARPHRD_HWX25 - no actual devices in Linux */
112 /* ARPHRD_CISCO - no actual devices in Linux */
113 /* ARPHRD_LAPB - no actual devices in Linux */
114 /* ARPHRD_DDCMP - no actual devices in Linux */
115 [ARPHRD_RAWHDLC] = 0,
117 [ARPHRD_TUNNEL] = 4 /* IPIP */,
118 [ARPHRD_TUNNEL6] = 16 /* sizeof(struct in6_addr) */,
119 /* ARPHRD_FRAD - no actual devices in Linux */
120 /* ARPHRD_SKIP - no actual devices in Linux */
121 [ARPHRD_LOOPBACK] = 6 /* ETH_ALEN */,
122 [ARPHRD_LOCALTLK] = 1 /* LTALK_ALEN */,
123 [ARPHRD_FDDI] = 6 /* FDDI_K_ALEN */,
124 /* ARPHRD_BIF - no actual devices in Linux */
129 [ARPHRD_HIPPI] = 6 /* HIPPI_ALEN */,
130 /* ARPHRD_ASH - no actual devices in Linux */
131 /* ARPHRD_ECONET - no actual devices in Linux */
132 [ARPHRD_IRDA] = 4 /* LAP_ALEN */,
133 /* ARPHRD_FCPP - no actual devices in Linux */
134 /* ARPHRD_FCAL - no actual devices in Linux */
135 /* ARPHRD_FCPL - no actual devices in Linux */
136 /* ARPHRD_FCFABRIC - no actual devices in Linux */
137 /* ARPHRD_IEEE802_TR - no actual devices in Linux */
138 [ARPHRD_IEEE80211] = 6 /* ETH_ALEN */,
139 [ARPHRD_IEEE80211_PRISM] = 6 /* ETH_ALEN */,
140 [ARPHRD_IEEE80211_RADIOTAP] = 6 /* ETH_ALEN */,
142 = 8 /* IEEE802154_EXTENDED_ADDR_LEN */,
143 [ARPHRD_IEEE802154_MONITOR]
144 = 8 /* IEEE802154_EXTENDED_ADDR_LEN */,
146 [ARPHRD_PHONET_PIPE] = 1,
148 [ARPHRD_IP6GRE] = 16 /* sizeof(struct in6_addr) */,
149 [ARPHRD_NETLINK] = 0,
150 [ARPHRD_6LOWPAN] = 8 /* EUI64_ADDR_LEN */
151 /* ^ or ETH_ALEN, depending on lltype */,
152 [ARPHRD_VSOCKMON] = 0,
155 uint16_t proto = ifr->ifr_hwaddr.sa_family;
156 uint8_t sz = (proto < ARRAY_SIZE(hwaddr_sizes))
157 ? hwaddr_sizes[proto] : 255;
159 PRINT_FIELD_XVAL("ifr_hwaddr={", ifr->ifr_hwaddr, sa_family,
160 arp_hardware_types, "ARPHRD_???");
161 PRINT_FIELD_MAC_SZ(", ", ifr->ifr_hwaddr, sa_data,
162 MIN(sizeof(ifr->ifr_hwaddr.sa_data), sz));
168 tprints("ifr_flags=");
169 printflags(iffflags, (unsigned short) ifr->ifr_flags, "IFF_???");
173 tprintf("ifr_metric=%d", ifr->ifr_metric);
177 tprintf("ifr_mtu=%d", ifr->ifr_mtu);
181 tprints("ifr_slave=");
182 print_ifname(ifr->ifr_slave);
186 tprintf("ifr_qlen=%d", ifr->ifr_qlen);
190 tprintf("ifr_map={mem_start=%#" PRI_klx ", "
191 "mem_end=%#" PRI_klx ", base_addr=%#x, "
192 "irq=%u, dma=%u, port=%u}",
193 (kernel_ulong_t) ifr->ifr_map.mem_start,
194 (kernel_ulong_t) ifr->ifr_map.mem_end,
195 (unsigned) ifr->ifr_map.base_addr,
196 (unsigned) ifr->ifr_map.irq,
197 (unsigned) ifr->ifr_map.dma,
198 (unsigned) ifr->ifr_map.port);
204 print_ifc_len(int len)
206 const unsigned int n = (unsigned int) len / sizeof(struct_ifreq);
208 if (len < 0 || n * sizeof(struct_ifreq) != (unsigned int) len)
211 tprintf("%u * sizeof(struct ifreq)", n);
217 print_ifconf_ifreq(struct tcb *tcp, void *elem_buf, size_t elem_size,
220 struct_ifreq *ifr = elem_buf;
222 tprints("{ifr_name=");
223 print_ifname(ifr->ifr_name);
224 PRINT_FIELD_SOCKADDR(", ", *ifr, ifr_addr);
231 * There are two different modes of operation:
233 * - Get buffer size. In this case, the callee sets ifc_buf to NULL,
234 * and the kernel returns the buffer size in ifc_len.
235 * - Get actual data. In this case, the callee specifies the buffer address
236 * in ifc_buf and its size in ifc_len. The kernel fills the buffer with
237 * the data, and its amount is returned in ifc_len.
239 * Note that, technically, the whole struct ifconf is overwritten,
240 * so ifc_buf could be different on exit, but current ioctl handler
241 * implementation does not touch it.
244 decode_ifconf(struct tcb *const tcp, const kernel_ulong_t addr)
246 struct_ifconf *entering_ifc = NULL;
248 entering(tcp) ? malloc(sizeof(*ifc)) : alloca(sizeof(*ifc));
251 entering_ifc = get_tcb_priv_data(tcp);
254 error_func_msg("where is my ifconf?");
259 if (!ifc || umove(tcp, addr, ifc) < 0) {
267 * We failed to fetch the structure on exiting syscall,
268 * print whatever was fetched on entering syscall.
270 if (!entering_ifc->ifc_buf)
271 print_ifc_len(entering_ifc->ifc_len);
273 tprints(", ifc_buf=");
274 printaddr(ptr_to_kulong(entering_ifc->ifc_buf));
279 return RVAL_IOCTL_DECODED;
283 tprints(", {ifc_len=");
285 print_ifc_len(ifc->ifc_len);
287 set_tcb_priv_data(tcp, ifc, free);
294 if (entering_ifc->ifc_buf && (entering_ifc->ifc_len != ifc->ifc_len))
296 if (!entering_ifc->ifc_buf || (entering_ifc->ifc_len != ifc->ifc_len))
297 print_ifc_len(ifc->ifc_len);
299 tprints(", ifc_buf=");
301 if (!entering_ifc->ifc_buf || syserror(tcp)) {
302 printaddr(ptr_to_kulong(entering_ifc->ifc_buf));
303 if (entering_ifc->ifc_buf != ifc->ifc_buf) {
305 printaddr(ptr_to_kulong(ifc->ifc_buf));
310 print_array(tcp, ptr_to_kulong(ifc->ifc_buf),
311 ifc->ifc_len / sizeof(struct_ifreq),
313 umoven_or_printaddr, print_ifconf_ifreq, NULL);
318 return RVAL_IOCTL_DECODED;
321 MPERS_PRINTER_DECL(int, sock_ioctl,
322 struct tcb *tcp, const unsigned int code,
323 const kernel_ulong_t arg)
329 return decode_ifconf(tcp, arg);
346 printnum_int(tcp, arg, "%d");
361 printnum_int(tcp, arg, "%d");
386 if (umove_or_printaddr(tcp, arg, &ifr))
389 tprints("{ifr_name=");
390 print_ifname(ifr.ifr_name);
392 if (code == SIOCSIFNAME) {
393 tprints("ifr_newname=");
394 print_ifname(ifr.ifr_newname);
396 print_ifreq(tcp, code, arg, &ifr);
416 if (umove_or_printaddr(tcp, arg, &ifr))
419 if (SIOCGIFNAME == code) {
420 tprintf("{ifr_index=%d", ifr.ifr_ifindex);
422 tprints("{ifr_name=");
423 print_ifname(ifr.ifr_name);
433 if (umove(tcp, arg, &ifr) < 0) {
438 if (SIOCGIFNAME == code) {
439 tprints("ifr_name=");
440 print_ifname(ifr.ifr_name);
442 print_ifreq(tcp, code, arg, &ifr);
452 return RVAL_IOCTL_DECODED;