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

ng_net: introduce checksum calculation #2553

Merged
merged 1 commit into from
Apr 10, 2015

Conversation

miri64
Copy link
Member

@miri64 miri64 commented Mar 7, 2015

The idea is that IPv6 (and later IPv4), after determining the source address, can call this new function and without actual knowledge of the calculation method for the checksum.

@miri64 miri64 added Area: network Area: Networking Type: new feature The issue requests / The PR implemements a new feature for RIOT Process: API change Integration Process: PR contains or issue proposes an API change. Should be handled with care. NSTF labels Mar 7, 2015
@miri64 miri64 added this to the Network Stack Task Force milestone Mar 7, 2015
@miri64 miri64 force-pushed the net/feat/hdr-csum branch 2 times, most recently from 7e4aa6e to 9e63509 Compare March 7, 2015 16:10
@miri64 miri64 mentioned this pull request Mar 7, 2015
* @return The generic network layer header on success.
* @return NULL on error.
*/
static inline ng_pktsnip_t *ng_netif_hdr_build(ng_pktsnip_t *payload,
Copy link
Contributor

Choose a reason for hiding this comment

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

don't like the payload parameter here -> as we can use this function then only for receiving (in the current form). I would rather allocate the interface header stand-alone and link it to the rest of the packtsnips manually...

Copy link
Member Author

Choose a reason for hiding this comment

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

Did you read the doc?

  • * @brief Builds a generic network interface header for sending and
  • * adds it to the packet buffer.

The reason why it looks like for receiving is because I had it reversed :D

Copy link
Member Author

Choose a reason for hiding this comment

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

But you are probably right, nevertheless…

@haukepetersen
Copy link
Contributor

I would vote for separating this PR in two: one for header creation and one for cksum calculation.

-> the checksum part I think looks good, with the header creation stuff I still have some problems, but I can't really say right now what it is...

@miri64 miri64 changed the title ng_net: introduce checksum calculation and header building facilities ng_net: introduce checksum calculation Mar 10, 2015
@miri64
Copy link
Member Author

miri64 commented Mar 10, 2015

Moved header creation to #2575 and rebased to current master.

ng_pktsnip_t *pkt)
{
switch (csum_hdr_type) {
#ifdef MODULE_NG_ICMPV6
Copy link
Member

Choose a reason for hiding this comment

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

A possible alternative to this ifdefapproach may be to put all csum functions (used below) in a common place with empty bodies and the __(weak)__ attribute to be able to overwrite them by their appropriate modules. This would remove the ifdef-ugliness and makes this part of code more readable. I am not sure how smart the compiler is, however, to optimize away the case statements for function calls, which have empty bodies.

Copy link
Member

Choose a reason for hiding this comment

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

I guess you cannot define empty-body functions, when these functions need to return something else then void, can you? :/ This would nullify my idea, so I think...

EDIT:
... at least in terms of optimization, not in terms of readability.

Copy link
Member Author

Choose a reason for hiding this comment

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

The bigger problem is not that the functions are not defined, but the different values for ng_nettype_t for different modules used, due to size optimization for the ng_netreg look-up table. If the UDP module does not exist at compile time, NG_NETTYPE_UDP is not defined for example.

@miri64
Copy link
Member Author

miri64 commented Mar 17, 2015

@haukepetersen ping?

@miri64
Copy link
Member Author

miri64 commented Mar 19, 2015

Rebased to current master

@miri64 miri64 assigned Lotterleben and unassigned haukepetersen Mar 23, 2015
*
* @param[in] pseudo_hdr_type The type of the pseudo header if required.
* May be NG_NETTYPE_UNDEF if no pseudo header is
* required for the checksum calculation.
Copy link
Contributor

Choose a reason for hiding this comment

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

You could be more consistent with the use of periods at the end of the comments -> I would omit them...

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.
Am 23.03.2015 15:42 schrieb "Hauke Petersen" [email protected]:

In sys/include/net/ng_netreg.h
#2553 (comment):

@@ -126,6 +126,30 @@ int ng_netreg_num(ng_nettype_t type, uint32_t demux_ctx);
*/
ng_netreg_entry_t *ng_netreg_getnext(ng_netreg_entry_t *entry);

+/**

  • * @brief Calculates the checksum for a packet of type @p checksum_hdr_type.
  • * @param[in] pseudo_hdr_type The type of the pseudo header if required.
  • * May be NG_NETTYPE_UNDEF if no pseudo header is
  • * required for the checksum calculation.

You could be more consistent with the use of periods at the end of the
comments -> I would omit them...


Reply to this email directly or view it on GitHub
https://github.com/RIOT-OS/RIOT/pull/2553/files#r26942061.

@Lotterleben
Copy link
Member

looks good to me...

@miri64
Copy link
Member Author

miri64 commented Mar 24, 2015

@Lotterleben was this an ACK?

@Lotterleben
Copy link
Member

@authmillenon Yup. But. I think it needs one more squash :)

@miri64
Copy link
Member Author

miri64 commented Mar 24, 2015

Done

@Lotterleben
Copy link
Member

👍

@miri64
Copy link
Member Author

miri64 commented Mar 24, 2015

Now we only have to wait a few days, until Travis gets its thing together -.-

@Lotterleben
Copy link
Member

🎈 go Travis!

@@ -19,6 +19,7 @@
#include "utlist.h"
#include "net/ng_netreg.h"
#include "net/ng_nettype.h"
#include "net/ng_ipv6.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

my compiler just told me that you also have to include net/ng_pkt.h

@haukepetersen
Copy link
Contributor

please fix the issue above before merging.

@haukepetersen
Copy link
Contributor

same for ng_netreg.h, so including net/ng_pkt.h in ng_netreg.h should be sufficient.

@haukepetersen
Copy link
Contributor

Sorry for bringing this up so late: I just started to implemented the checksum function for UDP, and I might just had a slightly nicer idea for the checksum calculation API:

int ng_netreg_calculate_csum(ng_pktsnip_t *hdr, ng_pktsnip_t *pseudo_hdr)
{
    switch (hdr->type) {
   [...]
#ifdef MODULE_NG_UDP

        case NG_NETTYPE_UDP:
            return ng_udp_calculate_csum(hdr, pseudo_hdr);
#endif
   [...]
}

// and 
ng_udp_calculate_csum(pktsnip_t *hdr, pktsnip_t *pseudo_hdr)
{
    switch (pseudo_hdr) {
        case NG_NETTYPE_IPV6:
// you get the idea...

Make the interface a little easier to use and nicer to look at. What do you think?

@haukepetersen
Copy link
Contributor

It's getting late, but if we have the assumption, that this function is only called when sending out data, it should even be enough to just give the pointer to network layer header (IP), as the transport header and the payload are chained after it:

int ng_netreg_calcualte_csum(ng_pktsnip_t *pseudo_hdr)
{
    switch (pseudo_hdr->next->type) {
...

@miri64
Copy link
Member Author

miri64 commented Mar 26, 2015

It's getting late, but if we have the assumption, that this function is only called when sending out data, it should even be enough to just give the pointer to network layer header (IP), as the transport header and the payload are chained after it:

You are forgetting Extension Headers once again, but with the two-header solution I might be able to live.

@miri64
Copy link
Member Author

miri64 commented Mar 26, 2015

@haukepetersen Have a look.

switch (hdr->type) {
#ifdef MODULE_NG_ICMPV6
case NG_NETTYPE_ICMPV6:
return (pseudo_hdr) ? ng_icmpv6_calc_csum(hdr, pseudo_hdr) : -EINVAL;
Copy link
Contributor

Choose a reason for hiding this comment

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

keep it simple, just do the if (pseudo_hdr == NULL) { return -EINVAL; } at the beginning of the fuction. Or compile both solutions and show that this notation acutally saves memory (which I say it does the contrary) :-)

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd rather be prepared for future protocol implementations where no pseudo header is required ;-).

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. But still, I would go with the 'standard notation' for now (as it saves memory), and switch to this notation here whenever we add a protocol that does not need a pseudo header.

Copy link
Member Author

Choose a reason for hiding this comment

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

What do you mean with "standard notation"?

if (pseudo_hdr) {
    return ng_icmpv6_calc_csum(hdr, pseudo_hdr);
}
else {
    return -EINVAL;

instead of the ternary operator?

@haukepetersen
Copy link
Contributor

Yes, always these extension-headers :-)

@miri64
Copy link
Member Author

miri64 commented Mar 28, 2015

Moved NULL pointer check for pseudo_hdr and squashed so we can get this thing merged already!

@miri64
Copy link
Member Author

miri64 commented Mar 29, 2015

Rebased to current master.

@miri64
Copy link
Member Author

miri64 commented Mar 30, 2015

@haukepetersen does the ACK uphold?

@Lotterleben
Copy link
Member

@haukepetersen ping? :>

@miri64
Copy link
Member Author

miri64 commented Apr 9, 2015

I guess since he uses it this way in #2430 he is okay with it, so I think you can make an executive decision, @Lotterleben (if not we can always change this one later ;-))

@Lotterleben
Copy link
Member

True.. I just didn't want to merge this over @haukepetersen s head, since he had the stronger opinions here. Let's give it a go. :)

Lotterleben added a commit that referenced this pull request Apr 10, 2015
ng_net: introduce checksum calculation
@Lotterleben Lotterleben merged commit e130b69 into RIOT-OS:master Apr 10, 2015
@miri64 miri64 deleted the net/feat/hdr-csum branch April 10, 2015 05:40
@haukepetersen
Copy link
Contributor

sorry for being in-responsive... I think this is fine for now, let's re-visit this maybe at some later point and see if we can optimize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: network Area: Networking Process: API change Integration Process: PR contains or issue proposes an API change. Should be handled with care. Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants