net: Don't return unreachable local addresses for peer #15671

pull dongcarl wants to merge 1 commits into bitcoin:master from dongcarl:2019-03-fix-getlocal changing 1 files +2 −1
  1. dongcarl commented at 6:58 PM on March 26, 2019: member

    It is possible for GetLocal to return an unreachable local address if there are no reachable ones. This change makes sure that it doesn't.

  2. net: Don't return unreachable local addresses for peer 2cc733d9b7
  3. fanquake added the label P2P on Mar 26, 2019
  4. MarcoFalke commented at 3:02 AM on March 27, 2019: member

    I think it would help review if the bugfix came with a test case that failed before the fix

  5. promag commented at 11:58 PM on March 27, 2019: member

    utACK 2cc733d, agree with Marco. Not sure about the TODO comment, maybe something like "// Local address reachability must be at least REACH_DEFAULT (1)"

  6. gmaxwell commented at 6:10 AM on March 28, 2019: contributor

    Neither the commit message nor the PR explain the motivation for the change. It isn't self apparent.

  7. gmaxwell commented at 6:27 AM on March 28, 2019: contributor

    I have some concern that this might make the behaviour incorrect?

    Say you only have a RFC1918 address because you have a port forward but don't know your external IP (e.g. not running the UPNP security hole...). https://github.com/bitcoin/bitcoin/blob/master/src/net.cpp#L181 calls GetLocalAddress, which calls GetLocal, which only finds your RFC1918 address, which is REACH_UNREACH https://github.com/bitcoin/bitcoin/blob/master/src/netaddress.cpp#L428 (pretty much the only case that is!), which gets returned which GetLocalAddress notes "IP may be changed to a useful one" https://github.com/bitcoin/bitcoin/blob/master/src/netaddress.cpp#L428 which happens back in Advertiselocal. https://github.com/bitcoin/bitcoin/blob/master/src/net.cpp#L193 Also in the case a non-routable address is returned it is always overridden in Advertiselocal.

    I believe after this change, this can never happen because the REACH_UNREACH will cause a false result that will propagate up and so a portmapped host will never successfully announce itself on the network... but I could be mistaken, it was just a quick glance and I'm not sure what this PR is actually intending to accomplish.

  8. dongcarl commented at 3:46 PM on March 28, 2019: member

    I have some concern that this might make the behaviour incorrect?

    Say you only have a RFC1918 address because you have a port forward but don't know your external IP (e.g. not running the UPNP security hole...). /src/net.cpp@master#L181 calls GetLocalAddress, which calls GetLocal, which only finds your RFC1918 address, which is REACH_UNREACH /src/netaddress.cpp@master#L428 (pretty much the only case that is!), which gets returned which GetLocalAddress notes "IP may be changed to a useful one" /src/netaddress.cpp@master#L428 which happens back in Advertiselocal. /src/net.cpp@master#L193 Also in the case a non-routable address is returned it is always overridden in Advertiselocal.

    I believe after this change, this can never happen because the REACH_UNREACH will cause a false result that will propagate up and so a portmapped host will never successfully announce itself on the network... but I could be mistaken, it was just a quick glance and I'm not sure what this PR is actually intending to accomplish.

    You are absolutely right. I will note this point in #15672 so it's clearer for future developers.

  9. dongcarl closed this on Mar 28, 2019

  10. MarcoFalke locked this on Dec 16, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-01 03:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me