[PATCH v2 14/18] tests: check decoding of packet_diag_msg attributes

JingPiao Chen chenjingpiao at gmail.com
Tue Jun 27 10:10:16 UTC 2017


* tests/nlattr_packet_diag_msg.c: New file.
* tests/gen_tests.in (nlattr_packet_diag_msg): New entry.
* tests/pure_executables.list: Add nlattr_packet_diag_msg.
* tests/.gitignore: Likewise.
---
 tests/.gitignore               |   1 +
 tests/gen_tests.in             |   1 +
 tests/nlattr_packet_diag_msg.c | 463 +++++++++++++++++++++++++++++++++++++++++
 tests/pure_executables.list    |   1 +
 4 files changed, 466 insertions(+)
 create mode 100644 tests/nlattr_packet_diag_msg.c

diff --git a/tests/.gitignore b/tests/.gitignore
index cca763f..f314e21 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -212,6 +212,7 @@ newfstatat
 nlattr
 nlattr_inet_diag_msg
 nlattr_netlink_diag_msg
+nlattr_packet_diag_msg
 nlattr_unix_diag_msg
 nsyscalls
 old_mmap
diff --git a/tests/gen_tests.in b/tests/gen_tests.in
index 57fd5fd..2ef9cdf 100644
--- a/tests/gen_tests.in
+++ b/tests/gen_tests.in
@@ -195,6 +195,7 @@ newfstatat	-a32 -v -P stat.sample -P /dev/full
 nlattr		+netlink_sock_diag.test
 nlattr_inet_diag_msg		+netlink_sock_diag.test
 nlattr_netlink_diag_msg		+netlink_sock_diag.test
+nlattr_packet_diag_msg		+netlink_sock_diag.test
 nlattr_unix_diag_msg		+netlink_sock_diag.test
 old_mmap	-a11 -e trace=mmap
 oldfstat	-a18 -v -P stat.sample
diff --git a/tests/nlattr_packet_diag_msg.c b/tests/nlattr_packet_diag_msg.c
new file mode 100644
index 0000000..ece309c
--- /dev/null
+++ b/tests/nlattr_packet_diag_msg.c
@@ -0,0 +1,463 @@
+/*
+ * Copyright (c) 2017 JingPiao Chen <chenjingpiao at gmail.com>
+ * Copyright (c) 2017 The strace developers.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "tests.h"
+#include "netlink.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+#include <sys/socket.h>
+#include <linux/filter.h>
+#include <linux/packet_diag.h>
+#include <linux/rtnetlink.h>
+#include <linux/sock_diag.h>
+
+static void
+init_packet_diag_msg(struct nlmsghdr *nlh, unsigned int msg_len)
+{
+	struct packet_diag_msg *msg;
+
+	SET_STRUCT(struct nlmsghdr, nlh,
+		.nlmsg_len = msg_len,
+		.nlmsg_type = SOCK_DIAG_BY_FAMILY,
+		.nlmsg_flags = NLM_F_DUMP
+	);
+
+	msg = NLMSG_DATA(nlh);
+	*msg = (struct packet_diag_msg) {
+		.pdiag_family = AF_PACKET,
+		.pdiag_type = SOCK_STREAM
+	};
+}
+
+static void
+test_packet_diag_info(const int fd)
+{
+	const int hdrlen = sizeof(struct packet_diag_msg);
+	struct nlmsghdr *nlh;
+	struct nlattr *nla;
+	unsigned int nla_len;
+	unsigned int msg_len;
+	void *const nlh0 = tail_alloc(NLMSG_SPACE(hdrlen));
+	long rc;
+
+	/* len < sizeof(struct packet_diag_info) */
+	nla_len = NLA_HDRLEN + 2;
+	msg_len = NLMSG_SPACE(hdrlen) + nla_len;
+	nlh = nlh0 - nla_len;
+	init_packet_diag_msg(nlh, msg_len);
+
+	nla = NLMSG_ATTR(nlh, hdrlen);
+	SET_STRUCT(struct nlattr, nla,
+		.nla_len = nla_len,
+		.nla_type = PACKET_DIAG_INFO
+	);
+	memcpy(RTA_DATA(nla), "12", 2);
+
+	rc = sendto(fd, nlh, msg_len, MSG_DONTWAIT, NULL, 0);
+
+	printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY"
+	       ", flags=NLM_F_DUMP, seq=0, pid=0}, {pdiag_family=AF_PACKET"
+	       ", pdiag_type=SOCK_STREAM, pdiag_num=0, pdiag_ino=0"
+	       ", pdiag_cookie=[0, 0]}, {{nla_len=%u"
+	       ", nla_type=PACKET_DIAG_INFO}, \"12\"}}"
+	       ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
+	       fd, msg_len, nla_len, msg_len, sprintrc(rc));
+
+	/* short read of packet_diag_info */
+	nla_len = NLA_HDRLEN + sizeof(struct packet_diag_info);
+	msg_len = NLMSG_SPACE(hdrlen) + nla_len;
+	nlh = nlh0 - (nla_len - 1);
+	init_packet_diag_msg(nlh, msg_len);
+
+	nla = NLMSG_ATTR(nlh, hdrlen);
+	SET_STRUCT(struct nlattr, nla,
+		.nla_len = nla_len,
+		.nla_type = PACKET_DIAG_INFO
+	);
+
+	rc = sendto(fd, nlh, msg_len, MSG_DONTWAIT, NULL, 0);
+
+	printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY"
+	       ", flags=NLM_F_DUMP, seq=0, pid=0}, {pdiag_family=AF_PACKET"
+	       ", pdiag_type=SOCK_STREAM, pdiag_num=0, pdiag_ino=0"
+	       ", pdiag_cookie=[0, 0]}, {{nla_len=%u"
+	       ", nla_type=PACKET_DIAG_INFO}, %p}}"
+	       ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
+	       fd, msg_len, nla_len, RTA_DATA(nla), msg_len, sprintrc(rc));
+
+	/* packet_diag_info */
+	nla_len = NLA_HDRLEN + sizeof(struct packet_diag_info);
+	msg_len = NLMSG_SPACE(hdrlen) + nla_len;
+	nlh = nlh0 - nla_len;
+	init_packet_diag_msg(nlh, msg_len);
+
+	nla = NLMSG_ATTR(nlh, hdrlen);
+	SET_STRUCT(struct nlattr, nla,
+		.nla_len = nla_len,
+		.nla_type = PACKET_DIAG_INFO
+	);
+	static const struct packet_diag_info pinfo = {
+		.pdi_index = 0xabcddafa,
+		.pdi_version = 0xbabcdafb,
+		.pdi_reserve = 0xcfaacdaf,
+		.pdi_copy_thresh = 0xdabacdaf,
+		.pdi_tstamp = 0xeafbaadf,
+		.pdi_flags = PDI_RUNNING
+	};
+	memcpy(RTA_DATA(nla), &pinfo, sizeof(pinfo));
+
+	rc = sendto(fd, nlh, msg_len, MSG_DONTWAIT, NULL, 0);
+
+	printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY"
+	       ", flags=NLM_F_DUMP, seq=0, pid=0}, {pdiag_family=AF_PACKET"
+	       ", pdiag_type=SOCK_STREAM, pdiag_num=0, pdiag_ino=0"
+	       ", pdiag_cookie=[0, 0]}, {{nla_len=%u"
+	       ", nla_type=PACKET_DIAG_INFO}, {pdi_index=%u, pdi_version=%u"
+	       ", pdi_reserve=%u, pdi_copy_thresh=%u, pdi_tstamp=%u"
+	       ", pdi_flags=PDI_RUNNING}}}, %u, MSG_DONTWAIT, NULL, 0) = %s\n",
+	       fd, msg_len, nla_len, pinfo.pdi_index, pinfo.pdi_version,
+	       pinfo.pdi_reserve, pinfo.pdi_copy_thresh, pinfo.pdi_tstamp,
+	       msg_len, sprintrc(rc));
+}
+
+static void
+test_packet_diag_mclist(const int fd)
+{
+	const int hdrlen = sizeof(struct packet_diag_msg);
+	struct nlmsghdr *nlh;
+	struct nlattr *nla;
+	unsigned int nla_len;
+	unsigned int msg_len;
+	void *const nlh0 = tail_alloc(NLMSG_SPACE(hdrlen));
+	long rc;
+
+	/* len = sizeof(struct packet_diag_mclist) * 2 */
+	nla_len = NLA_HDRLEN + sizeof(struct packet_diag_mclist) * 2;
+	msg_len = NLMSG_SPACE(hdrlen) + nla_len;
+	nlh = nlh0 - nla_len;
+	init_packet_diag_msg(nlh, msg_len);
+
+	nla = NLMSG_ATTR(nlh, hdrlen);
+	SET_STRUCT(struct nlattr, nla,
+		.nla_len = nla_len,
+		.nla_type = PACKET_DIAG_MCLIST
+	);
+	struct packet_diag_mclist dml[2] = {
+		{
+			.pdmc_index = 0xfbacdafb,
+			.pdmc_count = 0xabcdaefc,
+			.pdmc_type = 0xcdaf,
+			.pdmc_alen = 0xeacd,
+			.pdmc_addr = "1234"
+		},
+		{
+			.pdmc_index = 0xdafbdcda,
+			.pdmc_count = 0xdaefeafc,
+			.pdmc_type = 0xadef,
+			.pdmc_alen = 0xcecd,
+			.pdmc_addr = "5678"
+		}
+	};
+	memcpy(RTA_DATA(nla), dml, sizeof(dml));
+
+	rc = sendto(fd, nlh, msg_len, MSG_DONTWAIT, NULL, 0);
+
+	printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY"
+	       ", flags=NLM_F_DUMP, seq=0, pid=0}, {pdiag_family=AF_PACKET"
+	       ", pdiag_type=SOCK_STREAM, pdiag_num=0, pdiag_ino=0"
+	       ", pdiag_cookie=[0, 0]}, {{nla_len=%u"
+	       ", nla_type=PACKET_DIAG_MCLIST}, [{pdmc_index=%u"
+	       ", pdmc_count=%u, pdmc_type=%u, pdmc_alen=%u"
+	       ", pdmc_addr=\"1234\"}, {pdmc_index=%u, pdmc_count=%u"
+	       ", pdmc_type=%u, pdmc_alen=%u, pdmc_addr=\"5678\"}]}}"
+	       ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
+	       fd, msg_len, nla_len, dml[0].pdmc_index, dml[0].pdmc_count,
+	       dml[0].pdmc_type, dml[0].pdmc_alen,
+	       dml[1].pdmc_index, dml[1].pdmc_count,
+	       dml[1].pdmc_type, dml[1].pdmc_alen, msg_len, sprintrc(rc));
+
+	/* len = sizeof(struct packet_diag_mclist) * 2 - 1 */
+	nla_len = NLA_HDRLEN + sizeof(struct packet_diag_mclist) * 2 - 1;
+	msg_len = NLMSG_SPACE(hdrlen) + nla_len;
+	nlh = nlh0 - nla_len;
+	init_packet_diag_msg(nlh, msg_len);
+
+	nla = NLMSG_ATTR(nlh, hdrlen);
+	SET_STRUCT(struct nlattr, nla,
+		.nla_len = nla_len,
+		.nla_type = PACKET_DIAG_MCLIST
+	);
+	memcpy(RTA_DATA(nla), dml, sizeof(dml[0]));
+
+	rc = sendto(fd, nlh, msg_len, MSG_DONTWAIT, NULL, 0);
+
+	printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY"
+	       ", flags=NLM_F_DUMP, seq=0, pid=0}, {pdiag_family=AF_PACKET"
+	       ", pdiag_type=SOCK_STREAM, pdiag_num=0, pdiag_ino=0"
+	       ", pdiag_cookie=[0, 0]}, {{nla_len=%u"
+	       ", nla_type=PACKET_DIAG_MCLIST}, [{pdmc_index=%u, pdmc_count=%u"
+	       ", pdmc_type=%u, pdmc_alen=%u, pdmc_addr=\"1234\"}]}}"
+	       ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
+	       fd, msg_len, nla_len, dml[0].pdmc_index,
+	       dml[0].pdmc_count, dml[0].pdmc_type,
+	       dml[0].pdmc_alen, msg_len, sprintrc(rc));
+
+	/* len < sizeof(struct packet_diag_mclist) */
+	nla_len = NLA_HDRLEN + 4;
+	msg_len = NLMSG_SPACE(hdrlen) + nla_len;
+	nlh = nlh0 - nla_len;
+	init_packet_diag_msg(nlh, msg_len);
+
+	nla = NLMSG_ATTR(nlh, hdrlen);
+	SET_STRUCT(struct nlattr, nla,
+		.nla_len = nla_len,
+		.nla_type = PACKET_DIAG_MCLIST
+	);
+	memcpy(RTA_DATA(nla), "1234", 4);
+
+	rc = sendto(fd, nlh, msg_len, MSG_DONTWAIT, NULL, 0);
+
+	printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY"
+	       ", flags=NLM_F_DUMP, seq=0, pid=0}, {pdiag_family=AF_PACKET"
+	       ", pdiag_type=SOCK_STREAM, pdiag_num=0, pdiag_ino=0"
+	       ", pdiag_cookie=[0, 0]}, {{nla_len=%u"
+	       ", nla_type=PACKET_DIAG_MCLIST}, \"1234\"}}"
+	       ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
+	       fd, msg_len, nla_len, msg_len, sprintrc(rc));
+}
+
+static void
+test_packet_diag_rx_ring(const int fd)
+{
+	const int hdrlen = sizeof(struct packet_diag_msg);
+	struct nlmsghdr *nlh;
+	struct nlattr *nla;
+	unsigned int nla_len;
+	unsigned int msg_len;
+	void *const nlh0 = tail_alloc(NLMSG_SPACE(hdrlen));
+	long rc;
+
+	/* len < sizeof(struct packet_diag_ring) */
+	nla_len = NLA_HDRLEN + 2;
+	nlh = nlh0 - nla_len;
+	msg_len = NLMSG_SPACE(hdrlen) + nla_len;
+	init_packet_diag_msg(nlh, msg_len);
+
+	nla = NLMSG_ATTR(nlh, hdrlen);
+	SET_STRUCT(struct nlattr, nla,
+		.nla_len = nla_len,
+		.nla_type = PACKET_DIAG_RX_RING
+	);
+	memcpy(RTA_DATA(nla), "12", 2);
+
+	rc = sendto(fd, nlh, msg_len, MSG_DONTWAIT, NULL, 0);
+
+	printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY"
+	       ", flags=NLM_F_DUMP, seq=0, pid=0}, {pdiag_family=AF_PACKET"
+	       ", pdiag_type=SOCK_STREAM, pdiag_num=0, pdiag_ino=0"
+	       ", pdiag_cookie=[0, 0]}, {{nla_len=%u"
+	       ", nla_type=PACKET_DIAG_RX_RING}, \"12\"}}"
+	       ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
+	       fd, msg_len, nla_len, msg_len, sprintrc(rc));
+
+	/* short read of packet_diag_ring */
+	nla_len = NLA_HDRLEN + sizeof(struct packet_diag_ring);
+	msg_len = NLMSG_SPACE(hdrlen) + nla_len;
+	nlh = nlh0 - (nla_len - 1);
+	init_packet_diag_msg(nlh, msg_len);
+
+	nla = NLMSG_ATTR(nlh, hdrlen);
+	SET_STRUCT(struct nlattr, nla,
+		.nla_len = nla_len,
+		.nla_type = PACKET_DIAG_RX_RING
+	);
+
+	rc = sendto(fd, nlh, msg_len, MSG_DONTWAIT, NULL, 0);
+
+	printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY"
+	       ", flags=NLM_F_DUMP, seq=0, pid=0}, {pdiag_family=AF_PACKET"
+	       ", pdiag_type=SOCK_STREAM, pdiag_num=0, pdiag_ino=0"
+	       ", pdiag_cookie=[0, 0]}, {{nla_len=%u"
+	       ", nla_type=PACKET_DIAG_RX_RING}, %p}}"
+	       ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
+	       fd, msg_len, nla_len, RTA_DATA(nla), msg_len, sprintrc(rc));
+
+	/* packet_diag_ring */
+	nla_len = NLA_HDRLEN + sizeof(struct packet_diag_ring);
+	msg_len = NLMSG_SPACE(hdrlen) + nla_len;
+	nlh = nlh0 - nla_len;
+	init_packet_diag_msg(nlh, msg_len);
+
+	nla = NLMSG_ATTR(nlh, hdrlen);
+	SET_STRUCT(struct nlattr, nla,
+		.nla_len = nla_len,
+		.nla_type = PACKET_DIAG_RX_RING
+	);
+	static const struct packet_diag_ring pdr = {
+		.pdr_block_size = 0xabcdafed,
+		.pdr_block_nr = 0xbcadefae,
+		.pdr_frame_size = 0xcabdfeac,
+		.pdr_frame_nr = 0xdeaeadef,
+		.pdr_retire_tmo = 0xedbafeac,
+		.pdr_sizeof_priv = 0xfeadeacd,
+		.pdr_features = 0xadebadea
+	};
+	memcpy(RTA_DATA(nla), &pdr, sizeof(pdr));
+
+	rc = sendto(fd, nlh, msg_len, MSG_DONTWAIT, NULL, 0);
+
+	printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY"
+	       ", flags=NLM_F_DUMP, seq=0, pid=0}, {pdiag_family=AF_PACKET"
+	       ", pdiag_type=SOCK_STREAM, pdiag_num=0, pdiag_ino=0"
+	       ", pdiag_cookie=[0, 0]}, {{nla_len=%u"
+	       ", nla_type=PACKET_DIAG_RX_RING}, {pdr_block_size=%u"
+	       ", pdr_block_nr=%u, pdr_frame_size=%u, pdr_frame_nr=%u"
+	       ", pdr_retire_tmo=%u, pdr_sizeof_priv=%u"
+	       ", pdr_features=%u}}}, %u, MSG_DONTWAIT, NULL, 0) = %s\n",
+	       fd, msg_len, nla_len, pdr.pdr_block_size, pdr.pdr_block_nr,
+	       pdr.pdr_frame_size, pdr.pdr_frame_nr, pdr.pdr_retire_tmo,
+	       pdr.pdr_sizeof_priv, pdr.pdr_features, msg_len, sprintrc(rc));
+}
+
+static void
+test_packet_diag_filter(const int fd)
+{
+	const int hdrlen = sizeof(struct packet_diag_msg);
+	struct nlmsghdr *nlh;
+	struct nlattr *nla;
+	void *const nlh0 = tail_alloc(NLMSG_SPACE(hdrlen));
+	unsigned int nla_len;
+	unsigned int msg_len;
+	long rc;
+
+	/* len = sizeof(struct sock_filter) * 2 */
+	nla_len = NLA_HDRLEN + sizeof(struct sock_filter) * 2;
+	msg_len = NLMSG_SPACE(hdrlen) + nla_len;
+	nlh = nlh0 - nla_len;
+	init_packet_diag_msg(nlh, msg_len);
+
+	nla = NLMSG_ATTR(nlh, hdrlen);
+	SET_STRUCT(struct nlattr, nla,
+		.nla_len = nla_len,
+		.nla_type = PACKET_DIAG_FILTER
+	);
+	static const struct sock_filter filter[2] = {
+		{
+			.code = 0xdacd,
+			.jt = 0xda,
+			.jf = 0xbd,
+			.k = 0xabcdfead
+		},
+		{
+			.code = 0xabcd,
+			.jt = 0xfd,
+			.jf = 0xac,
+			.k = 0xfeacdaeb
+		}
+	};
+	memcpy(RTA_DATA(nla), filter, sizeof(filter));
+
+	rc = sendto(fd, nlh, msg_len, MSG_DONTWAIT, NULL, 0);
+
+	printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY"
+	       ", flags=NLM_F_DUMP, seq=0, pid=0}, {pdiag_family=AF_PACKET"
+	       ", pdiag_type=SOCK_STREAM, pdiag_num=0, pdiag_ino=0"
+	       ", pdiag_cookie=[0, 0]}, {{nla_len=%u"
+	       ", nla_type=PACKET_DIAG_FILTER}, [{code=%u, jt=%u"
+	       ", jf=%u, k=%u}, {code=%u, jt=%u, jf=%u, k=%u}]}}"
+	       ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
+	       fd, msg_len, nla_len,
+	       filter[0].code, filter[0].jt, filter[0].jf, filter[0].k,
+	       filter[1].code, filter[1].jt, filter[1].jf, filter[1].k,
+	       msg_len, sprintrc(rc));
+
+	/* len = sizeof(struct sock_filter) * 2 - 1 */
+	nla_len = NLA_HDRLEN + sizeof(struct sock_filter) * 2 - 1;
+	msg_len = NLMSG_SPACE(hdrlen) + nla_len;
+	nlh = nlh0 - nla_len;
+	init_packet_diag_msg(nlh, msg_len);
+
+	nla = NLMSG_ATTR(nlh, hdrlen);
+	SET_STRUCT(struct nlattr, nla,
+		.nla_len = nla_len,
+		.nla_type = PACKET_DIAG_FILTER
+	);
+	memcpy(RTA_DATA(nla), filter, sizeof(filter[0]));
+
+	rc = sendto(fd, nlh, msg_len, MSG_DONTWAIT, NULL, 0);
+
+	printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY"
+	       ", flags=NLM_F_DUMP, seq=0, pid=0}, {pdiag_family=AF_PACKET"
+	       ", pdiag_type=SOCK_STREAM, pdiag_num=0, pdiag_ino=0"
+	       ", pdiag_cookie=[0, 0]}, {{nla_len=%u"
+	       ", nla_type=PACKET_DIAG_FILTER}, [{code=%u, jt=%u"
+	       ", jf=%u, k=%u}]}}, %u, MSG_DONTWAIT, NULL, 0) = %s\n",
+	       fd, msg_len, nla_len, 0xdacd, 0xda, 0xbd,
+	       0xabcdfead, msg_len, sprintrc(rc));
+
+	/* len < sizeof(struct sock_filter) */
+	nla_len = NLA_HDRLEN + 4;
+	msg_len = NLMSG_SPACE(hdrlen) + nla_len;
+	nlh = nlh0 - nla_len;
+	init_packet_diag_msg(nlh, msg_len);
+
+	nla = NLMSG_ATTR(nlh, hdrlen);
+	SET_STRUCT(struct nlattr, nla,
+		.nla_len = nla_len,
+		.nla_type = PACKET_DIAG_FILTER
+	);
+	memcpy(RTA_DATA(nla), "1234", 4);
+
+	rc = sendto(fd, nlh, msg_len, MSG_DONTWAIT, NULL, 0);
+
+	printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY"
+	       ", flags=NLM_F_DUMP, seq=0, pid=0}, {pdiag_family=AF_PACKET"
+	       ", pdiag_type=SOCK_STREAM, pdiag_num=0, pdiag_ino=0"
+	       ", pdiag_cookie=[0, 0]}, {{nla_len=%u"
+	       ", nla_type=PACKET_DIAG_FILTER}, \"1234\"}}"
+	       ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
+	       fd, msg_len, nla_len, msg_len, sprintrc(rc));
+}
+
+int main(void)
+{
+	skip_if_unavailable("/proc/self/fd/");
+
+	int fd = create_nl_socket(NETLINK_SOCK_DIAG);
+
+	test_packet_diag_info(fd);
+	test_packet_diag_mclist(fd);
+	test_packet_diag_rx_ring(fd);
+	test_packet_diag_filter(fd);
+
+	printf("+++ exited with 0 +++\n");
+
+	return 0;
+}
diff --git a/tests/pure_executables.list b/tests/pure_executables.list
index 033208e..4b342f8 100755
--- a/tests/pure_executables.list
+++ b/tests/pure_executables.list
@@ -177,6 +177,7 @@ newfstatat
 nlattr
 nlattr_inet_diag_msg
 nlattr_netlink_diag_msg
+nlattr_packet_diag_msg
 nlattr_unix_diag_msg
 old_mmap
 oldfstat
-- 
2.7.4





More information about the Strace-devel mailing list