mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
gnrc_ipv6_ext: move ipv6_ext_rh (partly) to GNRC
This commit is contained in:
parent
6f37f7eda7
commit
c54ba49e82
@ -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)))
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
73
sys/include/net/gnrc/ipv6/ext/rh.h
Normal file
73
sys/include/net/gnrc/ipv6/ext/rh.h
Normal file
@ -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 */
|
||||
/** @} */
|
@ -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);
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
@ -1,3 +1,3 @@
|
||||
MODULE = ipv6_ext_rh
|
||||
MODULE = gnrc_ipv6_ext_rh
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
@ -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;
|
||||
}
|
||||
|
||||
/** @} */
|
@ -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;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
Loading…
Reference in New Issue
Block a user