Skip to content
Permalink
Browse files

net/iface: Rework how routers are handled

- router lifetime is always a u16_t so fixing
net_if_ipv6_router_update_lifetime() signature.
- Coalescing router timers into one: this reduces the net_if_router
structure by 22 bytes
- refactor IPv6 and IPv4 router code so it's handled in generic
functions, to avoid duplicating 90% of the code for each family. This
also fixes the lifetime support for IPv4 which was missing.

Note however that IPv4 routing support seems to be missing as none of
the relevant functions are used anywhere yet.

Fixes #8728

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
  • Loading branch information...
tbursztyka authored and jukkar committed May 22, 2019
1 parent b2d9584 commit eccc268d0a0ab964d83a07935cc7154579241bbd
Showing with 287 additions and 177 deletions.
  1. +53 −3 include/net/net_if.h
  2. +234 −174 subsys/net/ip/net_if.c
@@ -133,15 +133,21 @@ struct net_if_ipv6_prefix {
* Stores the router information.
*/
struct net_if_router {
/** Router lifetime */
struct k_delayed_work lifetime;
/** Slist lifetime timer node */
sys_snode_t node;

/** IP address */
struct net_addr address;

/** Network interface the router is connected to */
struct net_if *iface;

/** Router life timer start */
u32_t life_start;

/** Router lifetime */
u16_t lifetime;

/** Is this router used or not */
u8_t is_used : 1;

@@ -1154,6 +1160,28 @@ void net_if_ipv6_prefix_unset_timer(struct net_if_ipv6_prefix *prefix);
*/
bool net_if_ipv6_addr_onlink(struct net_if **iface, struct in6_addr *addr);

/**
* @brief Get the IPv6 address of the given router
* @param router a network router
*
* @return pointer to the IPv6 address, or NULL if none
*/
#if defined(CONFIG_NET_IPV6)
static inline struct in6_addr *net_if_router_ipv6(struct net_if_router *router)
{
return &router->address.in6_addr;
}
#else
static inline struct in6_addr *net_if_router_ipv6(struct net_if_router *router)
{
static struct in6_addr addr;

ARG_UNUSED(router);

return &addr;
}
#endif

/**
* @brief Check if IPv6 address is one of the routers configured
* in the system.
@@ -1185,7 +1213,7 @@ struct net_if_router *net_if_ipv6_router_find_default(struct net_if *iface,
* @param lifetime Lifetime of this router.
*/
void net_if_ipv6_router_update_lifetime(struct net_if_router *router,
u32_t lifetime);
u16_t lifetime);

/**
* @brief Add IPv6 router to the system.
@@ -1566,6 +1594,28 @@ bool net_if_ipv4_maddr_rm(struct net_if *iface, const struct in_addr *addr);
struct net_if_mcast_addr *net_if_ipv4_maddr_lookup(const struct in_addr *addr,
struct net_if **iface);

/**
* @brief Get the IPv4 address of the given router
* @param router a network router
*
* @return pointer to the IPv4 address, or NULL if none
*/
#if defined(CONFIG_NET_IPV4)
static inline struct in_addr *net_if_router_ipv4(struct net_if_router *router)
{
return &router->address.in_addr;
}
#else
static inline struct in_addr *net_if_router_ipv4(struct net_if_router *router)
{
static struct in_addr addr;

ARG_UNUSED(router);

return &addr;
}
#endif

/**
* @brief Check if IPv4 address is one of the routers configured
* in the system.

0 comments on commit eccc268

Please sign in to comment.
You can’t perform that action at this time.