]> granicus.if.org Git - strace/commitdiff
tests: check decoding of setsockopt(PACKET_[R|T]X_RING)
authorZhibin Li <08826794brmt@gmail.com>
Tue, 24 Jul 2018 08:59:15 +0000 (16:59 +0800)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 1 Aug 2018 14:57:16 +0000 (14:57 +0000)
* tests/net-tpacket_req.c: New file.
* tests/.gitignore: Add net-tpacket_req.
* tests/pure_executables.list: Likewise.
* tests/gen_tests.in (net-tpacket_req): New test.

tests/.gitignore
tests/gen_tests.in
tests/net-tpacket_req.c [new file with mode: 0644]
tests/pure_executables.list

index b98d535c6eb7888a1d8793027b28b79bd6e6f338..011e313216318d386e124ec7ce6eb9d252ce5052 100644 (file)
@@ -253,6 +253,7 @@ net-accept-connect
 net-icmp_filter
 net-packet_mreq
 net-sockaddr
+net-tpacket_req
 net-y-unix
 net-yy-inet
 net-yy-inet6
index 44d6d715c6a6ec5aed4ac82ec5f297fd5a488293..c3cd1a0b3c41dc7c110ed3010ac0f10a07df344d 100644 (file)
@@ -236,6 +236,7 @@ nanosleep   -a20
 net-icmp_filter        -e trace=getsockopt,setsockopt
 net-packet_mreq -e trace=setsockopt
 net-sockaddr   -a24 -e trace=connect
+net-tpacket_req -e trace=setsockopt
 net-yy-inet6   +net-yy-inet.test
 netlink_audit  +netlink_sock_diag.test
 netlink_crypto +netlink_sock_diag.test
diff --git a/tests/net-tpacket_req.c b/tests/net-tpacket_req.c
new file mode 100644 (file)
index 0000000..0695587
--- /dev/null
@@ -0,0 +1,52 @@
+#include "tests.h"
+#include <stdio.h>
+#include <sys/socket.h>
+#include <linux/if_packet.h>
+
+static const char *errstr;
+
+static long
+set_tpacket_req(int optname, void *optval, socklen_t len)
+{
+       long rc = setsockopt(-1, SOL_PACKET, optname, optval, len);
+       errstr = sprintrc(rc);
+       return rc;
+}
+
+static void
+test_tpacket_req(const int optname, const char *const optname_str)
+{
+       TAIL_ALLOC_OBJECT_CONST_PTR(struct tpacket_req, tpreq);
+       socklen_t len;
+
+       /* setsockopt with optname unknown */
+       set_tpacket_req(-1, NULL, 0);
+       printf("setsockopt(-1, SOL_PACKET, %#x /* PACKET_??? */, NULL, 0) = %s\n",
+              -1, errstr);
+
+       /* classic setsockopt */
+       len = sizeof(struct tpacket_req);
+       set_tpacket_req(optname, tpreq, len);
+       printf("setsockopt(-1, SOL_PACKET, %s, {tp_block_size=%u,"
+              " tp_block_nr=%u, tp_frame_size=%u, tp_frame_nr=%u}, %d) = %s\n",
+              optname_str, tpreq->tp_block_size, tpreq->tp_block_nr,
+              tpreq->tp_frame_size, tpreq->tp_frame_nr, len, errstr);
+
+       /* setsockopt with optlen larger than usual */
+       len = len + 1;
+       set_tpacket_req(optname, tpreq, len);
+       printf("setsockopt(-1, SOL_PACKET, %s, %p,"
+              " %d) = %s\n", optname_str, tpreq, len, errstr);
+}
+
+int
+main(void)
+{
+       test_tpacket_req(ARG_STR(PACKET_RX_RING));
+#ifdef PACKET_TX_RING
+       test_tpacket_req(ARG_STR(PACKET_TX_RING));
+#endif
+
+       puts("+++ exited with 0 +++");
+       return 0;
+}
index af6883f1a5fa87d7f52953747c87484e28d6e21a..e834525283a85de4cebe5b9111a5ca45a14f099d 100755 (executable)
@@ -207,6 +207,7 @@ nanosleep
 net-icmp_filter
 net-packet_mreq
 net-sockaddr
+net-tpacket_req
 net-y-unix
 net-yy-inet
 net-yy-inet6