-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Send IP packet on OpenBSD Loopback with correct address family. #1907
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1907 +/- ##
==========================================
+ Coverage 85.91% 85.92% +0.01%
==========================================
Files 187 187
Lines 42874 42872 -2
==========================================
+ Hits 36835 36838 +3
+ Misses 6039 6034 -5
|
scapy/layers/inet.py
Outdated
@@ -931,7 +932,8 @@ def mysummary(self): | |||
bind_layers(CookedLinux, IP, proto=2048) | |||
bind_layers(GRE, IP, proto=2048) | |||
bind_layers(SNAP, IP, code=2048) | |||
bind_layers(Loopback, IP, type=0) | |||
if not consts.OPENBSD: | |||
bind_layers(Loopback, IP, type=0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it only breaks building, I think we could leave the dissection for such values (so that you can open all pcaps) and default to the others for building.
You can replace bind_layers
with bind_bottom_up
so that it only affects dissection (it might require an import)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works for OpenBSD, but possibly not for other OS:
bind_layers(Loopback, IPv6, type=0x18)
bind_bottom_up(Loopback, IPv6, type=0x1c)
bind_bottom_up(Loopback, IPv6, type=0x1e)
What is your idea? Register all with bind_bottom_up() and only one per OS with bind_top_down()? I doubt that will help reading foreign pcap files from loopback with OpenBSD or vice versa as the encoding of the address family is still different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m not a big fan of having OS-specific bindings hanging around in the layer files :/
Even though it probably won’t be used, I’d rather have the code you posted above (it will work for other platforms)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or we could also use bind_layers(Loopback, IPv6, type=socket.AF_INET6)
I guess
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of type=socket.AF_INET6. For consistency I also did this for IPv4. To bind the unspecified type to IPv4 I have used bind_bottom_up. The new commit works for OpenBSD and should work for other OS.
Register the matching inet and inet6 address family number for the IP and IPv6 layer of the loopback device. This way it should work for all operating systems. Keep IP as the default layer if the type of the bottom up packet is unspecified.
I have commited the d64930e patch into the OpenBSD ports tree. So 2.4.2 with this additional fix will be tested by OpenBSD users. |
Thanks for the PR & sorry for the delay ! |
Sending packets via bpf requires the address family. Instead of
binding the internet layer to loopback with multiple values, only
use the correct one for each inet and inet6. This fixes send()
IPv6 on OpenBSD.