Skip to content

Commit

Permalink
netreg: add multiplexer for checksum calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed Mar 29, 2015
1 parent fa689fe commit 4571fe2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
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"

#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

0 comments on commit 4571fe2

Please sign in to comment.