0

I've been trying to independently verify the answer to this stackoverflow question about how the Linux kernel assigns a source address to IP packets when the source doesn't request a specific source address. One of the comments refers to this source which contains the following sentence:

lacking this hint, the kernel will choose the first address configured on the interface which falls in the same network as the destination address...

I think this sentence could be interpreted in two ways:

  • The kernel picks the interface which sits on the same network as the destination address, then picks the first address assigned to that interface.
  • Of the addresses assigned to the interface, the kernel picks the first one which sits on same network as the destination address.

I think the first one is the naïve (i.e. purely grammatical) interpretation of that sentence, but the second one is how I would have guessed the kernel chooses. My reasoning is this: Assume, for simplicity, there are no gateways/routers on this network. How could the destination send a response (e.g. TCP ACK) to the source address if the selected source address isn't on the same network (which is possible in the first interpretation)?

Which interpretation is correct?

  • If it's the first, how does the destination route a response back to the source?
  • Is this behaviour documented anywhere (ideally the Linux man pages)?
5
  • The meaning looks clear (to me): there's an additional condition to match, and the first address found matching all conditions is to be used. So it's the second case. As it's not the first case, the condition on your last question makes there's no question anymore. Do you have an actual problem to solve? Please read: meta.stackexchange.com/questions/66377/what-is-the-xy-problem Commented Dec 13, 2023 at 10:42
  • There is still the first question! Which interpretation is correct? I've edited the question because ideally I'd like a reliable source to confirm the answer, given that the linked answer seems to disagree. Commented Dec 13, 2023 at 11:25
  • RE the XY problem, while I am (quite obviously) trying to answer the question 'How does the Linux kernel select a source IP?', I'm also trying not to ask the same question as other people and show that I've done best-effort research on my own: unix.stackexchange.com/help/how-to-ask Commented Dec 13, 2023 at 11:39
  • If there's a contradiction in the linked document, can you also quote the part with the contradiction in this question? Commented Dec 13, 2023 at 12:29
  • Also if there are no gateway/routers (eg route add default dev wan0), then any network matches. While it still matches the 2nd case, it also matches the 1st case. So I'm not sure simplification will help for the actual problem. Commented Dec 13, 2023 at 12:35

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.