Fix AF_PACKET protocol on raw L3 sends#5015
Conversation
Set the sockaddr_ll protocol explicitly when sending raw L3 packets through Linux AF_PACKET sockets. This prevents PPP/PPPoE drivers from seeing skb->protocol as 0 and dropping IPv4/IPv6 packets sent with send() or sendp(). Add Linux regression coverage for IPv4 padding retry and IPv6 protocol selection on L3PacketSocket and raw-L3 L2Socket paths. Fixes secdev#4964 AI-Assisted: yes (OpenAI Codex)
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5015 +/- ##
==========================================
- Coverage 80.38% 80.36% -0.03%
==========================================
Files 385 386 +1
Lines 95889 95993 +104
==========================================
+ Hits 77083 77145 +62
- Misses 18806 18848 +42
🚀 New features to boost your workflow:
|
gpotter2
left a comment
There was a problem hiding this comment.
Thanks for the PR !
Although it may work, the code doesn't really make sense. I've made some comments
| i = 0 | ||
| for p in x.fragment(): | ||
| i += fd.send(bytes(self.LL() / p)) | ||
| if sock.lvl == 2: |
There was a problem hiding this comment.
What's the use case of this 'if' ?
|
|
||
| def send(self, x): | ||
| # type: (Packet) -> int | ||
| if self.lvl == 3: |
There was a problem hiding this comment.
What's the use case of this? I'm a bit lost
| elif isinstance(iff, NetworkInterface): | ||
| iff = network_name(iff) | ||
| type_x = type(x) | ||
| sdto = (iff, conf.l3types.layer2num.get(type_x, self.type)) |
| self.send_socks[iff] = L3PacketSocket( | ||
| iface=iff, | ||
| type=conf.l3types.layer2num.get(type_x, self.type), | ||
| type=sdto[1], |
There was a problem hiding this comment.
Just to extract if afterwards ?
| sx = bytes(sock.LL() / x) | ||
| else: | ||
| sx = bytes(x) | ||
| sdto = (iff, _get_packet_protocol(x, sx, sdto[1])) |
There was a problem hiding this comment.
And redefine it here ? _get_packet_protocol looks awfully like a duplicate of what this function is already doing
|
Thanks for the PR, I think the fix is too big. Will take a deeper look |
Description
Set the sockaddr_ll protocol explicitly when sending raw L3 packets through Linux AF_PACKET sockets. This prevents PPP/PPPoE drivers from seeing skb->protocol as 0 and dropping IPv4/IPv6 packets sent with send() or sendp().
Add Linux regression coverage for IPv4 padding retry and IPv6 protocol selection on L3PacketSocket and raw-L3 L2Socket paths.
Tested send and sendp can work on ppp0.
Fixes #4964
AI-Assisted: yes (OpenAI Codex)