]> granicus.if.org Git - strace/blobdiff - netlink.c
nlattr: add unsigned int decoders that print in hex form
[strace] / netlink.c
index 46a394c67f436b943a3cfbff0e9ec142c5724c5c..8a30483c39c45664e977511b2c89fc4ceff78483 100644 (file)
--- a/netlink.c
+++ b/netlink.c
  */
 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
@@ -161,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;
        }
 
@@ -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("{");
@@ -637,10 +644,11 @@ decode_netlink(struct tcb *const tcp,
        }
 
        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("]");
        }
 }