Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions sys/include/net/ng_netreg.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,22 @@ 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 header.
*
* @param[in] hdr The header the checksum should be calculated
* for.
* @param[in] pseudo_hdr The header the pseudo header shall be generated
* from. NULL if none is needed.
*
* @return 0, on success.
* @return -EINVAL, if @p pseudo_hdr is NULL but a pseudo header was required.
* @return -ENOENT, if @ref net_netreg does not know how to calculate checksum
* for ng_pktsnip_t::type of @p hdr.
*/

int ng_netreg_calc_csum(ng_pktsnip_t *hdr, ng_pktsnip_t *pseudo_hdr);

/**
* @brief Builds a header for sending and adds it to the packet buffer.
*
Expand Down
28 changes: 28 additions & 0 deletions sys/net/crosslayer/ng_netreg/ng_netreg.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "utlist.h"
#include "net/ng_netreg.h"
#include "net/ng_nettype.h"
#include "net/ng_pkt.h"
#include "net/ng_ipv6.h"
Copy link
Copy Markdown
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


#define _INVALID_TYPE(type) (((type) < NG_NETTYPE_UNDEF) || ((type) >= NG_NETTYPE_NUMOF))
Expand Down Expand Up @@ -102,6 +103,33 @@ ng_netreg_entry_t *ng_netreg_getnext(ng_netreg_entry_t *entry)
return entry;
}

int ng_netreg_calc_csum(ng_pktsnip_t *hdr, ng_pktsnip_t *pseudo_hdr)
{
if (pseudo_hdr == NULL) {
/* XXX: Might be allowed for future checksums.
* If this is the case: move this to the branches were it
* is needed. */
return -EINVAL;
}

switch (hdr->type) {
#ifdef MODULE_NG_ICMPV6
case NG_NETTYPE_ICMPV6:
return ng_icmpv6_calc_csum(hdr, pseudo_hdr);
#endif
#ifdef MODULE_NG_TCP
case NG_NETTYPE_TCP:
return ng_tcp_calc_csum(hdr, pseudo_hdr);
#endif
#ifdef MODULE_NG_UDP
case NG_NETTYPE_UDP:
return ng_udp_calc_csum(hdr, pseudo_hdr);
#endif
default:
return -ENOENT;
}
}

ng_pktsnip_t *ng_netreg_hdr_build(ng_nettype_t type, ng_pktsnip_t *payload,
uint8_t *src, uint8_t src_len,
uint8_t *dst, uint8_t dst_len)
Expand Down