gnrc_pktbuf: add gnrc_pktbuf_reverse_snips() helper function#10226
gnrc_pktbuf: add gnrc_pktbuf_reverse_snips() helper function#10226miri64 merged 3 commits intoRIOT-OS:masterfrom
Conversation
cef9e11 to
58b8d08
Compare
sys/include/net/gnrc/pktbuf.h
Outdated
| gnrc_pktsnip_t *gnrc_pktbuf_replace_snip(gnrc_pktsnip_t *pkt, gnrc_pktsnip_t *old, gnrc_pktsnip_t *add); | ||
|
|
||
| /** | ||
| * @brief Reverses snip order of a packet securely. |
There was a problem hiding this comment.
What does securely mean here?
There was a problem hiding this comment.
Write-protected. If ptr->users > 2 it is assuered that a copy is made before
sys/net/gnrc/pktbuf/gnrc_pktbuf.c
Outdated
|
|
||
| for (gnrc_pktsnip_t *ptr = pkt; ptr != NULL; | ||
| /* progress within loop, as next pointers get switched out */) { | ||
| gnrc_pktsnip_t *next = NULL; |
There was a problem hiding this comment.
This definition could be moved to L105
There was a problem hiding this comment.
I always put definitions on top of blocks, so I don't loose track of the variables used within it, but it is true, that the = NULL assignment is unnecessary here.
sys/net/gnrc/pktbuf/gnrc_pktbuf.c
Outdated
| gnrc_pktsnip_t *reversed = NULL; | ||
|
|
||
| for (gnrc_pktsnip_t *ptr = pkt; ptr != NULL; | ||
| /* progress within loop, as next pointers get switched out */) { |
There was a problem hiding this comment.
I know... it's also weird, that there is no progress statement. Do you have a better idea?
There was a problem hiding this comment.
What do you think of this?
gnrc_pktsnip_t *ptr = pkt;
while(ptr) {There was a problem hiding this comment.
Usually I think for loops are better to read, but I agree that in this instance while() might be better :-). Will adapt.
sys/net/gnrc/pktbuf/gnrc_pktbuf.c
Outdated
| gnrc_pktsnip_t *next = NULL; | ||
|
|
||
| /* use pkt as temporary variable */ | ||
| pkt = gnrc_pktbuf_start_write(ptr); |
There was a problem hiding this comment.
Why does this happen on every iteration inside the loop?
There was a problem hiding this comment.
Because gnrc_pktbuf_start_write() only write-protects snip-wise. To keep write-protection for the whole packet we need to call it for every snip we change the next pointer for (so all of them ;-)).
|
@gebart I addressed your comments. |
|
@gebart @Lotterleben any more comments or may I squash? |
|
@miri64 No more documentation nitpicks from me :) |
|
The docs for gnrc_pktbuf_start_write could use a rephrasing. Currently it says:
That is a separate PR though. |
jnohlgard
left a comment
There was a problem hiding this comment.
Looks fine now. OK to squash
You did not give any details on how it needs rephrasing. Do you mind to open a PR how you feel the rephrasing is required? |
This allows for a) testing the packet reversal properly in unittests b) use it in other places than `gnrc_ipv6`'s receive function
7c748b4 to
d6ea335
Compare
@gebart did you intend for @Lotterleben to set the 5-documentation label? (@Lotterleben since I believe you did not review in a long time, here's the reference to what I am talking about). |
|
(squashed btw) |
|
Unittests passed on |
Opened #10261 |
Contribution description
This allows for
a) testing the packet reversal properly in unittests
b) use it in other places than
gnrc_ipv6's receive functionTesting procedure
Run the newly provided unittests:
If that succeeds, try to compile
gnrc_networking. If you really want to be thorough, set up a multihop network withgnrc_networkingand see if forwarding still works (it should, but I did not test that).Issues/PRs references