mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-25 22:43:50 +01:00
Merge pull request #2553 from authmillenon/net/feat/hdr-csum
ng_net: introduce checksum calculation
This commit is contained in:
commit
e130b6929c
@ -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.
|
||||
*
|
||||
|
||||
@ -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))
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user