mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-25 22:43:50 +01:00
ng_ipv6_ext: add routing header parsing
This commit is contained in:
parent
dcfa2681d6
commit
5ffdbc5652
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
61
sys/include/net/ng_ipv6/ext/rh.h
Normal file
61
sys/include/net/ng_ipv6/ext/rh.h
Normal file
@ -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_ */
|
||||
/** @} */
|
||||
3
sys/net/network_layer/ng_ipv6/ext/rh/Makefile
Normal file
3
sys/net/network_layer/ng_ipv6/ext/rh/Makefile
Normal file
@ -0,0 +1,3 @@
|
||||
MODULE = ng_ipv6_ext_rh
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
||||
57
sys/net/network_layer/ng_ipv6/ext/rh/ng_ipv6_ext_rh.c
Normal file
57
sys/net/network_layer/ng_ipv6/ext/rh/ng_ipv6_ext_rh.c
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user