tst_send_dst_addr_udp - Specifying the source IPv6 address as ancillary data
To check that the source IPv6 address can be specified as ancillary data.
./tst_send_dst_addr_udp [-tooloption ...] -tooloption : v6api tool option
1. Create an IPv6/UDP socket 2. Bind the socket to address 3. Specifying the outgoing source IPv6 address to a bad IPv6 address as ancillary data and send the message 4. Check A: Message can not be send, return EINVAL error 5. Specifying the outgoing source IPv6 address to loopback address as ancillary data and send the message 6. Check B: Message can be send 7. Specifying the outgoing source IPv6 address to unspecified address as ancillary data and send the message 8. Check C: Kernel will choose the source address and message can be send 9. Specifying the outgoing source IPv6 address to link-local address as ancillary data and send the message 10.Check D: Message can not be send, return EINVAL error 11.Specifying the outgoing source IPv6 address to link-local address and the outgoing interface to eth0 as ancillary data and send the message 12.Check E: Message can be send 13.Bind the socket to interface 14.Specifying the outgoing source IPv6 address to link-local address and send the message 15.Check F: Message can be send
None
RFC 3542
6.2. Specifying/Receiving Source/Destination Address
The source IPv6 address can be specified by calling bind() before each output operation, but supplying the source address together with the data requires less overhead (i.e., fewer system calls) and requires less state to be stored and protected in a multithreaded application.
When specifying the source IPv6 address as ancillary data, if the ipi6_addr member of the in6_pktinfo structure is the unspecified address (IN6ADDR_ANY_INIT or in6addr_any), then (a) if an address is currently bound to the socket, it is used as the source address, or (b) if no address is currently bound to the socket, the kernel will choose the source address. If the ipi6_addr member is not the unspecified address, but the socket has already bound a source address, then the ipi6_addr value overrides the already-bound source address for this output operation only.
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.
IPV6_PKTINFO can also be used as a sticky option for specifying the socket's default source address. However, the ipi6_addr member must be the unspecified address for TCP sockets, because it is not possible to dynamically change the source address of a TCP connection. When the IPV6_PKTINFO option is specified for a TCP socket with a non-unspecified address, the call will fail. This restriction should be applied even before the socket binds a specific address.
When the in6_pktinfo structure is returned as ancillary data by recvmsg(), the ipi6_addr member contains the destination IPv6 address from the received packet.