Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: Replace ifname check with IFF_LOOPBACK in Discover #29984

Merged
merged 2 commits into from May 7, 2024

Conversation

laanwj
Copy link
Member

@laanwj laanwj commented Apr 28, 2024

Checking the interface name is kind of brittle. In the age of network namespaces and containers, there is no reason a loopback interface can't be called differently.

Check for the IFF_LOOPBACK flag to detect loopback interface instead.

Also remove a misleading comment in Discover's doc comment.

Checking the interface name is kind of brittle. In the age of network
namespaces and containers, there is no reason a loopback interface can't
be called differently.

Check for the `IFF_LOOPBACK` flag to detect loopback interface instead.
@laanwj laanwj added the P2P label Apr 28, 2024
@DrahtBot
Copy link
Contributor

DrahtBot commented Apr 28, 2024

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK sipa, willcl-ark, theuni

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #30043 (net: Replace libnatpmp with built-in PCP implementation by laanwj)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

All network addresses are being iterated over and added, not just the first one per interface.
@sipa
Copy link
Member

sipa commented Apr 28, 2024

utACK a68fed1

Copy link
Member

@willcl-ark willcl-ark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK a68fed1

Agree this will be less brittle than name-checking. I don't think it's possible that IFF_LOOPBACK would ever be unset for a loopback device unless someone had modified their kernel.

Copy link
Member

@theuni theuni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK a68fed1. Satoshi-era brittleness :)

@fanquake fanquake merged commit ef09f53 into bitcoin:master May 7, 2024
16 checks passed
@theStack
Copy link
Contributor

theStack commented May 7, 2024

post-merge ACK a68fed1

Interestingly, libpcap still implements both the "brittle" and the IFF_LOOPBACK flag way to detect loopback devices (https://github.com/the-tcpdump-group/libpcap/blob/0797ed7340f93618fd097ad870dfc1dde7cecc4f/pcap.c#L1042-L1053), but the code was seemingly introduced in 1998 (https://github.com/the-tcpdump-group/libpcap/blob/0797ed7340f93618fd097ad870dfc1dde7cecc4f/CHANGES#L1443-L1445) and I suspect that these days you won't find any Unix-like OS anymore that does not provide IFF_LOOPBACK.

@laanwj
Copy link
Member Author

laanwj commented May 8, 2024

Thanks for checking! it's kind of a belt-and-suspenders check: we only look for routable addresses in Discover, so unless someone assigned a routable address to the loopback interface-which would be really strange-it doesn't actually influence the result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants