]> granicus.if.org Git - strace/blobdiff - msghdr.c
tests: check decoding of netlink smc_diag_msg attributes
[strace] / msghdr.c
index 7a830b9523b04b2c831e85102bb59e95bf3a111d..14b0a8d159eb8727b2246405eb0278d1cfae06e7 100644 (file)
--- a/msghdr.c
+++ b/msghdr.c
@@ -30,6 +30,7 @@
  */
 
 #include "defs.h"
+#include "print_fields.h"
 #include "msghdr.h"
 #include <limits.h>
 #include <arpa/inet.h>
@@ -39,7 +40,7 @@
 #include "xlat/scmvals.h"
 #include "xlat/ip_cmsg_types.h"
 
-#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
+#ifndef current_wordsize
 struct cmsghdr32 {
        uint32_t cmsg_len;
        int cmsg_level;
@@ -50,7 +51,7 @@ struct cmsghdr32 {
 typedef union {
        char *ptr;
        struct cmsghdr *cmsg;
-#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
+#ifndef current_wordsize
        struct cmsghdr32 *cmsg32;
 #endif
 } union_cmsghdr;
@@ -84,8 +85,10 @@ print_scm_creds(struct tcb *tcp, const void *cmsg_data,
 {
        const struct ucred *uc = cmsg_data;
 
-       tprintf("{pid=%u, uid=%u, gid=%u}",
-               (unsigned) uc->pid, (unsigned) uc->uid, (unsigned) uc->gid);
+       PRINT_FIELD_U("{", *uc, pid);
+       PRINT_FIELD_UID(", ", *uc, uid);
+       PRINT_FIELD_UID(", ", *uc, gid);
+       tprints("}");
 }
 
 static void
@@ -95,18 +98,37 @@ print_scm_security(struct tcb *tcp, const void *cmsg_data,
        print_quoted_string(cmsg_data, data_len, 0);
 }
 
+static void
+print_scm_timestamp(struct tcb *tcp, const void *cmsg_data,
+                   const unsigned int data_len)
+{
+       print_struct_timeval_data_size(cmsg_data, data_len);
+}
+
+static void
+print_scm_timestampns(struct tcb *tcp, const void *cmsg_data,
+                     const unsigned int data_len)
+{
+       print_struct_timespec_data_size(cmsg_data, data_len);
+}
+
+static void
+print_scm_timestamping(struct tcb *tcp, const void *cmsg_data,
+                      const unsigned int data_len)
+{
+       print_struct_timespec_array_data_size(cmsg_data, 3, data_len);
+}
+
 static void
 print_cmsg_ip_pktinfo(struct tcb *tcp, const void *cmsg_data,
                      const unsigned int data_len)
 {
        const struct in_pktinfo *info = cmsg_data;
 
-       tprints("{ipi_ifindex=");
-       print_ifindex(info->ipi_ifindex);
-       tprintf(", ipi_spec_dst=inet_addr(\"%s\")",
-               inet_ntoa(info->ipi_spec_dst));
-       tprintf(", ipi_addr=inet_addr(\"%s\")}",
-               inet_ntoa(info->ipi_addr));
+       PRINT_FIELD_IFINDEX("{", *info, ipi_ifindex);
+       PRINT_FIELD_INET4_ADDR(", ", *info, ipi_spec_dst);
+       PRINT_FIELD_INET4_ADDR(", ", *info, ipi_addr);
+       tprints("}");
 }
 
 static void
@@ -164,11 +186,13 @@ print_cmsg_ip_recverr(struct tcb *tcp, const void *cmsg_data,
 {
        const struct sock_ee *const err = cmsg_data;
 
-       tprintf("{ee_errno=%u, ee_origin=%u, ee_type=%u, ee_code=%u"
-               ", ee_info=%u, ee_data=%u, offender=",
-               err->ee_errno, err->ee_origin, err->ee_type,
-               err->ee_code, err->ee_info, err->ee_data);
-       print_sockaddr(tcp, &err->offender, sizeof(err->offender));
+       PRINT_FIELD_U("{", *err, ee_errno);
+       PRINT_FIELD_U(", ", *err, ee_origin);
+       PRINT_FIELD_U(", ", *err, ee_type);
+       PRINT_FIELD_U(", ", *err, ee_code);
+       PRINT_FIELD_U(", ", *err, ee_info);
+       PRINT_FIELD_U(", ", *err, ee_data);
+       PRINT_FIELD_SOCKADDR(", ", *err, offender);
        tprints("}");
 }
 
@@ -180,7 +204,7 @@ print_cmsg_ip_origdstaddr(struct tcb *tcp, const void *cmsg_data,
                data_len > sizeof(struct sockaddr_storage)
                ? sizeof(struct sockaddr_storage) : data_len;
 
-       print_sockaddr(tcp, cmsg_data, addr_len);
+       print_sockaddr(cmsg_data, addr_len);
 }
 
 typedef void (* const cmsg_printer)(struct tcb *, const void *, unsigned int);
@@ -191,7 +215,10 @@ static const struct {
 } cmsg_socket_printers[] = {
        [SCM_RIGHTS] = { print_scm_rights, sizeof(int) },
        [SCM_CREDENTIALS] = { print_scm_creds, sizeof(struct ucred) },
-       [SCM_SECURITY] = { print_scm_security, 1 }
+       [SCM_SECURITY] = { print_scm_security, 1 },
+       [SCM_TIMESTAMP] = { print_scm_timestamp, 1 },
+       [SCM_TIMESTAMPNS] = { print_scm_timestampns, 1 },
+       [SCM_TIMESTAMPING] = { print_scm_timestamping, 1 }
 }, cmsg_ip_printers[] = {
        [IP_PKTINFO] = { print_cmsg_ip_pktinfo, sizeof(struct in_pktinfo) },
        [IP_TTL] = { print_cmsg_uint, sizeof(unsigned int) },
@@ -252,15 +279,15 @@ get_optmem_max(void)
 }
 
 static void
-decode_msg_control(struct tcb *const tcp, const kernel_ureg_t addr,
-                  const kernel_ureg_t in_control_len)
+decode_msg_control(struct tcb *const tcp, const kernel_ulong_t addr,
+                  const kernel_ulong_t in_control_len)
 {
        if (!in_control_len)
                return;
        tprints(", msg_control=");
 
        const unsigned int cmsg_size =
-#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
+#ifndef current_wordsize
                (current_wordsize < sizeof(long)) ? sizeof(struct cmsghdr32) :
 #endif
                        sizeof(struct cmsghdr);
@@ -279,33 +306,33 @@ decode_msg_control(struct tcb *const tcp, const kernel_ureg_t addr,
 
        tprints("[");
        while (buf_len >= cmsg_size) {
-               const kernel_ureg_t cmsg_len =
-#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
+               const kernel_ulong_t cmsg_len =
+#ifndef current_wordsize
                        (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_len :
 #endif
                                u.cmsg->cmsg_len;
                const int cmsg_level =
-#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
+#ifndef current_wordsize
                        (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_level :
 #endif
                                u.cmsg->cmsg_level;
                const int cmsg_type =
-#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
+#ifndef current_wordsize
                        (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_type :
 #endif
                                u.cmsg->cmsg_type;
 
                if (u.ptr != buf)
                        tprints(", ");
-               tprintf("{cmsg_len=%lu, cmsg_level=", (unsigned long) cmsg_len);
+               tprintf("{cmsg_len=%" PRI_klu ", cmsg_level=", cmsg_len);
                printxval(socketlayers, cmsg_level, "SOL_???");
                tprints(", cmsg_type=");
 
-               kernel_ureg_t len = cmsg_len > buf_len ? buf_len : cmsg_len;
+               kernel_ulong_t len = cmsg_len > buf_len ? buf_len : cmsg_len;
 
                print_cmsg_type_data(tcp, cmsg_level, cmsg_type,
                                     (const void *) (u.ptr + cmsg_size),
-                                    len > cmsg_size ? len - cmsg_size: 0);
+                                    len > cmsg_size ? len - cmsg_size : 0);
                tprints("}");
 
                if (len < cmsg_size) {
@@ -313,7 +340,7 @@ decode_msg_control(struct tcb *const tcp, const kernel_ureg_t addr,
                        break;
                }
                len = (cmsg_len + current_wordsize - 1) &
-                       ~((kernel_ureg_t) current_wordsize - 1);
+                       ~((kernel_ulong_t) current_wordsize - 1);
                if (len >= buf_len) {
                        buf_len = 0;
                        break;
@@ -334,7 +361,7 @@ decode_msg_control(struct tcb *const tcp, const kernel_ureg_t addr,
 void
 print_struct_msghdr(struct tcb *tcp, const struct msghdr *msg,
                    const int *const p_user_msg_namelen,
-                   const kernel_ureg_t data_size)
+                   const kernel_ulong_t data_size)
 {
        const int msg_namelen =
                p_user_msg_namelen && (int) msg->msg_namelen > *p_user_msg_namelen
@@ -352,22 +379,20 @@ print_struct_msghdr(struct tcb *tcp, const struct msghdr *msg,
        tprintf("%d", msg->msg_namelen);
 
        tprints(", msg_iov=");
-
        tprint_iov_upto(tcp, msg->msg_iovlen,
                        ptr_to_kulong(msg->msg_iov), decode, data_size);
-       tprintf(", msg_iovlen=%lu", (kernel_ureg_t) msg->msg_iovlen);
+       PRINT_FIELD_U(", ", *msg, msg_iovlen);
 
        decode_msg_control(tcp, ptr_to_kulong(msg->msg_control),
                           msg->msg_controllen);
-       tprintf(", msg_controllen=%lu", (kernel_ureg_t) msg->msg_controllen);
+       PRINT_FIELD_U(", ", *msg, msg_controllen);
 
-       tprints(", msg_flags=");
-       printflags(msg_flags, msg->msg_flags, "MSG_???");
+       PRINT_FIELD_FLAGS(", ", *msg, msg_flags, msg_flags, "MSG_???");
        tprints("}");
 }
 
 static bool
-fetch_msghdr_namelen(struct tcb *const tcp, const kernel_ureg_t addr,
+fetch_msghdr_namelen(struct tcb *const tcp, const kernel_ulong_t addr,
                     int *const p_msg_namelen)
 {
        struct msghdr msg;
@@ -382,7 +407,7 @@ fetch_msghdr_namelen(struct tcb *const tcp, const kernel_ureg_t addr,
 
 static void
 decode_msghdr(struct tcb *const tcp, const int *const p_user_msg_namelen,
-             const kernel_ureg_t addr, const kernel_ureg_t data_size)
+             const kernel_ulong_t addr, const kernel_ulong_t data_size)
 {
        struct msghdr msg;
 
@@ -393,8 +418,8 @@ decode_msghdr(struct tcb *const tcp, const int *const p_user_msg_namelen,
 }
 
 void
-dumpiov_in_msghdr(struct tcb *const tcp, const kernel_ureg_t addr,
-                 const kernel_ureg_t data_size)
+dumpiov_in_msghdr(struct tcb *const tcp, const kernel_ulong_t addr,
+                 const kernel_ulong_t data_size)
 {
        struct msghdr msg;