[PATCH v1] tests: add check for netlink protocol with -yy option

Dmitry V. Levin ldv at altlinux.org
Sat May 21 02:43:30 UTC 2016


On Wed, May 18, 2016 at 04:45:50PM +0000, Fabien Siron wrote:
[...]
> --- /dev/null
> +++ b/tests/net-yy-netlink.c
> @@ -0,0 +1,81 @@
> +/*
> + * This file is part of net-yy-unix strace test.

Really?  It looks more like a netlink test.

> +	const int fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_SOCK_DIAG);

NETLINK_SOCK_DIAG is not defined on old systems, a fallback definition
is needed, see tests/netlink_unix_diag.c for an example.

> +	if (fd < 0)
> +		perror_msg_and_skip("socket");
> +	const unsigned long inode = inode_of_sockfd(fd);
> +	printf("socket(AF_NETLINK, SOCK_RAW, NETLINK_SOCK_DIAG) = "
> +	       "%d<NETLINK:[%lu]>\n", fd, inode);
> +
> +	if (bind(fd, sa, *len))
> +		perror_msg_and_skip("bind");
> +	printf("bind(%d<NETLINK:[%lu]>, {sa_family=AF_NETLINK, pid=%u, "
> +	       "groups=00000000}, %u) = 0\n", fd, inode, magic,
> +	       (unsigned) *len);
> +
> +	assert(sendto(fd, text, sizeof(text) - 1, MSG_DONTWAIT, NULL, 0)
> +	       == sizeof(text) - 1);
> +	printf("sendto(%d<NETLINK:[SOCK_DIAG:%u]>, \"%s\", %u, MSG_DONTWAIT"
> +	       ", NULL, 0) = %u\n", fd, magic, text,
> +	       (unsigned) sizeof(text) - 1, (unsigned) sizeof(text) - 1);

There is a problem with this sendto call: on some systems it fails with
EINVAL.  I'd suggest replacing it with some other call, e.g. recvmsg:

	assert(recvmsg(fd, NULL, MSG_DONTWAIT) == -1);
	printf("recvmsg(%d<NETLINK:[SOCK_DIAG:%u]>, NULL, MSG_DONTWAIT)"
	       " = -1 %s (%m)\n", fd, magic, errno2name());

> --- /dev/null
> +++ b/tests/net-yy-netlink.test
> @@ -0,0 +1,47 @@
> +#!/bin/sh
> +#
> +# Check decoding of ip:port pairs associated with socket descriptors

Really?  ip:port pairs for netlink sockets?

> +	if (socket(AF_NETLINK, SOCK_RAW, NETLINK_SOCK_DIAG))

Another file that uses NETLINK_SOCK_DIAG, it also needs a fallback definition.


-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20160521/1a802db3/attachment.bin>


More information about the Strace-devel mailing list