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

Fallback to IPv6 default routes for network interface detection #4321

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

guedou
Copy link
Member

@guedou guedou commented Mar 16, 2024

This PR improves the selection of the default interface in an IPv6-only environment. See #4304 for context

To maintainers: shoud I add unit tests?

Copy link

codecov bot commented Mar 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.53%. Comparing base (ac3d5bb) to head (6a4d90a).
Report is 49 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4321      +/-   ##
==========================================
- Coverage   82.20%   78.53%   -3.67%     
==========================================
  Files         353      354       +1     
  Lines       83529    92937    +9408     
==========================================
+ Hits        68662    72985    +4323     
- Misses      14867    19952    +5085     
Files Coverage Δ
scapy/interfaces.py 96.80% <100.00%> (+0.20%) ⬆️
scapy/route6.py 86.26% <100.00%> (-2.14%) ⬇️

... and 66 files with indirect coverage changes

@guedou guedou force-pushed the guedou/20240316/ipv6_iface branch 2 times, most recently from c2745fc to 0087680 Compare March 16, 2024 12:18
@gpotter2
Copy link
Member

I would argue this needs tests considering it's already a regression.

Also you need to rebase ;p

@guedou guedou force-pushed the guedou/20240316/ipv6_iface branch 2 times, most recently from c21e446 to 425690a Compare March 19, 2024 19:43
@gpotter2
Copy link
Member

This makes me kinda wonder why we deprecated conf.iface6.

@guedou
Copy link
Member Author

guedou commented Mar 23, 2024 via email

@guedou guedou force-pushed the guedou/20240316/ipv6_iface branch from 425690a to 4447e20 Compare April 30, 2024 09:19
@guedou guedou added this to the 2.6.0 milestone Apr 30, 2024
@guedou guedou force-pushed the guedou/20240316/ipv6_iface branch 19 times, most recently from c1d43f4 to 478cb0c Compare May 1, 2024 20:15
@oskar456
Copy link

oskar456 commented May 7, 2024

Hey, I only noticed this after I opened my own PR #4380.
According to my tests, it is not going to work because conf.route6 is not populated by the time get_working_if() is called. This can be fixed by calling conf.ifaces.reload() at the end of route6.py.
Also I think it would be better to consider only default or generic enough routes. When someone has for instance an IPv6-only machine with a VPN that pushes route say 10.0.0.0/8, then the interface with IPv6 default route should be preferred over the VPN interface with /8 IPv4 route.

@guedou guedou marked this pull request as draft June 17, 2024 13:54
@guedou guedou modified the milestone: 2.6.0 Jul 11, 2024
@guedou guedou force-pushed the guedou/20240316/ipv6_iface branch from 478cb0c to 70c08cc Compare July 12, 2024 19:23
@guedou guedou force-pushed the guedou/20240316/ipv6_iface branch from 70c08cc to 6a4d90a Compare July 12, 2024 19:29
@guedou
Copy link
Member Author

guedou commented Jul 12, 2024

@oskar456 sorry for the delay. I slightly modified this PR and it should now work as expected. Do you have time to test it?

@oskar456
Copy link

Hey, thanks a lot! I can confirm that this PR fixes #4304.

@guedou guedou marked this pull request as ready for review July 14, 2024 09:06
@gpotter2
Copy link
Member

gpotter2 commented Jul 14, 2024

So we have to discuss a bit regarding this.
It's a good idea to have a better default selection when no IPv4 is available, however I disagree with the added documentation regarding iface and conf.iface.

Regarding link-local / multicast destinations, #4461 should properly add a route on interfaces that support multicast, so that should supposedly also fix the OP's question (as they only have a single interface with multicast). It also allows for a much more flexible behavior, which aims at avoiding to have to change conf.iface or iface.

Comment on lines +229 to +231
.. note::
Scapy automatically detects the network interface to be used by default, and stores this result in ``conf.iface``. Packets built by Scapy uses this variable to set relevant fields such as Ethernet source addresses. When sending packets, with functions such as ``send()``, Scapy will use the network interface stored in ``conf.iface``. This behavior can be changed using the ``iface=`` argument. With IPv6 and link-local addresses, it is mandatory to setup both ``conf.iface`` and ``iface=`` the same value to get the desired result, as Scapy cannot find which interface to use for link-local communications.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I disagree with that now that we have Scoped IPs.
The PR is still useful though, I think having a better default conf.iface is good, especially for L2 functions. (e.g. sniff)

@@ -360,3 +360,6 @@ def route(self, dst="", dev=None, verbose=conf.verb):


conf.route6 = Route6()

# Reload interfaces
conf.ifaces.reload()
Copy link
Member

Choose a reason for hiding this comment

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

That's a bit crappy. We only need to reload the default interface, not the entire interface list

@gpotter2 gpotter2 removed this from the 2.6.0 milestone Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants