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

IPPROTO_RAW wrongly used with AF_PACKET #86827

Open
go2sh opened this issue Mar 9, 2025 · 7 comments
Open

IPPROTO_RAW wrongly used with AF_PACKET #86827

go2sh opened this issue Mar 9, 2025 · 7 comments
Assignees
Labels
area: Networking bug The issue is a bug, or the PR is fixing a bug

Comments

@go2sh
Copy link
Contributor

go2sh commented Mar 9, 2025

Describe the bug
Zephyr specifies the use of IPPROTO_RAW with AF_PACKET sockets. This is not in line how Linux specifies this. `IPPROTO_RAW´ is specified as sub type for IP frames. [1] Used as EtherType this specifies an old length field type. [2]

To Reproduce
Use AF_PACKET socket.

Expected behavior
IPPROTO_RAW is not treated as a protocol with AF_PACKET sockets, but with AF_INET/AF_INET6 through a SOCK_RAW socket.

Impact
Incompatibility (and maintaining this). overhead when using AF_PACKET.

Logs and console output
None.

Environment (please complete the following information):

  • OS: Linux
  • Toolchain: Zephyr SDK
  • Commit SHA: df53184

Additional context
None.

@go2sh go2sh added the bug The issue is a bug, or the PR is fixing a bug label Mar 9, 2025
@jukkar
Copy link
Member

jukkar commented Mar 10, 2025

The original plan was to be aligned with Linux here, but it seems that target was missed then. I suppose you are talking about this line


I think we can easily remove that one, the original plan was to have some default value if user gives proto as 0 which is not a valid value.

@jukkar
Copy link
Member

jukkar commented Mar 10, 2025

More info. According to this page https://stackoverflow.com/questions/49309029/confusion-with-af-inet-with-sock-raw-as-the-socket-type-v-s-af-packet-with-so the protocol field should be allowed to be 0 with AF_PACKET.

@go2sh
Copy link
Contributor Author

go2sh commented Mar 10, 2025

It's not only this line. This adds additional overhead:

ret = net_packet_socket_input(pkt, IPPROTO_RAW);

@go2sh
Copy link
Contributor Author

go2sh commented Mar 10, 2025

More info. According to this page https://stackoverflow.com/questions/49309029/confusion-with-af-inet-with-sock-raw-as-the-socket-type-v-s-af-packet-with-so the protocol field should be allowed to be 0 with AF_PACKET.

Here is also more info: https://man7.org/linux/man-pages/man7/raw.7.html
TLDR:
IPPROTO_RAW means send only sockets and the IP header needs to be provided by the user.

@jukkar
Copy link
Member

jukkar commented Mar 10, 2025

I think raw7 manual page only talks about AF_INET/6 sockets, not AF_PACKET ones.

@go2sh
Copy link
Contributor Author

go2sh commented Mar 10, 2025

https://man7.org/linux/man-pages/man7/packet.7.html Doesn't talk about IPPROTO_RAW either.

AF_PACKET is a layer 2 socket and IPPROTO_RAW is used at l3/l4 sockets.

@jukkar
Copy link
Member

jukkar commented Mar 10, 2025

Doesn't talk about IPPROTO_RAW either.

Yes, I noticed the same, it does not talk about IPPROTO_RAW. Only place IPPROTO_RAW is mentioned is in raw(7).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Networking bug The issue is a bug, or the PR is fixing a bug
Projects
None yet
Development

No branches or pull requests

3 participants