Skip to content

Conversation

benpicco
Copy link
Contributor

Contribution description

IPHC only allows to elide the first 64, 96 or 128 bits of an address.
If e.g. a /32 subnet like fd00::/32 is added as a compression context, the address fd00:0:c000:0:6481:20ff:fef9:b694 would match it.
But when IPHC used, there is no way to recover the missing 32 bit - the receiver would interpret the address as fd00::6481:20ff:fef9:b694 which is wrong.

To prevent this, clamp prefixes to 64 bit.

We could also get rid of the prefix length field entirely, but that's a bit more of an invasive change.

Testing procedure

Issues/PRs references

@benpicco benpicco added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels May 22, 2023
@github-actions github-actions bot added Area: network Area: Networking Area: sys Area: System labels May 22, 2023
@benpicco benpicco requested review from miri64, OlegHahm and fabian18 May 22, 2023 17:16
@@ -165,6 +165,12 @@ static inline bool gnrc_sixlowpan_ctx_update_6ctx(const ipv6_addr_t *prefix, uin
gnrc_sixlowpan_ctx_t *ctx = gnrc_sixlowpan_ctx_lookup_addr(prefix);
uint8_t cid = 0;

/* IPHC does not support prefixes shorter than 64 bit
* see https://datatracker.ietf.org/doc/html/rfc6282#page-9 */
if (prefix_len < 64) {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't that rather result in an error instead of silently changing the passed value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's only about what can be compressed. Say you have a prefix of fd00::/32. With the proposed change, we can still use the compression context if all prefix bits are zero.

Address Can be compressed
fd00::1234
fd00:0:c000::1234
fd12::1234

If we would not accept the compression context at all, addresses that could have been compressed are not.

Address Can be compressed
fd00::1234
fd00:0:c000::1234
fd12::1234

@miri64
Copy link
Member

miri64 commented May 22, 2023

IPHC only allows to elide the first 64, 96 or 128 bits of an address.

And even for the 96 bits, the prefix is a 64-bit, the remaining bits are then 0000:00ff:fe00:XXXX https://datatracker.ietf.org/doc/html/rfc6282#section-3.1.1.

But besides that point, I am not sure that clamping the prefix length is a good idea. 6Lo-ND does not put any restrictions on the prefix length and also RFC 6282 is very clear on what should happen if a prefix is shorter or longer than 64-bit:

The address is derived using context information and the 64 bits carried in-line. Bits covered by context information are always used. Any IID bits not covered by context information are taken directly from the corresponding bits carried in-line. Any remaining bits are zero.

So if the prefix is shorter, the space between the prefix and the IID is filled with 0-bits, if the prefix is longer, its bits take preference over the IID bits.

If e.g. a /32 subnet like fd00::/32 is added as a compression context, the address fd00:0:c000:0:6481:20ff:fef9:b694 would match it.

I don't see how that is a problem with regards to header compression... Maybe there is a bug in compression where it is not checked if the bits not covered by either prefix or IID are actually 0?

@riot-ci
Copy link

riot-ci commented May 22, 2023

Murdock results

✔️ PASSED

f28ed48 gnrc/sixlowpan/ctx: clamp prefix length to 64 bit

Success Failures Total Runtime
6946 0 6946 10m:39s

Artifacts

@benpicco
Copy link
Contributor Author

Maybe there is a bug in compression where it is not checked if the bits not covered by either prefix or IID are actually 0?

Looks like it. _iphc_ipv6_encode() only takes the best matching prefix from gnrc_sixlowpan_ctx_lookup_addr(), it does not check whether the remaining prefix bits zero.

See #19649 for an alternative approach (still untested)

@benpicco
Copy link
Contributor Author

superseded by #19649

@benpicco benpicco closed this May 23, 2023
@benpicco benpicco deleted the 6ctx-64 branch May 23, 2023 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: network Area: Networking Area: sys Area: System CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants