Skip to content

Additional linux AF_PACKET functionality #3120

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

Closed
wants to merge 1 commit into from
Closed

Additional linux AF_PACKET functionality #3120

wants to merge 1 commit into from

Conversation

nathaniel-bennett
Copy link
Contributor

Added socket options, structs and other miscellaneous constants that make memory-mapped packet sockets possible in Linux (PACKET_TX_RING, PACKET_RX_RING, etc.).

@rustbot
Copy link
Collaborator

rustbot commented Feb 16, 2023

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @JohnTitor (or someone else) soon.

Please see the contribution instructions for more information.

@nathaniel-bennett
Copy link
Contributor Author

(Note that this change removes the netpacket/packet.h header file and replaces it with linux/if_packet.h. This is because if_packet.h is a proper superset of packet.h, and the inclusion of both would lead to build errors with structs/constants being defined twice)

@JohnTitor
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Feb 19, 2023

📌 Commit 0ffc639 has been approved by JohnTitor

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Feb 19, 2023

⌛ Testing commit 0ffc639 with merge feacf46...

bors added a commit that referenced this pull request Feb 19, 2023
Additional linux AF_PACKET functionality

Added socket options, structs and other miscellaneous constants that make memory-mapped packet sockets possible in Linux (PACKET_TX_RING, PACKET_RX_RING, etc.).
@bors
Copy link
Contributor

bors commented Feb 19, 2023

💔 Test failed - checks-actions

@JohnTitor
Copy link
Member

The failure is valid, I guess the cause is our musl image on CI is old, we could skip tests for that arch.

@nathaniel-bennett
Copy link
Contributor Author

It seems like fanout_args was the main culprit that was causing the musl build to fail, so I've added a check that skips that particular struct for musl tests.

@JohnTitor
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Feb 26, 2023

📌 Commit c412376 has been approved by JohnTitor

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Feb 26, 2023

⌛ Testing commit c412376 with merge eb58fcc...

bors added a commit that referenced this pull request Feb 26, 2023
Additional linux AF_PACKET functionality

Added socket options, structs and other miscellaneous constants that make memory-mapped packet sockets possible in Linux (PACKET_TX_RING, PACKET_RX_RING, etc.).
@bors
Copy link
Contributor

bors commented Feb 26, 2023

💔 Test failed - checks-actions

@nathaniel-bennett
Copy link
Contributor Author

Alright, so this time the musl build failed due to some issue with sockaddr_pkt (likely something to do with endianness). I've opted to just remove sockaddr_pkt, since it's considered obsolete. It was part of the original SOCK_PACKET raw socket interface for Linux that was superceded by AF_PACKET and the accompanying sockaddr_ll socket type many years ago.

Fingers crossed that this time we actually pass the extended checks :)

@workingjubilee
Copy link
Member

@bors r=JohnTitor

@JohnTitor
Copy link
Member

Failed on mips: @rustbot author

@nathaniel-bennett
Copy link
Contributor Author

Did a rebase for this--the issues with mips and BSD should (hopefully) all be fixed now

@JohnTitor
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented May 1, 2023

📌 Commit a3d0958 has been approved by JohnTitor

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented May 1, 2023

⌛ Testing commit a3d0958 with merge 9fbadf8...

bors added a commit that referenced this pull request May 1, 2023
Additional linux AF_PACKET functionality

Added socket options, structs and other miscellaneous constants that make memory-mapped packet sockets possible in Linux (PACKET_TX_RING, PACKET_RX_RING, etc.).
@bors
Copy link
Contributor

bors commented May 1, 2023

💔 Test failed - checks-actions

@nathaniel-bennett
Copy link
Contributor Author

Most recent issue was with MIPS--it's in the same camp as sparc64 and musl with big endian alignment. I've added an exception for sockaddr_pkt for mips, similar to what I did for the others.

     Running test/main.rs (target/mips-unknown-linux-gnu/debug/deps/main-ae76ee3ebd17d880)
RUNNING ALL TESTS
rust[16] = 0 != 16 (C): Rust "sockaddr_pkt" -> C
rust[17] = 0 != 17 (C): Rust "sockaddr_pkt" -> C

@JohnTitor
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented May 1, 2023

📌 Commit 40c5858 has been approved by JohnTitor

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented May 1, 2023

⌛ Testing commit 40c5858 with merge 662cd46...

bors added a commit that referenced this pull request May 1, 2023
Additional linux AF_PACKET functionality

Added socket options, structs and other miscellaneous constants that make memory-mapped packet sockets possible in Linux (PACKET_TX_RING, PACKET_RX_RING, etc.).
@bors
Copy link
Contributor

bors commented May 1, 2023

💔 Test failed - checks-actions

@JohnTitor
Copy link
Member

Seems something is wrong on powerpc64:

 bad TPACKET3_HDRLEN value at byte 7: rust: 84 (0x54) != c 68 (0x44)
bad tpacket_auxdata size: rust: 24 (0x18) != c 20 (0x14)
bad field offset tp_vlan_tci of tpacket_auxdata: rust: 20 (0x14) != c 16 (0x10)
bad field type tp_vlan_tci of tpacket_auxdata: rust: 0x40027409dc != c 0x40027409d8
bad field offset tp_vlan_tpid of tpacket_auxdata: rust: 22 (0x16) != c 18 (0x12)
bad field type tp_vlan_tpid of tpacket_auxdata: rust: 0x4002740a2e != c 0x4002740a2a
size of struct tpacket_auxdata is 20 in C and 24 in Rust
bad tpacket_hdr_variant1 size: rust: 16 (0x10) != c 12 (0xc)
bad field offset tp_vlan_tpid of tpacket_hdr_variant1: rust: 12 (0xc) != c 8 (0x8)
bad field type tp_vlan_tpid of tpacket_hdr_variant1: rust: 0x4002740ae4 != c 0x4002740ae0
bad field offset tp_padding of tpacket_hdr_variant1: rust: 14 (0xe) != c 10 (0xa)
bad field type tp_padding of tpacket_hdr_variant1: rust: 0x4002740b1e != c 0x4002740b1a
size of struct tpacket_hdr_variant1 is 12 in C and 16 in Rust
bad tpacket_req3 size: rust: 32 (0x20) != c 28 (0x1c)
bad field offset tp_feature_req_word of tpacket_req3: rust: 28 (0x1c) != c 24 (0x18)
bad field type tp_feature_req_word of tpacket_req3: rust: 0x4002740a2c != c 0x4002740a28
size of struct tpacket_req3 is 28 in C and 32 in Rust
bad tpacket_stats_v3 size: rust: 16 (0x10) != c 12 (0xc)
bad field offset tp_freeze_q_cnt of tpacket_stats_v3: rust: 12 (0xc) != c 8 (0x8)
bad field type tp_freeze_q_cnt of tpacket_stats_v3: rust: 0x4002740b6c != c 0x4002740b68
size of struct tpacket_stats_v3 is 12 in C and 16 in Rust
bad tpacket3_hdr size: rust: 52 (0x34) != c 48 (0x30)
bad field offset tp_padding of tpacket3_hdr: rust: 44 (0x2c) != c 40 (0x28)
bad field type tp_padding of tpacket3_hdr: rust: 0x400274097c != c 0x4002740978
size of struct tpacket3_hdr is 48 in C and 52 in Rust

@rustbot author

@JohnTitor
Copy link
Member

Closing as inactive, feel free to re-submit a PR if you're still interested in this change. Thanks anyway!

@JohnTitor JohnTitor closed this Nov 1, 2023
@nathaniel-bennett
Copy link
Contributor Author

nathaniel-bennett commented Nov 2, 2023

I kept running into struct alignment issues on 64-bit big-endian architectures (currently being tracked at rust-lang/rust#43894); these would lead to bors failing. Once rust-lang resolves those, I'll resubmit a PR and get this functionality merged in.

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.

5 participants