-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Provide definition of tcp_info #1609
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
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might work, so let's see what CI says first.
I'm not 100% sure what the C rules for bitsets are (e.g. whether C store the bitset in two u8 with an alignment requirement of 1 or in one u16 with an alignment requirement of 2 which might require padding before the first bitset). As long as these are private, it doesn't matter much, but you might want to add an impl in a future PR that looks like this:
and then the layout for this "hole" within the struct would need to be correct for these methods to return the right values. Let's try to merge this as is first, so that we know that the struct has the general layout correct, and worry about how to access these private fields in a different PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use bindgen in libc? I think bindgen would handle all these cases (including accessing the bitfields) for us.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By that I mean it would probably be feasible to copy whatever bindgen generates, but (in this case) this includes bindgen's bitfield helpers and I'm not sure whether you want to expose them. You could likely make them private though, and only expose accessor functions that do not expose bindgens internals.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the C bitset rules, the bitsets in the C header are exposed as two distinct
__u8, so I think that should clarify how they're laid out. Or rather, I'd find it weird if C merged both bitfields into one large-ish field.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can run bindgen yourself on the side and see what it does and try to replicate it here, but we can't use bindgen since it doesn't work well with cross-compiling. I hope doing this isn't two hard, you should just need a getter and a setter per bitfield, that does an
assertthat the bit index is in bounds, and just "test" or "sets" a bit in au8. The more complicated part is going to be adding a test for this tolibc-test. What we do there, is have some Rust code with a#[test]that creates atcp_info, and uses the setters to set the bitfields to some pattern. Then it calls some C code, that verifies the pattern by accessing the struct in C, and modifies it, returning thetcp_infostruct back to Rust. Finally, Rust uses the setters to verify the C patter, and the test succeeds. That's more or less how our roundtrip tests work, but for the getters and setters these would need to be written manually instead of being automatically generated.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I‘ve read here https://stackoverflow.com/a/6044223 that the data layout of bitfields isn‘t all that well-defined. Do you think it‘s safe to just do it the intuitive way and write regular getters and setters that shift the data around?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see this as a choice for this type. Rust does not have bitfields, so we need to treat the storage where they are stored as raw bytes. If we want to give those raw bytes some meaning, the only safe way to do that is via getter and setters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I think I wasn't really clear on that. I was just wondering how to implement the getters and setters correctly, given that the StackOverflow article suggests the actual data layout in bitfields isn't all that well-defined. But I might also just be overly cautious on that. I just don't have much experience with C and try to be careful if I have to deal with it.
I fully agree the data has to be exposed in a proper implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, makes sense. Let's only try to do that later in a different PR, when this one is merged.