From 4f650b31f9a79d4c602889b17c3ab8c059970f11 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Sun, 9 Aug 2015 23:53:40 +0200 Subject: [PATCH] ipv6: move non-GNRC types and functions in their own modules --- Makefile.dep | 15 +- sys/Makefile | 18 +- sys/include/net/ipv6.h | 2 + sys/include/net/ipv6/ext.h | 64 ++++ sys/include/net/{ng_ipv6 => ipv6}/ext/rh.h | 20 +- sys/include/net/ipv6/hdr.h | 311 ++++++++++++++++++ sys/include/net/ng_icmpv6.h | 2 - sys/include/net/ng_icmpv6/echo.h | 6 +- sys/include/net/ng_icmpv6/error.h | 1 - sys/include/net/ng_ipv6/ext.h | 36 +- sys/include/net/ng_ipv6/hdr.h | 280 +--------------- sys/include/net/ng_ndp.h | 4 +- sys/include/net/ng_ndp/internal.h | 5 +- sys/include/net/ng_rpl/srh.h | 3 +- sys/include/net/protnum.h | 2 +- sys/net/crosslayer/ng_pktdump/ng_pktdump.c | 4 +- .../link_layer/ng_netdev_eth/ng_netdev_eth.c | 9 +- sys/net/link_layer/ng_slip/ng_slip.c | 4 +- .../{ng_ipv6 => ipv6}/ext/rh/Makefile | 2 +- .../ext/rh/ipv6_ext_rh.c} | 8 +- sys/net/network_layer/ipv6/hdr/Makefile | 3 + .../hdr/ipv6_hdr_print.c} | 13 +- .../ng_icmpv6/echo/ng_icmpv6_echo.c | 2 +- sys/net/network_layer/ng_icmpv6/ng_icmpv6.c | 9 +- .../network_layer/ng_ipv6/ext/ng_ipv6_ext.c | 20 +- .../network_layer/ng_ipv6/hdr/ng_ipv6_hdr.c | 6 +- sys/net/network_layer/ng_ipv6/ng_ipv6.c | 18 +- sys/net/network_layer/ng_ndp/ng_ndp.c | 7 +- .../ng_sixlowpan/iphc/ng_sixlowpan_iphc.c | 44 +-- .../ng_sixlowpan/ng_sixlowpan_print.c | 10 +- sys/net/transport_layer/ng_udp/ng_udp.c | 7 +- .../unittests/tests-ipv6_hdr/Makefile.include | 1 + .../unittests/tests-ipv6_hdr/tests-ipv6_hdr.c | 40 ++- 33 files changed, 527 insertions(+), 449 deletions(-) create mode 100644 sys/include/net/ipv6/ext.h rename sys/include/net/{ng_ipv6 => ipv6}/ext/rh.h (79%) create mode 100644 sys/include/net/ipv6/hdr.h rename sys/net/network_layer/{ng_ipv6 => ipv6}/ext/rh/Makefile (59%) rename sys/net/network_layer/{ng_ipv6/ext/rh/ng_ipv6_ext_rh.c => ipv6/ext/rh/ipv6_ext_rh.c} (82%) create mode 100644 sys/net/network_layer/ipv6/hdr/Makefile rename sys/net/network_layer/{ng_ipv6/hdr/ng_ipv6_hdr_print.c => ipv6/hdr/ipv6_hdr_print.c} (69%) diff --git a/Makefile.dep b/Makefile.dep index bfcadf9342..82d8e112c8 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -108,19 +108,24 @@ ifneq (,$(filter ng_icmpv6,$(USEMODULE))) endif ifneq (,$(filter ng_ipv6_hdr,$(USEMODULE))) - USEMODULE += inet_csum + USEMODULE += ipv6_hdr USEMODULE += ng_pktbuf endif -ifneq (,$(filter ng_rpl_srh,$(USEMODULE))) - USEMODULE += ng_ipv6_ext_rh +ifneq (,$(filter ipv6_hdr,$(USEMODULE))) + USEMODULE += inet_csum endif -ifneq (,$(filter ng_ipv6_ext_rh,$(USEMODULE))) - USEMODULE += ng_ipv6_ext +ifneq (,$(filter ng_rpl_srh,$(USEMODULE))) + USEMODULE += ipv6_ext_rh +endif + +ifneq (,$(filter ipv6_ext_rh,$(USEMODULE))) + USEMODULE += ipv6_ext endif ifneq (,$(filter ng_ipv6_ext,$(USEMODULE))) + USEMODULE += ipv6_ext USEMODULE += ng_ipv6 endif diff --git a/sys/Makefile b/sys/Makefile index aa4cc34e90..bcde17877f 100644 --- a/sys/Makefile +++ b/sys/Makefile @@ -16,6 +16,18 @@ endif ifneq (,$(filter oneway_malloc,$(USEMODULE))) DIRS += oneway-malloc endif +ifneq (,$(filter ipv6_addr,$(USEMODULE))) + DIRS += net/network_layer/ipv6/addr +endif +ifneq (,$(filter ipv6_ext_rh,$(USEMODULE))) + DIRS += net/network_layer/ipv6/ext/rh +endif +ifneq (,$(filter ipv6_ext,$(USEMODULE))) + DIRS += net/network_layer/ipv6/ext +endif +ifneq (,$(filter ipv6_hdr,$(USEMODULE))) + DIRS += net/network_layer/ipv6/hdr +endif ifneq (,$(filter ng_icmpv6,$(USEMODULE))) DIRS += net/network_layer/ng_icmpv6 endif @@ -25,15 +37,9 @@ endif ifneq (,$(filter ng_ipv6,$(USEMODULE))) DIRS += net/network_layer/ng_ipv6 endif -ifneq (,$(filter ipv6_addr,$(USEMODULE))) - DIRS += net/network_layer/ipv6/addr -endif ifneq (,$(filter ng_ipv6_ext,$(USEMODULE))) DIRS += net/network_layer/ng_ipv6/ext endif -ifneq (,$(filter ng_ipv6_ext_rh,$(USEMODULE))) - DIRS += net/network_layer/ng_ipv6/ext/rh -endif ifneq (,$(filter ng_ipv6_hdr,$(USEMODULE))) DIRS += net/network_layer/ng_ipv6/hdr endif diff --git a/sys/include/net/ipv6.h b/sys/include/net/ipv6.h index a8d1605176..973c82555c 100644 --- a/sys/include/net/ipv6.h +++ b/sys/include/net/ipv6.h @@ -25,6 +25,8 @@ #define IPV6_H_ #include "ipv6/addr.h" +#include "ipv6/ext.h" +#include "ipv6/hdr.h" #ifdef __cplusplus extern "C" { diff --git a/sys/include/net/ipv6/ext.h b/sys/include/net/ipv6/ext.h new file mode 100644 index 0000000000..0f4ab66dd2 --- /dev/null +++ b/sys/include/net/ipv6/ext.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2015 Martine Lenders + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup net_ipv6_ext IPv6 extension headers + * @ingroup net_ipv6 + * @brief Provides IPv6 extension header definitions and helper functions. + * @{ + * + * @file + * @brief IPv6 extension header definitions. + * + * @author Martine Lenders + */ +#ifndef IPV6_EXT_H_ +#define IPV6_EXT_H_ + +#include + +#include "net/ipv6/ext/rh.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define IPV6_EXT_LEN_UNIT (8U) /**< Unit in byte for the extension header's + * length field */ + +/** + * @brief IPv6 extension headers. + * + * @see + * RFC 2460, section 4.1 + * + */ +typedef struct __attribute__((packed)) { + uint8_t nh; /**< next header */ + uint8_t len; /**< length in 8 octets without first octet */ +} ipv6_ext_t; + +/** + * @brief Gets the next extension header in a packet. + * + * @param[in] ext The current extension header. + * + * @return The next extension header. + */ +static inline ipv6_ext_t *ipv6_ext_get_next(ipv6_ext_t *ext) +{ + return (ipv6_ext_t *)((uint8_t *)(ext) + (ext->len * IPV6_EXT_LEN_UNIT) + + IPV6_EXT_LEN_UNIT); +} + +#ifdef __cplusplus +} +#endif + +#endif /* IPV6_EXT_H_ */ +/** @} */ diff --git a/sys/include/net/ng_ipv6/ext/rh.h b/sys/include/net/ipv6/ext/rh.h similarity index 79% rename from sys/include/net/ng_ipv6/ext/rh.h rename to sys/include/net/ipv6/ext/rh.h index 420dc0a76a..a752e2134c 100644 --- a/sys/include/net/ng_ipv6/ext/rh.h +++ b/sys/include/net/ipv6/ext/rh.h @@ -7,8 +7,8 @@ */ /** - * @defgroup net_ng_ipv6_ext_rh IPv6 routing header extension - * @ingroup net_ng_ipv6_ext + * @defgroup net_ipv6_ext_rh IPv6 routing header extension + * @ingroup net_ipv6_ext * @brief Implementation of IPv6 routing header extension. * @{ * @@ -17,11 +17,13 @@ * * @author Martine Lenders */ -#ifndef NG_IPV6_EXT_RH_H_ -#define NG_IPV6_EXT_RH_H_ +#ifndef IPV6_EXT_RH_H_ +#define IPV6_EXT_RH_H_ + +#include #include "net/ipv6/addr.h" -#include "net/ng_ipv6/hdr.h" +#include "net/ipv6/hdr.h" #ifdef __cplusplus extern "C" { @@ -34,14 +36,14 @@ extern "C" { * RFC 2460, section 4.4 * * - * @extends ng_ipv6_ext_t + * @extends ipv6_ext_t */ typedef struct __attribute__((packed)) { uint8_t nh; /**< next header */ uint8_t len; /**< length in 8 octets without first octet */ uint8_t type; /**< identifier of a particular routing header type */ uint8_t seg_left; /**< number of route segments remaining */ -} ng_ipv6_ext_rh_t; +} ipv6_ext_rh_t; /** * @brief Extract next hop from the routing header of an IPv6 packet. @@ -51,11 +53,11 @@ typedef struct __attribute__((packed)) { * @return next hop on success, on success * @return NULL, if not found. */ -ipv6_addr_t *ng_ipv6_ext_rh_next_hop(ng_ipv6_hdr_t *ipv6); +ipv6_addr_t *ipv6_ext_rh_next_hop(ipv6_hdr_t *ipv6); #ifdef __cplusplus } #endif -#endif /* NG_IPV6_EXT_RH_H_ */ +#endif /* IPV6_EXT_RH_H_ */ /** @} */ diff --git a/sys/include/net/ipv6/hdr.h b/sys/include/net/ipv6/hdr.h new file mode 100644 index 0000000000..f2df288c29 --- /dev/null +++ b/sys/include/net/ipv6/hdr.h @@ -0,0 +1,311 @@ +/* + * Copyright (C) 2015 Martine Lenders + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup net_ipv6_hdr IPv6 header + * @ingroup net_ipv6 + * @brief IPv6 header types and helper functions + * @{ + * + * @file + * @brief IPv6 header type and helper function definitions + * + * @author Martine Lenders + */ +#ifndef IPV6_HDR_H_ +#define IPV6_HDR_H_ + +#include + +#include "byteorder.h" +#include "net/ipv6/addr.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Data type to represent an IPv6 packet header + * + * @details The structure of the header is as follows: + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.unparsed} + * 1 2 3 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * |Version| Traffic Class | Flow Label | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Payload Length | Next Header | Hop Limit | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | | + * + + + * | | + * + Source Address + + * | | + * + + + * | | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | | + * + + + * | | + * + Destination Address + + * | | + * + + + * | | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * + * @see + * RFC 2460, section 3 + * + */ +typedef struct __attribute__((packed)) { + /** + * @brief Version, traffic class, and flow label + * + * @details The version are the 4 most significant bits, the traffic class + * the 8 next bit, and the remainding 20 bits are the flow label (see + * above). + * + * This module provides helper functions to set, get, and check these + * fields accordingly: + * * ipv6_hdr_set_version() + * * ipv6_hdr_get_version() + * * ipv6_hdr_is() + * * ipv6_hdr_set_tc() + * * ipv6_hdr_set_tc_ecn() + * * ipv6_hdr_set_tc_dscp() + * * ipv6_hdr_get_tc() + * * ipv6_hdr_get_tc_ecn() + * * ipv6_hdr_get_tc_dscp() + * * ipv6_hdr_set_fl() + * * ipv6_hdr_get_fl() + */ + network_uint32_t v_tc_fl; + network_uint16_t len; /**< payload length of this packet. */ + uint8_t nh; /**< type of next header in this packet. */ + uint8_t hl; /**< hop limit for this packet. */ + ipv6_addr_t src; /**< source address of this packet. */ + ipv6_addr_t dst; /**< destination address of this packet. */ +} ipv6_hdr_t; + +/** + * @brief Sets the version field of @p hdr to 6 + * + * @param[out] hdr Pointer to an IPv6 header. + */ +static inline void ipv6_hdr_set_version(ipv6_hdr_t *hdr) +{ + hdr->v_tc_fl.u8[0] &= 0x0f; + hdr->v_tc_fl.u8[0] |= 0x60; +} + +/** + * @brief Gets the value of the version field of @p hdr + * + * @param[in] hdr Pointer to an IPv6 header. + * + * @return Value of the version field of @p hdr. + */ +static inline uint8_t ipv6_hdr_get_version(const ipv6_hdr_t *hdr) +{ + return ((hdr->v_tc_fl.u8[0]) >> 4); +} + +/** + * @brief Checks if the version field is set to 6 + * + * @param[in] hdr Pointer to an IPv6 header. + * + * @return true, if version field is 6 + * @return false, otherwise + */ +static inline bool ipv6_hdr_is(const ipv6_hdr_t *hdr) +{ + return (((hdr->v_tc_fl.u8[0]) & 0xf0) == 0x60); +} + +/** + * @brief Sets the traffic class field of @p hdr + * + * @param[out] hdr Pointer to an IPv6 header. + * @param[in] tc The new value for the traffic class field. + */ +static inline void ipv6_hdr_set_tc(ipv6_hdr_t *hdr, uint8_t tc) +{ + hdr->v_tc_fl.u8[0] &= 0xf0; + hdr->v_tc_fl.u8[0] |= (0x0f & (tc >> 4)); + hdr->v_tc_fl.u8[1] &= 0x0f; + hdr->v_tc_fl.u8[1] |= (0xf0 & (tc << 4)); +} + +/** + * @brief Sets the value of the Explicit Congestion Notification (ECN) part + * of the traffic class field of @p hdr + * + * @details The field is needed e.g. in context of 6LoWPAN header compression + * + * @see + * RFC 3168, section 5 + * + * + * @param[out] hdr Pointer to an IPv6 header. + * @param[in] ecn The new value for the 2-bit ECN part of the traffic class + * field. + */ +static inline void ipv6_hdr_set_tc_ecn(ipv6_hdr_t *hdr, uint8_t ecn) +{ + hdr->v_tc_fl.u8[0] &= 0xf3; + hdr->v_tc_fl.u8[0] |= (0x0c & (ecn << 2)); +} + +/** + * @brief Sets the value of the Differentiated Service Codepoint (DSCP) part + * of the traffic class field of @p hdr + * + * @details The field is needed e.g. in context of 6LoWPAN header compression + * + * @see + * RFC 2474, section 3 + * + * + * @param[out] hdr Pointer to an IPv6 header. + * @param[in] dscp The new value for the 6-bit DSCP ng_part of the traffic class + * field. + */ +static inline void ipv6_hdr_set_tc_dscp(ipv6_hdr_t *hdr, uint8_t dscp) +{ + hdr->v_tc_fl.u8[0] &= 0xfc; + hdr->v_tc_fl.u8[0] |= (0x03 & (dscp >> 4)); + hdr->v_tc_fl.u8[1] &= 0x0f; + hdr->v_tc_fl.u8[1] |= (0xf0 & (dscp << 4)); +} + +/** + * @brief Gets the value of the traffic class field of @p hdr + * + * @param[in] hdr Pointer to an IPv6 header. + * + * @return Value of the traffic class field of @p hdr. + */ +static inline uint8_t ipv6_hdr_get_tc(const ipv6_hdr_t *hdr) +{ + return ((((hdr->v_tc_fl.u8[0]) & 0x0f) << 4) | + ((hdr->v_tc_fl.u8[1] & 0xf0) >> 4)); +} + +/** + * @brief Gets the value of the Explicit Congestion Notification (ECN) part + * of the traffic class field of @p hdr + * + * @details The field is needed e.g. in context of 6LoWPAN header compression + * + * @see + * RFC 3168, section 5 + * + * + * @param[in] hdr Pointer to an IPv6 header. + * + * @return Value of the ECN part of the traffic class field of @p hdr. + */ +static inline uint8_t ipv6_hdr_get_tc_ecn(const ipv6_hdr_t *hdr) +{ + return (((hdr->v_tc_fl.u8[0]) & 0x0c) >> 2); +} + + +/** + * @brief Gets the value of the Differentiated Service Codepoint (DSCP) part + * of the traffic class field of @p hdr + * + * @details The field is needed e.g. in context of 6LoWPAN header compression + * + * @see + * RFC 2474, section 3 + * + * + * @param[in] hdr Pointer to an IPv6 header. + * + * @return Value of the DSCP part of the traffic class field of @p hdr. + */ +static inline uint8_t ipv6_hdr_get_tc_dscp(const ipv6_hdr_t *hdr) +{ + return ((((hdr->v_tc_fl.u8[0]) & 0x03) << 4) | + ((hdr->v_tc_fl.u8[1] & 0xf0) >> 4)); +} + +/** + * @brief Sets the flow label field of @p hdr + * + * @param[out] hdr Pointer to an IPv6 header. + * @param[in] fl The new value for the flow label field in host byte order. + */ +static inline void ipv6_hdr_set_fl(ipv6_hdr_t *hdr, uint32_t fl) +{ + hdr->v_tc_fl.u8[1] &= 0xf0; + hdr->v_tc_fl.u8[1] |= (0x0f & (byteorder_htonl(fl).u8[1])); + hdr->v_tc_fl.u16[1] = byteorder_htonl(fl).u16[1]; +} + +/** + * @brief Gets the value of the flow label field of @p hdr + * + * @param[in] hdr Pointer to an IPv6 header. + * + * @return Value of the flow label field of @p hdr. + */ +static inline uint32_t ipv6_hdr_get_fl(const ipv6_hdr_t *hdr) +{ + return byteorder_ntohl(hdr->v_tc_fl) & 0x000fffff; +} + +/** + * @brief Calculates the Internet Checksum for the IPv6 Pseudo Header. + * + * @see + * RFC 2460, section 8.1 + * + * + * @param[in] sum Preinialized value of the sum. + * @param[in] prot_num The @ref net_protnum you want to calculate the + * checksum for. Can not be inferred from + * ipv6_hdr_t::nh, since it can be an IPv6 exentension + * header. + * @param[in] hdr An IPv6 header to derive the Pseudo Header from. + * @param[in] len The upper-layer packet length for the pseudo header. + * Can not be inferred from ipv6_hdr_t::len, since + * there can be extension headers between the IPv6 header + * and the payload. + * + * @return The non-normalized Internet Checksum of the given IPv6 pseudo header. + */ +static inline uint16_t ipv6_hdr_inet_csum(uint16_t sum, ipv6_hdr_t *hdr, + uint8_t prot_num, uint16_t len) +{ + if ((sum + len + prot_num) > 0xffff) { + /* increment by one for overflow to keep it as 1's complement sum */ + sum++; + } + + return inet_csum(sum + len + prot_num, hdr->src.u8, + (2 * sizeof(ipv6_addr_t))); +} + +/** + * @brief Outputs an IPv6 header to stdout. + * + * @param[in] hdr An IPv6 header. + */ +void ipv6_hdr_print(ipv6_hdr_t *hdr); + +#ifdef __cplusplus +} +#endif + +#endif /* IPV6_HDR_H_ */ +/** @} */ diff --git a/sys/include/net/ng_icmpv6.h b/sys/include/net/ng_icmpv6.h index 8bb2828d59..3410c98474 100644 --- a/sys/include/net/ng_icmpv6.h +++ b/sys/include/net/ng_icmpv6.h @@ -31,8 +31,6 @@ #include "byteorder.h" #include "kernel_types.h" -#include "net/ng_ipv6/hdr.h" -#include "net/ng_nettype.h" #include "net/ng_nettype.h" #include "net/ng_pkt.h" diff --git a/sys/include/net/ng_icmpv6/echo.h b/sys/include/net/ng_icmpv6/echo.h index e7470746a3..4539ad6dba 100644 --- a/sys/include/net/ng_icmpv6/echo.h +++ b/sys/include/net/ng_icmpv6/echo.h @@ -24,8 +24,8 @@ #include "byteorder.h" #include "kernel_types.h" +#include "net/ipv6/hdr.h" #include "net/ng_icmpv6/types.h" -#include "net/ng_ipv6/hdr.h" #ifdef __cplusplus extern "C" { @@ -115,10 +115,10 @@ static inline ng_pktsnip_t *ng_icmpv6_echo_rep_build(uint16_t id, uint16_t seq, * @param[in] iface The interface the echo requuest was received on. * @param[in] ipv6_hdr The IPv6 header of the echo request. * @param[in] echo The Echo Request message. - * @param[in] len Length of the echo request message (ng_ipv6_hdr_t::len + * @param[in] len Length of the echo request message (ipv6_hdr_t::len * of @p ipv6_hdr minus length of extension headers). */ -void ng_icmpv6_echo_req_handle(kernel_pid_t iface, ng_ipv6_hdr_t *ipv6_hdr, +void ng_icmpv6_echo_req_handle(kernel_pid_t iface, ipv6_hdr_t *ipv6_hdr, ng_icmpv6_echo_t *echo, uint16_t len); #ifdef __cplusplus diff --git a/sys/include/net/ng_icmpv6/error.h b/sys/include/net/ng_icmpv6/error.h index 634ff80015..cc9015c9ce 100644 --- a/sys/include/net/ng_icmpv6/error.h +++ b/sys/include/net/ng_icmpv6/error.h @@ -27,7 +27,6 @@ #include "byteorder.h" #include "kernel_types.h" #include "net/ng_icmpv6/types.h" -#include "net/ng_ipv6/hdr.h" #ifdef __cplusplus extern "C" { diff --git a/sys/include/net/ng_ipv6/ext.h b/sys/include/net/ng_ipv6/ext.h index 7aaa747193..6361432cdc 100644 --- a/sys/include/net/ng_ipv6/ext.h +++ b/sys/include/net/ng_ipv6/ext.h @@ -25,34 +25,18 @@ #ifndef NG_IPV6_EXT_H_ #define NG_IPV6_EXT_H_ -#include #include +#include +#include -#include "byteorder.h" #include "kernel_types.h" #include "net/ng_pkt.h" - -#include "net/ng_ipv6/ext/rh.h" +#include "net/ipv6/ext.h" #ifdef __cplusplus extern "C" { #endif -#define NG_IPV6_EXT_LEN_UNIT (8U) /**< Unit in byte for the extension header's - * length field */ - -/** - * @brief IPv6 extension headers. - * - * @see - * RFC 2460, section 4.1 - * - */ -typedef struct __attribute__((packed)) { - uint8_t nh; /**< next header */ - uint8_t len; /**< length in 8 octets without first octet */ -} ng_ipv6_ext_t; - /** * @brief Demultiplex extension headers according to @p nh. * @@ -68,20 +52,6 @@ typedef struct __attribute__((packed)) { bool ng_ipv6_ext_demux(kernel_pid_t iface, ng_pktsnip_t *pkt, uint8_t nh); -/** - * @brief Gets the next extension header in a packet. - * - * @param[in] ext The current extension header. - * - * @return The next extension header. - */ -static inline ng_ipv6_ext_t *ng_ipv6_ext_get_next(ng_ipv6_ext_t *ext) -{ - return (ng_ipv6_ext_t *)((uint8_t *)(ext) + - (ext->len * NG_IPV6_EXT_LEN_UNIT) + - NG_IPV6_EXT_LEN_UNIT); -} - /** * @brief Builds an extension header for sending. * diff --git a/sys/include/net/ng_ipv6/hdr.h b/sys/include/net/ng_ipv6/hdr.h index e71f32ec47..4aa95debdb 100644 --- a/sys/include/net/ng_ipv6/hdr.h +++ b/sys/include/net/ng_ipv6/hdr.h @@ -19,285 +19,14 @@ #ifndef NG_IPV6_HDR_H_ #define NG_IPV6_HDR_H_ -#include -#include +#include -#include "byteorder.h" -#include "net/ipv6/addr.h" -#include "net/inet_csum.h" #include "net/ng_pkt.h" #ifdef __cplusplus extern "C" { #endif -/** - * @brief Data type to represent an IPv6 packet header - * - * @details The structure of the header is as follows: - * - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.unparsed} - * 1 2 3 - * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * |Version| Traffic Class | Flow Label | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Payload Length | Next Header | Hop Limit | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | | - * + + - * | | - * + Source Address + - * | | - * + + - * | | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | | - * + + - * | | - * + Destination Address + - * | | - * + + - * | | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - * - * @see - * RFC 2460, section 3 - * - */ -typedef struct __attribute__((packed)) { - /** - * @brief Version, traffic class, and flow label - * - * @details The version are the 4 most significant bits, the traffic class - * the 8 next bit, and the remainding 20 bits are the flow label (see - * above). - * - * This module provides helper functions to set, get, and check these - * fields accordingly: - * * ng_ipv6_hdr_set_version() - * * ng_ipv6_hdr_get_version() - * * ng_ipv6_hdr_is() - * * ng_ipv6_hdr_set_tc() - * * ng_ipv6_hdr_set_tc_ecn() - * * ng_ipv6_hdr_set_tc_dscp() - * * ng_ipv6_hdr_get_tc() - * * ng_ipv6_hdr_get_tc_ecn() - * * ng_ipv6_hdr_get_tc_dscp() - * * ng_ipv6_hdr_set_fl() - * * ng_ipv6_hdr_get_fl() - */ - network_uint32_t v_tc_fl; - network_uint16_t len; /**< payload length of this packet. */ - uint8_t nh; /**< type of next header in this packet. */ - uint8_t hl; /**< hop limit for this packet. */ - ipv6_addr_t src; /**< source address of this packet. */ - ipv6_addr_t dst; /**< destination address of this packet. */ -} ng_ipv6_hdr_t; - -/** - * @brief Sets the version field of @p hdr to 6 - * - * @param[out] hdr Pointer to an IPv6 header. - */ -static inline void ng_ipv6_hdr_set_version(ng_ipv6_hdr_t *hdr) -{ - hdr->v_tc_fl.u8[0] &= 0x0f; - hdr->v_tc_fl.u8[0] |= 0x60; -} - -/** - * @brief Gets the value of the version field of @p hdr - * - * @param[in] hdr Pointer to an IPv6 header. - * - * @return Value of the version field of @p hdr. - */ -static inline uint8_t ng_ipv6_hdr_get_version(const ng_ipv6_hdr_t *hdr) -{ - return ((hdr->v_tc_fl.u8[0]) >> 4); -} - -/** - * @brief Checks if the version field is set to 6 - * - * @param[in] hdr Pointer to an IPv6 header. - * - * @return true, if version field is 6 - * @return false, otherwise - */ -static inline bool ng_ipv6_hdr_is(const ng_ipv6_hdr_t *hdr) -{ - return (((hdr->v_tc_fl.u8[0]) & 0xf0) == 0x60); -} - -/** - * @brief Sets the traffic class field of @p hdr - * - * @param[out] hdr Pointer to an IPv6 header. - * @param[in] tc The new value for the traffic class field. - */ -static inline void ng_ipv6_hdr_set_tc(ng_ipv6_hdr_t *hdr, uint8_t tc) -{ - hdr->v_tc_fl.u8[0] &= 0xf0; - hdr->v_tc_fl.u8[0] |= (0x0f & (tc >> 4)); - hdr->v_tc_fl.u8[1] &= 0x0f; - hdr->v_tc_fl.u8[1] |= (0xf0 & (tc << 4)); -} - -/** - * @brief Sets the value of the Explicit Congestion Notification (ECN) part - * of the traffic class field of @p hdr - * - * @details The field is needed e.g. in context of 6LoWPAN header compression - * - * @see - * RFC 3168, section 5 - * - * - * @param[out] hdr Pointer to an IPv6 header. - * @param[in] ecn The new value for the 2-bit ECN part of the traffic class - * field. - */ -static inline void ng_ipv6_hdr_set_tc_ecn(ng_ipv6_hdr_t *hdr, uint8_t ecn) -{ - hdr->v_tc_fl.u8[0] &= 0xf3; - hdr->v_tc_fl.u8[0] |= (0x0c & (ecn << 2)); -} - -/** - * @brief Sets the value of the Differentiated Service Codepoint (DSCP) part - * of the traffic class field of @p hdr - * - * @details The field is needed e.g. in context of 6LoWPAN header compression - * - * @see - * RFC 2474, section 3 - * - * - * @param[out] hdr Pointer to an IPv6 header. - * @param[in] dscp The new value for the 6-bit DSCP ng_part of the traffic class - * field. - */ -static inline void ng_ipv6_hdr_set_tc_dscp(ng_ipv6_hdr_t *hdr, uint8_t dscp) -{ - hdr->v_tc_fl.u8[0] &= 0xfc; - hdr->v_tc_fl.u8[0] |= (0x03 & (dscp >> 4)); - hdr->v_tc_fl.u8[1] &= 0x0f; - hdr->v_tc_fl.u8[1] |= (0xf0 & (dscp << 4)); -} - -/** - * @brief Gets the value of the traffic class field of @p hdr - * - * @param[in] hdr Pointer to an IPv6 header. - * - * @return Value of the traffic class field of @p hdr. - */ -static inline uint8_t ng_ipv6_hdr_get_tc(const ng_ipv6_hdr_t *hdr) -{ - return ((((hdr->v_tc_fl.u8[0]) & 0x0f) << 4) | - ((hdr->v_tc_fl.u8[1] & 0xf0) >> 4)); -} - -/** - * @brief Gets the value of the Explicit Congestion Notification (ECN) part - * of the traffic class field of @p hdr - * - * @details The field is needed e.g. in context of 6LoWPAN header compression - * - * @see - * RFC 3168, section 5 - * - * - * @param[in] hdr Pointer to an IPv6 header. - * - * @return Value of the ECN part of the traffic class field of @p hdr. - */ -static inline uint8_t ng_ipv6_hdr_get_tc_ecn(const ng_ipv6_hdr_t *hdr) -{ - return (((hdr->v_tc_fl.u8[0]) & 0x0c) >> 2); -} - - -/** - * @brief Gets the value of the Differentiated Service Codepoint (DSCP) part - * of the traffic class field of @p hdr - * - * @details The field is needed e.g. in context of 6LoWPAN header compression - * - * @see - * RFC 2474, section 3 - * - * - * @param[in] hdr Pointer to an IPv6 header. - * - * @return Value of the DSCP part of the traffic class field of @p hdr. - */ -static inline uint8_t ng_ipv6_hdr_get_tc_dscp(const ng_ipv6_hdr_t *hdr) -{ - return ((((hdr->v_tc_fl.u8[0]) & 0x03) << 4) | - ((hdr->v_tc_fl.u8[1] & 0xf0) >> 4)); -} - -/** - * @brief Sets the flow label field of @p hdr - * - * @param[out] hdr Pointer to an IPv6 header. - * @param[in] fl The new value for the flow label field in host byte order. - */ -static inline void ng_ipv6_hdr_set_fl(ng_ipv6_hdr_t *hdr, uint32_t fl) -{ - hdr->v_tc_fl.u8[1] &= 0xf0; - hdr->v_tc_fl.u8[1] |= (0x0f & (byteorder_htonl(fl).u8[1])); - hdr->v_tc_fl.u16[1] = byteorder_htonl(fl).u16[1]; -} - -/** - * @brief Gets the value of the flow label field of @p hdr - * - * @param[in] hdr Pointer to an IPv6 header. - * - * @return Value of the flow label field of @p hdr. - */ -static inline uint32_t ng_ipv6_hdr_get_fl(const ng_ipv6_hdr_t *hdr) -{ - return byteorder_ntohl(hdr->v_tc_fl) & 0x000fffff; -} - -/** - * @brief Calculates the Internet Checksum for the IPv6 Pseudo Header. - * - * @see - * RFC 2460, section 8.1 - * - * - * @param[in] sum Preinialized value of the sum. - * @param[in] prot_num The @ref net_protnum you want to calculate the - * checksum for. Can not be inferred from - * ng_ipv6_hdr_t::nh, since it can be an IPv6 exentension - * header. - * @param[in] hdr An IPv6 header to derive the Pseudo Header from. - * @param[in] len The upper-layer packet length for the pseudo header. - * Can not be inferred from ng_ipv6_hdr_t::len, since - * there can be extension headers between the IPv6 header - * and the payload. - * - * @return The non-normalized Internet Checksum of the given IPv6 pseudo header. - */ -static inline uint16_t ng_ipv6_hdr_inet_csum(uint16_t sum, ng_ipv6_hdr_t *hdr, - uint8_t prot_num, uint16_t len) -{ - if ((sum + len + prot_num) > 0xffff) { - /* increment by one for overflow to keep it as 1's complement sum */ - sum++; - } - - return inet_csum(sum + len + prot_num, hdr->src.u8, - (2 * sizeof(ipv6_addr_t))); -} - /** * @brief Builds an IPv6 header for sending and adds it to the packet buffer. * @@ -321,13 +50,6 @@ ng_pktsnip_t *ng_ipv6_hdr_build(ng_pktsnip_t *payload, uint8_t *src, uint8_t src_len, uint8_t *dst, uint8_t dst_len); -/** - * @brief Outputs an IPv6 header to stdout. - * - * @param[in] hdr An IPv6 header. - */ -void ng_ipv6_hdr_print(ng_ipv6_hdr_t *hdr); - #ifdef __cplusplus } #endif diff --git a/sys/include/net/ng_ndp.h b/sys/include/net/ng_ndp.h index 235e0916b4..1729fd0859 100644 --- a/sys/include/net/ng_ndp.h +++ b/sys/include/net/ng_ndp.h @@ -116,7 +116,7 @@ extern "C" { * @param[in] icmpv6_size The overall size of the neighbor solicitation. */ void ng_ndp_nbr_sol_handle(kernel_pid_t iface, ng_pktsnip_t *pkt, - ng_ipv6_hdr_t *ipv6, ng_ndp_nbr_sol_t *nbr_sol, + ipv6_hdr_t *ipv6, ng_ndp_nbr_sol_t *nbr_sol, size_t icmpv6_size); /** @@ -129,7 +129,7 @@ void ng_ndp_nbr_sol_handle(kernel_pid_t iface, ng_pktsnip_t *pkt, * @param[in] icmpv6_size The overall size of the neighbor advertisement. */ void ng_ndp_nbr_adv_handle(kernel_pid_t iface, ng_pktsnip_t *pkt, - ng_ipv6_hdr_t *ipv6, ng_ndp_nbr_adv_t *nbr_adv, + ipv6_hdr_t *ipv6, ng_ndp_nbr_adv_t *nbr_adv, size_t icmpv6_size); /** diff --git a/sys/include/net/ng_ndp/internal.h b/sys/include/net/ng_ndp/internal.h index 3d9614c873..8512f145bc 100644 --- a/sys/include/net/ng_ndp/internal.h +++ b/sys/include/net/ng_ndp/internal.h @@ -23,6 +23,7 @@ #define INTERNAL_H_ #include "net/ipv6/addr.h" +#include "net/ipv6/hdr.h" #include "net/ng_ndp/types.h" #ifdef __cplusplus @@ -96,7 +97,7 @@ void ng_ndp_internal_send_nbr_adv(kernel_pid_t iface, ipv6_addr_t *tgt, * @return false, if SL2A was not valid. */ bool ng_ndp_internal_sl2a_opt_handle(kernel_pid_t iface, ng_pktsnip_t *pkt, - ng_ipv6_hdr_t *ipv6, uint8_t icmpv6_type, + ipv6_hdr_t *ipv6, uint8_t icmpv6_type, ng_ndp_opt_t *sl2a_opt); /** @@ -112,7 +113,7 @@ bool ng_ndp_internal_sl2a_opt_handle(kernel_pid_t iface, ng_pktsnip_t *pkt, * @return length of the L2 address, on success. * @return -EINVAL, if TL2A was not valid. */ -int ng_ndp_internal_tl2a_opt_handle(ng_pktsnip_t *pkt, ng_ipv6_hdr_t *ipv6, +int ng_ndp_internal_tl2a_opt_handle(ng_pktsnip_t *pkt, ipv6_hdr_t *ipv6, uint8_t icmpv6_type, ng_ndp_opt_t *tl2a_opt, uint8_t *l2addr); diff --git a/sys/include/net/ng_rpl/srh.h b/sys/include/net/ng_rpl/srh.h index b6ef632c40..6af411ffee 100644 --- a/sys/include/net/ng_rpl/srh.h +++ b/sys/include/net/ng_rpl/srh.h @@ -24,7 +24,6 @@ #define NG_RPL_SRH_H_ #include "net/ipv6/addr.h" -#include "net/ng_ipv6/ext.h" #ifdef __cplusplus extern "C" { @@ -42,7 +41,7 @@ extern "C" { * RFC 6554 * * - * @extends ng_ipv6_ext_rh_t + * @extends ipv6_ext_rh_t */ typedef struct __attribute__((packed)) { uint8_t nh; /**< next header */ diff --git a/sys/include/net/protnum.h b/sys/include/net/protnum.h index fe5793c4f7..b1d00281f6 100644 --- a/sys/include/net/protnum.h +++ b/sys/include/net/protnum.h @@ -11,7 +11,7 @@ * @ingroup net * @brief Defines for the Protocol Numbers as they are used in the * IPv4 protocol field and the IPv6 next header field - * (ng_ipv6_hdr_t::nh). + * (ipv6_hdr_t::nh). * @see * IANA, Assigned Internet Protocol Numbers * diff --git a/sys/net/crosslayer/ng_pktdump/ng_pktdump.c b/sys/net/crosslayer/ng_pktdump/ng_pktdump.c index 7a9cfbfec1..d27088e7f6 100644 --- a/sys/net/crosslayer/ng_pktdump/ng_pktdump.c +++ b/sys/net/crosslayer/ng_pktdump/ng_pktdump.c @@ -29,7 +29,7 @@ #include "net/ng_pktdump.h" #include "net/ng_netbase.h" #include "net/ipv6/addr.h" -#include "net/ng_ipv6/hdr.h" +#include "net/ipv6/hdr.h" #include "net/ng_sixlowpan.h" #include "net/ng_udp.h" #include "od.h" @@ -66,7 +66,7 @@ static void _dump_snip(ng_pktsnip_t *pkt) #ifdef MODULE_NG_IPV6 case NG_NETTYPE_IPV6: printf("NETTYPE_IPV6 (%i)\n", pkt->type); - ng_ipv6_hdr_print(pkt->data); + ipv6_hdr_print(pkt->data); break; #endif #ifdef MODULE_NG_ICMPV6 diff --git a/sys/net/link_layer/ng_netdev_eth/ng_netdev_eth.c b/sys/net/link_layer/ng_netdev_eth/ng_netdev_eth.c index 8c19de3902..4d729a394b 100644 --- a/sys/net/link_layer/ng_netdev_eth/ng_netdev_eth.c +++ b/sys/net/link_layer/ng_netdev_eth/ng_netdev_eth.c @@ -32,6 +32,7 @@ #include "net/eui64.h" #include "net/ethernet.h" #include "net/ethertype.h" +#include "net/ipv6/hdr.h" #include "net/ng_netdev.h" #include "net/ng_netif/hdr.h" #include "net/ng_pkt.h" @@ -354,8 +355,6 @@ static inline void _addr_set_broadcast(uint8_t *dst) memset(dst, 0xff, ETHERNET_ADDR_LEN); } -#define _IPV6_DST_OFFSET (36) /* sizeof(ipv6_hdr_t) - 4 */ - static inline void _addr_set_multicast(uint8_t *dst, ng_pktsnip_t *payload) { switch (payload->type) { @@ -364,9 +363,11 @@ static inline void _addr_set_multicast(uint8_t *dst, ng_pktsnip_t *payload) dst[0] = 0x33; dst[1] = 0x33; if ((payload != NULL) && (payload->data != NULL)) { - memcpy(dst + 2, ((uint8_t *)payload->data) + _IPV6_DST_OFFSET, 4); + ipv6_hdr_t *hdr = payload->data; + uint16_t *prefix = (uint16_t *)(&dst[2]); + prefix[0] = hdr->dst.u16[6]; + prefix[1] = hdr->dst.u16[7]; } - /* TODO change to proper types when ng_ipv6_hdr_t got merged */ break; #endif default: diff --git a/sys/net/link_layer/ng_slip/ng_slip.c b/sys/net/link_layer/ng_slip/ng_slip.c index 61f95ef0be..ead9715d34 100644 --- a/sys/net/link_layer/ng_slip/ng_slip.c +++ b/sys/net/link_layer/ng_slip/ng_slip.c @@ -31,7 +31,7 @@ #include "periph/uart.h" #include "ringbuffer.h" #include "thread.h" -#include "net/ng_ipv6/hdr.h" +#include "net/ipv6/hdr.h" #include "net/ng_slip.h" @@ -140,7 +140,7 @@ static void _slip_receive(ng_slip_dev_t *dev, size_t bytes) } #ifdef MODULE_NG_IPV6 - if ((pkt->size >= sizeof(ng_ipv6_hdr_t)) && ng_ipv6_hdr_is_ipv6_hdr(pkt->data)) { + if ((pkt->size >= sizeof(ipv6_hdr_t)) && ipv6_hdr_is(pkt->data)) { pkt->type = NG_NETTYPE_IPV6; } #endif diff --git a/sys/net/network_layer/ng_ipv6/ext/rh/Makefile b/sys/net/network_layer/ipv6/ext/rh/Makefile similarity index 59% rename from sys/net/network_layer/ng_ipv6/ext/rh/Makefile rename to sys/net/network_layer/ipv6/ext/rh/Makefile index b9c1d575f7..aeefa0b6a9 100644 --- a/sys/net/network_layer/ng_ipv6/ext/rh/Makefile +++ b/sys/net/network_layer/ipv6/ext/rh/Makefile @@ -1,3 +1,3 @@ -MODULE = ng_ipv6_ext_rh +MODULE = ipv6_ext_rh include $(RIOTBASE)/Makefile.base diff --git a/sys/net/network_layer/ng_ipv6/ext/rh/ng_ipv6_ext_rh.c b/sys/net/network_layer/ipv6/ext/rh/ipv6_ext_rh.c similarity index 82% rename from sys/net/network_layer/ng_ipv6/ext/rh/ng_ipv6_ext_rh.c rename to sys/net/network_layer/ipv6/ext/rh/ipv6_ext_rh.c index b2f53ed2e3..ca732e56e5 100644 --- a/sys/net/network_layer/ng_ipv6/ext/rh/ng_ipv6_ext_rh.c +++ b/sys/net/network_layer/ipv6/ext/rh/ipv6_ext_rh.c @@ -15,12 +15,12 @@ #include #include "net/protnum.h" +#include "net/ipv6/ext/rh.h" #include "net/ng_rpl/srh.h" -#include "net/ng_ipv6/ext/rh.h" -ipv6_addr_t *ng_ipv6_ext_rh_next_hop(ng_ipv6_hdr_t *ipv6) +ipv6_addr_t *ipv6_ext_rh_next_hop(ipv6_hdr_t *ipv6) { - ng_ipv6_ext_rh_t *ext = (ng_ipv6_ext_rh_t *)(ipv6 + 1); + ipv6_ext_rh_t *ext = (ipv6_ext_rh_t *)(ipv6 + 1); bool c = true; while (c) { @@ -31,7 +31,7 @@ ipv6_addr_t *ng_ipv6_ext_rh_next_hop(ng_ipv6_hdr_t *ipv6) case PROTNUM_IPV6_EXT_AH: case PROTNUM_IPV6_EXT_ESP: case PROTNUM_IPV6_EXT_MOB: - ext = (ng_ipv6_ext_rh_t *)ng_ipv6_ext_get_next((ng_ipv6_ext_t *)ext); + ext = (ipv6_ext_rh_t *)ipv6_ext_get_next((ipv6_ext_t *)ext); break; case PROTNUM_IPV6_EXT_RH: diff --git a/sys/net/network_layer/ipv6/hdr/Makefile b/sys/net/network_layer/ipv6/hdr/Makefile new file mode 100644 index 0000000000..e0c7d0bc56 --- /dev/null +++ b/sys/net/network_layer/ipv6/hdr/Makefile @@ -0,0 +1,3 @@ +MODULE = ipv6_hdr + +include $(RIOTBASE)/Makefile.base diff --git a/sys/net/network_layer/ng_ipv6/hdr/ng_ipv6_hdr_print.c b/sys/net/network_layer/ipv6/hdr/ipv6_hdr_print.c similarity index 69% rename from sys/net/network_layer/ng_ipv6/hdr/ng_ipv6_hdr_print.c rename to sys/net/network_layer/ipv6/hdr/ipv6_hdr_print.c index dbf9acaf47..48aeb09c58 100644 --- a/sys/net/network_layer/ng_ipv6/hdr/ng_ipv6_hdr_print.c +++ b/sys/net/network_layer/ipv6/hdr/ipv6_hdr_print.c @@ -15,20 +15,19 @@ #include #include -#include "net/ng_ipv6/hdr.h" +#include "net/ipv6/hdr.h" -void ng_ipv6_hdr_print(ng_ipv6_hdr_t *hdr) +void ipv6_hdr_print(ipv6_hdr_t *hdr) { char addr_str[IPV6_ADDR_MAX_STR_LEN]; - if (!ng_ipv6_hdr_is(hdr)) { - printf("illegal version field: %" PRIu8 "\n", ng_ipv6_hdr_get_version(hdr)); + if (!ipv6_hdr_is(hdr)) { + printf("illegal version field: %" PRIu8 "\n", ipv6_hdr_get_version(hdr)); } printf("traffic class: 0x%02" PRIx8 " (ECN: 0x%" PRIx8 ", DSCP: 0x%02" PRIx8 ")\n", - ng_ipv6_hdr_get_tc(hdr), ng_ipv6_hdr_get_tc_ecn(hdr), - ng_ipv6_hdr_get_tc_dscp(hdr)); - printf("flow label: 0x%05" PRIx32 "\n", ng_ipv6_hdr_get_fl(hdr)); + ipv6_hdr_get_tc(hdr), ipv6_hdr_get_tc_ecn(hdr), ipv6_hdr_get_tc_dscp(hdr)); + printf("flow label: 0x%05" PRIx32 "\n", ipv6_hdr_get_fl(hdr)); printf("length: %" PRIu16 " next header: %" PRIu8 " hop limit: %" PRIu8 "\n", byteorder_ntohs(hdr->len), hdr->nh, hdr->hl); printf("source address: %s\n", ipv6_addr_to_str(addr_str, &hdr->src, diff --git a/sys/net/network_layer/ng_icmpv6/echo/ng_icmpv6_echo.c b/sys/net/network_layer/ng_icmpv6/echo/ng_icmpv6_echo.c index 829671d877..09daa4ab18 100644 --- a/sys/net/network_layer/ng_icmpv6/echo/ng_icmpv6_echo.c +++ b/sys/net/network_layer/ng_icmpv6/echo/ng_icmpv6_echo.c @@ -60,7 +60,7 @@ ng_pktsnip_t *ng_icmpv6_echo_build(uint8_t type, uint16_t id, uint16_t seq, return pkt; } -void ng_icmpv6_echo_req_handle(kernel_pid_t iface, ng_ipv6_hdr_t *ipv6_hdr, +void ng_icmpv6_echo_req_handle(kernel_pid_t iface, ipv6_hdr_t *ipv6_hdr, ng_icmpv6_echo_t *echo, uint16_t len) { uint8_t *payload = ((uint8_t *)echo) + sizeof(ng_icmpv6_echo_t); diff --git a/sys/net/network_layer/ng_icmpv6/ng_icmpv6.c b/sys/net/network_layer/ng_icmpv6/ng_icmpv6.c index 11913f598a..3c811976da 100644 --- a/sys/net/network_layer/ng_icmpv6/ng_icmpv6.c +++ b/sys/net/network_layer/ng_icmpv6/ng_icmpv6.c @@ -21,10 +21,10 @@ #include "byteorder.h" #include "kernel_types.h" +#include "net/ipv6/hdr.h" #include "net/ng_netbase.h" -#include "net/protnum.h" -#include "net/ng_ipv6/hdr.h" #include "net/ng_ndp.h" +#include "net/protnum.h" #include "od.h" #include "utlist.h" @@ -48,8 +48,7 @@ static inline uint16_t _calc_csum(ng_pktsnip_t *hdr, } csum = inet_csum(csum, hdr->data, hdr->size); - csum = ng_ipv6_hdr_inet_csum(csum, pseudo_hdr->data, PROTNUM_ICMPV6, - len); + csum = ipv6_hdr_inet_csum(csum, pseudo_hdr->data, PROTNUM_ICMPV6, len); return ~csum; } @@ -83,7 +82,7 @@ void ng_icmpv6_demux(kernel_pid_t iface, ng_pktsnip_t *pkt) #ifdef MODULE_NG_ICMPV6_ECHO case NG_ICMPV6_ECHO_REQ: DEBUG("icmpv6: handle echo request.\n"); - ng_icmpv6_echo_req_handle(iface, (ng_ipv6_hdr_t *)ipv6->data, + ng_icmpv6_echo_req_handle(iface, (ipv6_hdr_t *)ipv6->data, (ng_icmpv6_echo_t *)hdr, icmpv6->size); break; #endif diff --git a/sys/net/network_layer/ng_ipv6/ext/ng_ipv6_ext.c b/sys/net/network_layer/ng_ipv6/ext/ng_ipv6_ext.c index d7029289dc..f88e6b1dcc 100644 --- a/sys/net/network_layer/ng_ipv6/ext/ng_ipv6_ext.c +++ b/sys/net/network_layer/ng_ipv6/ext/ng_ipv6_ext.c @@ -24,10 +24,10 @@ bool ng_ipv6_ext_demux(kernel_pid_t iface, ng_pktsnip_t *pkt, uint8_t nh) { ng_pktsnip_t *ext_snip; - ng_ipv6_ext_t *ext; + ipv6_ext_t *ext; unsigned int offset = 0; - ext = ((ng_ipv6_ext_t *)(((uint8_t *)pkt->data) + sizeof(ng_ipv6_hdr_t))); + ext = ((ipv6_ext_t *)(((uint8_t *)pkt->data) + sizeof(ipv6_hdr_t))); bool c = true; @@ -42,14 +42,14 @@ bool ng_ipv6_ext_demux(kernel_pid_t iface, ng_pktsnip_t *pkt, case PROTNUM_IPV6_EXT_MOB: /* TODO: add handling of types */ nh = ext->nh; - offset += ((ext->len * NG_IPV6_EXT_LEN_UNIT) + NG_IPV6_EXT_LEN_UNIT); - ext = ng_ipv6_ext_get_next((ng_ipv6_ext_t *)ext); + offset += ((ext->len * IPV6_EXT_LEN_UNIT) + IPV6_EXT_LEN_UNIT); + ext = ipv6_ext_get_next((ipv6_ext_t *)ext); break; default: c = false; - offset += ((ext->len * NG_IPV6_EXT_LEN_UNIT) + NG_IPV6_EXT_LEN_UNIT); - ext = ng_ipv6_ext_get_next((ng_ipv6_ext_t *)ext); + offset += ((ext->len * IPV6_EXT_LEN_UNIT) + IPV6_EXT_LEN_UNIT); + ext = ipv6_ext_get_next((ipv6_ext_t *)ext); break; } } @@ -69,9 +69,9 @@ ng_pktsnip_t *ng_ipv6_ext_build(ng_pktsnip_t *ipv6, ng_pktsnip_t *next, uint8_t nh, size_t size) { ng_pktsnip_t *prev = NULL, *snip; - ng_ipv6_ext_t *ext; + ipv6_ext_t *ext; - if (size < NG_IPV6_EXT_LEN_UNIT) { + if (size < IPV6_EXT_LEN_UNIT) { return NULL; } @@ -94,10 +94,10 @@ ng_pktsnip_t *ng_ipv6_ext_build(ng_pktsnip_t *ipv6, ng_pktsnip_t *next, ext->nh = nh; if (size & 0x7) { /* not divisible by eight */ - ext->len = (size / NG_IPV6_EXT_LEN_UNIT); + ext->len = (size / IPV6_EXT_LEN_UNIT); } else { - ext->len = (size / NG_IPV6_EXT_LEN_UNIT) - 1; + ext->len = (size / IPV6_EXT_LEN_UNIT) - 1; } if (prev != NULL) { diff --git a/sys/net/network_layer/ng_ipv6/hdr/ng_ipv6_hdr.c b/sys/net/network_layer/ng_ipv6/hdr/ng_ipv6_hdr.c index 0b4db95249..67ce077ce0 100644 --- a/sys/net/network_layer/ng_ipv6/hdr/ng_ipv6_hdr.c +++ b/sys/net/network_layer/ng_ipv6/hdr/ng_ipv6_hdr.c @@ -37,7 +37,7 @@ ng_pktsnip_t *ng_ipv6_hdr_build(ng_pktsnip_t *payload, uint8_t *dst, uint8_t dst_len) { ng_pktsnip_t *ipv6; - ng_ipv6_hdr_t *hdr; + ipv6_hdr_t *hdr; if (((src_len != 0) && (src_len != sizeof(ipv6_addr_t))) || ((dst_len != 0) && (dst_len != sizeof(ipv6_addr_t)))) { @@ -46,14 +46,14 @@ ng_pktsnip_t *ng_ipv6_hdr_build(ng_pktsnip_t *payload, return NULL; } - ipv6 = ng_pktbuf_add(payload, NULL, sizeof(ng_ipv6_hdr_t), HDR_NETTYPE); + ipv6 = ng_pktbuf_add(payload, NULL, sizeof(ipv6_hdr_t), HDR_NETTYPE); if (ipv6 == NULL) { DEBUG("ipv6_hdr: no space left in packet buffer\n"); return NULL; } - hdr = (ng_ipv6_hdr_t *)ipv6->data; + hdr = (ipv6_hdr_t *)ipv6->data; if ((src != NULL) && (src_len != 0)) { #ifdef MODULE_IPV6_ADDR diff --git a/sys/net/network_layer/ng_ipv6/ng_ipv6.c b/sys/net/network_layer/ng_ipv6/ng_ipv6.c index 825a1c1d02..a6664aecbc 100644 --- a/sys/net/network_layer/ng_ipv6/ng_ipv6.c +++ b/sys/net/network_layer/ng_ipv6/ng_ipv6.c @@ -255,7 +255,7 @@ static int _fill_ipv6_hdr(kernel_pid_t iface, ng_pktsnip_t *ipv6, ng_pktsnip_t *payload) { int res; - ng_ipv6_hdr_t *hdr = ipv6->data; + ipv6_hdr_t *hdr = ipv6->data; hdr->len = byteorder_htons(ng_pkt_len(payload)); DEBUG("ipv6: set payload length to %zu (network byteorder %04" PRIx16 ")\n", @@ -471,7 +471,7 @@ static void _send(ng_pktsnip_t *pkt, bool prep_hdr) kernel_pid_t iface = KERNEL_PID_UNDEF; ng_pktsnip_t *ipv6, *payload; ipv6_addr_t *tmp; - ng_ipv6_hdr_t *hdr; + ipv6_hdr_t *hdr; /* get IPv6 snip and (if present) generic interface header */ if (pkt->type == NG_NETTYPE_NETIF) { /* If there is already a netif header (routing protocols and @@ -574,7 +574,7 @@ static void _send(ng_pktsnip_t *pkt, bool prep_hdr) } /* functions for receiving */ -static inline bool _pkt_not_for_me(kernel_pid_t *iface, ng_ipv6_hdr_t *hdr) +static inline bool _pkt_not_for_me(kernel_pid_t *iface, ipv6_hdr_t *hdr) { if (ipv6_addr_is_loopback(&hdr->dst)) { return false; @@ -605,7 +605,7 @@ static void _receive(ng_pktsnip_t *pkt) { kernel_pid_t iface = KERNEL_PID_UNDEF; ng_pktsnip_t *ipv6, *netif; - ng_ipv6_hdr_t *hdr; + ipv6_hdr_t *hdr; assert(pkt != NULL); @@ -616,18 +616,18 @@ static void _receive(ng_pktsnip_t *pkt) } if ((pkt->next != NULL) && (pkt->next->type == NG_NETTYPE_IPV6) && - (pkt->next->size == sizeof(ng_ipv6_hdr_t))) { + (pkt->next->size == sizeof(ipv6_hdr_t))) { /* IP header was already marked. Take it. */ ipv6 = pkt->next; - if (!ng_ipv6_hdr_is(ipv6->data)) { + if (!ipv6_hdr_is(ipv6->data)) { DEBUG("ipv6: Received packet was not IPv6, dropping packet\n"); ng_pktbuf_release(pkt); return; } } else { - if (!ng_ipv6_hdr_is(pkt->data)) { + if (!ipv6_hdr_is(pkt->data)) { DEBUG("ipv6: Received packet was not IPv6, dropping packet\n"); ng_pktbuf_release(pkt); return; @@ -644,7 +644,7 @@ static void _receive(ng_pktsnip_t *pkt) pkt = ipv6; /* reset pkt from temporary variable */ - ipv6 = ng_pktbuf_mark(pkt, sizeof(ng_ipv6_hdr_t), NG_NETTYPE_IPV6); + ipv6 = ng_pktbuf_mark(pkt, sizeof(ipv6_hdr_t), NG_NETTYPE_IPV6); if (ipv6 == NULL) { DEBUG("ipv6: error marking IPv6 header, dropping packet\n"); @@ -654,7 +654,7 @@ static void _receive(ng_pktsnip_t *pkt) } /* extract header */ - hdr = (ng_ipv6_hdr_t *)ipv6->data; + hdr = (ipv6_hdr_t *)ipv6->data; DEBUG("ipv6: Received (src = %s, ", ipv6_addr_to_str(addr_str, &(hdr->src), sizeof(addr_str))); diff --git a/sys/net/network_layer/ng_ndp/ng_ndp.c b/sys/net/network_layer/ng_ndp/ng_ndp.c index 51eb066b35..895708531e 100644 --- a/sys/net/network_layer/ng_ndp/ng_ndp.c +++ b/sys/net/network_layer/ng_ndp/ng_ndp.c @@ -19,9 +19,10 @@ #include #include "byteorder.h" +#include "net/fib.h" +#include "net/ipv6/ext/rh.h" #include "net/ng_icmpv6.h" #include "net/ng_ipv6.h" -#include "net/ng_ipv6/ext/rh.h" #include "net/ng_netbase.h" #include "random.h" #include "utlist.h" @@ -44,7 +45,7 @@ static char addr_str[IPV6_ADDR_MAX_STR_LEN]; /* random helper function */ void ng_ndp_nbr_sol_handle(kernel_pid_t iface, ng_pktsnip_t *pkt, - ng_ipv6_hdr_t *ipv6, ng_ndp_nbr_sol_t *nbr_sol, + ipv6_hdr_t *ipv6, ng_ndp_nbr_sol_t *nbr_sol, size_t icmpv6_size) { uint16_t opt_offset = 0; @@ -113,7 +114,7 @@ static inline bool _pkt_has_l2addr(ng_netif_hdr_t *netif_hdr) } void ng_ndp_nbr_adv_handle(kernel_pid_t iface, ng_pktsnip_t *pkt, - ng_ipv6_hdr_t *ipv6, ng_ndp_nbr_adv_t *nbr_adv, + ipv6_hdr_t *ipv6, ng_ndp_nbr_adv_t *nbr_adv, size_t icmpv6_size) { uint16_t opt_offset = 0; diff --git a/sys/net/network_layer/ng_sixlowpan/iphc/ng_sixlowpan_iphc.c b/sys/net/network_layer/ng_sixlowpan/iphc/ng_sixlowpan_iphc.c index db6019fea1..fa109b77b5 100644 --- a/sys/net/network_layer/ng_sixlowpan/iphc/ng_sixlowpan_iphc.c +++ b/sys/net/network_layer/ng_sixlowpan/iphc/ng_sixlowpan_iphc.c @@ -16,7 +16,7 @@ #include "byteorder.h" #include "net/ieee802154.h" -#include "net/ng_ipv6/hdr.h" +#include "net/ipv6/hdr.h" #include "net/ng_netbase.h" #include "net/ng_sixlowpan/ctx.h" #include "utlist.h" @@ -92,12 +92,12 @@ static inline bool _context_overlaps_iid(ng_sixlowpan_ctx_t *ctx, bool ng_sixlowpan_iphc_decode(ng_pktsnip_t *pkt) { ng_netif_hdr_t *netif_hdr = pkt->next->data; - ng_ipv6_hdr_t *ipv6_hdr; + ipv6_hdr_t *ipv6_hdr; uint8_t *iphc_hdr = pkt->data; uint16_t payload_offset = NG_SIXLOWPAN_IPHC_HDR_LEN; ng_sixlowpan_ctx_t *ctx = NULL; ng_pktsnip_t *payload; - ng_pktsnip_t *ipv6 = ng_pktbuf_add(NULL, NULL, sizeof(ng_ipv6_hdr_t), + ng_pktsnip_t *ipv6 = ng_pktbuf_add(NULL, NULL, sizeof(ipv6_hdr_t), NG_NETTYPE_IPV6); if (ipv6 == NULL) { @@ -111,32 +111,32 @@ bool ng_sixlowpan_iphc_decode(ng_pktsnip_t *pkt) payload_offset++; } - ng_ipv6_hdr_set_version(ipv6_hdr); + ipv6_hdr_set_version(ipv6_hdr); switch (iphc_hdr[IPHC1_IDX] & NG_SIXLOWPAN_IPHC1_TF) { case IPHC_TF_ECN_DSCP_FL: - ng_ipv6_hdr_set_tc(ipv6_hdr, iphc_hdr[payload_offset++]); + ipv6_hdr_set_tc(ipv6_hdr, iphc_hdr[payload_offset++]); ipv6_hdr->v_tc_fl.u8[1] |= iphc_hdr[payload_offset++] & 0x0f; ipv6_hdr->v_tc_fl.u8[2] |= iphc_hdr[payload_offset++]; ipv6_hdr->v_tc_fl.u8[3] |= iphc_hdr[payload_offset++]; break; case IPHC_TF_ECN_FL: - ng_ipv6_hdr_set_tc_ecn(ipv6_hdr, iphc_hdr[payload_offset] >> 6); - ng_ipv6_hdr_set_tc_dscp(ipv6_hdr, 0); + ipv6_hdr_set_tc_ecn(ipv6_hdr, iphc_hdr[payload_offset] >> 6); + ipv6_hdr_set_tc_dscp(ipv6_hdr, 0); ipv6_hdr->v_tc_fl.u8[1] |= iphc_hdr[payload_offset++] & 0x0f; ipv6_hdr->v_tc_fl.u8[2] |= iphc_hdr[payload_offset++]; ipv6_hdr->v_tc_fl.u8[3] |= iphc_hdr[payload_offset++]; break; case IPHC_TF_ECN_DSCP: - ng_ipv6_hdr_set_tc(ipv6_hdr, iphc_hdr[payload_offset++]); - ng_ipv6_hdr_set_fl(ipv6_hdr, 0); + ipv6_hdr_set_tc(ipv6_hdr, iphc_hdr[payload_offset++]); + ipv6_hdr_set_fl(ipv6_hdr, 0); break; case IPHC_TF_ECN_ELIDE: - ng_ipv6_hdr_set_tc(ipv6_hdr, 0); - ng_ipv6_hdr_set_fl(ipv6_hdr, 0); + ipv6_hdr_set_tc(ipv6_hdr, 0); + ipv6_hdr_set_fl(ipv6_hdr, 0); break; } @@ -386,7 +386,7 @@ bool ng_sixlowpan_iphc_decode(ng_pktsnip_t *pkt) bool ng_sixlowpan_iphc_encode(ng_pktsnip_t *pkt) { ng_netif_hdr_t *netif_hdr = pkt->data; - ng_ipv6_hdr_t *ipv6_hdr = pkt->next->data; + ipv6_hdr_t *ipv6_hdr = pkt->next->data; uint8_t *iphc_hdr; uint16_t inline_pos = NG_SIXLOWPAN_IPHC_HDR_LEN; bool addr_comp = false; @@ -431,34 +431,34 @@ bool ng_sixlowpan_iphc_encode(ng_pktsnip_t *pkt) } /* compress flow label and traffic class */ - if (ng_ipv6_hdr_get_fl(ipv6_hdr) == 0) { - if (ng_ipv6_hdr_get_tc(ipv6_hdr) == 0) { + if (ipv6_hdr_get_fl(ipv6_hdr) == 0) { + if (ipv6_hdr_get_tc(ipv6_hdr) == 0) { /* elide both traffic class and flow label */ iphc_hdr[IPHC1_IDX] |= IPHC_TF_ECN_ELIDE; } else { /* elide flow label, traffic class (ECN + DSCP) inline (1 byte) */ iphc_hdr[IPHC1_IDX] |= IPHC_TF_ECN_DSCP; - iphc_hdr[inline_pos++] = ng_ipv6_hdr_get_tc(ipv6_hdr); + iphc_hdr[inline_pos++] = ipv6_hdr_get_tc(ipv6_hdr); } } else { - if (ng_ipv6_hdr_get_tc_dscp(ipv6_hdr) == 0) { + if (ipv6_hdr_get_tc_dscp(ipv6_hdr) == 0) { /* elide DSCP, ECN + 2-bit pad + flow label inline (3 byte) */ iphc_hdr[IPHC1_IDX] |= IPHC_TF_ECN_FL; - iphc_hdr[inline_pos++] = (uint8_t)((ng_ipv6_hdr_get_tc_ecn(ipv6_hdr) << 6) | - ((ng_ipv6_hdr_get_fl(ipv6_hdr) & 0x000f0000) >> 16)); + iphc_hdr[inline_pos++] = (uint8_t)((ipv6_hdr_get_tc_ecn(ipv6_hdr) << 6) | + ((ipv6_hdr_get_fl(ipv6_hdr) & 0x000f0000) >> 16)); } else { /* ECN + DSCP + 4-bit pad + flow label (4 bytes) */ iphc_hdr[IPHC1_IDX] |= IPHC_TF_ECN_DSCP_FL; - iphc_hdr[inline_pos++] = ng_ipv6_hdr_get_tc(ipv6_hdr); - iphc_hdr[inline_pos++] = (uint8_t)((ng_ipv6_hdr_get_fl(ipv6_hdr) & 0x000f0000) >> 16); + iphc_hdr[inline_pos++] = ipv6_hdr_get_tc(ipv6_hdr); + iphc_hdr[inline_pos++] = (uint8_t)((ipv6_hdr_get_fl(ipv6_hdr) & 0x000f0000) >> 16); } /* copy remaining byteos of flow label */ - iphc_hdr[inline_pos++] = (uint8_t)((ng_ipv6_hdr_get_fl(ipv6_hdr) & 0x0000ff00) >> 8); - iphc_hdr[inline_pos++] = (uint8_t)((ng_ipv6_hdr_get_fl(ipv6_hdr) & 0x000000ff) >> 8); + iphc_hdr[inline_pos++] = (uint8_t)((ipv6_hdr_get_fl(ipv6_hdr) & 0x0000ff00) >> 8); + iphc_hdr[inline_pos++] = (uint8_t)((ipv6_hdr_get_fl(ipv6_hdr) & 0x000000ff) >> 8); } /* compress next header */ diff --git a/sys/net/network_layer/ng_sixlowpan/ng_sixlowpan_print.c b/sys/net/network_layer/ng_sixlowpan/ng_sixlowpan_print.c index b1c28c3106..f34c7b6f28 100644 --- a/sys/net/network_layer/ng_sixlowpan/ng_sixlowpan_print.c +++ b/sys/net/network_layer/ng_sixlowpan/ng_sixlowpan_print.c @@ -16,7 +16,7 @@ #include #include "od.h" -#include "net/ng_ipv6/hdr.h" +#include "net/ipv6/hdr.h" #include "net/ng_sixlowpan.h" void ng_sixlowpan_print(uint8_t *data, size_t size) @@ -25,10 +25,10 @@ void ng_sixlowpan_print(uint8_t *data, size_t size) puts("Uncompressed IPv6 packet"); /* might just be the dispatch (or fragmented) so better check */ - if (size > sizeof(ng_ipv6_hdr_t)) { - ng_ipv6_hdr_print((ng_ipv6_hdr_t *)(data + 1)); - od_hex_dump(data + sizeof(ng_ipv6_hdr_t) + 1, - size - sizeof(ng_ipv6_hdr_t) - 1, + if (size > sizeof(ipv6_hdr_t)) { + ipv6_hdr_print((ipv6_hdr_t *)(data + 1)); + od_hex_dump(data + sizeof(ipv6_hdr_t) + 1, + size - sizeof(ipv6_hdr_t) - 1, OD_WIDTH_DEFAULT); } } diff --git a/sys/net/transport_layer/ng_udp/ng_udp.c b/sys/net/transport_layer/ng_udp/ng_udp.c index f43f68e29e..d4e384b5b8 100644 --- a/sys/net/transport_layer/ng_udp/ng_udp.c +++ b/sys/net/transport_layer/ng_udp/ng_udp.c @@ -25,13 +25,11 @@ #include "msg.h" #include "thread.h" #include "utlist.h" +#include "net/ipv6/hdr.h" #include "net/ng_udp.h" #include "net/ng_netbase.h" #include "net/inet_csum.h" -#ifdef MODULE_NG_IPV6 -#include "net/ng_ipv6/hdr.h" -#endif #define ENABLE_DEBUG (0) #include "debug.h" @@ -81,8 +79,7 @@ static uint16_t _calc_csum(ng_pktsnip_t *hdr, ng_pktsnip_t *pseudo_hdr, switch (pseudo_hdr->type) { #ifdef MODULE_NG_IPV6 case NG_NETTYPE_IPV6: - csum = ng_ipv6_hdr_inet_csum(csum, pseudo_hdr->data, - PROTNUM_UDP, len); + csum = ipv6_hdr_inet_csum(csum, pseudo_hdr->data, PROTNUM_UDP, len); break; #endif default: diff --git a/tests/unittests/tests-ipv6_hdr/Makefile.include b/tests/unittests/tests-ipv6_hdr/Makefile.include index e8dcdd2cba..db096a6bb8 100644 --- a/tests/unittests/tests-ipv6_hdr/Makefile.include +++ b/tests/unittests/tests-ipv6_hdr/Makefile.include @@ -1 +1,2 @@ +USEMODULE += ipv6_hdr USEMODULE += ng_ipv6_hdr diff --git a/tests/unittests/tests-ipv6_hdr/tests-ipv6_hdr.c b/tests/unittests/tests-ipv6_hdr/tests-ipv6_hdr.c index ba9a91be9d..ed36234c3d 100644 --- a/tests/unittests/tests-ipv6_hdr/tests-ipv6_hdr.c +++ b/tests/unittests/tests-ipv6_hdr/tests-ipv6_hdr.c @@ -17,7 +17,7 @@ #include "embUnit.h" #include "net/ipv6/addr.h" -#include "net/ng_ipv6/hdr.h" +#include "net/ipv6/hdr.h" #include "net/ng_pktbuf.h" #include "net/protnum.h" #include "net/inet_csum.h" @@ -41,7 +41,7 @@ static void test_ipv6_hdr_set_version(void) { uint8_t val[] = { TEST_UINT8 }; - ng_ipv6_hdr_set_version((ng_ipv6_hdr_t *)val); + ipv6_hdr_set_version((ipv6_hdr_t *)val); /* * Header format: @@ -65,8 +65,7 @@ static void test_ipv6_hdr_get_version(void) * | 6 | * +----+---- */ - TEST_ASSERT_EQUAL_INT(TEST_UINT8 >> 4, - ng_ipv6_hdr_get_version((ng_ipv6_hdr_t *)val)); + TEST_ASSERT_EQUAL_INT(TEST_UINT8 >> 4, ipv6_hdr_get_version((ipv6_hdr_t *)val)); } static void test_ipv6_hdr_is_ipv6_hdr__false(void) @@ -80,7 +79,7 @@ static void test_ipv6_hdr_is_ipv6_hdr__false(void) */ uint8_t val[] = { 0 }; - TEST_ASSERT(!ng_ipv6_hdr_is((ng_ipv6_hdr_t *)val)); + TEST_ASSERT(!ipv6_hdr_is((ipv6_hdr_t *)val)); } static void test_ipv6_hdr_is_ipv6_hdr__true(void) @@ -94,14 +93,14 @@ static void test_ipv6_hdr_is_ipv6_hdr__true(void) */ uint8_t val[] = { 0x60 | (TEST_UINT8 & 0x0f) }; - TEST_ASSERT(ng_ipv6_hdr_is((ng_ipv6_hdr_t *)val)); + TEST_ASSERT(ipv6_hdr_is((ipv6_hdr_t *)val)); } static void test_ipv6_hdr_set_tc(void) { uint8_t val[] = { TEST_UINT8, 0 }; - ng_ipv6_hdr_set_tc((ng_ipv6_hdr_t *)val, OTHER_BYTE); + ipv6_hdr_set_tc((ipv6_hdr_t *)val, OTHER_BYTE); /* * Header format: @@ -118,7 +117,7 @@ static void test_ipv6_hdr_set_tc_ecn(void) { uint8_t val[] = { TEST_UINT8 }; - ng_ipv6_hdr_set_tc_ecn((ng_ipv6_hdr_t *)val, OTHER_BYTE); + ipv6_hdr_set_tc_ecn((ipv6_hdr_t *)val, OTHER_BYTE); /* * Header format: @@ -139,7 +138,7 @@ static void test_ipv6_hdr_set_tc_dscp(void) { uint8_t val[] = { TEST_UINT8, 0 }; - ng_ipv6_hdr_set_tc_dscp((ng_ipv6_hdr_t *)val, OTHER_BYTE); + ipv6_hdr_set_tc_dscp((ipv6_hdr_t *)val, OTHER_BYTE); /* * Header format: @@ -169,7 +168,7 @@ static void test_ipv6_hdr_get_tc(void) * +----+--------+-- */ TEST_ASSERT_EQUAL_INT(((TEST_UINT8 << 4) & 0xf0) | (OTHER_BYTE >> 4), - ng_ipv6_hdr_get_tc((ng_ipv6_hdr_t *)val)); + ipv6_hdr_get_tc((ipv6_hdr_t *)val)); } static void test_ipv6_hdr_get_tc_ecn(void) @@ -188,8 +187,7 @@ static void test_ipv6_hdr_get_tc_ecn(void) * | ecn| dscp | * +----+------------+ */ - TEST_ASSERT_EQUAL_INT(TEST_UINT8 & 0x03, - ng_ipv6_hdr_get_tc_ecn((ng_ipv6_hdr_t *)val)); + TEST_ASSERT_EQUAL_INT(TEST_UINT8 & 0x03, ipv6_hdr_get_tc_ecn((ipv6_hdr_t *)val)); } static void test_ipv6_hdr_get_tc_dscp(void) @@ -209,14 +207,14 @@ static void test_ipv6_hdr_get_tc_dscp(void) * +----+------------+ */ TEST_ASSERT_EQUAL_INT(((TEST_UINT8 & 0x03) << 4) | ((OTHER_BYTE & 0xf0) >> 4), - ng_ipv6_hdr_get_tc_dscp((ng_ipv6_hdr_t *)val)); + ipv6_hdr_get_tc_dscp((ipv6_hdr_t *)val)); } static void test_ipv6_hdr_set_fl(void) { uint8_t val[] = { 0, TEST_UINT8, 0, 0 }; - ng_ipv6_hdr_set_fl((ng_ipv6_hdr_t *)val, TEST_UINT32); + ipv6_hdr_set_fl((ipv6_hdr_t *)val, TEST_UINT32); /* * Header format: @@ -245,7 +243,7 @@ static void test_ipv6_hdr_get_fl(void) * +----+--------+--------------------+ */ TEST_ASSERT_EQUAL_INT((uint32_t)(OTHER_BYTE & 0x0f) << 16, - ng_ipv6_hdr_get_fl((ng_ipv6_hdr_t *)val)); + ipv6_hdr_get_fl((ipv6_hdr_t *)val)); } static void test_ipv6_hdr_inet_csum__initial_sum_overflows(void) @@ -261,8 +259,8 @@ static void test_ipv6_hdr_inet_csum__initial_sum_overflows(void) }; /* calculate checksum of pseudo header */ - res = ng_ipv6_hdr_inet_csum(sum, (ng_ipv6_hdr_t *)&val, PROTNUM_ICMPV6, - payload_len); + res = ipv6_hdr_inet_csum(sum, (ipv6_hdr_t *)&val, PROTNUM_ICMPV6, + payload_len); res = ~res; /* take 1's-complement for correct checksum */ TEST_ASSERT_EQUAL_INT(0x1749, res); @@ -287,13 +285,13 @@ static void test_ipv6_hdr_inet_csum__initial_sum_0(void) 0x01, 0x01, 0x58, 0x6d, 0x8f, 0x56, 0x30, 0x09 }; - payload_len = sizeof(val) - sizeof(ng_ipv6_hdr_t); + payload_len = sizeof(val) - sizeof(ipv6_hdr_t); /* calculate checksum of pseudo header */ - res = ng_ipv6_hdr_inet_csum(0, (ng_ipv6_hdr_t *)&val, PROTNUM_ICMPV6, - payload_len); + res = ipv6_hdr_inet_csum(0, (ipv6_hdr_t *)&val, PROTNUM_ICMPV6, + payload_len); /* calculate checksum of payload */ - res = inet_csum(res, val + sizeof(ng_ipv6_hdr_t), payload_len); + res = inet_csum(res, val + sizeof(ipv6_hdr_t), payload_len); res = ~res; /* take 1's-complement for correct checksum */ TEST_ASSERT_EQUAL_INT(0xab32, res);