Skip to content

Commit

Permalink
Merge pull request #3602 from authmillenon/ndp/api/take-out-msg-types
Browse files Browse the repository at this point in the history
ndp: move type definitions out of ng_ context
  • Loading branch information
miri64 committed Aug 18, 2015
2 parents e5d5c37 + 618a765 commit d0f530d
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 91 deletions.
82 changes: 41 additions & 41 deletions sys/include/net/ng_ndp/types.h → sys/include/net/ndp.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
*/

/**
* @defgroup net_ng_ndp_types Types for IPv6 neighbor discovery
* @ingroup net_ng_ndp
* @brief IPv6 neighbor discovery message types
* @defgroup net_ndp IPv6 neighbor discovery messages
* @ingroup net_ipv6
* @brief Provides IPv6 neighbor discovery message types
* @{
*
* @file
* @brief IPv6 neighbor discovery message type definitions
*
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
*/
#ifndef NG_NDP_TYPES_H_
#define NG_NDP_TYPES_H_
#ifndef NDP_H_
#define NDP_H_

#include <stdint.h>

Expand All @@ -29,46 +29,46 @@ extern "C" {
#endif

/**
* @{
* @name Flags for router advertisement messages
* @name Router advertisement flags
* @see <a href="https://tools.ietf.org/html/rfc4861#section-4.2">
* RFC 4861, section 4.2
* </a>
* @{
*/
#define NG_NDP_RTR_ADV_FLAGS_MASK (0xc0)
#define NG_NDP_RTR_ADV_FLAGS_M (0x80) /**< managed address configuration */
#define NG_NDP_RTR_ADV_FLAGS_O (0x40) /**< other configuration */
#define NDP_RTR_ADV_FLAGS_MASK (0xc0)
#define NDP_RTR_ADV_FLAGS_M (0x80) /**< managed address configuration */
#define NDP_RTR_ADV_FLAGS_O (0x40) /**< other configuration */
/**
* @}
*/

/**
* @{
* @name Flags for neighbor advertisement messages
* @name Neighbor advertisement flags
* @see <a href="https://tools.ietf.org/html/rfc4861#section-4.4">
* RFC 4861, section 4.2
* </a>
* @{
*/
#define NG_NDP_NBR_ADV_FLAGS_MASK (0xe0)
#define NG_NDP_NBR_ADV_FLAGS_R (0x80) /**< router */
#define NG_NDP_NBR_ADV_FLAGS_S (0x40) /**< solicited */
#define NG_NDP_NBR_ADV_FLAGS_O (0x20) /**< override */
#define NDP_NBR_ADV_FLAGS_MASK (0xe0)
#define NDP_NBR_ADV_FLAGS_R (0x80) /**< router */
#define NDP_NBR_ADV_FLAGS_S (0x40) /**< solicited */
#define NDP_NBR_ADV_FLAGS_O (0x20) /**< override */
/**
* @}
*/

/**
* @{
* @name NDP option types
* @{
* @see <a href="http://www.iana.org/assignments/icmpv6-parameters/icmpv6-parameters.xhtml#icmpv6-parameters-5">
* IANA, IPv6 Neighbor Discovery Option Formats
* </a>
*/
#define NG_NDP_OPT_SL2A (1) /**< source link-layer address option */
#define NG_NDP_OPT_TL2A (2) /**< target link-layer address option */
#define NG_NDP_OPT_PI (3) /**< prefix information option */
#define NG_NDP_OPT_RH (4) /**< redirected option */
#define NG_NDP_OPT_MTU (5) /**< MTU option */
#define NDP_OPT_SL2A (1) /**< source link-layer address option */
#define NDP_OPT_TL2A (2) /**< target link-layer address option */
#define NDP_OPT_PI (3) /**< prefix information option */
#define NDP_OPT_RH (4) /**< redirected option */
#define NDP_OPT_MTU (5) /**< MTU option */
/**
* @}
*/
Expand All @@ -77,9 +77,9 @@ extern "C" {
* @{
* @name Flags for prefix information option
*/
#define NG_NDP_OPT_PI_FLAGS_MASK (0xc0)
#define NG_NDP_OPT_PI_FLAGS_L (0x80) /**< on-link */
#define NG_NDP_OPT_PI_FLAGS_A (0x40) /**< autonomous address configuration */
#define NDP_OPT_PI_FLAGS_MASK (0xc0)
#define NDP_OPT_PI_FLAGS_L (0x80) /**< on-link */
#define NDP_OPT_PI_FLAGS_A (0x40) /**< autonomous address configuration */
/**
* @}
*/
Expand All @@ -89,8 +89,8 @@ extern "C" {
* @name Lengths for fixed length options
* @brief Options don't use bytes as their length unit, but 8 bytes.
*/
#define NG_NDP_OPT_PI_LEN (4U)
#define NG_NDP_OPT_MTU_LEN (1U)
#define NDP_OPT_PI_LEN (4U)
#define NDP_OPT_MTU_LEN (1U)
/**
* @}
*/
Expand All @@ -108,7 +108,7 @@ typedef struct __attribute__((packed)) {
uint8_t code; /**< message code */
network_uint16_t csum; /**< checksum */
network_uint32_t resv; /**< reserved field */
} ng_ndp_rtr_sol_t;
} ndp_rtr_sol_t;

/**
* @brief Router advertisement message format.
Expand All @@ -127,7 +127,7 @@ typedef struct __attribute__((packed)) {
network_uint16_t ltime; /**< router lifetime */
network_uint32_t reach_time; /**< reachable time */
network_uint32_t retrans_timer; /**< retransmission timer */
} ng_ndp_rtr_adv_t;
} ndp_rtr_adv_t;

/**
* @brief Neighbor solicitation message format.
Expand All @@ -143,7 +143,7 @@ typedef struct __attribute__((packed)) {
network_uint16_t csum; /**< checksum */
network_uint32_t resv; /**< reserved field */
ipv6_addr_t tgt; /**< target address */
} ng_ndp_nbr_sol_t;
} ndp_nbr_sol_t;

/**
* @brief Neighbor advertisement message format.
Expand All @@ -160,7 +160,7 @@ typedef struct __attribute__((packed)) {
uint8_t flags; /**< flags */
uint8_t resv[3]; /**< reserved fields */
ipv6_addr_t tgt; /**< target address */
} ng_ndp_nbr_adv_t;
} ndp_nbr_adv_t;

/**
* @brief Neighbor advertisement message format.
Expand All @@ -177,7 +177,7 @@ typedef struct __attribute__((packed)) {
network_uint32_t resv; /**< reserved field */
ipv6_addr_t tgt; /**< target address */
ipv6_addr_t dst; /**< destination address */
} ng_ndp_redirect_t;
} ndp_redirect_t;

/**
* @brief General NDP option format
Expand All @@ -188,14 +188,14 @@ typedef struct __attribute__((packed)) {
typedef struct __attribute__((packed)) {
uint8_t type; /**< option type */
uint8_t len; /**< length in units of 8 octets */
} ng_ndp_opt_t;
} ndp_opt_t;

/* XXX: slla and tlla are just ng_ndp_opt_t with variable link layer address
/* XXX: slla and tlla are just ndp_opt_t with variable link layer address
* appended */

/**
* @brief Prefix information option format
* @extends ng_ndp_opt_t
* @extends ndp_opt_t
*
* @see <a href="https://tools.ietf.org/html/rfc4861#section-4.6.2">
* RFC 4861, section 4.6.2
Expand All @@ -210,11 +210,11 @@ typedef struct __attribute__((packed)) {
network_uint32_t pref_ltime; /**< preferred lifetime */
network_uint32_t resv; /**< reserved field */
ipv6_addr_t prefix; /**< prefix */
} ng_ndp_opt_pi_t;
} ndp_opt_pi_t;

/**
* @brief Redirected header option format
* @extends ng_ndp_opt_t
* @extends ndp_opt_t
*
* @see <a href="https://tools.ietf.org/html/rfc4861#section-4.6.3">
* RFC 4861, section 4.6.3
Expand All @@ -224,11 +224,11 @@ typedef struct __attribute__((packed)) {
uint8_t type; /**< option type */
uint8_t len; /**< length in units of 8 octets */
uint8_t resv[6]; /**< reserved field */
} ng_ndp_opt_rh_t;
} ndp_opt_rh_t;

/**
* @brief MTU option format
* @extends ng_ndp_opt_t
* @extends ndp_opt_t
*
* @see <a href="https://tools.ietf.org/html/rfc4861#section-4.6.4">
* RFC 4861, section 4.6.4
Expand All @@ -239,12 +239,12 @@ typedef struct __attribute__((packed)) {
uint8_t len; /**< length in units of 8 octets */
network_uint16_t resv; /**< reserved field */
network_uint32_t mtu; /**< MTU */
} ng_ndp_opt_mtu_t;
} ndp_opt_mtu_t;


#ifdef __cplusplus
}
#endif

#endif /* NG_NDP_TYPES_H_ */
#endif /* NDP_H_ */
/** @} */
41 changes: 31 additions & 10 deletions sys/include/net/ng_ndp.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
*/

#ifndef NG_NDP_H_
#define NG_NDP_H_

#include <inttypes.h>

#include "byteorder.h"
#include "net/ndp.h"
#include "net/ng_pkt.h"
#include "net/ng_icmpv6.h"
#include "net/ipv6/addr.h"
#include "net/ng_ipv6/nc.h"
#include "net/ng_ipv6/netif.h"

#include "net/ng_ndp/node.h"
#include "net/ng_ndp/types.h"

#ifndef NG_NDP_H_
#define NG_NDP_H_

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -116,7 +116,7 @@ extern "C" {
* @param[in] icmpv6_size The overall size of the neighbor solicitation.
*/
void ng_ndp_nbr_sol_handle(kernel_pid_t iface, ng_pktsnip_t *pkt,
ipv6_hdr_t *ipv6, ng_ndp_nbr_sol_t *nbr_sol,
ipv6_hdr_t *ipv6, ndp_nbr_sol_t *nbr_sol,
size_t icmpv6_size);

/**
Expand All @@ -129,7 +129,7 @@ void ng_ndp_nbr_sol_handle(kernel_pid_t iface, ng_pktsnip_t *pkt,
* @param[in] icmpv6_size The overall size of the neighbor advertisement.
*/
void ng_ndp_nbr_adv_handle(kernel_pid_t iface, ng_pktsnip_t *pkt,
ipv6_hdr_t *ipv6, ng_ndp_nbr_adv_t *nbr_adv,
ipv6_hdr_t *ipv6, ndp_nbr_adv_t *nbr_adv,
size_t icmpv6_size);

/**
Expand Down Expand Up @@ -168,6 +168,27 @@ void ng_ndp_netif_add(ng_ipv6_netif_t *iface);
*/
void ng_ndp_netif_remove(ng_ipv6_netif_t *iface);

/**
* @brief Get link-layer address and interface for next hop to destination
* IPv6 address.
*
* @param[out] l2addr The link-layer for the next hop to @p dst.
* @param[out] l2addr_len Length of @p l2addr.
* @param[in] iface The interface to search the next hop on.
* May be @ref KERNEL_PID_UNDEF if not specified.
* @param[in] dst An IPv6 address to search the next hop for.
* @param[in] pkt Packet to send to @p dst. Leave NULL if you
* just want to get the addresses.
*
* @return The PID of the interface, on success.
* @return -EHOSTUNREACH, if @p dst is not reachable.
* @return -ENOBUFS, if @p l2addr_len was smaller than the resulting @p l2addr
* would be long.
*/
kernel_pid_t ng_ndp_next_hop_l2addr(uint8_t *l2addr, uint8_t *l2addr_len,
kernel_pid_t iface, ipv6_addr_t *dst,
ng_pktsnip_t *pkt);

/**
* @brief Builds a neighbor solicitation message for sending.
*
Expand All @@ -190,13 +211,13 @@ ng_pktsnip_t *ng_ndp_nbr_sol_build(ipv6_addr_t *tgt, ng_pktsnip_t *options);
* RFC 4861, section 4.4
* </a>
*
* @param[in] flags Flags as defined above.
* @ref NG_NDP_NBR_ADV_FLAGS_R == 1 indicates, that the
* @param[in] flags Neighbor advertisement flags:
* @ref NDP_NBR_ADV_FLAGS_R == 1 indicates, that the
* sender is a router,
* @ref NG_NDP_NBR_ADV_FLAGS_S == 1 indicates that the
* @ref NDP_NBR_ADV_FLAGS_S == 1 indicates that the
* advertisement was sent in response to a neighbor
* solicitation,
* @ref NG_NDP_NBR_ADV_FLAGS_O == 1 indicates that the
* @ref NDP_NBR_ADV_FLAGS_O == 1 indicates that the
* advertisement should override an existing cache entry
* and update the cached link-layer address.
* @param[in] tgt For solicited advertisements, the Target Address field
Expand Down
6 changes: 3 additions & 3 deletions sys/include/net/ng_ndp/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

#include "net/ipv6/addr.h"
#include "net/ipv6/hdr.h"
#include "net/ng_ndp/types.h"
#include "net/ndp.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -98,7 +98,7 @@ void ng_ndp_internal_send_nbr_adv(kernel_pid_t iface, ipv6_addr_t *tgt,
*/
bool ng_ndp_internal_sl2a_opt_handle(kernel_pid_t iface, ng_pktsnip_t *pkt,
ipv6_hdr_t *ipv6, uint8_t icmpv6_type,
ng_ndp_opt_t *sl2a_opt);
ndp_opt_t *sl2a_opt);

/**
* @brief Handles a TL2A option.
Expand All @@ -114,7 +114,7 @@ bool ng_ndp_internal_sl2a_opt_handle(kernel_pid_t iface, ng_pktsnip_t *pkt,
* @return -EINVAL, if TL2A was not valid.
*/
int ng_ndp_internal_tl2a_opt_handle(ng_pktsnip_t *pkt, ipv6_hdr_t *ipv6,
uint8_t icmpv6_type, ng_ndp_opt_t *tl2a_opt,
uint8_t icmpv6_type, ndp_opt_t *tl2a_opt,
uint8_t *l2addr);

#ifdef __cplusplus
Expand Down
4 changes: 2 additions & 2 deletions sys/net/network_layer/ng_icmpv6/ng_icmpv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ void ng_icmpv6_demux(kernel_pid_t iface, ng_pktsnip_t *pkt)

case ICMPV6_NBR_SOL:
DEBUG("icmpv6: neighbor solicitation received\n");
ng_ndp_nbr_sol_handle(iface, pkt, ipv6->data, (ng_ndp_nbr_sol_t *)hdr,
ng_ndp_nbr_sol_handle(iface, pkt, ipv6->data, (ndp_nbr_sol_t *)hdr,
icmpv6->size);
break;

case ICMPV6_NBR_ADV:
DEBUG("icmpv6: neighbor advertisement received\n");
ng_ndp_nbr_adv_handle(iface, pkt, ipv6->data, (ng_ndp_nbr_adv_t *)hdr,
ng_ndp_nbr_adv_handle(iface, pkt, ipv6->data, (ndp_nbr_adv_t *)hdr,
icmpv6->size);
break;

Expand Down
Loading

0 comments on commit d0f530d

Please sign in to comment.