Skip to content

gnrc_pktbuf: add gnrc_pktbuf_reverse_snips() helper function#10226

Merged
miri64 merged 3 commits intoRIOT-OS:masterfrom
miri64:gnrc_pktbuf/enh/reverse-snips
Oct 25, 2018
Merged

gnrc_pktbuf: add gnrc_pktbuf_reverse_snips() helper function#10226
miri64 merged 3 commits intoRIOT-OS:masterfrom
miri64:gnrc_pktbuf/enh/reverse-snips

Conversation

@miri64
Copy link
Copy Markdown
Member

@miri64 miri64 commented Oct 23, 2018

Contribution description

This allows for

a) testing the packet reversal properly in unittests
b) use it in other places than gnrc_ipv6's receive function

Testing procedure

Run the newly provided unittests:

make -C tests/unittests tests-pktbuf test

If that succeeds, try to compile gnrc_networking. If you really want to be thorough, set up a multihop network with gnrc_networking and see if forwarding still works (it should, but I did not test that).

Issues/PRs references

PR dependencies

@miri64 miri64 requested review from bergzand and cgundogan October 23, 2018 11:23
@miri64 miri64 added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Area: network Area: Networking Process: API change Integration Process: PR contains or issue proposes an API change. Should be handled with care. CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Oct 23, 2018
@miri64 miri64 force-pushed the gnrc_pktbuf/enh/reverse-snips branch 2 times, most recently from cef9e11 to 58b8d08 Compare October 23, 2018 11:34
miri64 added a commit to miri64/RIOT that referenced this pull request Oct 23, 2018
miri64 added a commit to miri64/RIOT that referenced this pull request Oct 23, 2018
miri64 added a commit to miri64/RIOT that referenced this pull request Oct 23, 2018
Copy link
Copy Markdown
Member

@jnohlgard jnohlgard left a comment

Choose a reason for hiding this comment

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

Some comments inline

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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What does securely mean here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Write-protected. If ptr->users > 2 it is assuered that a copy is made before

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Will clarify.


for (gnrc_pktsnip_t *ptr = pkt; ptr != NULL;
/* progress within loop, as next pointers get switched out */) {
gnrc_pktsnip_t *next = NULL;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This definition could be moved to L105

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

gnrc_pktsnip_t *reversed = NULL;

for (gnrc_pktsnip_t *ptr = pkt; ptr != NULL;
/* progress within loop, as next pointers get switched out */) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a weird line wrap

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I know... it's also weird, that there is no progress statement. Do you have a better idea?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What do you think of this?

gnrc_pktsnip_t *ptr = pkt;
while(ptr) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Usually I think for loops are better to read, but I agree that in this instance while() might be better :-). Will adapt.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

gnrc_pktsnip_t *next = NULL;

/* use pkt as temporary variable */
pkt = gnrc_pktbuf_start_write(ptr);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why does this happen on every iteration inside the loop?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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 ;-)).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Will add a comment.

@miri64 miri64 removed the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Oct 24, 2018
@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Oct 24, 2018

@gebart I addressed your comments.

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Oct 25, 2018

@gebart @Lotterleben any more comments or may I squash?

@Lotterleben
Copy link
Copy Markdown
Member

@miri64 No more documentation nitpicks from me :)

@jnohlgard
Copy link
Copy Markdown
Member

The docs for gnrc_pktbuf_start_write could use a rephrasing. Currently it says:

gnrc_pktsnip_t* gnrc_pktbuf_start_write(gnrc_pktsnip_t *pkt)

Must be called once before there is a write operation in a thread.

This function duplicates a packet in the packet buffer if gnrc_pktsnip_t::users of pkt > 1.

Note
Do not call this function in a thread twice on the same packet.

That is a separate PR though.

Copy link
Copy Markdown
Member

@jnohlgard jnohlgard left a comment

Choose a reason for hiding this comment

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

Looks fine now. OK to squash

@jnohlgard jnohlgard added Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Oct 25, 2018
@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Oct 25, 2018

The docs for gnrc_pktbuf_start_write could use a rephrasing

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
@miri64 miri64 force-pushed the gnrc_pktbuf/enh/reverse-snips branch from 7c748b4 to d6ea335 Compare October 25, 2018 21:11
@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Oct 25, 2018

@miri64 No more documentation nitpicks from me :)

@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).

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Oct 25, 2018

(squashed btw)

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Oct 25, 2018

Unittests passed on native.

@miri64 miri64 added the Reviewed: 3-testing The PR was tested according to the maintainer guidelines label Oct 25, 2018
@miri64 miri64 merged commit f597c6a into RIOT-OS:master Oct 25, 2018
@miri64 miri64 deleted the gnrc_pktbuf/enh/reverse-snips branch October 25, 2018 21:51
@jnohlgard
Copy link
Copy Markdown
Member

The docs for gnrc_pktbuf_start_write could use a rephrasing

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?

Opened #10261
My main confusion is the use of the word packet to refer to a gnrc snip.

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 Process: API change Integration Process: PR contains or issue proposes an API change. Should be handled with care. Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants