Skip to content

Commit

Permalink
ng_ipv6_ext: add routing header parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed May 17, 2015
1 parent dcfa268 commit 5ffdbc5
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 1 deletion.
3 changes: 3 additions & 0 deletions sys/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions sys/include/net/ng_ipv6/ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
61 changes: 61 additions & 0 deletions sys/include/net/ng_ipv6/ext/rh.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (C) 2015 Martine Lenders <[email protected]>
*
* 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 <[email protected]>
*/
#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 changes: 3 additions & 0 deletions sys/net/network_layer/ng_ipv6/ext/rh/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
MODULE = ng_ipv6_ext_rh

include $(RIOTBASE)/Makefile.base
57 changes: 57 additions & 0 deletions sys/net/network_layer/ng_ipv6/ext/rh/ng_ipv6_ext_rh.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (C) 2015 Martine Lenders <[email protected]>
*
* 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;
}

/** @} */
9 changes: 8 additions & 1 deletion sys/net/network_layer/ng_ndp/ng_ndp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 5ffdbc5

Please sign in to comment.