Discussion:
IPv6 scopeid not supported?
(too old to reply)
Lloyd Parkes
2010-11-07 03:28:50 UTC
Permalink
Hi all,
While trying to get ntp running on an IPv6 network using multicast I
ran in to a bit of a problem. It looks like the sin6_scope_id field in
struct sockaddr_in6 isn't used by bind(2), resulting in multicast
listeners only being able to listen the first interface. This is
especially troublesome if your first interface is fwip0.

Is this known, expected? I can't find a PR for anything mentioning
"scope".

My sample program works just fine on Archangel which has a running
interface with scopeid 0x01, and fails on Hobble, which doesn't. Note
that the scopeid 0x02 is compiled in to it both times, and both
machines have running interface with scopeid 0x02.

Cheers,
Lloyd

==============8<==============
#include <sys/time.h>
#include <sys/socket.h>

#include <netinet/in.h>

#include <stdio.h>

main()
{
int errval;
int fd;
struct sockaddr_in6 addr;

addr.sin6_len = sizeof addr;
addr.sin6_family = AF_INET6;
addr.sin6_port = htons (1230);
addr.sin6_flowinfo = 0;
inet_pton (AF_INET6, "ff02::101", &addr.sin6_addr);
addr.sin6_scope_id = 2;

fd = socket (PF_INET6, SOCK_DGRAM, 0);
if (fd < 0)
err (2, "socket");

errval = bind (fd, (struct sockaddr *)&addr, sizeof addr);
err (1, "bind");
}
==============8<==============
hobble-5.99.39$ uname -a
NetBSD hobble.must-have-coffee.gen.nz 5.99.39 NetBSD 5.99.39 (GENERIC)
#0: Sun Oct 10 01:26:03 NZDT 2010 ***@thallid.must-have-
coffee.gen.nz:/vol/scratch/build/obj.macppc/sys/arch/macppc/compile/
GENERIC macppc
hobble-5.99.39$ ifconfig -a
fwip0: flags=8802<BROADCAST,SIMPLEX,MULTICAST> mtu 1500
address: 00:0d:93:ff:fe:60:8c:16
gem0: flags=8863<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST>
mtu 1500
capabilities=800<TCP4CSUM_Tx>
enabled=0
address: 00:0d:93:60:8c:16
media: Ethernet autoselect (100baseTX full-duplex)
status: active
inet 10.0.1.49 netmask 0xffffff00 broadcast 10.0.1.255
inet6 fe80::20d:93ff:fe60:8c16%gem0 prefixlen 64 scopeid 0x2
inet6 2002:cb61:d534:3:20d:93ff:fe60:8c16 prefixlen 64
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 33192
inet 127.0.0.1 netmask 0xff000000
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x3
==============8<==============
archangel-5.1_RC3$ uname -a
NetBSD archangel.must-have-coffee.gen.nz 5.1_RC3 NetBSD 5.1_RC3
(GENERIC) #0: Mon Jun 28 10:02:18 NZST 2010 ***@thallid.must-have-coffee.gen.nz
:/vol/scratch/build5/obj.sparc64/sys/arch/sparc64/compile/GENERIC
sparc64
archangel-5.1_RC3$ ifconfig -a
hme0: flags=8863<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST>
mtu 1500

capabilities=3c00<TCP4CSUM_Rx,TCP4CSUM_Tx,UDP4CSUM_Rx,UDP4CSUM_Tx>
enabled=3c00<TCP4CSUM_Rx,TCP4CSUM_Tx,UDP4CSUM_Rx,UDP4CSUM_Tx>
address: 08:00:20:b0:7a:28
media: Ethernet autoselect (100baseTX full-duplex)
status: active
inet 10.0.1.22 netmask 0xffffff00 broadcast 10.0.1.255
inet6 fe80::a00:20ff:feb0:7a28%hme0 prefixlen 64 scopeid 0x1
inet6 2002:cb61:d534:3:a00:20ff:feb0:7a28 prefixlen 64
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 33136
inet 127.0.0.1 netmask 0xff000000
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x2



--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
David Young
2010-11-07 16:27:35 UTC
Permalink
Post by Lloyd Parkes
Hi all,
While trying to get ntp running on an IPv6 network using multicast I
ran in to a bit of a problem. It looks like the sin6_scope_id field
in struct sockaddr_in6 isn't used by bind(2), resulting in multicast
listeners only being able to listen the first interface. This is
especially troublesome if your first interface is fwip0.
Lloyd,

You're probably right that the scope ID is not supported.

You can use setsockopt(2) to set the interfaces on which to transmit and
receive IPv6 multicasts. ip6(4) should tell how. In a routing daemon, I
used these routines to choose the multicast interface:

static int
beacon6_rx_v6mcast_joinleave(int s, int optname,
const struct in6_addr *addr, u_int ifindex)
{
struct ipv6_mreq mreq6;

mreq6.ipv6mr_interface = ifindex;

(void)memcpy(&mreq6.ipv6mr_multiaddr, addr,
sizeof(mreq6.ipv6mr_multiaddr));

return setsockopt(s, IPPROTO_IPV6, optname, &mreq6,
(socklen_t)sizeof(mreq6));
}

int
beacon6_rx_v6mcast_leave(int s, const struct in6_addr *addr, u_int ifindex)
{
return beacon6_rx_v6mcast_joinleave(s, IPV6_LEAVE_GROUP, addr, ifindex);
}

int
beacon6_rx_v6mcast_join(int s, const struct in6_addr *addr, u_int ifindex)
{
return beacon6_rx_v6mcast_joinleave(s, IPV6_JOIN_GROUP, addr, ifindex);
}

int
beacon6_tx_mcastif_set(int s, u_int outif0)
{
u_int outif = outif0;

LOGLIB_LOG(&log_warn,
"%s: setsockopt(, IPV6_MULTICAST_IF, ifindex<%#08x>, %zu)",
__func__, outif, sizeof(outif));

return setsockopt(s, IPPROTO_IPV6, IPV6_MULTICAST_IF, &outif,
(socklen_t)sizeof(outif));
}

Dave
--
David Young OJC Technologies
***@ojctech.com Urbana, IL * (217) 278-3933

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Daniel Hagerty
2010-11-07 19:28:04 UTC
Permalink
Your test program works just fine on 4.0_STABLE. I assume from
the way you wrote the test program that you're expecting bind to fail,
in which case you're probably dealing with a regression. I don't have
a 5.x box around to compare with.

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Lloyd Parkes
2010-11-09 04:49:25 UTC
Permalink
Post by Daniel Hagerty
Your test program works just fine on 4.0_STABLE.
What was the scope ID of the first UP interface? If it was 0x01, then
it works the same as 5.x, if it was something else, then we may have a
regression.

Cheers,
Lloyd



--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Daniel Hagerty
2010-11-09 14:33:18 UTC
Permalink
Post by Lloyd Parkes
Post by Daniel Hagerty
Your test program works just fine on 4.0_STABLE.
What was the scope ID of the first UP interface? If it was 0x01, then
it works the same as 5.x, if it was something else, then we may have a
regression.
$ ifconfig -a |head
fwip0: flags=8802<BROADCAST,SIMPLEX,MULTICAST> mtu 1500
address: 00:11:d8:00:01:34:4c:34
nfe0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
capabilities=3f00<IP4CSUM_Rx,IP4CSUM_Tx,TCP4CSUM_Rx,TCP4CSUM_Tx,UDP4CSUM_Rx,UDP4CSUM_Tx>
enabled=0
address: 00:1b:fc:b1:4a:85
media: Ethernet autoselect (100baseTX full-duplex)
status: active
inet 10.12.0.118 netmask 0xffff0000 broadcast 10.12.255.255
inet6 fe80::21b:fcff:feb1:4a85%nfe0 prefixlen 64 scopeid 0x2
$ ./a.out
a.out: bind: Undefined error: 0

and with a slightly modified version of the test program that sleeps
after the bind:

$ netstat -finet6 -na |grep ff02
udp6 0 0 ff02::101%nfe0.1230 *.*

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Loading...