From 5ffdbc56528cc33374f9da0593e6631093967785 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Thu, 30 Apr 2015 21:16:38 +0200 Subject: [PATCH] ng_ipv6_ext: add routing header parsing --- sys/Makefile | 3 + sys/include/net/ng_ipv6/ext.h | 2 + sys/include/net/ng_ipv6/ext/rh.h | 61 +++++++++++++++++++ sys/net/network_layer/ng_ipv6/ext/rh/Makefile | 3 + .../ng_ipv6/ext/rh/ng_ipv6_ext_rh.c | 57 +++++++++++++++++ sys/net/network_layer/ng_ndp/ng_ndp.c | 9 ++- 6 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 sys/include/net/ng_ipv6/ext/rh.h create mode 100644 sys/net/network_layer/ng_ipv6/ext/rh/Makefile create mode 100644 sys/net/network_layer/ng_ipv6/ext/rh/ng_ipv6_ext_rh.c diff --git a/sys/Makefile b/sys/Makefile index d48d954c2..489cc1152 100644 --- a/sys/Makefile +++ b/sys/Makefile @@ -77,6 +77,9 @@ 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/ng_ipv6/ext.h b/sys/include/net/ng_ipv6/ext.h index f86c9f0d7..880306077 100644 --- a/sys/include/net/ng_ipv6/ext.h +++ b/sys/include/net/ng_ipv6/ext.h @@ -32,6 +32,8 @@ #include "kernel_types.h" #include "net/ng_pkt.h" +#include "net/ng_ipv6/ext/rh.h" + #ifdef __cplusplus extern "C" { #endif diff --git a/sys/include/net/ng_ipv6/ext/rh.h b/sys/include/net/ng_ipv6/ext/rh.h new file mode 100644 index 000000000..8bb781d22 --- /dev/null +++ b/sys/include/net/ng_ipv6/ext/rh.h @@ -0,0 +1,61 @@ +/* + * 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_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 + */ +#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 + * RFC 2460, section 4.4 + * + * + * @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_ */ +/** @} */ diff --git a/sys/net/network_layer/ng_ipv6/ext/rh/Makefile b/sys/net/network_layer/ng_ipv6/ext/rh/Makefile new file mode 100644 index 000000000..b9c1d575f --- /dev/null +++ b/sys/net/network_layer/ng_ipv6/ext/rh/Makefile @@ -0,0 +1,3 @@ +MODULE = ng_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/ng_ipv6/ext/rh/ng_ipv6_ext_rh.c new file mode 100644 index 000000000..ae09b16fe --- /dev/null +++ b/sys/net/network_layer/ng_ipv6/ext/rh/ng_ipv6_ext_rh.c @@ -0,0 +1,57 @@ +/* + * 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. + */ + +/** + * @{ + * + * @file + */ + +#include + +#include "net/ng_protnum.h" +#include "net/ng_rpl/srh.h" +#include "net/ng_ipv6/ext/rh.h" + +ng_ipv6_addr_t *ng_ipv6_ext_rh_next_hop(ng_ipv6_hdr_t *ipv6) +{ + ng_ipv6_ext_rh_t *ext = (ng_ipv6_ext_rh_t *)(ipv6 + 1); + bool c = true; + + while (c) { + switch (ext->type) { + case NG_PROTNUM_IPV6_EXT_HOPOPT: + case NG_PROTNUM_IPV6_EXT_DST: + case NG_PROTNUM_IPV6_EXT_FRAG: + case NG_PROTNUM_IPV6_EXT_AH: + case NG_PROTNUM_IPV6_EXT_ESP: + case NG_PROTNUM_IPV6_EXT_MOB: + ext = (ng_ipv6_ext_rh_t *)ng_ipv6_ext_get_next((ng_ipv6_ext_t *)ext); + break; + + case NG_PROTNUM_IPV6_EXT_RH: + c = false; + break; + + default: + c = false; + break; + } + } + + if (ipv6->nh == NG_PROTNUM_IPV6_EXT_RH) { + switch (ext->type) { + default: + break; + } + } + + return NULL; +} + +/** @} */ diff --git a/sys/net/network_layer/ng_ndp/ng_ndp.c b/sys/net/network_layer/ng_ndp/ng_ndp.c index 64f68a3ca..33071ba31 100644 --- a/sys/net/network_layer/ng_ndp/ng_ndp.c +++ b/sys/net/network_layer/ng_ndp/ng_ndp.c @@ -20,6 +20,7 @@ #include "byteorder.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" @@ -337,8 +338,14 @@ kernel_pid_t ng_ndp_next_hop_l2addr(uint8_t *l2addr, uint8_t *l2addr_len, ng_ipv6_addr_t *next_hop_ip = NULL, *prefix = NULL; #ifdef MODULE_FIB size_t next_hop_size; +#endif - if ((fib_get_next_hop(&iface, (uint8_t *)next_hop_ip, &next_hop_size, +#ifdef MODULE_NG_IPV6_EXT_RH + next_hop_ip = ng_ipv6_ext_rh_next_hop(hdr); +#endif +#ifdef MODULE_FIB + if ((next_hop_ip == NULL) && + (fib_get_next_hop(&iface, (uint8_t *)next_hop_ip, &next_hop_size, (uint8_t *)dst, sizeof(ng_ipv6_addr_t), 0) < 0) || (next_hop_ip != sizeof(ng_ipv6_addr_t))) { next_hop_ip = NULL;