blob: 7dca3e0ed4112872ed3ce22aa5317b2d63b74fbc [file] [log] [blame]
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +00001/*
2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
5 * Copyright (c) 1996-2000 Wichert Akkerman <wichert@cistron.nl>
6 * Copyright (c) 2005-2016 Dmitry V. Levin <ldv@altlinux.org>
Elliott Hughes03a418e2018-06-15 13:11:40 -07007 * Copyright (c) 2016-2018 The strace developers.
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +00008 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#include "defs.h"
Elliott Hughes77c3ff82017-09-08 17:11:00 -070034#include "print_fields.h"
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +000035#include "msghdr.h"
Dmitry V. Levin8da96682016-07-15 22:58:48 +000036#include <limits.h>
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +000037#include <arpa/inet.h>
38#include <netinet/in.h>
39
40#include "xlat/msg_flags.h"
41#include "xlat/scmvals.h"
42#include "xlat/ip_cmsg_types.h"
43
Elliott Hughesd35df492017-02-15 15:19:05 -080044#ifndef current_wordsize
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +000045struct cmsghdr32 {
46 uint32_t cmsg_len;
47 int cmsg_level;
48 int cmsg_type;
49};
50#endif
51
52typedef union {
53 char *ptr;
54 struct cmsghdr *cmsg;
Elliott Hughesd35df492017-02-15 15:19:05 -080055#ifndef current_wordsize
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +000056 struct cmsghdr32 *cmsg32;
57#endif
58} union_cmsghdr;
59
60static void
Elliott Hughesd35df492017-02-15 15:19:05 -080061print_scm_rights(struct tcb *tcp, const void *cmsg_data,
62 const unsigned int data_len)
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +000063{
64 const int *fds = cmsg_data;
Elliott Hughesd35df492017-02-15 15:19:05 -080065 const unsigned int nfds = data_len / sizeof(*fds);
66 unsigned int i;
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +000067
Dmitry V. Levindf57a9b2016-06-30 22:49:36 +000068 tprints("[");
Dmitry V. Levin029d9792016-06-30 22:20:56 +000069
70 for (i = 0; i < nfds; ++i) {
71 if (i)
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +000072 tprints(", ");
Dmitry V. Levind35d5ec2016-07-02 21:14:26 +000073 if (abbrev(tcp) && i >= max_strlen) {
74 tprints("...");
75 break;
76 }
Dmitry V. Levin029d9792016-06-30 22:20:56 +000077 printfd(tcp, fds[i]);
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +000078 }
Dmitry V. Levin029d9792016-06-30 22:20:56 +000079
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +000080 tprints("]");
81}
82
83static void
Elliott Hughesd35df492017-02-15 15:19:05 -080084print_scm_creds(struct tcb *tcp, const void *cmsg_data,
85 const unsigned int data_len)
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +000086{
87 const struct ucred *uc = cmsg_data;
88
Elliott Hughes77c3ff82017-09-08 17:11:00 -070089 PRINT_FIELD_U("{", *uc, pid);
90 PRINT_FIELD_UID(", ", *uc, uid);
91 PRINT_FIELD_UID(", ", *uc, gid);
92 tprints("}");
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +000093}
94
95static void
96print_scm_security(struct tcb *tcp, const void *cmsg_data,
Elliott Hughesd35df492017-02-15 15:19:05 -080097 const unsigned int data_len)
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +000098{
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +000099 print_quoted_string(cmsg_data, data_len, 0);
100}
101
102static void
Elliott Hughesdc75b012017-07-05 13:54:44 -0700103print_scm_timestamp(struct tcb *tcp, const void *cmsg_data,
104 const unsigned int data_len)
105{
106 print_struct_timeval_data_size(cmsg_data, data_len);
107}
108
109static void
110print_scm_timestampns(struct tcb *tcp, const void *cmsg_data,
111 const unsigned int data_len)
112{
113 print_struct_timespec_data_size(cmsg_data, data_len);
114}
115
116static void
117print_scm_timestamping(struct tcb *tcp, const void *cmsg_data,
118 const unsigned int data_len)
119{
120 print_struct_timespec_array_data_size(cmsg_data, 3, data_len);
121}
122
123static void
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000124print_cmsg_ip_pktinfo(struct tcb *tcp, const void *cmsg_data,
Elliott Hughesd35df492017-02-15 15:19:05 -0800125 const unsigned int data_len)
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000126{
127 const struct in_pktinfo *info = cmsg_data;
128
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700129 PRINT_FIELD_IFINDEX("{", *info, ipi_ifindex);
130 PRINT_FIELD_INET4_ADDR(", ", *info, ipi_spec_dst);
131 PRINT_FIELD_INET4_ADDR(", ", *info, ipi_addr);
132 tprints("}");
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000133}
134
135static void
Elliott Hughesd35df492017-02-15 15:19:05 -0800136print_cmsg_uint(struct tcb *tcp, const void *cmsg_data,
137 const unsigned int data_len)
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000138{
Dmitry V. Levinb7937bd2016-06-30 22:39:02 +0000139 const unsigned int *p = cmsg_data;
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000140
Dmitry V. Levindf57a9b2016-06-30 22:49:36 +0000141 tprintf("[%u]", *p);
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000142}
143
144static void
Dmitry V. Levindf57a9b2016-06-30 22:49:36 +0000145print_cmsg_uint8_t(struct tcb *tcp, const void *cmsg_data,
Elliott Hughesd35df492017-02-15 15:19:05 -0800146 const unsigned int data_len)
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000147{
Dmitry V. Levindf57a9b2016-06-30 22:49:36 +0000148 const uint8_t *p = cmsg_data;
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000149
Dmitry V. Levindf57a9b2016-06-30 22:49:36 +0000150 tprintf("[%#x]", *p);
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000151}
152
153static void
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000154print_cmsg_ip_opts(struct tcb *tcp, const void *cmsg_data,
Elliott Hughesd35df492017-02-15 15:19:05 -0800155 const unsigned int data_len)
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000156{
157 const unsigned char *opts = cmsg_data;
Elliott Hughesd35df492017-02-15 15:19:05 -0800158 unsigned int i;
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000159
Dmitry V. Levindf57a9b2016-06-30 22:49:36 +0000160 tprints("[");
Dmitry V. Levin2a897372016-06-28 22:25:10 +0000161 for (i = 0; i < data_len; ++i) {
162 if (i)
163 tprints(", ");
Dmitry V. Levin67135822016-07-02 21:14:48 +0000164 if (abbrev(tcp) && i >= max_strlen) {
165 tprints("...");
166 break;
167 }
Dmitry V. Levin2a897372016-06-28 22:25:10 +0000168 tprintf("0x%02x", opts[i]);
169 }
170 tprints("]");
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000171}
172
Dmitry V. Levindf57a9b2016-06-30 22:49:36 +0000173struct sock_ee {
174 uint32_t ee_errno;
175 uint8_t ee_origin;
176 uint8_t ee_type;
177 uint8_t ee_code;
178 uint8_t ee_pad;
179 uint32_t ee_info;
180 uint32_t ee_data;
181 struct sockaddr_in offender;
182};
183
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000184static void
185print_cmsg_ip_recverr(struct tcb *tcp, const void *cmsg_data,
Elliott Hughesd35df492017-02-15 15:19:05 -0800186 const unsigned int data_len)
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000187{
Dmitry V. Levindf57a9b2016-06-30 22:49:36 +0000188 const struct sock_ee *const err = cmsg_data;
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000189
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700190 PRINT_FIELD_U("{", *err, ee_errno);
191 PRINT_FIELD_U(", ", *err, ee_origin);
192 PRINT_FIELD_U(", ", *err, ee_type);
193 PRINT_FIELD_U(", ", *err, ee_code);
194 PRINT_FIELD_U(", ", *err, ee_info);
195 PRINT_FIELD_U(", ", *err, ee_data);
196 PRINT_FIELD_SOCKADDR(", ", *err, offender);
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000197 tprints("}");
198}
199
200static void
201print_cmsg_ip_origdstaddr(struct tcb *tcp, const void *cmsg_data,
Elliott Hughesd35df492017-02-15 15:19:05 -0800202 const unsigned int data_len)
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000203{
Elliott Hughesd35df492017-02-15 15:19:05 -0800204 const unsigned int addr_len =
Dmitry V. Levindfeea692016-06-30 22:26:35 +0000205 data_len > sizeof(struct sockaddr_storage)
206 ? sizeof(struct sockaddr_storage) : data_len;
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000207
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700208 print_sockaddr(cmsg_data, addr_len);
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000209}
210
Elliott Hughesd35df492017-02-15 15:19:05 -0800211typedef void (* const cmsg_printer)(struct tcb *, const void *, unsigned int);
Dmitry V. Levindf57a9b2016-06-30 22:49:36 +0000212
213static const struct {
214 const cmsg_printer printer;
Elliott Hughesd35df492017-02-15 15:19:05 -0800215 const unsigned int min_len;
Dmitry V. Levindf57a9b2016-06-30 22:49:36 +0000216} cmsg_socket_printers[] = {
217 [SCM_RIGHTS] = { print_scm_rights, sizeof(int) },
218 [SCM_CREDENTIALS] = { print_scm_creds, sizeof(struct ucred) },
Elliott Hughesdc75b012017-07-05 13:54:44 -0700219 [SCM_SECURITY] = { print_scm_security, 1 },
220 [SCM_TIMESTAMP] = { print_scm_timestamp, 1 },
221 [SCM_TIMESTAMPNS] = { print_scm_timestampns, 1 },
222 [SCM_TIMESTAMPING] = { print_scm_timestamping, 1 }
Dmitry V. Levindf57a9b2016-06-30 22:49:36 +0000223}, cmsg_ip_printers[] = {
224 [IP_PKTINFO] = { print_cmsg_ip_pktinfo, sizeof(struct in_pktinfo) },
225 [IP_TTL] = { print_cmsg_uint, sizeof(unsigned int) },
226 [IP_TOS] = { print_cmsg_uint8_t, 1 },
227 [IP_RECVOPTS] = { print_cmsg_ip_opts, 1 },
228 [IP_RETOPTS] = { print_cmsg_ip_opts, 1 },
229 [IP_RECVERR] = { print_cmsg_ip_recverr, sizeof(struct sock_ee) },
230 [IP_ORIGDSTADDR] = { print_cmsg_ip_origdstaddr, sizeof(struct sockaddr_in) },
231 [IP_CHECKSUM] = { print_cmsg_uint, sizeof(unsigned int) },
232 [SCM_SECURITY] = { print_scm_security, 1 }
233};
234
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000235static void
236print_cmsg_type_data(struct tcb *tcp, const int cmsg_level, const int cmsg_type,
Elliott Hughesd35df492017-02-15 15:19:05 -0800237 const void *cmsg_data, const unsigned int data_len)
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000238{
Dmitry V. Levindf57a9b2016-06-30 22:49:36 +0000239 const unsigned int utype = cmsg_type;
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000240 switch (cmsg_level) {
241 case SOL_SOCKET:
242 printxval(scmvals, cmsg_type, "SCM_???");
Dmitry V. Levindf57a9b2016-06-30 22:49:36 +0000243 if (utype < ARRAY_SIZE(cmsg_socket_printers)
244 && cmsg_socket_printers[utype].printer
245 && data_len >= cmsg_socket_printers[utype].min_len) {
246 tprints(", cmsg_data=");
247 cmsg_socket_printers[utype].printer(tcp, cmsg_data, data_len);
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000248 }
249 break;
250 case SOL_IP:
251 printxval(ip_cmsg_types, cmsg_type, "IP_???");
Dmitry V. Levindf57a9b2016-06-30 22:49:36 +0000252 if (utype < ARRAY_SIZE(cmsg_ip_printers)
253 && cmsg_ip_printers[utype].printer
254 && data_len >= cmsg_ip_printers[utype].min_len) {
255 tprints(", cmsg_data=");
256 cmsg_ip_printers[utype].printer(tcp, cmsg_data, data_len);
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000257 }
258 break;
259 default:
Dmitry V. Levin6c30aec2016-06-30 22:14:51 +0000260 tprintf("%#x", cmsg_type);
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000261 }
262}
263
Dmitry V. Levinbf2698a2016-07-03 22:15:45 +0000264static unsigned int
Elliott Hughesb7556142018-02-20 17:03:16 -0800265get_optmem_max(struct tcb *tcp)
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000266{
Dmitry V. Levinbf2698a2016-07-03 22:15:45 +0000267 static int optmem_max;
268
269 if (!optmem_max) {
Elliott Hughesb7556142018-02-20 17:03:16 -0800270 if (read_int_from_file(tcp, "/proc/sys/net/core/optmem_max",
Dmitry V. Levinbf2698a2016-07-03 22:15:45 +0000271 &optmem_max) || optmem_max <= 0) {
Dmitry V. Levin8da96682016-07-15 22:58:48 +0000272 optmem_max = sizeof(long long) * (2 * IOV_MAX + 512);
Dmitry V. Levinbf2698a2016-07-03 22:15:45 +0000273 } else {
274 optmem_max = (optmem_max + sizeof(long long) - 1)
275 & ~(sizeof(long long) - 1);
276 }
277 }
278
279 return optmem_max;
280}
281
282static void
Elliott Hughesd35df492017-02-15 15:19:05 -0800283decode_msg_control(struct tcb *const tcp, const kernel_ulong_t addr,
284 const kernel_ulong_t in_control_len)
Dmitry V. Levinbf2698a2016-07-03 22:15:45 +0000285{
286 if (!in_control_len)
Dmitry V. Levin1d532102016-06-30 22:34:27 +0000287 return;
288 tprints(", msg_control=");
289
Elliott Hughesd35df492017-02-15 15:19:05 -0800290 const unsigned int cmsg_size =
291#ifndef current_wordsize
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000292 (current_wordsize < sizeof(long)) ? sizeof(struct cmsghdr32) :
293#endif
294 sizeof(struct cmsghdr);
295
Elliott Hughesb7556142018-02-20 17:03:16 -0800296 unsigned int control_len = in_control_len > get_optmem_max(tcp)
297 ? get_optmem_max(tcp) : in_control_len;
Elliott Hughesd35df492017-02-15 15:19:05 -0800298 unsigned int buf_len = control_len;
Dmitry V. Levin1d532102016-06-30 22:34:27 +0000299 char *buf = buf_len < cmsg_size ? NULL : malloc(buf_len);
300 if (!buf || umoven(tcp, addr, buf_len, buf) < 0) {
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000301 printaddr(addr);
302 free(buf);
303 return;
304 }
305
306 union_cmsghdr u = { .ptr = buf };
307
308 tprints("[");
Dmitry V. Levin1d532102016-06-30 22:34:27 +0000309 while (buf_len >= cmsg_size) {
Elliott Hughesd35df492017-02-15 15:19:05 -0800310 const kernel_ulong_t cmsg_len =
311#ifndef current_wordsize
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000312 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_len :
313#endif
314 u.cmsg->cmsg_len;
Dmitry V. Levin1d532102016-06-30 22:34:27 +0000315 const int cmsg_level =
Elliott Hughesd35df492017-02-15 15:19:05 -0800316#ifndef current_wordsize
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000317 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_level :
318#endif
319 u.cmsg->cmsg_level;
Dmitry V. Levin1d532102016-06-30 22:34:27 +0000320 const int cmsg_type =
Elliott Hughesd35df492017-02-15 15:19:05 -0800321#ifndef current_wordsize
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000322 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_type :
323#endif
324 u.cmsg->cmsg_type;
325
326 if (u.ptr != buf)
327 tprints(", ");
Elliott Hughesd35df492017-02-15 15:19:05 -0800328 tprintf("{cmsg_len=%" PRI_klu ", cmsg_level=", cmsg_len);
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000329 printxval(socketlayers, cmsg_level, "SOL_???");
330 tprints(", cmsg_type=");
331
Elliott Hughesd35df492017-02-15 15:19:05 -0800332 kernel_ulong_t len = cmsg_len > buf_len ? buf_len : cmsg_len;
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000333
334 print_cmsg_type_data(tcp, cmsg_level, cmsg_type,
335 (const void *) (u.ptr + cmsg_size),
Elliott Hughesdc75b012017-07-05 13:54:44 -0700336 len > cmsg_size ? len - cmsg_size : 0);
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000337 tprints("}");
338
Dmitry V. Levin1d532102016-06-30 22:34:27 +0000339 if (len < cmsg_size) {
340 buf_len -= cmsg_size;
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000341 break;
342 }
Dmitry V. Levin1d532102016-06-30 22:34:27 +0000343 len = (cmsg_len + current_wordsize - 1) &
Elliott Hughesd35df492017-02-15 15:19:05 -0800344 ~((kernel_ulong_t) current_wordsize - 1);
Dmitry V. Levin1d532102016-06-30 22:34:27 +0000345 if (len >= buf_len) {
346 buf_len = 0;
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000347 break;
348 }
Dmitry V. Levin1d532102016-06-30 22:34:27 +0000349 u.ptr += len;
350 buf_len -= len;
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000351 }
Dmitry V. Levin1d532102016-06-30 22:34:27 +0000352 if (buf_len) {
Elliott Hughes03a418e2018-06-15 13:11:40 -0700353 tprints(", ...");
354 printaddr_comment(addr + (control_len - buf_len));
Dmitry V. Levinbf2698a2016-07-03 22:15:45 +0000355 } else if (control_len < in_control_len) {
356 tprints(", ...");
Dmitry V. Levin1d532102016-06-30 22:34:27 +0000357 }
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000358 tprints("]");
359 free(buf);
360}
361
Dmitry V. Levin7c37ce42016-07-14 22:13:58 +0000362void
363print_struct_msghdr(struct tcb *tcp, const struct msghdr *msg,
364 const int *const p_user_msg_namelen,
Elliott Hughesd35df492017-02-15 15:19:05 -0800365 const kernel_ulong_t data_size)
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000366{
Dmitry V. Levind8f77cd2016-07-13 21:56:16 +0000367 const int msg_namelen =
368 p_user_msg_namelen && (int) msg->msg_namelen > *p_user_msg_namelen
369 ? *p_user_msg_namelen : (int) msg->msg_namelen;
Fabien Siron2850f742016-07-06 15:49:22 +0000370
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000371 tprints("{msg_name=");
Dmitry V. Levind8f77cd2016-07-13 21:56:16 +0000372 const int family =
Elliott Hughesd35df492017-02-15 15:19:05 -0800373 decode_sockaddr(tcp, ptr_to_kulong(msg->msg_name), msg_namelen);
Dmitry V. Levind8f77cd2016-07-13 21:56:16 +0000374 const enum iov_decode decode =
375 (family == AF_NETLINK) ? IOV_DECODE_NETLINK : IOV_DECODE_STR;
376
377 tprints(", msg_namelen=");
378 if (p_user_msg_namelen && *p_user_msg_namelen != (int) msg->msg_namelen)
379 tprintf("%d->", *p_user_msg_namelen);
380 tprintf("%d", msg->msg_namelen);
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000381
382 tprints(", msg_iov=");
Elliott Hughesd35df492017-02-15 15:19:05 -0800383 tprint_iov_upto(tcp, msg->msg_iovlen,
384 ptr_to_kulong(msg->msg_iov), decode, data_size);
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700385 PRINT_FIELD_U(", ", *msg, msg_iovlen);
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000386
Elliott Hughesd35df492017-02-15 15:19:05 -0800387 decode_msg_control(tcp, ptr_to_kulong(msg->msg_control),
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000388 msg->msg_controllen);
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700389 PRINT_FIELD_U(", ", *msg, msg_controllen);
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000390
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700391 PRINT_FIELD_FLAGS(", ", *msg, msg_flags, msg_flags, "MSG_???");
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000392 tprints("}");
393}
394
Dmitry V. Levindc84fa32016-07-14 22:26:28 +0000395static bool
Elliott Hughesd35df492017-02-15 15:19:05 -0800396fetch_msghdr_namelen(struct tcb *const tcp, const kernel_ulong_t addr,
397 int *const p_msg_namelen)
Dmitry V. Levind8f77cd2016-07-13 21:56:16 +0000398{
399 struct msghdr msg;
400
401 if (addr && verbose(tcp) && fetch_struct_msghdr(tcp, addr, &msg)) {
402 *p_msg_namelen = msg.msg_namelen;
403 return true;
404 } else {
405 return false;
406 }
407}
408
Dmitry V. Levindc84fa32016-07-14 22:26:28 +0000409static void
Elliott Hughesd35df492017-02-15 15:19:05 -0800410decode_msghdr(struct tcb *const tcp, const int *const p_user_msg_namelen,
411 const kernel_ulong_t addr, const kernel_ulong_t data_size)
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000412{
413 struct msghdr msg;
414
415 if (addr && verbose(tcp) && fetch_struct_msghdr(tcp, addr, &msg))
Dmitry V. Levin7c37ce42016-07-14 22:13:58 +0000416 print_struct_msghdr(tcp, &msg, p_user_msg_namelen, data_size);
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000417 else
418 printaddr(addr);
419}
420
421void
Elliott Hughesd35df492017-02-15 15:19:05 -0800422dumpiov_in_msghdr(struct tcb *const tcp, const kernel_ulong_t addr,
423 const kernel_ulong_t data_size)
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000424{
425 struct msghdr msg;
426
Elliott Hughesd35df492017-02-15 15:19:05 -0800427 if (fetch_struct_msghdr(tcp, addr, &msg)) {
428 dumpiov_upto(tcp, msg.msg_iovlen,
429 ptr_to_kulong(msg.msg_iov), data_size);
430 }
Dmitry V. Levin95cce4f2016-06-27 00:02:55 +0000431}
Dmitry V. Levindc84fa32016-07-14 22:26:28 +0000432
433SYS_FUNC(sendmsg)
434{
435 printfd(tcp, tcp->u_arg[0]);
436 tprints(", ");
Elliott Hughesd35df492017-02-15 15:19:05 -0800437 decode_msghdr(tcp, 0, tcp->u_arg[1], -1);
Dmitry V. Levindc84fa32016-07-14 22:26:28 +0000438 /* flags */
439 tprints(", ");
440 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
441
442 return RVAL_DECODED;
443}
444
445SYS_FUNC(recvmsg)
446{
447 int msg_namelen;
448
449 if (entering(tcp)) {
450 printfd(tcp, tcp->u_arg[0]);
451 tprints(", ");
452 if (fetch_msghdr_namelen(tcp, tcp->u_arg[1], &msg_namelen)) {
Dmitry V. Levinb759d272016-07-15 16:08:19 +0000453 set_tcb_priv_ulong(tcp, msg_namelen);
Dmitry V. Levindc84fa32016-07-14 22:26:28 +0000454 return 0;
455 }
456 printaddr(tcp->u_arg[1]);
457 } else {
Dmitry V. Levinb759d272016-07-15 16:08:19 +0000458 msg_namelen = get_tcb_priv_ulong(tcp);
Dmitry V. Levindc84fa32016-07-14 22:26:28 +0000459
460 if (syserror(tcp))
461 tprintf("{msg_namelen=%d}", msg_namelen);
462 else
463 decode_msghdr(tcp, &msg_namelen, tcp->u_arg[1],
464 tcp->u_rval);
465 }
466
467 /* flags */
468 tprints(", ");
469 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
470
471 return RVAL_DECODED;
472}