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 19, 2015
1 parent cc36dfd commit 67e7c49
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
24 changes: 24 additions & 0 deletions sys/include/net/ng_netreg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* @param[in] csum_hdr_type The type of the packet the checksum should be
* calculated for
* @param[in,out] pkt The packet the checksum should be calculated
* for.
*
* @return 0, on success.
* @return -EBADMSG, @p pkt did not contain a header of type @p pseudo_hdr_type
* (if not NG_NETTYPE_UNDEF) or @p csum_hdr_type
* @return -EFAULT, @p pkt was NULL.
* @return -EINVAL, if @p pseudo_hdr_type is NG_NETTYPE_UNDEF but a pseudo
* header was required
* @return -ENOENT, if @ref net_netreg does not know how to calculate checksum
* for @p csum_hdr_type
*/
int ng_netreg_calculate_csum(ng_nettype_t pseudo_hdr_type,
ng_nettype_t csum_hdr_type,
ng_pktsnip_t *pkt);

#ifdef __cplusplus
}
#endif
Expand Down
27 changes: 27 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_ipv6.h"

#define _INVALID_TYPE(type) (((type) <= NG_NETTYPE_UNDEF) || ((type) >= NG_NETTYPE_NUMOF))

Expand Down Expand Up @@ -101,4 +102,30 @@ ng_netreg_entry_t *ng_netreg_getnext(ng_netreg_entry_t *entry)
return entry;
}

int ng_netreg_calculate_csum(ng_nettype_t pseudo_hdr_type,
ng_nettype_t csum_hdr_type,
ng_pktsnip_t *pkt)
{
switch (csum_hdr_type) {
#ifdef MODULE_NG_ICMPV6

case NG_NETTYPE_ICMPV6:
return ng_icmpv6_calculate_csum(pseudo_hdr_type, pkt);
#endif
#ifdef MODULE_NG_TCP

case NG_NETTYPE_TCP:
return ng_tcp_calculate_csum(pseudo_hdr_type, pkt);
#endif
#ifdef MODULE_NG_UDP

case NG_NETTYPE_UDP:
return ng_udp_calculate_csum(pseudo_hdr_type, pkt);
#endif

default:
return -ENOENT;
}
}

/** @} */

0 comments on commit 67e7c49

Please sign in to comment.