Skip to content

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

Merged
merged 1 commit into from
Apr 27, 2019

Conversation

bluhm
Copy link
Contributor

@bluhm bluhm commented Mar 15, 2019

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.

@codecov
Copy link

codecov bot commented Mar 15, 2019

Codecov Report

Merging #1907 into master will increase coverage by 0.01%.
The diff coverage is 100%.

@@            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
Impacted Files Coverage Δ
scapy/layers/inet6.py 88.28% <100%> (+0.04%) ⬆️
scapy/layers/inet.py 70.57% <100%> (ø) ⬆️
scapy/layers/tls/crypto/pkcs1.py 78.67% <0%> (-1.48%) ⬇️
scapy/layers/ntp.py 91.51% <0%> (-0.54%) ⬇️
scapy/contrib/isotp.py 88.77% <0%> (+0.45%) ⬆️
scapy/automaton.py 82.36% <0%> (+0.55%) ⬆️

@@ -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)
Copy link
Member

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)

Copy link
Contributor Author

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.

Copy link
Member

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)

Copy link
Member

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

Copy link
Contributor Author

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.
@bluhm
Copy link
Contributor Author

bluhm commented Apr 24, 2019

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.

@gpotter2 gpotter2 merged commit 32619f4 into secdev:master Apr 27, 2019
@gpotter2
Copy link
Member

Thanks for the PR & sorry for the delay !

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

Successfully merging this pull request may close these issues.

2 participants