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

Support for Scope Identifiers in IP addresses for multicast/link-local support #4461

Merged
merged 1 commit into from
Aug 22, 2024

Conversation

gpotter2
Copy link
Member

@gpotter2 gpotter2 commented Jul 13, 2024

This PR does a few changes to how Scapy handles IP addresses, in order to properly support link-layer / multicast scopes on L3. In particular:

  • add implicit multicast routes in Linux when the interface supports multicast (note: on Windows, those routes are explicitly provided by the OS so no change was required)
  • add support for a RFC6874-like scope identifier. One can now do:
pkt1 = IPv6(dst="ff02::fb%eth0")
pkt2 = IPv6(dst="ff02::fb%eth1")
assert pkt1.src != pkt2.src
# etc.
pkt3 = IP(dst="224.0.0.1%eth0")

The interface is then taken into account when calling route(). This enables support for multicast addresses using L3-functions (send, sr, etc.) as it also automatically choses the correct source addresses.

  • The above behavior is allowed through the introduction of a hidden ScopedIP (I'm open to some other name) class/function that returns a str that has a secret scope attribute (in order to remember the interface)
  • Deprecate the iface attribute of L3 functions. It was already mostly doing nothing, as L3sockets already implement chosing the proper interface when sending. This was confusing.
  • remove the second attribute of SourceIPField and SourceIP6Field. The code path was generally a duplicate since those packets already implement a route() function.

Demo (see doc)

conf.checkIPaddr = False
sr(IPv6(dst="ff02::2%eth0")/ICMPv6EchoRequest(), multi=True)
sr(IPv6(dst="ff02::2%eth1")/ICMPv6EchoRequest(), multi=True)

Other changes

Copy link

codecov bot commented Jul 13, 2024

Codecov Report

Attention: Patch coverage is 81.56028% with 26 lines in your changes missing coverage. Please review.

Project coverage is 81.65%. Comparing base (18b3d6c) to head (3b50178).
Report is 11 commits behind head on master.

Files Patch % Lines
scapy/sendrecv.py 61.53% 10 Missing ⚠️
scapy/base_classes.py 82.92% 7 Missing ⚠️
scapy/fields.py 88.46% 3 Missing ⚠️
scapy/layers/dns.py 40.00% 3 Missing ⚠️
scapy/route.py 77.77% 2 Missing ⚠️
scapy/arch/linux/rtnetlink.py 92.85% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4461      +/-   ##
==========================================
+ Coverage   81.42%   81.65%   +0.22%     
==========================================
  Files         355      355              
  Lines       84815    84880      +65     
==========================================
+ Hits        69062    69307     +245     
+ Misses      15753    15573     -180     
Files Coverage Δ
scapy/layers/hsrp.py 90.00% <ø> (ø)
scapy/layers/inet.py 71.84% <100.00%> (+0.05%) ⬆️
scapy/layers/inet6.py 88.54% <100.00%> (+0.07%) ⬆️
scapy/layers/l2.py 84.95% <100.00%> (+0.48%) ⬆️
scapy/main.py 70.37% <ø> (ø)
scapy/route6.py 88.39% <100.00%> (+2.20%) ⬆️
scapy/arch/linux/rtnetlink.py 93.39% <92.85%> (+0.40%) ⬆️
scapy/route.py 90.37% <77.77%> (+0.14%) ⬆️
scapy/fields.py 92.75% <88.46%> (+0.13%) ⬆️
scapy/layers/dns.py 84.20% <40.00%> (+0.20%) ⬆️
... and 2 more

... and 17 files with indirect coverage changes

@gpotter2 gpotter2 force-pushed the scope-id branch 5 times, most recently from 38cb410 to 1449b84 Compare July 13, 2024 15:53
@gpotter2 gpotter2 force-pushed the scope-id branch 2 times, most recently from 05dfc47 to d97baad Compare July 14, 2024 16:29
@gpotter2 gpotter2 changed the title Support for Scope Identifiers in IP addresses Support for Scope Identifiers in IP addresses for multicast/link-local support Jul 14, 2024
@gpotter2 gpotter2 added this to the 2.6.0 milestone Jul 14, 2024
scapy/main.py Show resolved Hide resolved
doc/scapy/usage.rst Outdated Show resolved Hide resolved
scapy/base_classes.py Outdated Show resolved Hide resolved
doc/scapy/usage.rst Outdated Show resolved Hide resolved
scapy/base_classes.py Show resolved Hide resolved
scapy/layers/inet6.py Outdated Show resolved Hide resolved
@gpotter2
Copy link
Member Author

/packit build

@gpotter2
Copy link
Member Author

gpotter2 commented Aug 22, 2024

I'm gonna go ahead and merge this. It worked fine on the BSDs and should avoids issues like #4506

@gpotter2 gpotter2 merged commit 97a49f3 into secdev:master Aug 22, 2024
24 checks passed
@gpotter2 gpotter2 deleted the scope-id branch August 22, 2024 13:00
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.

2 participants