diff --git a/Makefile.dep b/Makefile.dep index 9b01c11117a1443d3d76a90abc273a295deaccd4..e0f0641169df1fb615f71c7685d888472b58d72e 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -245,11 +245,11 @@ ifneq (,$(filter gnrc_icmpv6,$(USEMODULE))) endif ifneq (,$(filter gnrc_rpl_srh,$(USEMODULE))) - USEMODULE += ipv6_ext_rh + USEMODULE += gnrc_ipv6_ext_rh endif -ifneq (,$(filter ipv6_ext_rh,$(USEMODULE))) - USEMODULE += ipv6_ext +ifneq (,$(filter gnrc_ipv6_ext_rh,$(USEMODULE))) + USEMODULE += gnrc_ipv6_ext endif ifneq (,$(filter gnrc_ipv6_ext,$(USEMODULE))) diff --git a/sys/Makefile b/sys/Makefile index bab6d947837d8e43f9d67dfab3059edd5fcc882e..58631e23dada4c3ff28cbc87d00833d493b9d2d0 100644 --- a/sys/Makefile +++ b/sys/Makefile @@ -46,9 +46,6 @@ 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 diff --git a/sys/include/net/gnrc/ipv6/ext.h b/sys/include/net/gnrc/ipv6/ext.h index 84fdf17d83b93f838c49530eb38d09c9cf333924..e772e7f7eb41fa6759a2430c78aa43eb75a7827a 100644 --- a/sys/include/net/gnrc/ipv6/ext.h +++ b/sys/include/net/gnrc/ipv6/ext.h @@ -31,6 +31,10 @@ #include "net/gnrc/pkt.h" #include "net/ipv6/ext.h" +#ifdef MODULE_GNRC_IPV6_EXT_RH +#include "net/gnrc/ipv6/ext/rh.h" +#endif + #ifdef __cplusplus extern "C" { #endif diff --git a/sys/include/net/gnrc/ipv6/ext/rh.h b/sys/include/net/gnrc/ipv6/ext/rh.h new file mode 100644 index 0000000000000000000000000000000000000000..e657eb07267978460b7259d33a17170583d5d31d --- /dev/null +++ b/sys/include/net/gnrc/ipv6/ext/rh.h @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2018 Freie Universität Berlin + * + * 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_gnrc_ipv6_ext_rh Support for IPv6 routing header extension + * @ingroup net_gnrc_ipv6_ext + * @brief GNRC implementation of IPv6 routing header extension. + * @{ + * + * @file + * @brief GNRC routing extension header definitions. + * + * @author Martine Lenders <m.lenders@fu-berlin.de> + */ +#ifndef NET_GNRC_IPV6_EXT_RH_H +#define NET_GNRC_IPV6_EXT_RH_H + +#include "net/ipv6/hdr.h" + +#include "net/ipv6/ext/rh.h" + +#ifdef __cplusplus +extern "C" { +#endif + +enum { + /** + * @brief An error occurred during routing header processing + */ + GNRC_IPV6_EXT_RH_ERROR = 0, + /** + * @brief The routing header was successfully processed and this node + * is the destination (i.e. ipv6_ext_rh_t::seg_left == 0) + */ + GNRC_IPV6_EXT_RH_OK, + /** + * @brief The routing header was successfully processed and the packet + * was forwarded to another node or should be forwarded to another + * node. + * + * When @ref gnrc_ipv6_ext_rh_process() returns this value, the packet was + * already forwarded to another node. Implementations for specific routing + * header types should leave the forwarding to the calling @ref + * gnrc_ipv6_ext_rh_process() and should return @ref + * GNRC_IPV6_EXT_RH_FORWARDED if they want the packet to be forwarded. They + * should however set ipv6_hdr_t::dst accordingly. + */ + GNRC_IPV6_EXT_RH_FORWARDED, +}; + +/** + * @brief Process the routing header of an IPv6 packet. + * + * @param[in, out] ipv6 An IPv6 packet. + * @param[in] ext A routing header of @p ipv6. + * + * @return @ref GNRC_IPV6_EXT_RH_OK, on success + * @return @ref GNRC_IPV6_EXT_RH_FORWARDED, when @p pkt was forwarded + * @return @ref GNRC_IPV6_EXT_RH_ERROR, on error + */ +int gnrc_ipv6_ext_rh_process(ipv6_hdr_t *ipv6, ipv6_ext_rh_t *ext); + +#ifdef __cplusplus +} +#endif + +#endif /* NET_GNRC_IPV6_EXT_RH_H */ +/** @} */ diff --git a/sys/include/net/gnrc/rpl/srh.h b/sys/include/net/gnrc/rpl/srh.h index 5078198d4d0f9a4e4c911d847074869d3bae4ee8..e4639696c5dae0b3448bd26ff5e6cd05c8fada40 100644 --- a/sys/include/net/gnrc/rpl/srh.h +++ b/sys/include/net/gnrc/rpl/srh.h @@ -60,9 +60,9 @@ typedef struct __attribute__((packed)) { * @param[in,out] ipv6 The IPv6 header of the incoming packet. * @param[in] rh A RPL source routing header. * - * @return EXT_RH_CODE_ERROR - * @return EXT_RH_CODE_FORWARD - * @return EXT_RH_CODE_OK + * @return @ref GNRC_IPV6_EXT_RH_OK, on success + * @return @ref GNRC_IPV6_EXT_RH_FORWARDED, when @p pkt *should be* forwarded + * @return @ref GNRC_IPV6_EXT_RH_ERROR, on error */ int gnrc_rpl_srh_process(ipv6_hdr_t *ipv6, gnrc_rpl_srh_t *rh); diff --git a/sys/include/net/ipv6/ext/rh.h b/sys/include/net/ipv6/ext/rh.h index 39848d6c8c77d952e8079693e6ba2fb3d94bba86..882b57b392a12cf2fd5896e0d282a172956a63c4 100644 --- a/sys/include/net/ipv6/ext/rh.h +++ b/sys/include/net/ipv6/ext/rh.h @@ -1,5 +1,6 @@ /* - * Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de> + * Copyright (C) 2015 Cenk Gündoğan <cnkgndgn@gmail.com> + * Copyright (C) 2018 Freie Universität Berlin * * 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 @@ -9,13 +10,14 @@ /** * @defgroup net_ipv6_ext_rh IPv6 routing header extension * @ingroup net_ipv6_ext - * @brief Implementation of IPv6 routing header extension. + * @brief Definitions for IPv6 routing header extension. * @{ * * @file * @brief Routing extension header definitions. * - * @author Martine Lenders <mlenders@inf.fu-berlin.de> + * @author Cenk Gündoğan <cnkgndgn@gmail.com> + * @author Martine Lenders <m.lenders@fu-berlin.de> */ #ifndef NET_IPV6_EXT_RH_H #define NET_IPV6_EXT_RH_H @@ -30,17 +32,6 @@ extern "C" { #endif -/** - * @name Return codes for routing header processing - * @{ - */ -#define EXT_RH_CODE_ERROR (-1) -#define EXT_RH_CODE_FORWARD (0) -#define EXT_RH_CODE_OK (1) -/** - * @} - */ - /** * @brief IPv6 routing extension header. * @@ -55,18 +46,6 @@ typedef struct __attribute__((packed)) { uint8_t seg_left; /**< number of route segments remaining */ } ipv6_ext_rh_t; -/** - * @brief Process the routing header of an IPv6 packet. - * - * @param[in, out] ipv6 An IPv6 packet. - * @param[in] ext A routing header of @p ipv6. - * - * @return EXT_RH_CODE_ERROR - * @return EXT_RH_CODE_FORWARD - * @return EXT_RH_CODE_OK - */ -int ipv6_ext_rh_process(ipv6_hdr_t *ipv6, ipv6_ext_rh_t *ext); - #ifdef __cplusplus } #endif diff --git a/sys/net/gnrc/Makefile b/sys/net/gnrc/Makefile index 372b1e3b737729dfabe02585949b2d15f86ed02d..eeae57137e7641f85c9b3bf1acbd779c153ec220 100644 --- a/sys/net/gnrc/Makefile +++ b/sys/net/gnrc/Makefile @@ -13,6 +13,9 @@ endif ifneq (,$(filter gnrc_ipv6_ext,$(USEMODULE))) DIRS += network_layer/ipv6/ext endif +ifneq (,$(filter gnrc_ipv6_ext_rh,$(USEMODULE))) + DIRS += network_layer/ipv6/ext/rh +endif ifneq (,$(filter gnrc_ipv6_hdr,$(USEMODULE))) DIRS += network_layer/ipv6/hdr endif diff --git a/sys/net/gnrc/network_layer/ipv6/ext/gnrc_ipv6_ext.c b/sys/net/gnrc/network_layer/ipv6/ext/gnrc_ipv6_ext.c index 9458869bfc31cba95b5202abc1b437dad6816714..9e2a802b17d35245c725be00421e5d5e55b9c87e 100644 --- a/sys/net/gnrc/network_layer/ipv6/ext/gnrc_ipv6_ext.c +++ b/sys/net/gnrc/network_layer/ipv6/ext/gnrc_ipv6_ext.c @@ -18,14 +18,14 @@ #include "net/gnrc/netif.h" #include "net/gnrc/pktbuf.h" #include "net/gnrc/ipv6.h" +#include "net/gnrc/ipv6/ext/rh.h" #include "net/gnrc/ipv6/ext.h" #define ENABLE_DEBUG (0) #include "debug.h" -#ifdef MODULE_GNRC_RPL_SRH - +#ifdef MODULE_GNRC_IPV6_EXT_RH enum gnrc_ipv6_ext_demux_status { GNRC_IPV6_EXT_OK, GNRC_IPV6_EXT_FORWARDED, @@ -65,13 +65,13 @@ static enum gnrc_ipv6_ext_demux_status _handle_rh(gnrc_pktsnip_t *current, gnrc_ hdr = ipv6->data; } - switch (ipv6_ext_rh_process(hdr, (ipv6_ext_rh_t *)ext)) { - case EXT_RH_CODE_ERROR: + switch (gnrc_ipv6_ext_rh_process(hdr, (ipv6_ext_rh_t *)ext)) { + case GNRC_IPV6_EXT_RH_ERROR: /* TODO: send ICMPv6 error codes */ gnrc_pktbuf_release(pkt); return GNRC_IPV6_EXT_ERROR; - case EXT_RH_CODE_FORWARD: + case GNRC_IPV6_EXT_RH_FORWARDED: /* forward packet */ if (!gnrc_netapi_dispatch_receive(GNRC_NETTYPE_IPV6, GNRC_NETREG_DEMUX_CTX_ALL, pkt)) { DEBUG("ipv6: could not dispatch packet to the ipv6 thread\n"); @@ -79,7 +79,7 @@ static enum gnrc_ipv6_ext_demux_status _handle_rh(gnrc_pktsnip_t *current, gnrc_ } return GNRC_IPV6_EXT_FORWARDED; - case EXT_RH_CODE_OK: + case GNRC_IPV6_EXT_RH_OK: /* this should not happen since we checked seg_left early */ gnrc_pktbuf_release(pkt); return GNRC_IPV6_EXT_ERROR; @@ -87,8 +87,7 @@ static enum gnrc_ipv6_ext_demux_status _handle_rh(gnrc_pktsnip_t *current, gnrc_ return GNRC_IPV6_EXT_OK; } - -#endif +#endif /* MODULE_GNRC_IPV6_EXT_RH */ /** * @brief marks IPv6 extension header if needed. @@ -183,7 +182,7 @@ void gnrc_ipv6_ext_demux(gnrc_netif_t *netif, switch (nh) { case PROTNUM_IPV6_EXT_RH: -#ifdef MODULE_GNRC_RPL_SRH +#ifdef MODULE_GNRC_IPV6_EXT_RH /* if current != pkt, size is already checked */ if (current == pkt && !_has_valid_size(pkt, nh)) { DEBUG("ipv6_ext: invalid size\n"); @@ -215,7 +214,7 @@ void gnrc_ipv6_ext_demux(gnrc_netif_t *netif, } break; -#endif +#endif /* MODULE_GNRC_IPV6_EXT_RH */ case PROTNUM_IPV6_EXT_HOPOPT: case PROTNUM_IPV6_EXT_DST: diff --git a/sys/net/network_layer/ipv6/ext/rh/Makefile b/sys/net/gnrc/network_layer/ipv6/ext/rh/Makefile similarity index 57% rename from sys/net/network_layer/ipv6/ext/rh/Makefile rename to sys/net/gnrc/network_layer/ipv6/ext/rh/Makefile index aeefa0b6a9278836ced4411f513a81eaf78bd0a2..66206685832dc108cc75f95f678ad7d9a245cc18 100644 --- a/sys/net/network_layer/ipv6/ext/rh/Makefile +++ b/sys/net/gnrc/network_layer/ipv6/ext/rh/Makefile @@ -1,3 +1,3 @@ -MODULE = ipv6_ext_rh +MODULE = gnrc_ipv6_ext_rh include $(RIOTBASE)/Makefile.base diff --git a/sys/net/network_layer/ipv6/ext/rh/ipv6_ext_rh.c b/sys/net/gnrc/network_layer/ipv6/ext/rh/gnrc_ipv6_ext_rh.c similarity index 81% rename from sys/net/network_layer/ipv6/ext/rh/ipv6_ext_rh.c rename to sys/net/gnrc/network_layer/ipv6/ext/rh/gnrc_ipv6_ext_rh.c index 187a5c8056f4d2f044d4802cb6ab0c57994cfd6e..e00cf2d03fdf8b104b97b1d3fb6a0d2153f30d67 100644 --- a/sys/net/network_layer/ipv6/ext/rh/ipv6_ext_rh.c +++ b/sys/net/gnrc/network_layer/ipv6/ext/rh/gnrc_ipv6_ext_rh.c @@ -16,10 +16,10 @@ #include "net/protnum.h" #include "net/ipv6/ext.h" -#include "net/ipv6/ext/rh.h" +#include "net/gnrc/ipv6/ext/rh.h" #include "net/gnrc/rpl/srh.h" -int ipv6_ext_rh_process(ipv6_hdr_t *hdr, ipv6_ext_rh_t *ext) +int gnrc_ipv6_ext_rh_process(ipv6_hdr_t *hdr, ipv6_ext_rh_t *ext) { (void) hdr; @@ -32,7 +32,7 @@ int ipv6_ext_rh_process(ipv6_hdr_t *hdr, ipv6_ext_rh_t *ext) default: break; } - return EXT_RH_CODE_ERROR; + return GNRC_IPV6_EXT_RH_ERROR; } /** @} */ diff --git a/sys/net/gnrc/routing/rpl/srh/gnrc_rpl_srh.c b/sys/net/gnrc/routing/rpl/srh/gnrc_rpl_srh.c index c1e5deaa2607c7aa1b99fe6f17403f669a215f3c..11ece166554bb6212054e4781fede9ccfd097914 100644 --- a/sys/net/gnrc/routing/rpl/srh/gnrc_rpl_srh.c +++ b/sys/net/gnrc/routing/rpl/srh/gnrc_rpl_srh.c @@ -14,7 +14,7 @@ #include <string.h> #include "net/gnrc/netif/internal.h" -#include "net/ipv6/ext/rh.h" +#include "net/gnrc/ipv6/ext/rh.h" #include "net/gnrc/rpl/srh.h" #define ENABLE_DEBUG (0) @@ -29,7 +29,7 @@ static char addr_str[IPV6_ADDR_MAX_STR_LEN]; int gnrc_rpl_srh_process(ipv6_hdr_t *ipv6, gnrc_rpl_srh_t *rh) { if (rh->seg_left == 0) { - return EXT_RH_CODE_OK; + return GNRC_IPV6_EXT_RH_OK; } uint8_t n = (((rh->len * 8) - GNRC_RPL_SRH_PADDING(rh->pad_resv) - @@ -45,7 +45,7 @@ int gnrc_rpl_srh_process(ipv6_hdr_t *ipv6, gnrc_rpl_srh_t *rh) if (rh->seg_left > n) { DEBUG("RPL SRH: number of segments left > number of addresses - discard\n"); /* TODO ICMP Parameter Problem - Code 0 */ - return EXT_RH_CODE_ERROR; + return GNRC_IPV6_EXT_RH_ERROR; } rh->seg_left--; @@ -58,7 +58,7 @@ int gnrc_rpl_srh_process(ipv6_hdr_t *ipv6, gnrc_rpl_srh_t *rh) if (ipv6_addr_is_multicast(&ipv6->dst) || ipv6_addr_is_multicast(&addr)) { DEBUG("RPL SRH: found a multicast address - discard\n"); /* TODO discard the packet */ - return EXT_RH_CODE_ERROR; + return GNRC_IPV6_EXT_RH_ERROR; } /* check if multiple addresses of my interface exist */ @@ -75,7 +75,7 @@ int gnrc_rpl_srh_process(ipv6_hdr_t *ipv6, gnrc_rpl_srh_t *rh) if (found && ((k - found_pos) > 1)) { DEBUG("RPL SRH: found multiple addresses that belong to me - discard\n"); /* TODO send an ICMP Parameter Problem (Code 0) and discard the packet */ - return EXT_RH_CODE_ERROR; + return GNRC_IPV6_EXT_RH_ERROR; } found_pos = k; found = true; @@ -89,7 +89,7 @@ int gnrc_rpl_srh_process(ipv6_hdr_t *ipv6, gnrc_rpl_srh_t *rh) ipv6->dst = addr; - return EXT_RH_CODE_FORWARD; + return GNRC_IPV6_EXT_RH_FORWARDED; } /** @} */