-
Notifications
You must be signed in to change notification settings - Fork 2k
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
eui64_t
type needs a cleanup
#14690
Comments
Option 1 for a cleanup (vote with thumbs up / down):typedef network_uint64_t eui64_t |
Option 2 for a cleanup (vote with thumbs up / down):typedef union {
uint8_t u8[8]; /**< EUI-64 as byte array. */
uint64_t u64; /**< EUI-64 as number. Must be **big** **endian**!!!11eleven */
} eui64_t |
Option 3 for a cleanup (vote with thumbs up / down):typedef struct {
uint8_t u8[8]; /**< EUI-64 as byte array. Must be **big** **endian**!!!11eleven */
} eui64_t Update: Don't using |
Two arguments against Option 3:
|
I think these can be mitigated by wrapping in functions, e.g., "eui64_equal(*a, *b)", "eui64_is_global(*a)", "eui64_from_u64()". When is conversion between endianness necessary other than for displaying to the user? Anyhow, I'd try to compare endianness bugs (which show up right away when not working) to alignment bugs (which show up in the field, when somehow the memory layout is different than in the test vectors). Alignment errors are a different class of bugs, which IMO should have priority to avoid or fix. Also, I'm impressed that having a 20 line type definition is even considered to be preferable to a simple byte array. :) |
The network stack can set the L2 address and will always do so in big endian. The driver has to convert, if little endian is used by the hardware. |
This is generally true and I agree. However, we still managed to miss an endianess bug in the It would be nice to have a generic test for this, which would work on top of any IEEE 802.15.4 driver. Sadly, if the bug is applied consistently on both setting and getting the L2 address, this is not trivially to detect. I think we need a second device sniffing for frames send by this device. If the second device is using a known-good driver, this should catch any endianess issues. |
The following is just a thought that came up and for some reason i wanted to share it (please season it to your taste). Since this data has so many accessors and i thought C++ has a solution (private internals and some getter and setter), but this is C how can we get around. How about creating a structure that has its internals not known to the user but has its content only accessed through static functions, which the compiler optimization will take care of. One could even put something like a scrambler define in (#define u8 abzgt) and undef at the end into the header that will let the compiler scream if someone accesses the internals of that struct. |
My experience with trying to mimic features like I would prefer proper documentation (so that offenders at least are aware of their wrongdoing) and proper review. |
yes the accessors function would clutter the code but a the moment in most case u need to use a accessor anyway hton the only difference is its generality (the scrambler define is a second thought to make the non "legit" use scream at compiletime) and ofcause it may be switched of for debuging (like one would put the famous #define privat public). |
why is that? If the network stack uses eui64_t, it needs to get it somewhere (user input, from the network, freshly created). In all cases, |
I agree on adding the helper functions. But please let's keep the driver in charge of doing any conversion, if needed. Otherwise the network code would look like this (pseudo-code): upper_layer_set_l2_addr(dev_t *dev, eui64_t addr)
{
if (dev->get_preferred_byte_order() == BIG_ENDIAN) {
dev->set_l2_addr(addr);
}
else {
dev->set_l2_addr(eui64_to_lsb(addr));
}
} And I really think that the network stack should not care about the internal representation of an L2 addr in the device it is running on. |
+1 |
what is |
At least for |
I agree this snippet is not something we would like, but note that in most cases such an "upper_layer_set_l2_addr" might not be needed, since that In practice, this function would be the specific E.g setting LoRaWAN EUIs (little endian) works like this: static int _set(gnrc_netif_t *netif, const gnrc_netapi_opt_t *opt)
{
...
case NETOPT_ADDRESS_LONG:
assert(opt->data_len == LORAMAC_DEVEUI_LEN);
_memcpy_reversed(netif->lorawan.deveui, opt->data, LORAMAC_DEVEUI_LEN);
break;
case NETOPT_LORAWAN_APPEUI:
assert(opt->data_len == LORAMAC_APPEUI_LEN);
_memcpy_reversed(netif->lorawan.appeui, opt->data, LORAMAC_APPEUI_LEN);
break;
... GNRC LoRaWAN expects EUIs in litle endian, but NETOPTs are in network byte order. Still, it would be possible to bypass this |
I just noticed that With this attribute, the type basically behaves exactly like Option 3 already; this is just well hidden under layers of complexity in the type definition. |
IMO, the other byteoder types should just be cleaned up as well: #14737 |
Which, IMO, is the kind of complexity that we should avoid by using the simplest type possible. principle of least surprise. Don't say you were not surprised when you spotted the "packed". 😕 |
Maybe we should discuss #14737 first. As Option 1 will reuse |
I previously said that I do not care what the type of |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
Description
There was some backlash on consistently using the
eui64_t
type for EUI-64 identifiers, mostly due to the type being messy.Steps to reproduce the issue
Check the definition of the type.
Expected results
Something reasonable.
Actual results
I replaced all
network_uint<NUM>_t
with an inlineunion network_uint<NUM>
definition, so that the full depth of the definition is easier to see.Versions
Current master
The text was updated successfully, but these errors were encountered: