blob: 546c651cf46c74788d348063e9d4e543b1b6dfa9 [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
2 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000026 */
27
28#include "defs.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000029#include <sys/socket.h>
Roland McGrath5687ff12004-07-12 07:13:06 +000030#include <linux/sockios.h>
Roland McGrath5687ff12004-07-12 07:13:06 +000031#include <arpa/inet.h>
Denys Vlasenkoc36c3522012-02-25 02:47:15 +010032#if defined(ALPHA) || defined(SH) || defined(SH64)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010033# if defined(HAVE_SYS_IOCTL_H)
Denys Vlasenkoc36c3522012-02-25 02:47:15 +010034# include <sys/ioctl.h>
35# elif defined(HAVE_IOCTLS_H)
36# include <ioctls.h>
37# endif
Wichert Akkerman2e2553a1999-05-09 00:29:58 +000038#endif
Roland McGrath5687ff12004-07-12 07:13:06 +000039#include <net/if.h>
40
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000041#include "xlat/iffflags.h"
Roland McGrathe6a432d2005-02-02 20:25:17 +000042
Roland McGrathe6a432d2005-02-02 20:25:17 +000043static void
Denys Vlasenko12014262011-05-30 14:00:14 +020044print_addr(struct tcb *tcp, long addr, struct ifreq *ifr)
Roland McGrathe6a432d2005-02-02 20:25:17 +000045{
46 if (ifr->ifr_addr.sa_family == AF_INET) {
47 struct sockaddr_in *sinp;
48 sinp = (struct sockaddr_in *) &ifr->ifr_addr;
49 tprintf("inet_addr(\"%s\")", inet_ntoa(sinp->sin_addr));
50 } else
51 printstr(tcp, addr, sizeof(ifr->ifr_addr.sa_data));
52}
53
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000054int
Dmitry V. Levin40284242007-03-21 13:52:14 +000055sock_ioctl(struct tcb *tcp, long code, long arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000056{
Roland McGrath5687ff12004-07-12 07:13:06 +000057 struct ifreq ifr;
58 struct ifconf ifc;
Roland McGrathe6a432d2005-02-02 20:25:17 +000059 const char *str = NULL;
60 unsigned char *bytes;
Roland McGrath5687ff12004-07-12 07:13:06 +000061
62 if (entering(tcp)) {
Dmitry V. Levin788c0d62014-10-31 19:36:01 +000063 switch (code) {
64 case SIOCGIFCONF:
Dmitry V. Levin652e4482007-03-21 14:18:17 +000065 if (umove(tcp, tcp->u_arg[2], &ifc) >= 0
66 && ifc.ifc_buf == NULL)
Roland McGrath5687ff12004-07-12 07:13:06 +000067 tprintf(", {%d -> ", ifc.ifc_len);
68 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +020069 tprints(", {");
Dmitry V. Levin788c0d62014-10-31 19:36:01 +000070 break;
71 case SIOCSIFNAME:
72 if (umove(tcp, tcp->u_arg[2], &ifr) < 0)
73 tprintf(", %#lx", tcp->u_arg[2]);
74 else
75 tprintf(", {ifr_name=\"%.*s\", ifr_newname=\"%.*s\"}",
76 IFNAMSIZ, ifr.ifr_name,
77 IFNAMSIZ, ifr.ifr_newname);
78 break;
Roland McGrath5687ff12004-07-12 07:13:06 +000079 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000080 return 0;
Roland McGrath5687ff12004-07-12 07:13:06 +000081 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000082
83 switch (code) {
84#ifdef SIOCSHIWAT
85 case SIOCSHIWAT:
86#endif
87#ifdef SIOCGHIWAT
88 case SIOCGHIWAT:
89#endif
90#ifdef SIOCSLOWAT
91 case SIOCSLOWAT:
92#endif
93#ifdef SIOCGLOWAT
94 case SIOCGLOWAT:
95#endif
96#ifdef FIOSETOWN
97 case FIOSETOWN:
98#endif
99#ifdef FIOGETOWN
100 case FIOGETOWN:
101#endif
102#ifdef SIOCSPGRP
103 case SIOCSPGRP:
104#endif
105#ifdef SIOCGPGRP
106 case SIOCGPGRP:
107#endif
108#ifdef SIOCATMARK
109 case SIOCATMARK:
110#endif
111 printnum(tcp, arg, ", %#d");
Dmitry V. Levin788c0d62014-10-31 19:36:01 +0000112 case SIOCSIFNAME:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000113 return 1;
Roland McGrath5687ff12004-07-12 07:13:06 +0000114 case SIOCGIFNAME:
115 case SIOCGIFINDEX:
Roland McGrathe6a432d2005-02-02 20:25:17 +0000116 case SIOCGIFADDR:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000117 case SIOCSIFADDR:
Roland McGrathe6a432d2005-02-02 20:25:17 +0000118 case SIOCGIFDSTADDR:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000119 case SIOCSIFDSTADDR:
Roland McGrathe6a432d2005-02-02 20:25:17 +0000120 case SIOCGIFBRDADDR:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000121 case SIOCSIFBRDADDR:
Roland McGrathe6a432d2005-02-02 20:25:17 +0000122 case SIOCGIFNETMASK:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000123 case SIOCSIFNETMASK:
Roland McGrathe6a432d2005-02-02 20:25:17 +0000124 case SIOCGIFFLAGS:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000125 case SIOCSIFFLAGS:
Roland McGrathe6a432d2005-02-02 20:25:17 +0000126 case SIOCGIFMETRIC:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000127 case SIOCSIFMETRIC:
Roland McGrathe6a432d2005-02-02 20:25:17 +0000128 case SIOCGIFMTU:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000129 case SIOCSIFMTU:
Roland McGrathe6a432d2005-02-02 20:25:17 +0000130 case SIOCGIFSLAVE:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000131 case SIOCSIFSLAVE:
Roland McGrathe6a432d2005-02-02 20:25:17 +0000132 case SIOCGIFHWADDR:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000133 case SIOCSIFHWADDR:
Dmitry V. Levin40284242007-03-21 13:52:14 +0000134 case SIOCGIFTXQLEN:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000135 case SIOCSIFTXQLEN:
Dmitry V. Levinecdd0bb2007-03-21 13:57:50 +0000136 case SIOCGIFMAP:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000137 case SIOCSIFMAP:
Dmitry V. Levin652e4482007-03-21 14:18:17 +0000138 if (umove(tcp, tcp->u_arg[2], &ifr) < 0)
139 tprintf(", %#lx", tcp->u_arg[2]);
140 else if (syserror(tcp)) {
Mike Frysingerf27263d2014-10-21 08:34:08 -0400141 if (code == SIOCGIFNAME) {
142 tprintf(", {ifr_index=%d, ifr_name=???}",
143 ifr.ifr_ifindex);
144 } else {
Dmitry V. Levin788c0d62014-10-31 19:36:01 +0000145 tprintf(", {ifr_name=\"%.*s\", ???}",
Mike Frysinger8b5fbee2014-10-21 08:34:08 -0400146 IFNAMSIZ, ifr.ifr_name);
Mike Frysingerf27263d2014-10-21 08:34:08 -0400147 }
148 } else if (code == SIOCGIFNAME) {
Mike Frysinger8b5fbee2014-10-21 08:34:08 -0400149 tprintf(", {ifr_index=%d, ifr_name=\"%.*s\"}",
150 ifr.ifr_ifindex, IFNAMSIZ, ifr.ifr_name);
Mike Frysingerf27263d2014-10-21 08:34:08 -0400151 } else {
Mike Frysinger8b5fbee2014-10-21 08:34:08 -0400152 tprintf(", {ifr_name=\"%.*s\", ",
153 IFNAMSIZ, ifr.ifr_name);
Roland McGrathe6a432d2005-02-02 20:25:17 +0000154 switch (code) {
155 case SIOCGIFINDEX:
156 tprintf("ifr_index=%d", ifr.ifr_ifindex);
157 break;
158 case SIOCGIFADDR:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000159 case SIOCSIFADDR:
Roland McGrathe6a432d2005-02-02 20:25:17 +0000160 str = "ifr_addr";
161 case SIOCGIFDSTADDR:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000162 case SIOCSIFDSTADDR:
163 if (!str)
Roland McGrathe6a432d2005-02-02 20:25:17 +0000164 str = "ifr_dstaddr";
165 case SIOCGIFBRDADDR:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000166 case SIOCSIFBRDADDR:
167 if (!str)
Roland McGrathe6a432d2005-02-02 20:25:17 +0000168 str = "ifr_broadaddr";
169 case SIOCGIFNETMASK:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000170 case SIOCSIFNETMASK:
171 if (!str)
Roland McGrathe6a432d2005-02-02 20:25:17 +0000172 str = "ifr_netmask";
173 tprintf("%s={", str);
174 printxval(addrfams,
175 ifr.ifr_addr.sa_family,
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000176 "AF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200177 tprints(", ");
Roland McGrathe6a432d2005-02-02 20:25:17 +0000178 print_addr(tcp, ((long) tcp->u_arg[2]
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200179 + offsetof(struct ifreq,
Roland McGrathe6a432d2005-02-02 20:25:17 +0000180 ifr_addr.sa_data)),
181 &ifr);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200182 tprints("}");
Roland McGrathe6a432d2005-02-02 20:25:17 +0000183 break;
184 case SIOCGIFHWADDR:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000185 case SIOCSIFHWADDR:
Roland McGrathe6a432d2005-02-02 20:25:17 +0000186 /* XXX Are there other hardware addresses
187 than 6-byte MACs? */
188 bytes = (unsigned char *) &ifr.ifr_hwaddr.sa_data;
189 tprintf("ifr_hwaddr=%02x:%02x:%02x:%02x:%02x:%02x",
190 bytes[0], bytes[1], bytes[2],
191 bytes[3], bytes[4], bytes[5]);
192 break;
193 case SIOCGIFFLAGS:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000194 case SIOCSIFFLAGS:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200195 tprints("ifr_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000196 printflags(iffflags, ifr.ifr_flags, "IFF_???");
Roland McGrathe6a432d2005-02-02 20:25:17 +0000197 break;
198 case SIOCGIFMETRIC:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000199 case SIOCSIFMETRIC:
Roland McGrathe6a432d2005-02-02 20:25:17 +0000200 tprintf("ifr_metric=%d", ifr.ifr_metric);
201 break;
202 case SIOCGIFMTU:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000203 case SIOCSIFMTU:
Roland McGrathe6a432d2005-02-02 20:25:17 +0000204 tprintf("ifr_mtu=%d", ifr.ifr_mtu);
205 break;
206 case SIOCGIFSLAVE:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000207 case SIOCSIFSLAVE:
Roland McGrathe6a432d2005-02-02 20:25:17 +0000208 tprintf("ifr_slave=\"%s\"", ifr.ifr_slave);
209 break;
Dmitry V. Levin40284242007-03-21 13:52:14 +0000210 case SIOCGIFTXQLEN:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000211 case SIOCSIFTXQLEN:
Dmitry V. Levin40284242007-03-21 13:52:14 +0000212 tprintf("ifr_qlen=%d", ifr.ifr_qlen);
213 break;
Dmitry V. Levinecdd0bb2007-03-21 13:57:50 +0000214 case SIOCGIFMAP:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000215 case SIOCSIFMAP:
Dmitry V. Levinecdd0bb2007-03-21 13:57:50 +0000216 tprintf("ifr_map={mem_start=%#lx, "
217 "mem_end=%#lx, base_addr=%#x, "
218 "irq=%u, dma=%u, port=%u}",
219 ifr.ifr_map.mem_start,
220 ifr.ifr_map.mem_end,
221 (unsigned) ifr.ifr_map.base_addr,
222 (unsigned) ifr.ifr_map.irq,
223 (unsigned) ifr.ifr_map.dma,
224 (unsigned) ifr.ifr_map.port);
225 break;
Roland McGrathe6a432d2005-02-02 20:25:17 +0000226 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200227 tprints("}");
Roland McGrathe6a432d2005-02-02 20:25:17 +0000228 }
Roland McGrath5687ff12004-07-12 07:13:06 +0000229 return 1;
230 case SIOCGIFCONF:
Dmitry V. Levin652e4482007-03-21 14:18:17 +0000231 if (umove(tcp, tcp->u_arg[2], &ifc) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200232 tprints("???}");
Dmitry V. Levin652e4482007-03-21 14:18:17 +0000233 return 1;
234 }
Roland McGrath5687ff12004-07-12 07:13:06 +0000235 tprintf("%d, ", ifc.ifc_len);
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000236 if (syserror(tcp)) {
Roland McGrath5687ff12004-07-12 07:13:06 +0000237 tprintf("%lx", (unsigned long) ifc.ifc_buf);
238 } else if (ifc.ifc_buf == NULL) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200239 tprints("NULL");
Roland McGrath5687ff12004-07-12 07:13:06 +0000240 } else {
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000241 unsigned int i;
242 unsigned int nifra = ifc.ifc_len / sizeof(struct ifreq);
Roland McGrath5687ff12004-07-12 07:13:06 +0000243 struct ifreq ifra[nifra];
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000244
245 if (umoven(tcp, (unsigned long) ifc.ifc_buf,
246 sizeof(ifra), (char *) ifra) < 0) {
247 tprintf("%lx}", (unsigned long) ifc.ifc_buf);
248 return 1;
249 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200250 tprints("{");
Roland McGrath5687ff12004-07-12 07:13:06 +0000251 for (i = 0; i < nifra; ++i ) {
252 if (i > 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200253 tprints(", ");
Mike Frysinger8b5fbee2014-10-21 08:34:08 -0400254 tprintf("{\"%.*s\", {",
Mike Frysingerf27263d2014-10-21 08:34:08 -0400255 IFNAMSIZ, ifra[i].ifr_newname);
Roland McGrath5687ff12004-07-12 07:13:06 +0000256 if (verbose(tcp)) {
257 printxval(addrfams,
258 ifra[i].ifr_addr.sa_family,
259 "AF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200260 tprints(", ");
Roland McGrathe6a432d2005-02-02 20:25:17 +0000261 print_addr(tcp, ((long) tcp->u_arg[2]
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200262 + offsetof(struct ifreq,
Roland McGrathe6a432d2005-02-02 20:25:17 +0000263 ifr_addr.sa_data)
264 + ((char *) &ifra[i]
265 - (char *) &ifra[0])),
266 &ifra[i]);
Roland McGrath5687ff12004-07-12 07:13:06 +0000267 } else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200268 tprints("...");
269 tprints("}}");
Roland McGrath5687ff12004-07-12 07:13:06 +0000270 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200271 tprints("}");
Roland McGrath5687ff12004-07-12 07:13:06 +0000272 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200273 tprints("}");
Roland McGrath5687ff12004-07-12 07:13:06 +0000274 return 1;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000275 default:
276 return 0;
277 }
278}
Dmitry V. Levinb5e88d42012-02-20 17:02:38 +0000279
280int
281sys_socketcall(struct tcb *tcp)
282{
283 return printargs(tcp);
284}