Skip to content
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

gnrc_sixlowpan_iphc.c: add nhc udp encoding and decoding #4189

Merged
merged 3 commits into from
Dec 8, 2015
Merged

gnrc_sixlowpan_iphc.c: add nhc udp encoding and decoding #4189

merged 3 commits into from
Dec 8, 2015

Conversation

jfischer-no
Copy link
Contributor

This PR adds NHC UDP decoding and encoding.

@cgundogan @authmillenon @OlegHahm ~~~I need your support to get it pretty.
For first, my mayor problem is that gnrc_pktbuf_realloc_data fails after a few calls.
What would be the alternative?~~~

References:
https://tools.ietf.org/html/rfc6282#section-4.3
https://github.com/torvalds/linux/blob/master/net/6lowpan/nhc_udp.c

@jfischer-no jfischer-no added Area: network Area: Networking State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet Discussion: RFC The issue/PR is used as a discussion starting point about the item of the issue/PR labels Oct 29, 2015
@miri64
Copy link
Member

miri64 commented Oct 29, 2015

@cgundogan @authmillenon @OlegHahm I need your support to get it pretty.
For first, my mayor problem is that gnrc_pktbuf_realloc_data fails after a few calls.
What would be the alternative?

Interesting. Have you found a way to reproduce this isolated (with the unittests e.g.) Would be gread if we could find the reason for that ;).

@miri64
Copy link
Member

miri64 commented Oct 29, 2015

alternative: (what I did for IPHC) just create a new header for UDP and replace it with the UDP NHC header, when you're done.

@@ -368,7 +369,74 @@ size_t gnrc_sixlowpan_iphc_decode(gnrc_pktsnip_t *ipv6, gnrc_pktsnip_t *pkt, siz

}

/* TODO: add next header decoding */
/* next header decoding */
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer to have this whole chunk of code in a seperate module gnrc_sixlowpan_nhc, so one can turn it of.

@jfischer-no
Copy link
Contributor Author

Interesting. Have you found a way to reproduce this isolated (with the unittests e.g.) Would be gread if we could find the reason for that ;).

Unfortunately not, if I have time I try to investigate.

alternative: (what I did for IPHC) just create a new header for UDP and replace it with the UDP NHC header, when you're done.

That was my first idea, but then I need a pointer to pointer to pkt inside gnrc_sixlowpan_iphc_decode ?


/* make place for udp length */
if(gnrc_pktbuf_realloc_data(pkt, pkt->size + 2)) {
printf("realloc failed\n");
Copy link
Member

Choose a reason for hiding this comment

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

I assume this is just for debugging purpose while implementing. But should be replaced with DEBUG and a proper cleanup pktbuf_free(pkt); return 0;

Copy link
Member

Choose a reason for hiding this comment

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

I am not so sure about pktbuf_free anymore in this context, because it is never used in the above code (@authmillenon?)

@jfischer-no
Copy link
Contributor Author

@authmillenon @cgundogan I have rebuilt it,but it still ends in a disaster after some time (after receive and send ca 42 udp packets, 16 ... 11 bytes payload):

@jfischer-no jfischer-no added the CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable label Nov 2, 2015
@jfischer-no
Copy link
Contributor Author

rebased on master, still WIP

decoding is working and can be tested from linux host with something like:

#!/bin/sh

echo "sd-inline" | nc6 -q0 -u fe80::2695:4d4f:5ea9:200a%lowpan0 -p 192 23025
sleep 0.1

echo "s-inline" | nc6 -q0 -u fe80::2695:4d4f:5ea9:200a%lowpan0 -p 23025 61441
sleep 0.1

echo "d-inline" | nc6 -q0 -u fe80::2695:4d4f:5ea9:200a%lowpan0 -p 61442 23025
sleep 0.1

echo "sd-elided" | nc6 -q0 -u fe80::2695:4d4f:5ea9:200a%lowpan0 -p 61617 61617

@jfischer-no jfischer-no changed the title gnrc_sixlowpan_iphc.c: add nhc udp decoding gnrc_sixlowpan_iphc.c: add nhc udp encoding and decoding Nov 4, 2015
@jfischer-no jfischer-no removed the State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet label Nov 4, 2015
@jfischer-no
Copy link
Contributor Author

@authmillenon ping

@miri64
Copy link
Member

miri64 commented Nov 4, 2015

Why is it a pseudo-module? The way you set it up now iphc_nhc_udp_encode() and iphc_nhc_udp_decode() can (if sufficiently prefixed with sixlowpan_iphc_nhc_...) in their own sys/net/gnrc/network_layer/sixlowpan/iphc/nhc/gnrc_sixlowpan_iphc_nhc.c. Also: don't we need the extension header part of RFC 6282 to allow for UDP header compression in case there are extension headers?

@miri64
Copy link
Member

miri64 commented Nov 4, 2015

Other then that, the code looks great.

@jfischer-no
Copy link
Contributor Author

Why is it a pseudo-module?

From the code structure, I find it more readable if it stays in gnrc_sixlowpan_iphc.c.

Also: don't we need the extension header part of RFC 6282 to allow for UDP header compression in case there are extension headers?

Yes it would be good, I have to read how I can test it.

@OlegHahm
Copy link
Member

OlegHahm commented Nov 6, 2015

My first initial test found it working. Will test at the ETSI plugtest tomorrow.

uint8_t *udp_data = udp->data;
size_t nhc_len = 0;

/* TODO: Add support for elided checksum when it is available in the linux kernel. */
Copy link
Member

Choose a reason for hiding this comment

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

We will need also something like IPsec for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

elided checksum?

Copy link
Member

Choose a reason for hiding this comment

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

Yes. RFC6282 requires authorization of an upper lay in case that e.g. tunneling or a message integrity check is in place by something like IPsec.

Copy link
Member

Choose a reason for hiding this comment

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

Authorization to be allowed eliding the checksum, right?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, exactly.

@jfischer-no
Copy link
Contributor Author

The problem is: how to implement/test it with extension header (https://tools.ietf.org/html/rfc6282#section-4.2). 🌴

@OlegHahm
Copy link
Member

OlegHahm commented Nov 7, 2015

Luckily this is out of scope for the plugtest. ;)

@OlegHahm
Copy link
Member

OlegHahm commented Nov 8, 2015

Needs #4235 and jfischer-phytec-iot/RIOT#17 to build for applications without UDP (e.g. gnrc_border_router).


/* TODO: Add support for elided checksum when it is available in the linux kernel. */

/* Compressing UDP ports, follow the same sequence as the linux kernel (nhc_udp module). */
Copy link
Member

Choose a reason for hiding this comment

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

might be nit-picking, but I would be more happy with a reference to the RFC instead of a mentioning a module from the linux kernel.

Copy link
Member

Choose a reason for hiding this comment

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

Can you "fix" this?

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 is expressed a little wrong. It means that if first 8 bits of Destination Port are 0xf0 and first 8 bits of Source Port are 0xf0 then dst will be elided. (L504).

Should I remove the comment?

Copy link
Member

Choose a reason for hiding this comment

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

If I look at the code it seems rather that if the first 12 bits of destination and source port are 0xf0b then only four bits are carried inline which is exactly what the RFC says. Or am I mistaken?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, I mean: if first 8 bits of Destination Port are 0xf0 and first 8 bits of Source Port are 0xf0 there are IMHO two capabilities (RFC leaves free to choose):

  • dst will be elided
  • src will be elided

Nothing special, the comment is just confusing.

Copy link
Member

Choose a reason for hiding this comment

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

Okay, whatever. I don't quite agree to your comment, but I agree with your code. ;-) And this is obviously more important. As for the comment: I think it's actually okay to leave as is.

@OlegHahm OlegHahm added this to the Release 2015.12 milestone Dec 7, 2015
@OlegHahm
Copy link
Member

OlegHahm commented Dec 7, 2015

Can you rebase, please?

@jfischer-no
Copy link
Contributor Author

@OlegHahm rebased on master, untested

@OlegHahm
Copy link
Member

OlegHahm commented Dec 7, 2015

Can you also squash my commits?

@jfischer-no
Copy link
Contributor Author

@OlegHahm ok?

@OlegHahm
Copy link
Member

OlegHahm commented Dec 7, 2015

If you can also replace the SQUASH ME prefix with gnrc 6lowpan iphc, I'm fine.

@OlegHahm OlegHahm added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable and removed CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable labels Dec 7, 2015
@OlegHahm
Copy link
Member

OlegHahm commented Dec 7, 2015

@jfischer-phytec-iot, please address @cgundogan's comment and squash immediately. I tested for RIOT-to-RIOT and RIOT-to-Linux with and without elided ports. Everything works. ACK!

@OlegHahm
Copy link
Member

OlegHahm commented Dec 8, 2015

Ok, please squash your commits and we're ready to go, I think.

@OlegHahm OlegHahm removed the CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable label Dec 8, 2015
@OlegHahm
Copy link
Member

OlegHahm commented Dec 8, 2015

Please apply:

diff --git a/sys/net/gnrc/network_layer/sixlowpan/iphc/gnrc_sixlowpan_iphc.c b/sys/net/gnrc/network_layer/sixlowpan/iphc/gnrc_sixlowpan_iphc.c
index 6dea595..267f0da 100644
--- a/sys/net/gnrc/network_layer/sixlowpan/iphc/gnrc_sixlowpan_iphc.c
+++ b/sys/net/gnrc/network_layer/sixlowpan/iphc/gnrc_sixlowpan_iphc.c
@@ -111,6 +111,7 @@ static inline bool _context_overlaps_iid(gnrc_sixlowpan_ctx_t *ctx,
              (iid->uint8[(ctx->prefix_len / 8) - 8] & byte_mask[ctx->prefix_len % 8])));
 }

+#ifdef MODULE_GNRC_UDP
 inline static size_t iphc_nhc_udp_decode(gnrc_pktsnip_t *pkt, gnrc_pktsnip_t *ipv6, size_t offset)
 {
     uint8_t *payload = pkt->data;
@@ -181,6 +182,7 @@ inline static size_t iphc_nhc_udp_decode(gnrc_pktsnip_t *pkt, gnrc_pktsnip_t *ip

     return offset;
 }
+#endif

 size_t gnrc_sixlowpan_iphc_decode(gnrc_pktsnip_t *ipv6, gnrc_pktsnip_t *pkt, size_t datagram_size,
                                   size_t offset)

and squash immediately.

@jfischer-no
Copy link
Contributor Author

@OlegHahm Travis is right, it needs to be fixed, are you on it or should I? #4437

@OlegHahm
Copy link
Member

OlegHahm commented Dec 8, 2015

It's probably easiest if you just do it. I'm without access to a real computer currently anyway .

On 8 December 2015 13:46:49 CET, Johann Fischer notifications@github.com wrote:

@OlegHahm Travis is right, it needs to be fixed, are you on it or
should I?


Reply to this email directly or view it on GitHub:
#4189 (comment)

Join the RIOT
http://www.riot-os.org

OlegHahm added a commit that referenced this pull request Dec 8, 2015
gnrc_sixlowpan_iphc.c: add nhc udp encoding and decoding
@OlegHahm OlegHahm merged commit 693d438 into RIOT-OS:master Dec 8, 2015
@jfischer-no jfischer-no deleted the wip@nhc-udp branch December 8, 2015 15:50
@miri64 miri64 mentioned this pull request Dec 11, 2015
ipv6_hdr->nh = PROTNUM_UDP;
ipv6_hdr->len = udp_hdr->length;

ipv6->next = udp;
Copy link
Member

Choose a reason for hiding this comment

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

This is the cause for #4397: Decoding happens on receive, this means the udp snip must come before the IPv6 snip. But since the IPv6 snip is only inserted after decoding, this is not easy to fix. Will try anyway :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: network Area: Networking CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Discussion: RFC The issue/PR is used as a discussion starting point about the item of the issue/PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants