]> granicus.if.org Git - strace/commitdiff
Honor xlat styles when decoding mac addresses
authorShankara Pailoor <shankarapailoor@gmail.com>
Sun, 13 Jan 2019 23:34:04 +0000 (15:34 -0800)
committerDmitry V. Levin <ldv@altlinux.org>
Sun, 17 Mar 2019 23:38:24 +0000 (23:38 +0000)
* defs.h (print_mac_addr): Add xlat_style support, move ...
* print_mac.c: ... here.
* tests/sockaddr_xlat.c [HAVE_BLUETOOTH_BLUETOOTH_H]: Include
<bluetooth/bluetooth.h>, <bluetooth/hci.h>, <bluetooth/l2cap.h>
<bluetooth/rfcomm.h>, and <bluetooth/sco.h>.
[HAVE_BLUETOOTH_BLUETOOTH_H] (check_sco, check_rc): New functions.
(main) [HAVE_BLUETOOTH_BLUETOOTH_H]: Call them to verify
new xlat_style support in print_mac_addr().
* tests/net-packet_mreq.c: Handle XLAT_RAW, XLAT_ABBREV,
and XLAT_VERBOSE macros.
* tests/net-packet_mreq-Xabbrev.c: New test.
* tests/net-packet_mreq-Xraw.c: Likewise.
* tests/net-packet_mreq-Xverbose.c: Likewise.
* tests/gen_tests.in (net-packet_mreq-Xabbrev, net-packet_mreq-Xraw,
net-packet_mreq-Xverbose): New tests.
* tests/pure_executables.list: Add net-packet_mreq-Xabbrev,
net-packet_mreq-Xraw, and et-packet_mreq-Xverbose.
* tests/.gitignore: Likewise.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
defs.h
print_mac.c
tests/.gitignore
tests/gen_tests.in
tests/net-packet_mreq-Xabbrev.c [new file with mode: 0644]
tests/net-packet_mreq-Xraw.c [new file with mode: 0644]
tests/net-packet_mreq-Xverbose.c [new file with mode: 0644]
tests/net-packet_mreq.c
tests/pure_executables.list
tests/sockaddr_xlat.c

diff --git a/defs.h b/defs.h
index b316703fa3a556b3c5626f9c8936d428e9e6ad36..0a00716562e6a8f5b3abbd35ec3698e8b8b181aa 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -814,6 +814,8 @@ extern const char *sprinttime_nsec(long long sec, unsigned long long nsec);
 extern const char *sprinttime_usec(long long sec, unsigned long long usec);
 
 extern const char *sprint_mac_addr(const uint8_t addr[], size_t size);
+extern void print_mac_addr(const char *prefix,
+                          const uint8_t addr[], size_t size);
 
 extern void print_uuid(const unsigned char *uuid);
 
@@ -1168,13 +1170,6 @@ printaddr_comment(const kernel_ulong_t addr)
        tprintf_comment("%#llx", (unsigned long long) addr);
 }
 
-static inline void
-print_mac_addr(const char *prefix, const uint8_t addr[], size_t size)
-{
-       tprints(prefix);
-       tprints(sprint_mac_addr(addr, size));
-}
-
 # if SUPPORTED_PERSONALITIES > 1
 extern void set_personality(unsigned int personality);
 extern unsigned current_personality;
index f6bfad54e052157d398f8608899a86fc61a2eccd..50ba702ed49ebea22eef46f483b44532b44b4701 100644 (file)
@@ -33,3 +33,16 @@ sprint_mac_addr(const uint8_t addr[], size_t size)
 
        return res;
 }
+
+void
+print_mac_addr(const char *prefix, const uint8_t addr[], size_t size)
+{
+       tprints(prefix);
+       if (xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
+               print_quoted_string((const char *) addr, size,
+                                   QUOTE_FORCE_HEX);
+       if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
+               return;
+       (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE
+               ? tprints_comment : tprints)(sprint_mac_addr(addr, size));
+}
index e70388feaebac565859fc172cc4d233ed7d89989..5a601641fb8a4459ee3963e78ca5e8665af3b1bc 100644 (file)
@@ -277,6 +277,9 @@ nanosleep
 net-accept-connect
 net-icmp_filter
 net-packet_mreq
+net-packet_mreq-Xabbrev
+net-packet_mreq-Xraw
+net-packet_mreq-Xverbose
 net-sockaddr
 net-tpacket_req
 net-tpacket_stats
index f82b041022e8ba0b114b18820c82de2551a2e581..686df181b2ff5f00618fd9bd9c03e14f76babb2d 100644 (file)
@@ -235,6 +235,9 @@ munlockall  -a13
 nanosleep      -a20
 net-icmp_filter        -e trace=getsockopt,setsockopt
 net-packet_mreq -e trace=setsockopt
+net-packet_mreq-Xabbrev        -e trace=setsockopt -Xabbrev
+net-packet_mreq-Xraw   -e trace=setsockopt -Xraw
+net-packet_mreq-Xverbose       -e trace=setsockopt -Xverbose
 net-sockaddr   -a24 -e trace=connect
 net-tpacket_req -e trace=setsockopt
 net-tpacket_stats -e trace=getsockopt
diff --git a/tests/net-packet_mreq-Xabbrev.c b/tests/net-packet_mreq-Xabbrev.c
new file mode 100644 (file)
index 0000000..027bf5a
--- /dev/null
@@ -0,0 +1 @@
+#include "net-packet_mreq.c"
diff --git a/tests/net-packet_mreq-Xraw.c b/tests/net-packet_mreq-Xraw.c
new file mode 100644 (file)
index 0000000..0b041c3
--- /dev/null
@@ -0,0 +1,2 @@
+#define XLAT_RAW 1
+#include "net-packet_mreq.c"
diff --git a/tests/net-packet_mreq-Xverbose.c b/tests/net-packet_mreq-Xverbose.c
new file mode 100644 (file)
index 0000000..02185ba
--- /dev/null
@@ -0,0 +1,2 @@
+#define XLAT_VERBOSE 1
+#include "net-packet_mreq.c"
index 8059ff90af171054b6e13e7d41fbde45816c947e..540af1eba16a67efd8f61d5c1896bb2178444119 100644 (file)
@@ -28,39 +28,111 @@ test_packet_mreq(const int optname, const char *const optname_str)
 
        /* setsockopt with optname unknown */
        packet_mreq_membership(-1, NULL, 0);
+#if XLAT_RAW
+       printf("setsockopt(-1, %#x, %#x, NULL, 0) = %s\n",
+              SOL_PACKET, -1, errstr);
+#elif XLAT_VERBOSE
+       printf("setsockopt(-1, %#x /* SOL_PACKET */, %#x /* PACKET_??? */"
+              ", NULL, 0) = %s\n", SOL_PACKET, -1, errstr);
+#else
        printf("setsockopt(-1, SOL_PACKET, %#x /* PACKET_??? */, NULL, 0) = %s\n",
               -1, errstr);
+#endif
 
        /* setsockopt with mr_type unknown */
        pmreq->mr_ifindex = 0;
        pmreq->mr_alen = ARRAY_SIZE(pmreq->mr_address);
        packet_mreq_membership(optname, pmreq, len);
+#if XLAT_RAW
+       printf("setsockopt(-1, %#x, %#x, {mr_ifindex=%d,"
+              " mr_type=%#x, mr_alen=%d, mr_address=",
+              SOL_PACKET, optname, pmreq->mr_ifindex,
+              pmreq->mr_type, pmreq->mr_alen);
+       print_quoted_hex((const void *) pmreq->mr_address,
+                        ARRAY_SIZE(pmreq->mr_address));
+       printf("}, %d) = %s\n", len, errstr);
+#elif XLAT_VERBOSE
+       printf("setsockopt(-1, %#x /* SOL_PACKET */, %#x /* %s */"
+              ", {mr_ifindex=%d, mr_type=%#x /* PACKET_MR_??? */"
+              ", mr_alen=%d, mr_address=",
+              SOL_PACKET, optname, optname_str, pmreq->mr_ifindex,
+              pmreq->mr_type, pmreq->mr_alen);
+       print_quoted_hex((const void *) pmreq->mr_address,
+                        ARRAY_SIZE(pmreq->mr_address));
+       printf(" /* ");
+       for (unsigned int i = 0; i < ARRAY_SIZE(pmreq->mr_address); i++)
+               printf("%s%02x", i > 0 ? ":" : "", pmreq->mr_address[i]);
+       printf(" */}, %d) = %s\n", len, errstr);
+#else
        printf("setsockopt(-1, SOL_PACKET, %s, {mr_ifindex=%d,"
               " mr_type=%#x /* PACKET_MR_??? */, mr_alen=%d, mr_address=",
               optname_str, pmreq->mr_ifindex, pmreq->mr_type, pmreq->mr_alen);
        for (unsigned int i = 0; i < ARRAY_SIZE(pmreq->mr_address); i++)
                printf("%s%02x", i > 0 ? ":" : "", pmreq->mr_address[i]);
        printf("}, %d) = %s\n", len, errstr);
+#endif
 
        /* setsockopt with mr_type unknown and mr_alen > sizeof(mr_address) */
        pmreq->mr_alen = ARRAY_SIZE(pmreq->mr_address) + 1;
        packet_mreq_membership(optname, pmreq, len);
+#if XLAT_RAW
+       printf("setsockopt(-1, %#x, %#x, {mr_ifindex=%d,"
+              " mr_type=%#x, mr_alen=%d, mr_address=",
+              SOL_PACKET, optname, pmreq->mr_ifindex,
+              pmreq->mr_type, pmreq->mr_alen);
+       print_quoted_hex((const void *) pmreq->mr_address,
+                        ARRAY_SIZE(pmreq->mr_address));
+       printf("}, %d) = %s\n", len, errstr);
+#elif XLAT_VERBOSE
+       printf("setsockopt(-1, %#x /* SOL_PACKET */, %#x /* %s */"
+              ", {mr_ifindex=%d, mr_type=%#x /* PACKET_MR_??? */"
+              ", mr_alen=%d, mr_address=",
+              SOL_PACKET, optname, optname_str, pmreq->mr_ifindex,
+              pmreq->mr_type, pmreq->mr_alen);
+       print_quoted_hex((const void *) pmreq->mr_address,
+                        ARRAY_SIZE(pmreq->mr_address));
+       printf(" /* ");
+       for (unsigned int i = 0; i < ARRAY_SIZE(pmreq->mr_address); i++)
+               printf("%s%02x", i > 0 ? ":" : "", pmreq->mr_address[i]);
+       printf(" */}, %d) = %s\n", len, errstr);
+#else
        printf("setsockopt(-1, SOL_PACKET, %s, {mr_ifindex=%d,"
               " mr_type=%#x /* PACKET_MR_??? */, mr_alen=%d, mr_address=",
               optname_str, pmreq->mr_ifindex, pmreq->mr_type, pmreq->mr_alen);
        for (unsigned int i = 0; i < ARRAY_SIZE(pmreq->mr_address); i++)
                printf("%s%02x", i > 0 ? ":" : "", pmreq->mr_address[i]);
        printf("}, %d) = %s\n", len, errstr);
+#endif
 
        /* setsockopt with mr_type unknown and mr_alen < sizeof(mr_address) */
        pmreq->mr_alen = ARRAY_SIZE(pmreq->mr_address) - 1;
        packet_mreq_membership(optname, pmreq, len);
+#if XLAT_RAW
+       printf("setsockopt(-1, %#x, %#x, {mr_ifindex=%d,"
+              " mr_type=%#x, mr_alen=%d, mr_address=",
+              SOL_PACKET, optname, pmreq->mr_ifindex,
+              pmreq->mr_type, pmreq->mr_alen);
+       print_quoted_hex((const void *) pmreq->mr_address, pmreq->mr_alen);
+       printf("}, %d) = %s\n", len, errstr);
+#elif XLAT_VERBOSE
+       printf("setsockopt(-1, %#x /* SOL_PACKET */, %#x /* %s */"
+              ", {mr_ifindex=%d, mr_type=%#x /* PACKET_MR_??? */"
+              ", mr_alen=%d, mr_address=",
+              SOL_PACKET, optname, optname_str, pmreq->mr_ifindex,
+              pmreq->mr_type, pmreq->mr_alen);
+       print_quoted_hex((const void *) pmreq->mr_address, pmreq->mr_alen);
+       printf(" /* ");
+       for (unsigned int i = 0; i < pmreq->mr_alen; i++)
+               printf("%s%02x", i > 0 ? ":" : "", pmreq->mr_address[i]);
+       printf(" */}, %d) = %s\n", len, errstr);
+#else
        printf("setsockopt(-1, SOL_PACKET, %s, {mr_ifindex=%d,"
               " mr_type=%#x /* PACKET_MR_??? */, mr_alen=%d, mr_address=",
               optname_str, pmreq->mr_ifindex, pmreq->mr_type, pmreq->mr_alen);
        for (unsigned int i = 0; i < pmreq->mr_alen; i++)
                printf("%s%02x", i > 0 ? ":" : "", pmreq->mr_address[i]);
        printf("}, %d) = %s\n", len, errstr);
+#endif
 
        /* setsockopt with valid mr_type */
        pmreq->mr_alen = ARRAY_SIZE(pmreq->mr_address);
@@ -79,19 +151,48 @@ test_packet_mreq(const int optname, const char *const optname_str)
        for (unsigned int i = 0; i < ARRAY_SIZE(a); i++) {
                pmreq->mr_type = a[i].type;
                packet_mreq_membership(optname, pmreq, len);
+#if XLAT_RAW
+               printf("setsockopt(-1, %#x, %#x, {mr_ifindex=%d,"
+                      " mr_type=%#x, mr_alen=%d, mr_address=",
+                      SOL_PACKET, optname, pmreq->mr_ifindex,
+                      pmreq->mr_type, pmreq->mr_alen);
+               print_quoted_hex((const void *) pmreq->mr_address, pmreq->mr_alen);
+               printf("}, %d) = %s\n", len, errstr);
+#elif XLAT_VERBOSE
+               printf("setsockopt(-1, %#x /* SOL_PACKET */, %#x /* %s */"
+                      ", {mr_ifindex=%d, mr_type=%#x /* %s */"
+                      ", mr_alen=%d, mr_address=",
+                      SOL_PACKET, optname, optname_str, pmreq->mr_ifindex,
+                      pmreq->mr_type, a[i].type_str, pmreq->mr_alen);
+               print_quoted_hex((const void *) pmreq->mr_address, pmreq->mr_alen);
+               printf(" /* ");
+               for (unsigned int i = 0; i < pmreq->mr_alen; i++)
+                       printf("%s%02x", i > 0 ? ":" : "", pmreq->mr_address[i]);
+               printf(" */}, %d) = %s\n", len, errstr);
+#else
                printf("setsockopt(-1, SOL_PACKET, %s, {mr_ifindex=%d,"
                       " mr_type=%s, mr_alen=%d, mr_address=",
                       optname_str, pmreq->mr_ifindex, a[i].type_str, pmreq->mr_alen);
                for (unsigned int i = 0; i < pmreq->mr_alen; i++)
                        printf("%s%02x", i > 0 ? ":" : "", pmreq->mr_address[i]);
                printf("}, %d) = %s\n", len, errstr);
+#endif
        }
 
        /* setsockopt with optlen larger than usual */
        len = len + 1;
        packet_mreq_membership(optname, pmreq, len);
+#if XLAT_RAW
+       printf("setsockopt(-1, %#x, %#x, %p, %d) = %s\n",
+              SOL_PACKET, optname, pmreq, len, errstr);
+#elif XLAT_VERBOSE
+       printf("setsockopt(-1, %#x /* SOL_PACKET */, %#x /* %s */"
+              ", %p, %d) = %s\n", SOL_PACKET, optname, optname_str,
+              pmreq, len, errstr);
+#else
        printf("setsockopt(-1, SOL_PACKET, %s, %p,"
               " %d) = %s\n", optname_str, pmreq, len, errstr);
+#endif
 }
 
 int
index edb0be938fd00f46196a9aeaf9cda64e61ba6dfe..af796256268f0b2bf757c1cb797160e2dd05780b 100755 (executable)
@@ -233,6 +233,9 @@ munlockall
 nanosleep
 net-icmp_filter
 net-packet_mreq
+net-packet_mreq-Xabbrev
+net-packet_mreq-Xraw
+net-packet_mreq-Xverbose
 net-sockaddr
 net-tpacket_req
 net-tpacket_stats
index 420dcfef53d947a77ca32989e3d5b99c14f96e98..2a5122d587935a62f542017ecc12468230708116 100644 (file)
 #include <linux/if_arp.h>
 #include <linux/if_ether.h>
 #include <linux/if_packet.h>
+#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
+# include <bluetooth/bluetooth.h>
+# include <bluetooth/hci.h>
+# include <bluetooth/l2cap.h>
+# include <bluetooth/rfcomm.h>
+# include <bluetooth/sco.h>
+#endif
 
 static void
 check_ll(void)
@@ -170,12 +177,95 @@ check_in6(void)
        validate_in6(&in6, "::1");
 }
 
+#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
+static void
+check_sco(void)
+{
+       const struct sockaddr_sco c_sco = {
+               .sco_family = AF_BLUETOOTH,
+               .sco_bdaddr.b = "abcdef"
+       };
+       void *sco = tail_memdup(&c_sco, sizeof(c_sco));
+       unsigned int len = sizeof(c_sco);
+       int ret = connect(-1, sco, len);
+       const char *errstr = sprintrc(ret);
+# if XLAT_RAW
+       printf("connect(-1, {sa_family=%#x, sco_bdaddr=", AF_BLUETOOTH);
+       print_quoted_hex((const void *) &c_sco.sco_bdaddr,
+                        sizeof(c_sco.sco_bdaddr));
+       printf("}, %u) = %s\n", len, errstr);
+# elif XLAT_VERBOSE
+       printf("connect(-1, {sa_family=%#x /* AF_BLUETOOTH */"
+              ", sco_bdaddr=", AF_BLUETOOTH);
+       print_quoted_hex((const void *) &c_sco.sco_bdaddr,
+                        sizeof(c_sco.sco_bdaddr));
+       printf(" /* %02x:%02x:%02x:%02x:%02x:%02x */"
+              "}, %u) = %s\n",
+              c_sco.sco_bdaddr.b[0], c_sco.sco_bdaddr.b[1],
+              c_sco.sco_bdaddr.b[2], c_sco.sco_bdaddr.b[3],
+              c_sco.sco_bdaddr.b[4], c_sco.sco_bdaddr.b[5],
+              len, errstr);
+# else
+       printf("connect(-1, {sa_family=AF_BLUETOOTH"
+              ", sco_bdaddr=%02x:%02x:%02x:%02x:%02x:%02x"
+              "}, %u) = %s\n",
+              c_sco.sco_bdaddr.b[0], c_sco.sco_bdaddr.b[1],
+              c_sco.sco_bdaddr.b[2], c_sco.sco_bdaddr.b[3],
+              c_sco.sco_bdaddr.b[4], c_sco.sco_bdaddr.b[5],
+              len, errstr);
+# endif
+}
+
+static void
+check_rc(void)
+{
+       const struct sockaddr_rc c_rc = {
+               .rc_family = AF_BLUETOOTH,
+               .rc_bdaddr.b = "abcdef",
+               .rc_channel = 42
+       };
+       void *rc = tail_memdup(&c_rc, sizeof(c_rc));
+       unsigned int len = sizeof(c_rc);
+       int ret = connect(-1, rc, len);
+       const char *errstr = sprintrc(ret);
+# if XLAT_RAW
+       printf("connect(-1, {sa_family=%#x, rc_bdaddr=", AF_BLUETOOTH);
+       print_quoted_hex((const void *) &c_rc.rc_bdaddr,
+                        sizeof(c_rc.rc_bdaddr));
+       printf(", rc_channel=%u}, %u) = %s\n", c_rc.rc_channel, len, errstr);
+# elif XLAT_VERBOSE
+       printf("connect(-1, {sa_family=%#x /* AF_BLUETOOTH */"
+              ", rc_bdaddr=", AF_BLUETOOTH);
+       print_quoted_hex((const void *) &c_rc.rc_bdaddr,
+                        sizeof(c_rc.rc_bdaddr));
+       printf(" /* %02x:%02x:%02x:%02x:%02x:%02x */"
+              ", rc_channel=%u}, %u) = %s\n",
+              c_rc.rc_bdaddr.b[0], c_rc.rc_bdaddr.b[1],
+              c_rc.rc_bdaddr.b[2], c_rc.rc_bdaddr.b[3],
+              c_rc.rc_bdaddr.b[4], c_rc.rc_bdaddr.b[5],
+              c_rc.rc_channel, len, errstr);
+# else
+       printf("connect(-1, {sa_family=AF_BLUETOOTH"
+              ", rc_bdaddr=%02x:%02x:%02x:%02x:%02x:%02x"
+              ", rc_channel=%u}, %u) = %s\n",
+              c_rc.rc_bdaddr.b[0], c_rc.rc_bdaddr.b[1],
+              c_rc.rc_bdaddr.b[2], c_rc.rc_bdaddr.b[3],
+              c_rc.rc_bdaddr.b[4], c_rc.rc_bdaddr.b[5],
+              c_rc.rc_channel, len, errstr);
+# endif
+}
+#endif /* HAVE_BLUETOOTH_BLUETOOTH_H */
+
 int
 main(void)
 {
        check_ll();
        check_in();
        check_in6();
+#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
+       check_sco();
+       check_rc();
+#endif
        puts("+++ exited with 0 +++");
        return 0;
 }