-
Notifications
You must be signed in to change notification settings - Fork 23
icmp6: replace endian-dependent bitfields with flag enums #377
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
Conversation
📝 WalkthroughWalkthroughAdds two public enum types, Pre-merge checks✅ Passed checks (2 passed)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (5)
🚧 Files skipped from review as they are similar to previous changes (4)
🧰 Additional context used📓 Path-based instructions (1)**/*.{c,h}⚙️ CodeRabbit configuration file
Files:
🧠 Learnings (1)📓 Common learnings🔇 Additional comments (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| #if BYTE_ORDER == BIG_ENDIAN | ||
| uint8_t managed_addr : 1, other_config : 1, __unused_flags : 6; | ||
| #else | ||
| uint8_t __unused_flags : 6, managed_addr : 1, other_config : 1; |
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.
Does it mean we should not allow any bit-fields in grout ?
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.
We're trading a known complexity in 1 header with a more complex code to write, read and debug in all other files.
I'm not sure if I'm a fan of that.
@rjarry Do we have a test that this works on big endian arch ? Otherwise, I'd refrain merging that.
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.
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.
we can have bitfields, but for stuff that goes in the network, it is "unsafe" to rely on compiler implementation details.
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.
The C standard only mentions byte ordering. Not bit ordering. Compilers can store them in any order they want.
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 prefer the approach in the BZ comment, using __attribute__((scalar_storage_order("big-endian"))).
Wouldn't it be better ? Even on the debugging side, this feels cleaner.
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.
scalar_storage_order doesn't exist on clang : https://bugs.llvm.org/show_bug.cgi?id=35293
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.
As Maxime noted, this isn't supported by clang. And not standard at all.
What's wrong with using an enum with flags? Debuggers will display them without issues.
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.
It's the same problem with vi. You should use emacs ;-) . Why ? Because !
5d22337 to
5eaebc8
Compare
The icmp6_router_advert and icmp6_neigh_advert structures used bitfields to represent flag bits. The order of bitfield members in memory is implementation-defined and requires #ifdef BYTE_ORDER guards to ensure correctness across different architectures. Replace bitfields with uint8_t flag members and define flag constants as typed enums using the GR_BIT8() macro. This approach is portable, explicit, and does not rely on compiler-specific behavior. Update all code accessing these flags to use bitwise operations instead of direct member access. Signed-off-by: Robin Jarry <[email protected]> Reviewed-by: Christophe Fontaine <[email protected]> Reviewed-by: Maxime Leroy <[email protected]>
5eaebc8 to
24502df
Compare
The
icmp6_router_advertandicmp6_neigh_advertstructures used bitfields to represent flag bits. The order of bitfield members in memory is implementation-defined and requires#ifdef BYTE_ORDERguards to ensure correctness across different architectures.Replace bitfields with
uint8_tflag members and define flag constants as typed enums using theGR_BIT8()macro. This approach is portable, explicit, and does not rely on compiler-specific behavior.Update all code accessing these flags to use bitwise operations instead of direct member access.
Summary by CodeRabbit