blob: d3a5b35adcd3d96e459eef27a0ee0888cbff2e89 [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)) {
63 if (code == SIOCGIFCONF) {
Dmitry V. Levin652e4482007-03-21 14:18:17 +000064 if (umove(tcp, tcp->u_arg[2], &ifc) >= 0
65 && ifc.ifc_buf == NULL)
Roland McGrath5687ff12004-07-12 07:13:06 +000066 tprintf(", {%d -> ", ifc.ifc_len);
67 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +020068 tprints(", {");
Roland McGrath5687ff12004-07-12 07:13:06 +000069 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000070 return 0;
Roland McGrath5687ff12004-07-12 07:13:06 +000071 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000072
73 switch (code) {
74#ifdef SIOCSHIWAT
75 case SIOCSHIWAT:
76#endif
77#ifdef SIOCGHIWAT
78 case SIOCGHIWAT:
79#endif
80#ifdef SIOCSLOWAT
81 case SIOCSLOWAT:
82#endif
83#ifdef SIOCGLOWAT
84 case SIOCGLOWAT:
85#endif
86#ifdef FIOSETOWN
87 case FIOSETOWN:
88#endif
89#ifdef FIOGETOWN
90 case FIOGETOWN:
91#endif
92#ifdef SIOCSPGRP
93 case SIOCSPGRP:
94#endif
95#ifdef SIOCGPGRP
96 case SIOCGPGRP:
97#endif
98#ifdef SIOCATMARK
99 case SIOCATMARK:
100#endif
101 printnum(tcp, arg, ", %#d");
102 return 1;
Roland McGrath5687ff12004-07-12 07:13:06 +0000103 case SIOCGIFNAME:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000104 case SIOCSIFNAME:
Roland McGrath5687ff12004-07-12 07:13:06 +0000105 case SIOCGIFINDEX:
Roland McGrathe6a432d2005-02-02 20:25:17 +0000106 case SIOCGIFADDR:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000107 case SIOCSIFADDR:
Roland McGrathe6a432d2005-02-02 20:25:17 +0000108 case SIOCGIFDSTADDR:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000109 case SIOCSIFDSTADDR:
Roland McGrathe6a432d2005-02-02 20:25:17 +0000110 case SIOCGIFBRDADDR:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000111 case SIOCSIFBRDADDR:
Roland McGrathe6a432d2005-02-02 20:25:17 +0000112 case SIOCGIFNETMASK:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000113 case SIOCSIFNETMASK:
Roland McGrathe6a432d2005-02-02 20:25:17 +0000114 case SIOCGIFFLAGS:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000115 case SIOCSIFFLAGS:
Roland McGrathe6a432d2005-02-02 20:25:17 +0000116 case SIOCGIFMETRIC:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000117 case SIOCSIFMETRIC:
Roland McGrathe6a432d2005-02-02 20:25:17 +0000118 case SIOCGIFMTU:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000119 case SIOCSIFMTU:
Roland McGrathe6a432d2005-02-02 20:25:17 +0000120 case SIOCGIFSLAVE:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000121 case SIOCSIFSLAVE:
Roland McGrathe6a432d2005-02-02 20:25:17 +0000122 case SIOCGIFHWADDR:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000123 case SIOCSIFHWADDR:
Dmitry V. Levin40284242007-03-21 13:52:14 +0000124 case SIOCGIFTXQLEN:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000125 case SIOCSIFTXQLEN:
Dmitry V. Levinecdd0bb2007-03-21 13:57:50 +0000126 case SIOCGIFMAP:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000127 case SIOCSIFMAP:
Dmitry V. Levin652e4482007-03-21 14:18:17 +0000128 if (umove(tcp, tcp->u_arg[2], &ifr) < 0)
129 tprintf(", %#lx", tcp->u_arg[2]);
130 else if (syserror(tcp)) {
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000131 if (code == SIOCGIFNAME || code == SIOCSIFNAME)
Roland McGrathe6a432d2005-02-02 20:25:17 +0000132 tprintf(", {ifr_index=%d, ifr_name=???}", ifr.ifr_ifindex);
133 else
134 tprintf(", {ifr_name=\"%s\", ???}", ifr.ifr_name);
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000135 } else if (code == SIOCGIFNAME || code == SIOCSIFNAME)
Roland McGrathe6a432d2005-02-02 20:25:17 +0000136 tprintf(", {ifr_index=%d, ifr_name=\"%s\"}",
Roland McGrath5687ff12004-07-12 07:13:06 +0000137 ifr.ifr_ifindex, ifr.ifr_name);
Roland McGrathe6a432d2005-02-02 20:25:17 +0000138 else {
139 tprintf(", {ifr_name=\"%s\", ", ifr.ifr_name);
140 switch (code) {
141 case SIOCGIFINDEX:
142 tprintf("ifr_index=%d", ifr.ifr_ifindex);
143 break;
144 case SIOCGIFADDR:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000145 case SIOCSIFADDR:
Roland McGrathe6a432d2005-02-02 20:25:17 +0000146 str = "ifr_addr";
147 case SIOCGIFDSTADDR:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000148 case SIOCSIFDSTADDR:
149 if (!str)
Roland McGrathe6a432d2005-02-02 20:25:17 +0000150 str = "ifr_dstaddr";
151 case SIOCGIFBRDADDR:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000152 case SIOCSIFBRDADDR:
153 if (!str)
Roland McGrathe6a432d2005-02-02 20:25:17 +0000154 str = "ifr_broadaddr";
155 case SIOCGIFNETMASK:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000156 case SIOCSIFNETMASK:
157 if (!str)
Roland McGrathe6a432d2005-02-02 20:25:17 +0000158 str = "ifr_netmask";
159 tprintf("%s={", str);
160 printxval(addrfams,
161 ifr.ifr_addr.sa_family,
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000162 "AF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200163 tprints(", ");
Roland McGrathe6a432d2005-02-02 20:25:17 +0000164 print_addr(tcp, ((long) tcp->u_arg[2]
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200165 + offsetof(struct ifreq,
Roland McGrathe6a432d2005-02-02 20:25:17 +0000166 ifr_addr.sa_data)),
167 &ifr);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200168 tprints("}");
Roland McGrathe6a432d2005-02-02 20:25:17 +0000169 break;
170 case SIOCGIFHWADDR:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000171 case SIOCSIFHWADDR:
Roland McGrathe6a432d2005-02-02 20:25:17 +0000172 /* XXX Are there other hardware addresses
173 than 6-byte MACs? */
174 bytes = (unsigned char *) &ifr.ifr_hwaddr.sa_data;
175 tprintf("ifr_hwaddr=%02x:%02x:%02x:%02x:%02x:%02x",
176 bytes[0], bytes[1], bytes[2],
177 bytes[3], bytes[4], bytes[5]);
178 break;
179 case SIOCGIFFLAGS:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000180 case SIOCSIFFLAGS:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200181 tprints("ifr_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000182 printflags(iffflags, ifr.ifr_flags, "IFF_???");
Roland McGrathe6a432d2005-02-02 20:25:17 +0000183 break;
184 case SIOCGIFMETRIC:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000185 case SIOCSIFMETRIC:
Roland McGrathe6a432d2005-02-02 20:25:17 +0000186 tprintf("ifr_metric=%d", ifr.ifr_metric);
187 break;
188 case SIOCGIFMTU:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000189 case SIOCSIFMTU:
Roland McGrathe6a432d2005-02-02 20:25:17 +0000190 tprintf("ifr_mtu=%d", ifr.ifr_mtu);
191 break;
192 case SIOCGIFSLAVE:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000193 case SIOCSIFSLAVE:
Roland McGrathe6a432d2005-02-02 20:25:17 +0000194 tprintf("ifr_slave=\"%s\"", ifr.ifr_slave);
195 break;
Dmitry V. Levin40284242007-03-21 13:52:14 +0000196 case SIOCGIFTXQLEN:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000197 case SIOCSIFTXQLEN:
Dmitry V. Levin40284242007-03-21 13:52:14 +0000198 tprintf("ifr_qlen=%d", ifr.ifr_qlen);
199 break;
Dmitry V. Levinecdd0bb2007-03-21 13:57:50 +0000200 case SIOCGIFMAP:
Dmitry V. Levin5414bf72008-12-10 13:51:40 +0000201 case SIOCSIFMAP:
Dmitry V. Levinecdd0bb2007-03-21 13:57:50 +0000202 tprintf("ifr_map={mem_start=%#lx, "
203 "mem_end=%#lx, base_addr=%#x, "
204 "irq=%u, dma=%u, port=%u}",
205 ifr.ifr_map.mem_start,
206 ifr.ifr_map.mem_end,
207 (unsigned) ifr.ifr_map.base_addr,
208 (unsigned) ifr.ifr_map.irq,
209 (unsigned) ifr.ifr_map.dma,
210 (unsigned) ifr.ifr_map.port);
211 break;
Roland McGrathe6a432d2005-02-02 20:25:17 +0000212 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200213 tprints("}");
Roland McGrathe6a432d2005-02-02 20:25:17 +0000214 }
Roland McGrath5687ff12004-07-12 07:13:06 +0000215 return 1;
216 case SIOCGIFCONF:
Dmitry V. Levin652e4482007-03-21 14:18:17 +0000217 if (umove(tcp, tcp->u_arg[2], &ifc) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200218 tprints("???}");
Dmitry V. Levin652e4482007-03-21 14:18:17 +0000219 return 1;
220 }
Roland McGrath5687ff12004-07-12 07:13:06 +0000221 tprintf("%d, ", ifc.ifc_len);
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000222 if (syserror(tcp)) {
Roland McGrath5687ff12004-07-12 07:13:06 +0000223 tprintf("%lx", (unsigned long) ifc.ifc_buf);
224 } else if (ifc.ifc_buf == NULL) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200225 tprints("NULL");
Roland McGrath5687ff12004-07-12 07:13:06 +0000226 } else {
227 int i;
228 unsigned nifra = ifc.ifc_len / sizeof(struct ifreq);
229 struct ifreq ifra[nifra];
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000230
231 if (umoven(tcp, (unsigned long) ifc.ifc_buf,
232 sizeof(ifra), (char *) ifra) < 0) {
233 tprintf("%lx}", (unsigned long) ifc.ifc_buf);
234 return 1;
235 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200236 tprints("{");
Roland McGrath5687ff12004-07-12 07:13:06 +0000237 for (i = 0; i < nifra; ++i ) {
238 if (i > 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200239 tprints(", ");
Roland McGrath5687ff12004-07-12 07:13:06 +0000240 tprintf("{\"%s\", {",
241 ifra[i].ifr_name);
242 if (verbose(tcp)) {
243 printxval(addrfams,
244 ifra[i].ifr_addr.sa_family,
245 "AF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200246 tprints(", ");
Roland McGrathe6a432d2005-02-02 20:25:17 +0000247 print_addr(tcp, ((long) tcp->u_arg[2]
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200248 + offsetof(struct ifreq,
Roland McGrathe6a432d2005-02-02 20:25:17 +0000249 ifr_addr.sa_data)
250 + ((char *) &ifra[i]
251 - (char *) &ifra[0])),
252 &ifra[i]);
Roland McGrath5687ff12004-07-12 07:13:06 +0000253 } else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200254 tprints("...");
255 tprints("}}");
Roland McGrath5687ff12004-07-12 07:13:06 +0000256 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200257 tprints("}");
Roland McGrath5687ff12004-07-12 07:13:06 +0000258 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200259 tprints("}");
Roland McGrath5687ff12004-07-12 07:13:06 +0000260 return 1;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000261 default:
262 return 0;
263 }
264}
Dmitry V. Levinb5e88d42012-02-20 17:02:38 +0000265
266int
267sys_socketcall(struct tcb *tcp)
268{
269 return printargs(tcp);
270}