Subject: JOIN_ANYCAST breakage w. "net: ipv6: put host and anycast routes on device with address"

From: Florian Westphal <[email-masked]>
Date: Tue, 14 Nov 2017 18:36:16 +0100

Hi David

This test program no longer works with 4.14
(recvfrom: Resource temporarily unavailable)

after reverting commit
4832c30d5458387ff2533ff66fbde26ad8bb5a2d
(net: ipv6: put host and anycast routes on device with address)

it will work again ("OK").

Could you please have a look at this?

Thanks!
----------------------
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <string.h>
#include <netinet/in.h>
#include <errno.h>
#include <sys/ioctl.h>

#include <unistd.h>
#include <stdint.h>

#define ADDR	"fe80::1"
#define MAGIC	0x1c3c01a

int main(int argc, char *argv[])
{
	struct ipv6_mreq nreq = {};
	struct sockaddr_in6 addr = {
		.sin6_family = AF_INET6,
		.sin6_port = htons(12345),
	};
	int fd, fd2, index, tmp;

	if (argc < 2)
		return 1;

	fd = socket(AF_INET6, SOCK_DGRAM, 0);
	fd2 = socket(AF_INET6, SOCK_DGRAM, 0);
	if (fd < 0 || fd2 < 0) {
		perror("socket");
		return 1;
	}
	index = if_nametoindex(argv[1]);
	if (index <= 0) {
		perror("if_nametoindex");
		return 1;
	}

	nreq.ipv6mr_interface = index;
	inet_pton(AF_INET6, ADDR, &nreq.ipv6mr_multiaddr);
	if (setsockopt(fd, IPPROTO_IPV6, IPV6_JOIN_ANYCAST,
	    &nreq, sizeof(nreq)) < 0) {
		perror("setsockopt");
		return 1;
	}

	addr.sin6_addr = in6addr_any;
	if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
		perror("bind");
		return 1;
	}

	addr.sin6_port = htons(12346);
	inet_pton(AF_INET6, "::", &addr.sin6_addr);
	if (bind(fd2, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
		perror("bind");
		return 1;
	}

	inet_pton(AF_INET6, ADDR, &addr.sin6_addr);
	addr.sin6_port = htons(12345);
	tmp = MAGIC;
	if (sendto(fd2, &tmp, sizeof(tmp), 0,
			(struct sockaddr *)&addr, sizeof(addr)) < 0) {
		perror("sendto");
		return 1;
	}

	if (recvfrom(fd, (void *)&tmp, sizeof(tmp), MSG_DONTWAIT,
				NULL, NULL) < 0) {
		perror("recvfrom");
		return 1;
	}

	if (tmp != MAGIC)
		return 111;

	puts("OK");
	return 0;
}