IPV6_PKTINFO socket option
From: Renata Saiakhova
Date: Wed Dec 07 2016 - 08:40:27 EST
Hi all,
I would like to use IPV6_PKTINFO option to specify an outgoing IPv6
address in sendmsg(). The socket is not bound neither to an address nor
to an interface. Should I always specify ifindex together with source
address?
(according to rfc3542 :
The kernel must verify that the requested source address is indeed a
unicast address assigned to the node. When the address is a scoped one,
there may be ambiguity about its scope zone. This is particularly the
case for link-local addresses. In such a case, the kernel must first
determine the appropriate scope zone based on the zone of the
destination address or the outgoing interface (if known), then qualify
the address. This also means that it is not feasible to specify the
source address for a non-binding socket by the IPV6_PKTINFO sticky
option, unless the outgoing interface is also specified. The application
should simply use bind() for such purposes. )
It looks somewhat ambiguous, for me it is not clear, should ifindex be
always specified, suppose, for global addresses?
I looked at linux kernel implementation as a reference, and it seems
that this sticky option information is stored in ipv6_pinfo structure,
but only ipi6_ifindex is used while constructing i6 flow in
udpv6_sendmsg. ipi6_addr part is used only in getsockopt to return this
information. Why ipi6_addr is not used in constructing i6 flow?
Kind regards,
Renata