I read that when kernel determines a source ipv6 address for the packet, it takes into consideration what interface will be used to send the packet,
(http://www.rfc-editor.org/rfc/rfc3484.txt, Section 5) Rule 5: Prefer outgoing interface. If SA is assigned to the interface that will be used to send to D and SB is assigned to a different interface, then prefer SA. Similarly, if SB is assigned to the interface that will be used to send to D and SA is assigned to a different interface, then prefer SB.
*D = Destination Address
But how is the interface itself determined? Let's take tcp handshake as an example:
- Host A has one interface and one ip address
1:0:0:0:0:0:0:a
- Host B has two interfaces eth0 with ip
1:0:0:0:0:0:0:b0
and eth1 with ip1:0:0:0:0:0:0:b1
- A sends SYN to B's
1:0:0:0:0:0:0:b0
. B responds with SYN-ACK. It should set src ip in Ipv6 header.
As I understand(correct me if I am wrong!) it will choose between 1:0:0:0:0:0:0:b0
and 1:0:0:0:0:0:0:b1
based on rules in the rfc I linked above, but I can't wrap my mind around them, especially the rule 5 as I can't find out how the interface is chosen at the first place.