Skip to content
Snippets Groups Projects
Commit c54ba49e authored by Martine Lenders's avatar Martine Lenders Committed by Martine Lenders
Browse files

gnrc_ipv6_ext: move ipv6_ext_rh (partly) to GNRC

parent 6f37f7ed
No related branches found
No related tags found
No related merge requests found
...@@ -245,11 +245,11 @@ ifneq (,$(filter gnrc_icmpv6,$(USEMODULE))) ...@@ -245,11 +245,11 @@ ifneq (,$(filter gnrc_icmpv6,$(USEMODULE)))
endif endif
ifneq (,$(filter gnrc_rpl_srh,$(USEMODULE))) ifneq (,$(filter gnrc_rpl_srh,$(USEMODULE)))
USEMODULE += ipv6_ext_rh USEMODULE += gnrc_ipv6_ext_rh
endif endif
ifneq (,$(filter ipv6_ext_rh,$(USEMODULE))) ifneq (,$(filter gnrc_ipv6_ext_rh,$(USEMODULE)))
USEMODULE += ipv6_ext USEMODULE += gnrc_ipv6_ext
endif endif
ifneq (,$(filter gnrc_ipv6_ext,$(USEMODULE))) ifneq (,$(filter gnrc_ipv6_ext,$(USEMODULE)))
......
...@@ -46,9 +46,6 @@ endif ...@@ -46,9 +46,6 @@ endif
ifneq (,$(filter ipv6_ext_rh,$(USEMODULE))) ifneq (,$(filter ipv6_ext_rh,$(USEMODULE)))
DIRS += net/network_layer/ipv6/ext/rh DIRS += net/network_layer/ipv6/ext/rh
endif endif
ifneq (,$(filter ipv6_ext,$(USEMODULE)))
DIRS += net/network_layer/ipv6/ext
endif
ifneq (,$(filter ipv6_hdr,$(USEMODULE))) ifneq (,$(filter ipv6_hdr,$(USEMODULE)))
DIRS += net/network_layer/ipv6/hdr DIRS += net/network_layer/ipv6/hdr
endif endif
......
...@@ -31,6 +31,10 @@ ...@@ -31,6 +31,10 @@
#include "net/gnrc/pkt.h" #include "net/gnrc/pkt.h"
#include "net/ipv6/ext.h" #include "net/ipv6/ext.h"
#ifdef MODULE_GNRC_IPV6_EXT_RH
#include "net/gnrc/ipv6/ext/rh.h"
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
......
/*
* 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 */
/** @} */
...@@ -60,9 +60,9 @@ typedef struct __attribute__((packed)) { ...@@ -60,9 +60,9 @@ typedef struct __attribute__((packed)) {
* @param[in,out] ipv6 The IPv6 header of the incoming packet. * @param[in,out] ipv6 The IPv6 header of the incoming packet.
* @param[in] rh A RPL source routing header. * @param[in] rh A RPL source routing header.
* *
* @return EXT_RH_CODE_ERROR * @return @ref GNRC_IPV6_EXT_RH_OK, on success
* @return EXT_RH_CODE_FORWARD * @return @ref GNRC_IPV6_EXT_RH_FORWARDED, when @p pkt *should be* forwarded
* @return EXT_RH_CODE_OK * @return @ref GNRC_IPV6_EXT_RH_ERROR, on error
*/ */
int gnrc_rpl_srh_process(ipv6_hdr_t *ipv6, gnrc_rpl_srh_t *rh); int gnrc_rpl_srh_process(ipv6_hdr_t *ipv6, gnrc_rpl_srh_t *rh);
......
/* /*
* 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 * 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 * General Public License v2.1. See the file LICENSE in the top level
...@@ -9,13 +10,14 @@ ...@@ -9,13 +10,14 @@
/** /**
* @defgroup net_ipv6_ext_rh IPv6 routing header extension * @defgroup net_ipv6_ext_rh IPv6 routing header extension
* @ingroup net_ipv6_ext * @ingroup net_ipv6_ext
* @brief Implementation of IPv6 routing header extension. * @brief Definitions for IPv6 routing header extension.
* @{ * @{
* *
* @file * @file
* @brief Routing extension header definitions. * @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 #ifndef NET_IPV6_EXT_RH_H
#define NET_IPV6_EXT_RH_H #define NET_IPV6_EXT_RH_H
...@@ -30,17 +32,6 @@ ...@@ -30,17 +32,6 @@
extern "C" { extern "C" {
#endif #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. * @brief IPv6 routing extension header.
* *
...@@ -55,18 +46,6 @@ typedef struct __attribute__((packed)) { ...@@ -55,18 +46,6 @@ typedef struct __attribute__((packed)) {
uint8_t seg_left; /**< number of route segments remaining */ uint8_t seg_left; /**< number of route segments remaining */
} ipv6_ext_rh_t; } 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 #ifdef __cplusplus
} }
#endif #endif
......
...@@ -13,6 +13,9 @@ endif ...@@ -13,6 +13,9 @@ endif
ifneq (,$(filter gnrc_ipv6_ext,$(USEMODULE))) ifneq (,$(filter gnrc_ipv6_ext,$(USEMODULE)))
DIRS += network_layer/ipv6/ext DIRS += network_layer/ipv6/ext
endif endif
ifneq (,$(filter gnrc_ipv6_ext_rh,$(USEMODULE)))
DIRS += network_layer/ipv6/ext/rh
endif
ifneq (,$(filter gnrc_ipv6_hdr,$(USEMODULE))) ifneq (,$(filter gnrc_ipv6_hdr,$(USEMODULE)))
DIRS += network_layer/ipv6/hdr DIRS += network_layer/ipv6/hdr
endif endif
......
...@@ -18,14 +18,14 @@ ...@@ -18,14 +18,14 @@
#include "net/gnrc/netif.h" #include "net/gnrc/netif.h"
#include "net/gnrc/pktbuf.h" #include "net/gnrc/pktbuf.h"
#include "net/gnrc/ipv6.h" #include "net/gnrc/ipv6.h"
#include "net/gnrc/ipv6/ext/rh.h"
#include "net/gnrc/ipv6/ext.h" #include "net/gnrc/ipv6/ext.h"
#define ENABLE_DEBUG (0) #define ENABLE_DEBUG (0)
#include "debug.h" #include "debug.h"
#ifdef MODULE_GNRC_RPL_SRH #ifdef MODULE_GNRC_IPV6_EXT_RH
enum gnrc_ipv6_ext_demux_status { enum gnrc_ipv6_ext_demux_status {
GNRC_IPV6_EXT_OK, GNRC_IPV6_EXT_OK,
GNRC_IPV6_EXT_FORWARDED, GNRC_IPV6_EXT_FORWARDED,
...@@ -65,13 +65,13 @@ static enum gnrc_ipv6_ext_demux_status _handle_rh(gnrc_pktsnip_t *current, gnrc_ ...@@ -65,13 +65,13 @@ static enum gnrc_ipv6_ext_demux_status _handle_rh(gnrc_pktsnip_t *current, gnrc_
hdr = ipv6->data; hdr = ipv6->data;
} }
switch (ipv6_ext_rh_process(hdr, (ipv6_ext_rh_t *)ext)) { switch (gnrc_ipv6_ext_rh_process(hdr, (ipv6_ext_rh_t *)ext)) {
case EXT_RH_CODE_ERROR: case GNRC_IPV6_EXT_RH_ERROR:
/* TODO: send ICMPv6 error codes */ /* TODO: send ICMPv6 error codes */
gnrc_pktbuf_release(pkt); gnrc_pktbuf_release(pkt);
return GNRC_IPV6_EXT_ERROR; return GNRC_IPV6_EXT_ERROR;
case EXT_RH_CODE_FORWARD: case GNRC_IPV6_EXT_RH_FORWARDED:
/* forward packet */ /* forward packet */
if (!gnrc_netapi_dispatch_receive(GNRC_NETTYPE_IPV6, GNRC_NETREG_DEMUX_CTX_ALL, pkt)) { 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"); 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_ ...@@ -79,7 +79,7 @@ static enum gnrc_ipv6_ext_demux_status _handle_rh(gnrc_pktsnip_t *current, gnrc_
} }
return GNRC_IPV6_EXT_FORWARDED; 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 */ /* this should not happen since we checked seg_left early */
gnrc_pktbuf_release(pkt); gnrc_pktbuf_release(pkt);
return GNRC_IPV6_EXT_ERROR; return GNRC_IPV6_EXT_ERROR;
...@@ -87,8 +87,7 @@ static enum gnrc_ipv6_ext_demux_status _handle_rh(gnrc_pktsnip_t *current, gnrc_ ...@@ -87,8 +87,7 @@ static enum gnrc_ipv6_ext_demux_status _handle_rh(gnrc_pktsnip_t *current, gnrc_
return GNRC_IPV6_EXT_OK; return GNRC_IPV6_EXT_OK;
} }
#endif /* MODULE_GNRC_IPV6_EXT_RH */
#endif
/** /**
* @brief marks IPv6 extension header if needed. * @brief marks IPv6 extension header if needed.
...@@ -183,7 +182,7 @@ void gnrc_ipv6_ext_demux(gnrc_netif_t *netif, ...@@ -183,7 +182,7 @@ void gnrc_ipv6_ext_demux(gnrc_netif_t *netif,
switch (nh) { switch (nh) {
case PROTNUM_IPV6_EXT_RH: 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, size is already checked */
if (current == pkt && !_has_valid_size(pkt, nh)) { if (current == pkt && !_has_valid_size(pkt, nh)) {
DEBUG("ipv6_ext: invalid size\n"); DEBUG("ipv6_ext: invalid size\n");
...@@ -215,7 +214,7 @@ void gnrc_ipv6_ext_demux(gnrc_netif_t *netif, ...@@ -215,7 +214,7 @@ void gnrc_ipv6_ext_demux(gnrc_netif_t *netif,
} }
break; break;
#endif #endif /* MODULE_GNRC_IPV6_EXT_RH */
case PROTNUM_IPV6_EXT_HOPOPT: case PROTNUM_IPV6_EXT_HOPOPT:
case PROTNUM_IPV6_EXT_DST: case PROTNUM_IPV6_EXT_DST:
......
MODULE = ipv6_ext_rh MODULE = gnrc_ipv6_ext_rh
include $(RIOTBASE)/Makefile.base include $(RIOTBASE)/Makefile.base
...@@ -16,10 +16,10 @@ ...@@ -16,10 +16,10 @@
#include "net/protnum.h" #include "net/protnum.h"
#include "net/ipv6/ext.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" #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; (void) hdr;
...@@ -32,7 +32,7 @@ int ipv6_ext_rh_process(ipv6_hdr_t *hdr, ipv6_ext_rh_t *ext) ...@@ -32,7 +32,7 @@ int ipv6_ext_rh_process(ipv6_hdr_t *hdr, ipv6_ext_rh_t *ext)
default: default:
break; break;
} }
return EXT_RH_CODE_ERROR; return GNRC_IPV6_EXT_RH_ERROR;
} }
/** @} */ /** @} */
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include <string.h> #include <string.h>
#include "net/gnrc/netif/internal.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" #include "net/gnrc/rpl/srh.h"
#define ENABLE_DEBUG (0) #define ENABLE_DEBUG (0)
...@@ -29,7 +29,7 @@ static char addr_str[IPV6_ADDR_MAX_STR_LEN]; ...@@ -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) int gnrc_rpl_srh_process(ipv6_hdr_t *ipv6, gnrc_rpl_srh_t *rh)
{ {
if (rh->seg_left == 0) { 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) - 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) ...@@ -45,7 +45,7 @@ int gnrc_rpl_srh_process(ipv6_hdr_t *ipv6, gnrc_rpl_srh_t *rh)
if (rh->seg_left > n) { if (rh->seg_left > n) {
DEBUG("RPL SRH: number of segments left > number of addresses - discard\n"); DEBUG("RPL SRH: number of segments left > number of addresses - discard\n");
/* TODO ICMP Parameter Problem - Code 0 */ /* TODO ICMP Parameter Problem - Code 0 */
return EXT_RH_CODE_ERROR; return GNRC_IPV6_EXT_RH_ERROR;
} }
rh->seg_left--; rh->seg_left--;
...@@ -58,7 +58,7 @@ int gnrc_rpl_srh_process(ipv6_hdr_t *ipv6, gnrc_rpl_srh_t *rh) ...@@ -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)) { if (ipv6_addr_is_multicast(&ipv6->dst) || ipv6_addr_is_multicast(&addr)) {
DEBUG("RPL SRH: found a multicast address - discard\n"); DEBUG("RPL SRH: found a multicast address - discard\n");
/* TODO discard the packet */ /* TODO discard the packet */
return EXT_RH_CODE_ERROR; return GNRC_IPV6_EXT_RH_ERROR;
} }
/* check if multiple addresses of my interface exist */ /* 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) ...@@ -75,7 +75,7 @@ int gnrc_rpl_srh_process(ipv6_hdr_t *ipv6, gnrc_rpl_srh_t *rh)
if (found && ((k - found_pos) > 1)) { if (found && ((k - found_pos) > 1)) {
DEBUG("RPL SRH: found multiple addresses that belong to me - discard\n"); DEBUG("RPL SRH: found multiple addresses that belong to me - discard\n");
/* TODO send an ICMP Parameter Problem (Code 0) and discard the packet */ /* 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_pos = k;
found = true; found = true;
...@@ -89,7 +89,7 @@ int gnrc_rpl_srh_process(ipv6_hdr_t *ipv6, gnrc_rpl_srh_t *rh) ...@@ -89,7 +89,7 @@ int gnrc_rpl_srh_process(ipv6_hdr_t *ipv6, gnrc_rpl_srh_t *rh)
ipv6->dst = addr; ipv6->dst = addr;
return EXT_RH_CODE_FORWARD; return GNRC_IPV6_EXT_RH_FORWARDED;
} }
/** @} */ /** @} */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment