1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

ipv6: move non-GNRC types and functions in their own modules

This commit is contained in:
Martine Lenders 2015-08-09 23:53:40 +02:00
parent f65f721b6a
commit 4f650b31f9
33 changed files with 527 additions and 449 deletions

View File

@ -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

View File

@ -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

View File

@ -25,6 +25,8 @@
#define IPV6_H_
#include "ipv6/addr.h"
#include "ipv6/ext.h"
#include "ipv6/hdr.h"
#ifdef __cplusplus
extern "C" {

View File

@ -0,0 +1,64 @@
/*
* Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
*
* 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 <mlenders@inf.fu-berlin.de>
*/
#ifndef IPV6_EXT_H_
#define IPV6_EXT_H_
#include <stdint.h>
#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 <a href="https://tools.ietf.org/html/rfc2460#section-4">
* RFC 2460, section 4.1
* </a>
*/
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_ */
/** @} */

View File

@ -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 <mlenders@inf.fu-berlin.de>
*/
#ifndef NG_IPV6_EXT_RH_H_
#define NG_IPV6_EXT_RH_H_
#ifndef IPV6_EXT_RH_H_
#define IPV6_EXT_RH_H_
#include <stdint.h>
#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
* </a>
*
* @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_ */
/** @} */

311
sys/include/net/ipv6/hdr.h Normal file
View File

@ -0,0 +1,311 @@
/*
* Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
*
* 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 <mlenders@inf.fu-berlin.de>
*/
#ifndef IPV6_HDR_H_
#define IPV6_HDR_H_
#include <stdint.h>
#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 <a href="http://tools.ietf.org/html/rfc2460#section-3">
* RFC 2460, section 3
* </a>
*/
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 <a href="https://tools.ietf.org/html/rfc3168#section-5">
* RFC 3168, section 5
* </a>
*
* @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 <a href="https://tools.ietf.org/html/rfc2474#section-3">
* RFC 2474, section 3
* </a>
*
* @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 <a href="https://tools.ietf.org/html/rfc3168#section-5">
* RFC 3168, section 5
* </a>
*
* @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 <a href="https://tools.ietf.org/html/rfc2474#section-3">
* RFC 2474, section 3
* </a>
*
* @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 <a href="https://tools.ietf.org/html/rfc2460#section-8.1">
* RFC 2460, section 8.1
* </a>
*
* @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_ */
/** @} */

View File

@ -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"

View File

@ -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

View File

@ -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" {

View File

@ -25,34 +25,18 @@
#ifndef NG_IPV6_EXT_H_
#define NG_IPV6_EXT_H_
#include <inttypes.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#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 <a href="https://tools.ietf.org/html/rfc2460#section-4">
* RFC 2460, section 4.1
* </a>
*/
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.
*

View File

@ -19,285 +19,14 @@
#ifndef NG_IPV6_HDR_H_
#define NG_IPV6_HDR_H_
#include <inttypes.h>
#include <stdbool.h>
#include <stdint.h>
#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 <a href="http://tools.ietf.org/html/rfc2460#section-3">
* RFC 2460, section 3
* </a>
*/
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 <a href="https://tools.ietf.org/html/rfc3168#section-5">
* RFC 3168, section 5
* </a>
*
* @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 <a href="https://tools.ietf.org/html/rfc2474#section-3">
* RFC 2474, section 3
* </a>
*
* @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 <a href="https://tools.ietf.org/html/rfc3168#section-5">
* RFC 3168, section 5
* </a>
*
* @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 <a href="https://tools.ietf.org/html/rfc2474#section-3">
* RFC 2474, section 3
* </a>
*
* @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 <a href="https://tools.ietf.org/html/rfc2460#section-8.1">
* RFC 2460, section 8.1
* </a>
*
* @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

View File

@ -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);
/**

View File

@ -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);

View File

@ -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
* </a>
*
* @extends ng_ipv6_ext_rh_t
* @extends ipv6_ext_rh_t
*/
typedef struct __attribute__((packed)) {
uint8_t nh; /**< next header */

View File

@ -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 <a href="http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml">
* IANA, Assigned Internet Protocol Numbers
* </a>

View File

@ -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

View File

@ -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:

View File

@ -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

View File

@ -1,3 +1,3 @@
MODULE = ng_ipv6_ext_rh
MODULE = ipv6_ext_rh
include $(RIOTBASE)/Makefile.base

View File

@ -15,12 +15,12 @@
#include <stdbool.h>
#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:

View File

@ -0,0 +1,3 @@
MODULE = ipv6_hdr
include $(RIOTBASE)/Makefile.base

View File

@ -15,20 +15,19 @@
#include <stdio.h>
#include <inttypes.h>
#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,

View File

@ -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);

View File

@ -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

View File

@ -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) {

View File

@ -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

View File

@ -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)));

View File

@ -19,9 +19,10 @@
#include <string.h>
#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;

View File

@ -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 */

View File

@ -16,7 +16,7 @@
#include <inttypes.h>
#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);
}
}

View File

@ -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:

View File

@ -1 +1,2 @@
USEMODULE += ipv6_hdr
USEMODULE += ng_ipv6_hdr

View File

@ -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);