]> granicus.if.org Git - strace/blobdiff - netlink.c
nlattr: add unsigned int decoders that print in hex form
[strace] / netlink.c
index f5fa1f13a5de2880d75eab2c62becf3cd2968c1b..8a30483c39c45664e977511b2c89fc4ceff78483 100644 (file)
--- a/netlink.c
+++ b/netlink.c
@@ -1,7 +1,7 @@
 /*
  * Copyright (c) 2016 Fabien Siron <fabien.siron@epita.fr>
  * Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
- * Copyright (c) 2016-2017 The strace developers.
+ * Copyright (c) 2016-2018 The strace developers.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -53,7 +53,6 @@
 #include "xlat/nf_ulog_msg_types.h"
 #include "xlat/nl_audit_types.h"
 #include "xlat/nl_crypto_types.h"
-#include "xlat/nl_netfilter_msg_types.h"
 #include "xlat/nl_netfilter_subsys_ids.h"
 #include "xlat/nl_selinux_types.h"
 #include "xlat/nl_sock_diag_types.h"
  */
 static bool
 fetch_nlmsghdr(struct tcb *const tcp, struct nlmsghdr *const nlmsghdr,
-              const kernel_ulong_t addr, const kernel_ulong_t len)
+              const kernel_ulong_t addr, const kernel_ulong_t len,
+              const bool in_array)
 {
        if (len < sizeof(struct nlmsghdr)) {
                printstr_ex(tcp, addr, len, QUOTE_FORCE_HEX);
                return false;
        }
 
-       if (umove_or_printaddr(tcp, addr, nlmsghdr))
-               return false;
+       if (tfetch_obj(tcp, addr, nlmsghdr))
+               return true;
 
-       return true;
+       if (in_array) {
+               tprints("...");
+               printaddr_comment(addr);
+       } else {
+               printaddr(addr);
+       }
+
+       return false;
 }
 
 static int
@@ -162,7 +169,7 @@ decode_nlmsg_type_netfilter(struct tcb *tcp, const struct xlat *const xlat,
        /* Reserved control nfnetlink messages first. */
        const char *const text = xlookup(nl_netfilter_msg_types, type);
        if (text) {
-               tprints(text);
+               print_xlat_ex(type, text, XLAT_STYLE_DEFAULT);
                return;
        }
 
@@ -431,7 +438,8 @@ decode_nlmsg_flags(const uint16_t flags, const uint16_t type,
        } else if (family < ARRAY_SIZE(nlmsg_flags) && nlmsg_flags[family])
                table = nlmsg_flags[family](type);
 
-       printflags_ex(flags, "NLM_F_???", netlink_flags, table, NULL);
+       printflags_ex(flags, "NLM_F_???", XLAT_STYLE_ABBREV,
+                     netlink_flags, table, NULL);
 }
 
 static void
@@ -473,7 +481,7 @@ decode_nlmsgerr_attr_cookie(struct tcb *const tcp,
        const size_t nmemb = len / sizeof(cookie);
 
        print_array(tcp, addr, nmemb, &cookie, sizeof(cookie),
-                   umoven_or_printaddr, print_cookie, 0);
+                   tfetch_mem, print_cookie, 0);
 
        return true;
 }
@@ -522,7 +530,7 @@ decode_nlmsgerr(struct tcb *const tcp,
 
        if (len) {
                tprints(", msg=");
-               if (fetch_nlmsghdr(tcp, &err.msg, addr, len)) {
+               if (fetch_nlmsghdr(tcp, &err.msg, addr, len, false)) {
                        unsigned int payload =
                                capped ? sizeof(err.msg) : err.msg.nlmsg_len;
                        if (payload > len)
@@ -607,8 +615,7 @@ decode_nlmsghdr_with_payload(struct tcb *const tcp,
                             const kernel_ulong_t addr,
                             const kernel_ulong_t len)
 {
-       const unsigned int nlmsg_len =
-               nlmsghdr->nlmsg_len > len ? len : nlmsghdr->nlmsg_len;
+       const unsigned int nlmsg_len = MIN(nlmsghdr->nlmsg_len, len);
 
        if (nlmsg_len > NLMSG_HDRLEN)
                tprints("{");
@@ -632,15 +639,16 @@ decode_netlink(struct tcb *const tcp,
        const int family = get_fd_nl_family(tcp, fd);
 
        if (family == NETLINK_KOBJECT_UEVENT) {
-               printstrn(tcp, addr, len);
+               decode_netlink_kobject_uevent(tcp, addr, len);
                return;
        }
 
        struct nlmsghdr nlmsghdr;
-       bool print_array = false;
+       bool is_array = false;
        unsigned int elt;
 
-       for (elt = 0; fetch_nlmsghdr(tcp, &nlmsghdr, addr, len); elt++) {
+       for (elt = 0; fetch_nlmsghdr(tcp, &nlmsghdr, addr, len, is_array);
+            elt++) {
                if (abbrev(tcp) && elt == max_strlen) {
                        tprints("...");
                        break;
@@ -657,9 +665,9 @@ decode_netlink(struct tcb *const tcp,
                                next_addr = addr + nlmsg_len;
                }
 
-               if (!print_array && next_addr) {
+               if (!is_array && next_addr) {
                        tprints("[");
-                       print_array = true;
+                       is_array = true;
                }
 
                decode_nlmsghdr_with_payload(tcp, fd, family,
@@ -673,7 +681,7 @@ decode_netlink(struct tcb *const tcp,
                len = next_len;
        }
 
-       if (print_array) {
+       if (is_array) {
                tprints("]");
        }
 }