-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Conversation
7e4aa6e
to
9e63509
Compare
* @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, |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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…
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... |
87bb904
to
2d69105
Compare
Moved header creation to #2575 and rebased to current master. |
ng_pktsnip_t *pkt) | ||
{ | ||
switch (csum_hdr_type) { | ||
#ifdef MODULE_NG_ICMPV6 |
There was a problem hiding this comment.
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 ifdef
approach 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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@haukepetersen ping? |
2d69105
to
67e7c49
Compare
Rebased to current master |
* | ||
* @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. |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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);+/**
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.
looks good to me... |
@Lotterleben was this an ACK? |
@authmillenon Yup. But. I think it needs one more squash :) |
224b254
to
4c33b1a
Compare
Done |
👍 |
Now we only have to wait a few days, until Travis gets its thing together -.- |
🎈 go Travis! |
@@ -19,6 +19,7 @@ | |||
#include "utlist.h" | |||
#include "net/ng_netreg.h" | |||
#include "net/ng_nettype.h" | |||
#include "net/ng_ipv6.h" |
There was a problem hiding this comment.
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
please fix the issue above before merging. |
same for |
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? |
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) {
... |
You are forgetting Extension Headers once again, but with the two-header solution I might be able to live. |
@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; |
There was a problem hiding this comment.
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) :-)
There was a problem hiding this comment.
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 ;-).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
Yes, always these extension-headers :-) |
21ab32e
to
c12c49f
Compare
Moved |
c12c49f
to
4571fe2
Compare
Rebased to current master. |
@haukepetersen does the ACK uphold? |
9f184dd
to
45554bf
Compare
@haukepetersen ping? :> |
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 ;-)) |
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. :) |
ng_net: introduce checksum calculation
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. |
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.