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.

PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Oct 25, 2024
…iscover

a68fed1 net: Fix misleading comment for Discover (laanwj)
7766dd2 net: Replace ifname check with IFF_LOOPBACK in Discover (laanwj)

Pull request description:

  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.

ACKs for top commit:
  sipa:
    utACK a68fed1
  willcl-ark:
    utACK a68fed1
  theuni:
    utACK a68fed1. Satoshi-era brittleness :)

Tree-SHA512: e2d7fc541f40f6a6af08286e7bcb0873ff55debdcd8b38b03f274897b673a6fb51d84d6c7241a02a9567ddf2645f50231d91bb1f55307ba7c6e68196c29b0edf
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Oct 26, 2024
…iscover

a68fed1 net: Fix misleading comment for Discover (laanwj)
7766dd2 net: Replace ifname check with IFF_LOOPBACK in Discover (laanwj)

Pull request description:

  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.

ACKs for top commit:
  sipa:
    utACK a68fed1
  willcl-ark:
    utACK a68fed1
  theuni:
    utACK a68fed1. Satoshi-era brittleness :)

Tree-SHA512: e2d7fc541f40f6a6af08286e7bcb0873ff55debdcd8b38b03f274897b673a6fb51d84d6c7241a02a9567ddf2645f50231d91bb1f55307ba7c6e68196c29b0edf
PastaPastaPasta added a commit to dashpay/dash that referenced this pull request Oct 27, 2024
700b8c5 Merge bitcoin#29658: Bugfix: GUI: Help messages already have a trailing newline, so don't add an extra one (merge-script)
a0cd305 Merge bitcoin#29948: test: add missing comparison of node1's mempool in MempoolPackagesTest (Ava Chow)
f1907ea Merge bitcoin#29984: net: Replace ifname check with IFF_LOOPBACK in Discover (merge-script)
daa6eee Merge bitcoin#29960: depends: pass verbose through to cmake based makefiles (merge-script)
61a5832 Merge bitcoin#29907: test: Fix `test/streams_tests.cpp` compilation on SunOS / illumos (merge-script)
23f25a9 Merge bitcoin#29872: test: Add missing Assert(mock_time_in >= 0s) to SetMockTime (merge-script)
a7daee7 Merge bitcoin#29689: lint: scripted-diff verification also requires GNU grep (Ava Chow)
3df1ca1 Merge bitcoin#29953: doc: Bash is needed in gen_id and is not installed on FreeBSD by default (merge-script)
b53b854 Merge bitcoin#29850: net: Decrease nMaxIPs when learning from DNS seeds (Ava Chow)
c4a147c Merge bitcoin#28340: security: restrict abis in bitcoind.service (Ryan Ofsky)
acfdf9e Merge bitcoin#28373: doc: Add example of mixing private and public keys in descriptors (Ava Chow)
51bc8bd Merge bitcoin#29859: build: Fix false positive `CHECK_ATOMIC` test (merge-script)
bb4102c Merge bitcoin#29893: test: fix intermittent failure in p2p_compactblocks_hb.py (glozow)
4ecb761 Merge bitcoin#29786: Drop Windows Socket dependency for `randomenv.cpp` (fanquake)
1a8e805 Merge bitcoin#29498: test: Update --tmpdir doc string to say directory must not exist (fanquake)
81ca71c Merge bitcoin#29781: depends: add new LLVM debug macro (fanquake)
5ce92ca Merge bitcoin#29527: depends: add -g to DEBUG=1 flags (fanquake)

Pull request description:

  ## Issue being fixed or feature implemented
  Trivial backports

  ## What was done?

  ## How Has This Been Tested?
  built locally

  ## Breaking Changes

  ## Checklist:
    _Go over all the following points, and put an `x` in all the boxes that apply._
  - [ ] I have performed a self-review of my own code
  - [ ] I have commented my code, particularly in hard-to-understand areas
  - [ ] I have added or updated relevant unit/integration/functional/e2e tests
  - [ ] I have made corresponding changes to the documentation
  - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_

ACKs for top commit:
  UdjinM6:
    utACK 700b8c5 but pls confirm Guix is happy now before merging
  kwvg:
    utACK 700b8c5

Tree-SHA512: 9722979c4f0589cb02bfeaf39373713372a4aa1c8c5a55aa5b4d33388f73ef19231de3963b80ffaad25fbe0db90a133de5080baac691daed41b86a762b867b2d
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.

7 participants