-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ng_ipv6_ext: add routing header parsing
- Loading branch information
Showing
6 changed files
with
134 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ */ | ||
/** @} */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
MODULE = ng_ipv6_ext_rh | ||
|
||
include $(RIOTBASE)/Makefile.base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
/** @} */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters