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

[0.2] Add additional Linux AF_PACKET options #3540

Merged
merged 1 commit into from
Oct 1, 2024

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.

(adding this to libc 0.2 as 0.3 is in early development)

@rustbot
Copy link
Collaborator

rustbot commented Jan 12, 2024

r? @JohnTitor

(rustbot has picked a reviewer for you, use r? to override)

@JohnTitor
Copy link
Member

Sorry but could you add cfgs here? 0.2's MSRV is 1.13 and we need to add them, see https://github.com/rust-lang/libc/tree/libc-0.2#rust-version-support.

@nathaniel-bennett
Copy link
Contributor Author

Added cfgs for union types in latest force-push

@JohnTitor
Copy link
Member

JohnTitor commented Jan 19, 2024

CI fails, seems you also need libc_align cfg.
@rustbot author

@nathaniel-bennett
Copy link
Contributor Author

Added libc_align cfg to any structs that use repr(align)

@nathaniel-bennett nathaniel-bennett force-pushed the libc-0.2 branch 8 times, most recently from d48b986 to d0e72e9 Compare March 11, 2024 14:37
@nathaniel-bennett nathaniel-bennett force-pushed the libc-0.2 branch 7 times, most recently from 8b168d1 to e5e8b78 Compare May 3, 2024 11:55
@nathaniel-bennett
Copy link
Contributor Author

r? @tgross35

@rustbot rustbot assigned tgross35 and unassigned JohnTitor Aug 13, 2024
@nathaniel-bennett nathaniel-bennett force-pushed the libc-0.2 branch 3 times, most recently from af37ff7 to ed656e0 Compare August 16, 2024 09:49
@tgross35
Copy link
Contributor

tgross35 commented Aug 16, 2024

This is a big-ish API surface so it's still taking me a while to going through it. Feel free to hold off rebasing until I get back to you.

Some brief notes below.

Comment on lines 3693 to 3748
// FIXME: pass by value for structs that are not an even 32/64 bits on
// big-endian systems corrupts the value for unknown reasons.
if (sparc64 || ppc || ppc64 || s390x)
&& (ty == "sockaddr_pkt"
|| ty == "tpacket_auxdata"
|| ty == "tpacket_hdr_variant1"
|| ty == "tpacket_req3"
|| ty == "tpacket_stats_v3"
|| ty == "tpacket_req_u")
{
return true;
}
// FIXME: musl doesn't compile with `struct fanout_args` for unknown reasons.
if musl && ty == "fanout_args" {
return true;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are these unknown reasons, or what is the error? Ideally we link actual rust-lang/rust issues here so we know when this can be removed.

Comment on lines 221 to 222


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks spurious

Comment on lines 1445 to 1474
#[cfg(libc_union)]
impl ::fmt::Debug for tpacket_req_u {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("tpacket_req_u")
.field("req3", unsafe { &self.req3 })
.finish()
}
}

#[cfg(libc_union)]
impl ::fmt::Debug for tpacket_bd_header_u {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("tpacket_bd_header_u")
.field("bh1", unsafe { &self.bh1 })
.finish()
}
}

#[cfg(libc_union)]
impl ::fmt::Debug for tpacket_block_desc {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("tpacket_bd_header_u")
.field("version", &self.version)
.field("offset_to_priv", &self.offset_to_priv)
.field("hdr", &self.hdr)
.finish()
}
}


Copy link
Contributor

@tgross35 tgross35 Aug 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading req3 on tpacket_req_u reads potentially uninitialized data if the variant is actually req. It is probably best to just drop these Debug implementations entirely, considering they may be removed anyway in 1.0.

@nathaniel-bennett
Copy link
Contributor Author

Linked to (rust-lang/rust#43894), removed the spurious whitespace, and dropped the Debug implementations. This is a backport of a PR that was already added to the 1.0 branch, so I'll open up a PR taking out the bad Debug implementations there too

@nathaniel-bennett
Copy link
Contributor Author

@rustbot label S-waiting-on-review

@nathaniel-bennett
Copy link
Contributor Author

@rustbot label -S-waiting-on-author

@tgross35 tgross35 added this pull request to the merge queue Oct 1, 2024
@tgross35 tgross35 removed this pull request from the merge queue due to a manual request Oct 1, 2024
@tgross35 tgross35 enabled auto-merge October 1, 2024 03:31
@tgross35 tgross35 added this pull request to the merge queue Oct 1, 2024
Merged via the queue into rust-lang:libc-0.2 with commit 42d1000 Oct 1, 2024
53 checks passed
@github-actions github-actions bot mentioned this pull request Oct 1, 2024
@tgross35 tgross35 added the main-needs-cherry-pick This PR was merged against libc-0.2 but does not yet exist in main. label Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
main-needs-cherry-pick This PR was merged against libc-0.2 but does not yet exist in main. S-waiting-on-review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants