-
Notifications
You must be signed in to change notification settings - Fork 904
Geonet: Update to Version 1. #1388
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
base: master
Are you sure you want to change the base?
Geonet: Update to Version 1. #1388
Conversation
|
Please see After all the fix-ups have been made, please make this one clean commit. |
9d95316 to
ca35a2b
Compare
|
Thank you. At a glance, this code needs to use Also the use of Also most of the details that are now in the pull request message concern the commit, not the pull request, so should be in the commit message. Also this removes support for GeoNet version 0 altogether, correct? And the new code prints the version, but does not check that it is version 1, correct? |
|
Also this removes 4 existing tests. |
|
I'll look into using As for the use of This does remove support for GeoNet version 0. There are two things I would point out, one is that GeoNet version 0 was drafted for a preliminary ETSI technical spec (as mentioned in this issue) and a new version was published in 2013 (12 years ago). Second, seeing that GeoNet-related services are rare, and all providers follow current standards I think it's better to remove support for GeoNet version 0 (for simplicity). You are correct, the current PR doesn't check it's version 1... I'll make sure to fix that. In the meantime, can you confirm that it's okay to remove support for GeoNet version 0? I can add it, but don't know if it will be used much. |
|
Thank you for explaining. Regarding the 32-bit TST field, the standard defines it to wrap this often and to have this much precision, it does not include a notion of a calendar date or a wrap counter. It would be wrong for a protocol decoder to present the TS field as if it has more data than it actually has. If the user needs to interpret the recorded 32-bit value of TST relative to "real" date and time, that's what the libpcap packet timestamp is for. So the best this decoder could do is to print TST exactly as it is (an integer number of milliseconds, or something formatted as "seconds.millieconds" or "dd:hh:mm:ss.ms" or whatever is the common notation for this 32-bit value in this practice). Regarding the versions, to comprehend this better, I had a look at the following specifications available at etsi.org:
As far as these documents define it, version 1 did not exist until 2017. As far as I understand V1.2.1 Section 8.4, digital signatures are optional. So, seemingly, version 0 could be not entirely irrelevant, but the problem is, the two version 0 specifications indeed define GeoNet packet structure differently:
This way, I agree that the best move is to lose the current V1.1.1 (version 0) code in the tcpdump decoder, whether anybody gets to implement V1.2.1 (version 0) code in future or not. |
…, making tcpdump wrongly dissect GeoNet packets (issue the-tcpdump-group#992). This PR updates ETSI GeoNetworking protocol to version 1 (ETSI EN 302 636-4-1 V1.4.1 (2020-01)). The update includes dissectors for GeoNet Beacon messages and TopoScopeBcast-SH. Additionally, the Basic Transport Protocol (ETSI EN 302 636-5-1 V2.2.1 (2019-05)) has also been updated. It includes BTP-A and BTP-B in all its variants.
|
Perfect! I've done the following changes;
The GeoNet header has a lot of fields encoded in smaller than 1 byte (i.e., 1-7 bits) values. Achieving pefectly clean code is difficult, since there is a lot of big masking and shifting. |
…, making tcpdump wrongly dissect GeoNet packets (issue the-tcpdump-group#992). This PR updates ETSI GeoNetworking protocol to version 1 (ETSI EN 302 636-4-1 V1.4.1 (2020-01)). The update includes dissectors for GeoNet Beacon messages and TopoScopeBcast-SH. Additionally, the Basic Transport Protocol (ETSI EN 302 636-5-1 V2.2.1 (2019-05)) has also been updated. It includes BTP-A and BTP-B in all its variants.
print-geonet.c
Outdated
|
|
||
| const char *next_header_text = basic_header_next_header_text_from_bytes(*next_header); | ||
| version = (value >> (4 + THREE_BYTES)) & FOUR_BITS_MASK; | ||
| if (!memchr(implemented_gn_versions, version, IMPLEMENTED_GN_VERSIONS_NUM)) |
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.
Please note that memchr(), at least if used this way, does not work as expected on big-endian architectures. A simple if or switch would be sufficient. The same likely applies to NH below.
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.
Ok! I'll make sure to fix that.
| reserved = (value >> (TWO_BYTES)) & EIGHT_BITS_MASK; | ||
| lt_multiplier = (value >> (2 + ONE_BYTE)) & SIX_BITS_MASK; | ||
| lt_base = (value >> ONE_BYTE) & THREE_BITS_MASK; | ||
| rhl = value & FOUR_BITS_MASK; |
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.
Fetching the entire header as a 32-bit integer does not work well. One common way to do that would be using a structure, and another would be just fetching one octet at a time, for example:
// Validate that length is at least 4.
uint8_t ver_nh = GET_U_1(*bp);
version = ver_nh & 0xf0;
nh = ver_nh & 0x0f;
*bp++;
*length--;
reserved = GET_U_1(*bp);
*bp++;
*length--;
lt = GET_U_1(*bp);
lt_multiplier = lt & 0x3f;
lt_base = (lt & 0xc0) >> 6;
*bp++;
*length--;
rhl = GET_U_1(*bp);
*bp++;
*length--;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.
For reference, that's ETSI EN 302 636-4-1 V1.4.1 Section 9.6. It would be useful to say that in a comment before the function to make it clear what it implements.
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.
Ok! A structure would be great but since there are many <8 bit values I thing going with fetching one octet at a time is better.
Out of curiosity, what do you mean with "Fetching the entire header as a 32-bit integer does not work well."?
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 difference should be easy to see if you compare the complexity of code. Also rhl = value & FOUR_BITS_MASK is wrong because RHL is an 8-bit integer.
|
|
||
| const char *next_header_text = tok2str(common_header_next_header_values, "Unknown", *next_header); | ||
| const char *header_type_text = tok2str(header_type_tok, "Unknown", HT_HST(*header_type, *header_subtype)); | ||
| const char *flags_text = tok2str(flags_text_from_bytes, "Unknown", flags); |
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.
Likewise, the Common Header should have been a structure or a series of 1-octet and 2-octet fetches, not a 64-bit fetch. Section 9.7 Ibid.
|
Please make it one clean commit and wrap the commit message at 72 columns, "as was the style at the time". |
| if (ndo->ndo_vflag > NDO_V_FLAG_FIRST_DEBUG_LEVEL) | ||
| { | ||
| ND_PRINT("GN_ADDR:%s tst:%s lat:%u lon:%u pai:%u, s:%u, h:%u; ", process_gn_addr(ndo, gn_addr), process_tst(tst), lat, lon, pai, s, h); | ||
| ND_PRINT("GN_ADDR:%s tst:%u lat:%u lon:%u pai:%u, s:%u, h:%u; ", process_gn_addr(ndo, gn_addr), tst, lat, lon, pai, s, h); |
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.
Lat, Long and S are signed, please fix. For Lat and Long it may be useful to convert the sign to N/S/E/W. For all three (and H as well) it may be useful to print using a decimal dot to make it easier to read degrees and metres per second. See arista_print_date_hms_time() for an example.
| static const struct tok common_header_next_header_values[] = { | ||
| {0, "Any"}, | ||
| {1, "BTP-A"}, | ||
| {2, "BTP-B"}, |
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.
Are these 1 and 2 the BTP_A and BTP_B below?
| {0, "Any"}, | ||
| {1, "BTP-A"}, | ||
| {2, "BTP-B"}, | ||
| {3, "IPv6"}, |
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.
Please either terminate every array of struct tok with a { 0, NULL } record or switch to struct uint_tokary and uint2tokary(), otherwise this code will crash.
| case 3: // 100 seconds | ||
| base_seconds = 100.0; | ||
| break; | ||
| default: // default to 0 second |
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 default case is dead code (LT Base is a 2-bit value). Perhaps this should have been a comment.
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.
Also the comments for the LT Base values 0, 1, 2 and 3 indicate it would make sense to use named constants.
| base_seconds = 0.0; | ||
| break; | ||
| } | ||
| return (u_int)(base_seconds * lt_multiplier); |
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.
When LT Base is 50ms, handling LT as an integer (rather than a float) discards any sub-second precision. It would be better to print LT Base and LT Multiplier separately to make it clear what is in the packet (if the product is wrong, it is desirable to know whether the base is off or the multiplier is off or both), after that it may be convenient to print LT (the product) as a decimal with two significant figures after the dot.
| u_int lt_seconds = convert_lt_to_seconds(lt_base, lt_multiplier); | ||
| if (ndo->ndo_vflag == NDO_V_FLAG_FIRST_DEBUG_LEVEL) | ||
| { | ||
| ND_PRINT("ver:%u nh:%s lt:%us rhl:%u; ", |
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 is what I meant (LT ought to be a float or a string).
| } | ||
| else if (ndo->ndo_vflag > NDO_V_FLAG_FIRST_DEBUG_LEVEL) | ||
| { | ||
| ND_PRINT("ver:%u nh:%s reserved:%u lt:[base:%u mult:%u = %us] rhl:%u; ", |
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.
And this. Also here LT base could be decoded using tok2str(). Also it may be simpler to print LT using the same format in all cases, unless there is a good reason to make the verbosity granular.
infrastation
left a comment
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.
Well, this is good progress, thank you. This code requires a bit more work before it is ready.
Previous GeoNet was outdated and didn't comply with current standards, making tcpdump wrongly dissect GeoNet packets (issue) .
This PR updates ETSI GeoNetworking protocol to version 1 (ETSI EN 302 636-4-1 V1.4.1 (2020-01)). The update includes dissectors for GeoNet Beacon messages and TopoScopeBcast-SH. Additionally, the Basic Transport Protocol (ETSI EN 302 636-5-1 V2.2.1 (2019-05)) has also been updated. It includes BTP-A and BTP-B in all its variants.