Skip to content

Commit

Permalink
gnrc_ipv6_nib: port to gnrc_netif2
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed Nov 8, 2017
1 parent 8fac66e commit a7d2c65
Show file tree
Hide file tree
Showing 21 changed files with 571 additions and 676 deletions.
57 changes: 5 additions & 52 deletions Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -136,29 +136,30 @@ endif

ifneq (,$(filter gnrc_sixlowpan_default,$(USEMODULE)))
USEMODULE += gnrc_ipv6_default
USEMODULE += gnrc_ipv6_nib_6ln
USEMODULE += gnrc_sixlowpan
USEMODULE += gnrc_sixlowpan_nd
USEMODULE += gnrc_sixlowpan_frag
USEMODULE += gnrc_sixlowpan_iphc
endif

ifneq (,$(filter gnrc_sixlowpan_router_default,$(USEMODULE)))
USEMODULE += gnrc_ipv6_router_default
USEMODULE += gnrc_ipv6_nib_6lr
USEMODULE += gnrc_sixlowpan_router
USEMODULE += gnrc_sixlowpan_frag
USEMODULE += gnrc_sixlowpan_iphc
endif

ifneq (,$(filter gnrc_sixlowpan_border_router_default,$(USEMODULE)))
USEMODULE += gnrc_ipv6_nib_6lbr
USEMODULE += gnrc_ipv6_router_default
USEMODULE += gnrc_sixlowpan_nd_border_router
USEMODULE += gnrc_sixlowpan_router
USEMODULE += gnrc_sixlowpan_frag
USEMODULE += gnrc_sixlowpan_iphc
endif

ifneq (,$(filter gnrc_sixlowpan_router,$(USEMODULE)))
USEMODULE += gnrc_sixlowpan_nd_router
USEMODULE += gnrc_ipv6_router
endif

ifneq (,$(filter gnrc_sixlowpan_frag,$(USEMODULE)))
Expand All @@ -182,50 +183,14 @@ ifneq (,$(filter gnrc_sixlowpan_ctx,$(USEMODULE)))
USEMODULE += xtimer
endif

ifneq (,$(filter gnrc_sixlowpan_nd_border_router,$(USEMODULE)))
USEMODULE += gnrc_sixlowpan_nd_router
endif

ifneq (,$(filter gnrc_sixlowpan_nd_router,$(USEMODULE)))
USEMODULE += gnrc_sixlowpan_nd
endif

ifneq (,$(filter gnrc_sixlowpan_nd,$(USEMODULE)))
USEMODULE += gnrc_ndp
USEMODULE += gnrc_ndp_internal
USEMODULE += gnrc_sixlowpan_ctx
USEMODULE += random
USEMODULE += xtimer
endif

ifneq (,$(filter gnrc_ipv6_default,$(USEMODULE)))
USEMODULE += gnrc_ipv6
USEMODULE += gnrc_icmpv6
ifeq (1,$(GNRC_NETIF_NUMOF))
ifeq (,$(filter gnrc_sixlowpan_nd,$(USEMODULE)))
USEMODULE += gnrc_ndp_host
endif
else
USEMODULE += gnrc_ndp_host
endif
endif

ifneq (,$(filter gnrc_ipv6_router_default,$(USEMODULE)))
USEMODULE += gnrc_ipv6_router
USEMODULE += gnrc_icmpv6
ifeq (1,$(GNRC_NETIF_NUMOF))
ifeq (,$(filter gnrc_sixlowpan_nd_router,$(USEMODULE)))
USEMODULE += gnrc_ndp_router
endif
else
USEMODULE += gnrc_ndp_router
endif
endif

ifneq (,$(filter gnrc_ndp_host,$(USEMODULE)))
USEMODULE += gnrc_ndp_node
USEMODULE += random
USEMODULE += xtimer
endif

ifneq (,$(filter gnrc_ndp_router,$(USEMODULE)))
Expand All @@ -242,18 +207,6 @@ ifneq (,$(filter gnrc_ndp_%,$(USEMODULE)))
USEMODULE += gnrc_ndp
endif

ifneq (,$(filter gnrc_ndp,$(USEMODULE)))
ifneq (,$(filter gnrc_sixlowpan,$(USEMODULE)))
USEMODULE += gnrc_sixlowpan_nd
else
USEMODULE += gnrc_ndp_node
endif
USEMODULE += gnrc_ndp_internal
USEMODULE += gnrc_icmpv6
USEMODULE += random
USEMODULE += xtimer
endif

ifneq (,$(filter gnrc_ndp2,$(USEMODULE)))
USEMODULE += gnrc_icmpv6
USEMODULE += gnrc_netif2
Expand Down Expand Up @@ -302,7 +255,7 @@ ifneq (,$(filter gnrc_ipv6,$(USEMODULE)))
USEMODULE += inet_csum
USEMODULE += ipv6_addr
USEMODULE += gnrc_ipv6_hdr
USEMODULE += gnrc_ipv6_nc
USEMODULE += gnrc_ipv6_nib
USEMODULE += gnrc_netif2
endif

Expand Down
4 changes: 1 addition & 3 deletions sys/include/net/gnrc/ipv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@
#include "net/ipv6.h"
#include "net/gnrc/ipv6/ext.h"
#include "net/gnrc/ipv6/hdr.h"
#ifndef MODULE_GNRC_IPV6_NIB
#include "net/gnrc/ipv6/nc.h"
#endif
#include "net/gnrc/ipv6/nib.h"

#ifdef MODULE_FIB
#include "net/fib.h"
Expand Down
94 changes: 84 additions & 10 deletions sys/include/net/gnrc/ipv6/nib.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "net/ipv6/addr.h"
#include "net/ipv6/hdr.h"
#include "net/gnrc/ipv6/nib/nc.h"
#include "net/gnrc/netif2.h"
#include "net/gnrc/pkt.h"

#ifdef __cplusplus
Expand Down Expand Up @@ -194,13 +195,67 @@ extern "C" {
* @brief Recalculate reachability timeout time.
*
* This message type is for the event of recalculating the reachability timeout
* time. The expected message context is a valid interface.
* time. The expected message context is a valid
* [interface](@ref net_gnrc_netif2).
*
* @note Only handled with @ref GNRC_IPV6_NIB_CONF_ARSM != 0
*/
#define GNRC_IPV6_NIB_RECALC_REACH_TIME (0x4fceU)
/** @} */

/**
* @brief Types for gnrc_netif2_ipv6_t::route_info_cb
* @anchor net_gnrc_ipv6_nib_route_info_type
*/
enum {
GNRC_IPV6_NIB_ROUTE_INFO_TYPE_UNDEF = 0, /**< undefined */
/**
* @brief reactive routing query
*
* A reactive routing query is issued when a route is unknown to the NIB.
* A reactive routing protocol can use this call to search for a route in a
* reactive manner.
*
* The `ctx_addr` will be the destination address of the unknown route,
* `ctx` a pointer to the packet as `gnrc_pktsnip_t` that caused the route
* look-up (to possibly queue it for later sending).
*/
GNRC_IPV6_NIB_ROUTE_INFO_TYPE_RRQ,

/**
* @brief route notification
*
* A route notification is issued when an already established route is
* taken. A routing protocol can use this call to update its information on
* the route.
*
* The `ctx_addr` is the prefix of the route, `ctx` is set to a value equal
* to the length of the prefix in bits.
*/
GNRC_IPV6_NIB_ROUTE_INFO_TYPE_RN,

/**
* @brief neighbor state change
*
* A neighbor state change is issued when ever the NUD state of a neighbor
* changes. A routing protocol can use this call to update its information
* on routes via this neighbor.
*
* The `ctx_addr` is the address of the neighbor, `ctx` is a value equal
* to the new NUD state as defined in [the NC info flags](@ref
* net_gnrc_ipv6_nib_nc_info). If the entry is deleted, `ctx` will be set
* to @ref GNRC_IPV6_NIB_NC_INFO_NUD_STATE_UNREACHABLE (except if it was
* already in the `UNREACHABLE` state). This does not include cache-outs,
* since they give no information about the neighbor's reachability (you
* might however get an INCOMPLETE or STALE notification due to that, as
* soon as the neighbor enters the neighbor cache again).
*
* Be adviced to only use `ctx_addr` in the context of the callback, since
* it might be overwritten, after the callback was left.
*/
GNRC_IPV6_NIB_ROUTE_INFO_TYPE_NSC,
};

/**
* @brief Initialize NIB
*/
Expand All @@ -209,20 +264,20 @@ void gnrc_ipv6_nib_init(void);
/**
* @brief Adds an interface to be managed by the NIB.
*
* @pre `(KERNEL_PID_UNDEF < iface)`
* @pre `netif != NULL`
*
* @param[in] iface The interface to be managed by the NIB
* @param[in,out] netif The interface to be managed by the NIB
*/
void gnrc_ipv6_nib_init_iface(kernel_pid_t iface);
void gnrc_ipv6_nib_init_iface(gnrc_netif2_t *netif);

/**
* @brief Gets link-layer address of next hop to a destination address
*
* @pre `(dst != NULL) && (nce != NULL)`
*
* @param[in] dst Destination address of a packet.
* @param[in] iface Restrict search to this interface. May be
* `KERNEL_PID_UNDEF` for any interface.
* @param[in] netif Restrict search to this interface. May be `NULL` for any
* interface.
* @param[in] pkt The IPv6 packet in sending order for which the next hop
* is searched. Needed for queuing for with reactive
* routing or address resolution. May be `NULL`.
Expand All @@ -237,13 +292,13 @@ void gnrc_ipv6_nib_init_iface(kernel_pid_t iface);
* solicitation sent).
*/
int gnrc_ipv6_nib_get_next_hop_l2addr(const ipv6_addr_t *dst,
kernel_pid_t iface, gnrc_pktsnip_t *pkt,
gnrc_netif2_t *netif, gnrc_pktsnip_t *pkt,
gnrc_ipv6_nib_nc_t *nce);

/**
* @brief Handles a received ICMPv6 packet
*
* @pre `iface != KERNEL_PID_UNDEF`
* @pre `netif != NULL`
* @pre `ipv6 != NULL`
* @pre `icmpv6 != NULL`
* @pre `icmpv6_len > sizeof(icmpv6_hdr_t)`
Expand Down Expand Up @@ -274,13 +329,13 @@ int gnrc_ipv6_nib_get_next_hop_l2addr(const ipv6_addr_t *dst,
* @see [RFC 6775, section 8.2.4](https://tools.ietf.org/html/rfc6775#section-8.2.4)
* @see [RFC 6775, section 8.2.5](https://tools.ietf.org/html/rfc6775#section-8.2.5)
*
* @param[in] iface The interface the packet came over.
* @param[in] netif The interface the packet came over.
* @param[in] ipv6 The IPv6 header of the received packet.
* @param[in] icmpv6 The ICMPv6 header and payload of the received
* packet.
* @param[in] icmpv6_len The number of bytes at @p icmpv6.
*/
void gnrc_ipv6_nib_handle_pkt(kernel_pid_t iface, const ipv6_hdr_t *ipv6,
void gnrc_ipv6_nib_handle_pkt(gnrc_netif2_t *netif, const ipv6_hdr_t *ipv6,
const icmpv6_hdr_t *icmpv6, size_t icmpv6_len);

/**
Expand All @@ -292,6 +347,25 @@ void gnrc_ipv6_nib_handle_pkt(kernel_pid_t iface, const ipv6_hdr_t *ipv6,
*/
void gnrc_ipv6_nib_handle_timer_event(void *ctx, uint16_t type);

#if GNRC_IPV6_NIB_CONF_ROUTER || defined(DOXYGEN)
/**
* @brief Changes the state if an interface advertises itself as a router
* or not
*
* @param[in] netif The interface for which the state should be changed.
* @param[in] enable `true`, to enable advertising the interface as a router.
* `false`, to disable advertising the interface as a
* router.
*/
void gnrc_ipv6_nib_change_rtr_adv_iface(gnrc_netif2_t *netif, bool enable);
#else
/**
* @brief Optimization to NOP for non-routers
*/
#define gnrc_ipv6_nib_change_rtr_adv_iface(netif, enable) \
(void)netif; (void)enable
#endif

#ifdef __cplusplus
}
#endif
Expand Down
6 changes: 2 additions & 4 deletions sys/include/net/gnrc/ipv6/nib/conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,8 @@ extern "C" {
/**
* @brief Maximum link-layer address length (aligned)
*/
#if (GNRC_NETIF_HDR_L2ADDR_MAX_LEN % 8)
#define GNRC_IPV6_NIB_L2ADDR_MAX_LEN (((GNRC_NETIF_HDR_L2ADDR_MAX_LEN >> 3) + 1) << 3)
#else
#define GNRC_IPV6_NIB_L2ADDR_MAX_LEN (GNRC_NETIF_HDR_L2ADDR_MAX_LEN)
#ifndef GNRC_IPV6_NIB_L2ADDR_MAX_LEN
#define GNRC_IPV6_NIB_L2ADDR_MAX_LEN (8U)
#endif

/**
Expand Down
5 changes: 3 additions & 2 deletions sys/include/net/gnrc/netif2/conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "net/ieee802154.h"
#include "net/ethernet/hdr.h"
#include "net/gnrc/ipv6/nib/conf.h"
#include "thread.h"

#ifdef __cplusplus
Expand Down Expand Up @@ -60,7 +61,7 @@ extern "C" {
*
* @note Used for calculation of @ref GNRC_NETIF2_IPV6_GROUPS_NUMOF
*/
#ifdef MODULE_GNRC_IPV6_ROUTER
#if GNRC_IPV6_NIB_CONF_ROUTER
#define GNRC_NETIF2_IPV6_RTR_ADDR (1)
#else
#define GNRC_NETIF2_IPV6_RTR_ADDR (0)
Expand Down Expand Up @@ -109,7 +110,7 @@ extern "C" {
#elif MODULE_CC110X
#define GNRC_NETIF2_L2ADDR_MAXLEN (1U)
#else
#define GNRC_NETIF2_L2ADDR_MAXLEN (8U)
#define GNRC_NETIF2_L2ADDR_MAXLEN (GNRC_IPV6_NIB_L2ADDR_MAX_LEN)
#endif
#endif

Expand Down
5 changes: 2 additions & 3 deletions sys/include/net/gnrc/netif2/ipv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,8 @@ typedef struct {
* The callback may be `NULL` if no such behavior is required by the routing
* protocol (or no routing protocol is present).
*
* @todo Define types (RRQ, RRN, NSC) in NIB
*
* @param[in] type Type of the route info.
* @param[in] type [Type](@ref net_gnrc_ipv6_nib_route_info_type) of
* the route info.
* @param[in] ctx_addr Context address of the route info.
* @param[in] ctx Further context of the route info.
*/
Expand Down
13 changes: 6 additions & 7 deletions sys/net/gnrc/netif2/gnrc_netif2.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#include "net/ethernet.h"
#include "net/ipv6.h"
#include "net/gnrc.h"
#ifdef MODULE_GNRC_IPV6_NIB
#include "net/gnrc/ipv6/nib.h"
#endif /* MODULE_GNRC_IPV6_NIB */
#ifdef MODULE_NETSTATS_IPV6
#include "net/netstats.h"
#endif
Expand Down Expand Up @@ -278,20 +281,16 @@ int gnrc_netif2_set_from_netdev(gnrc_netif2_t *netif,
}
else {
if (gnrc_netif2_is_rtr_adv(netif)) {
gnrc_ipv6_nib_iface_cease_rtr_adv(netif);
gnrc_ipv6_nib_change_rtr_adv_iface(netif, false);
}
netif->flags &= ~GNRC_NETIF2_FLAGS_IPV6_FORWARDING;
}
res = sizeof(netopt_enable_t);
break;
case NETOPT_IPV6_SND_RTR_ADV:
assert(opt->data_len == sizeof(netopt_enable_t));
if (*(((netopt_enable_t *)opt->data)) == NETOPT_ENABLE) {
gnrc_ipv6_nib_iface_start_rtr_adv(netif);
}
else {
gnrc_ipv6_nib_iface_cease_rtr_adv(netif);
}
gnrc_ipv6_nib_change_rtr_adv_iface(netif,
(*(((netopt_enable_t *)opt->data)) == NETOPT_ENABLE));
res = sizeof(netopt_enable_t);
break;
#endif /* GNRC_IPV6_NIB_CONF_ROUTER */
Expand Down
Loading

0 comments on commit a7d2c65

Please sign in to comment.