Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ng_ipv6_ext: initial import of extension header handling (including RPL SRH) #2898

Merged
merged 3 commits into from
May 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ ifneq (,$(filter ng_ipv6_hdr,$(USEMODULE)))
USEMODULE += ng_pktbuf
endif

ifneq (,$(filter ng_rpl_srh,$(USEMODULE)))
USEMODULE += ng_ipv6_ext_rh
endif

ifneq (,$(filter ng_ipv6_ext_rh,$(USEMODULE)))
USEMODULE += ng_ipv6_ext
endif

ifneq (,$(filter ng_ipv6_ext,$(USEMODULE)))
USEMODULE += ng_ipv6
endif

ifneq (,$(filter ng_ipv6_router,$(USEMODULE)))
USEMODULE += ng_ipv6
endif
Expand Down
9 changes: 9 additions & 0 deletions sys/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ endif
ifneq (,$(filter ng_ipv6_addr,$(USEMODULE)))
DIRS += net/network_layer/ng_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
Expand Down Expand Up @@ -107,6 +113,9 @@ endif
ifneq (,$(filter ng_pktbuf,$(USEMODULE)))
DIRS += net/crosslayer/ng_pktbuf
endif
ifneq (,$(filter ng_rpl_srh,$(USEMODULE)))
DIRS += net/routing/ng_rpl/srh
endif
ifneq (,$(filter ng_sixlowpan,$(USEMODULE)))
DIRS += net/network_layer/ng_sixlowpan
endif
Expand Down
1 change: 1 addition & 0 deletions sys/include/net/ng_ipv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "thread.h"

#include "net/ng_ipv6/addr.h"
#include "net/ng_ipv6/ext.h"
#include "net/ng_ipv6/hdr.h"
#include "net/ng_ipv6/nc.h"
#include "net/ng_ipv6/netif.h"
Expand Down
107 changes: 107 additions & 0 deletions sys/include/net/ng_ipv6/ext.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* 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_ng_ipv6_ext IPv6 extension headers.
* @ingroup net_ng_ipv6
* @brief Implementation of IPv6 extension headers
* @see <a href="https://tools.ietf.org/html/rfc2460#section-4">
* RFC 2460, section 4
* </a>
* @{
*
* @file
* @brief Definititions for IPv6 extension headers
*
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
*/


#ifndef NG_IPV6_EXT_H_
#define NG_IPV6_EXT_H_

#include <inttypes.h>
#include <stdbool.h>

#include "byteorder.h"
#include "kernel_types.h"
#include "net/ng_pkt.h"

#include "net/ng_ipv6/ext/rh.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.
*
* @internal
*
* @param[in] iface The receiving interface.
* @param[in] pkt A packet.
* @param[in] nh A protocol number (see @ref net_ng_protnum).
*
* @return true, on success.
* @return false, on failure.
*/
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.
*
* @param[in] ipv6 The IPv6 header. Can be NULL.
* @param[in] next The next header. Must be a successor to @p ipv6 if it is
* not NULL.
* @param[in] nh @ref net_ng_protnum of the next header.
* @param[in] size Size of the extension header.
*
* @return The extension header on success.
* @return NULL, on error.
*/
ng_pktsnip_t *ng_ipv6_ext_build(ng_pktsnip_t *ipv6, ng_pktsnip_t *next,
uint8_t nh, size_t size);

#ifdef __cplusplus
}
#endif

#endif /* NG_IPV6_EXT_H_ */
/**
* @}
*/
61 changes: 61 additions & 0 deletions sys/include/net/ng_ipv6/ext/rh.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* 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_ng_ipv6_ext_rh IPv6 routing header extension
* @ingroup net_ng_ipv6_ext
* @brief Implementation of IPv6 routing header extension.
* @{
*
* @file
* @brief Routing extension header definitions.
*
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
*/
#ifndef NG_IPV6_EXT_RH_H_
#define NG_IPV6_EXT_RH_H_

#include "net/ng_ipv6/addr.h"
#include "net/ng_ipv6/hdr.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief IPv6 routing extension header.
*
* @see <a href="https://tools.ietf.org/html/rfc2460#section-4.4">
* RFC 2460, section 4.4
* </a>
*
* @extends ng_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;

/**
* @brief Extract next hop from the routing header of an IPv6 packet.
*
* @param[in] ipv6 An IPv6 packet.
*
* @return next hop on success, on success
* @return NULL, if not found.
*/
ng_ipv6_addr_t *ng_ipv6_ext_rh_next_hop(ng_ipv6_hdr_t *ipv6);

#ifdef __cplusplus
}
#endif

#endif /* NG_IPV6_EXT_RH_H_ */
/** @} */
6 changes: 3 additions & 3 deletions sys/include/net/ng_protnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ extern "C" {
#define NG_PROTNUM_IL (40) /**< IL Transport Protocol */
#define NG_PROTNUM_IPV6 (41) /**< IPv6 encapsulation */
#define NG_PROTNUM_SDRP (42) /**< Source Demand Routing Protocol */
#define NG_PROTNUM_IPV6_EXT_ROUTE (43) /**< Routing Header for IPv6 */
#define NG_PROTNUM_IPV6_EXT_RH (43) /**< Routing Header for IPv6 */
#define NG_PROTNUM_IPV6_EXT_FRAG (44) /**< Fragment Header for IPv6 */
#define NG_PROTNUM_IDRP (45) /**< Inter-Domain Routing Protocol */
#define NG_PROTNUM_RSVP (46) /**< Reservation Protocol */
Expand All @@ -95,7 +95,7 @@ extern "C" {
#define NG_PROTNUM_SKIP (57) /**< SKIP */
#define NG_PROTNUM_ICMPV6 (58) /**< ICMP for IPv6 */
#define NG_PROTNUM_IPV6_NONXT (59) /**< No Next Header for IPv6 */
#define NG_PROTNUM_IPV6_EXT_DEST_OPTS (60) /**< IPv6 Extension Header:
#define NG_PROTNUM_IPV6_EXT_DST (60) /**< IPv6 Extension Header:
* Destination Options */
#define NG_PROTNUM_CFTP (62) /**< CFTP */
#define NG_PROTNUM_SAT_EXPAK (64) /**< SATNET and Backroom EXPAK */
Expand Down Expand Up @@ -168,7 +168,7 @@ extern "C" {
#define NG_PROTNUM_SCTP (132) /**< Stream Control Transmission Protocol */
#define NG_PROTNUM_FC (133) /**< Fibre Channel */
#define NG_PROTNUM_RSVP_E2E_IGNORE (134) /**< RSVP-E2E-IGNORE */
#define NG_PROTNUM_IPV6_EXT_MOB_HDR (135) /**< IPv6 Mobility Extension Header */
#define NG_PROTNUM_IPV6_EXT_MOB (135) /**< IPv6 Mobility Extension Header */
#define NG_PROTNUM_UDPLITE (136) /**< UDPLite */
#define NG_PROTNUM_MPLS_IN_IP (137) /**< MPLS-in-IP */
#define NG_PROTNUM_MANET (138) /**< MANET Protocols */
Expand Down
33 changes: 33 additions & 0 deletions sys/include/net/ng_rpl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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_ng_rpl New RPL
* @ingroup net
* @{
*
* @file
* @brief TODO
*
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
*/
#ifndef NG_RPL_H_
#define NG_RPL_H_



#ifdef __cplusplus
extern "C" {
#endif

#ifdef __cplusplus
}
#endif

#endif /* NG_RPL_H_ */
/** @} */
69 changes: 69 additions & 0 deletions sys/include/net/ng_rpl/srh.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* 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_rpl_srh RPL source routing header extension
* @ingroup net_rpl
* @brief Implementation of RPL source routing extension headers
* @see <a href="https://tools.ietf.org/html/rfc6554">
* RFC 6554
* </a>
* @{
*
* @file
* @brief Definititions for RPL source routing extension headers
*
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
*/
#ifndef NG_RPL_SRH_H_
#define NG_RPL_SRH_H_

#include "net/ng_ipv6/addr.h"
#include "net/ng_ipv6/ext.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Type for source routing header.
*/
#define NG_RPL_SRH_TYPE (3U)

/**
* @brief The RPL Source routing header.
*
* @see <a href="https://tools.ietf.org/html/rfc6554">
* RFC 6554
* </a>
*
* @extends ng_ipv6_ext_rh_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_rpl_srh_t;

/**
* @brief Extract next hop from the RPL source routing header.
*
* @param[in] rh A RPL source routing header.
*
* @return next hop, on success
* @return NULL, if not found.
*/
ng_ipv6_addr_t *ng_rpl_srh_next_hop(ng_rpl_srh_t *rh);

#ifdef __cplusplus
}
#endif

#endif /* NG_RPL_SRH_H_ */
/** @} */
3 changes: 3 additions & 0 deletions sys/net/network_layer/ng_ipv6/ext/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
MODULE = ng_ipv6_ext

include $(RIOTBASE)/Makefile.base
Loading