Skip to content
Permalink
Browse files

net/iface: Modify function to get IPv6 global address

Let's filter out on a state parameter.

There is no impact as this function is not used anywhere yet.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
  • Loading branch information...
tbursztyka authored and jukkar committed May 14, 2019
1 parent 60cb25d commit 979aedfab4e1eaecc27686a3a0a2f470bcf26f18
Showing with 34 additions and 29 deletions.
  1. +4 −2 include/net/net_if.h
  2. +30 −27 subsys/net/ip/net_if.c
@@ -1353,15 +1353,17 @@ void net_if_ipv6_dad_failed(struct net_if *iface, const struct in6_addr *addr);

/**
* @brief Return global IPv6 address from the first interface that has
* a global IPv6 address either in TENTATIVE or PREFERRED state.
* a global IPv6 address matching the given state.
*
* @param state IPv6 address state (ANY, TENTATIVE, PREFERRED, DEPRECATED)
* @param iface Caller can give an interface to check. If iface is set to NULL,
* then all the interfaces are checked. Pointer to interface where the IPv6
* address is defined is returned to the caller.
*
* @return Pointer to IPv6 address, NULL if not found.
*/
struct in6_addr *net_if_ipv6_get_global_addr(struct net_if **iface);
struct in6_addr *net_if_ipv6_get_global_addr(enum net_addr_state state,
struct net_if **iface);

/**
* @brief Allocate network interface IPv4 config.
@@ -958,31 +958,6 @@ static inline void net_if_addr_init(struct net_if_addr *ifaddr,
}
}

static inline struct in6_addr *check_global_addr(struct net_if *iface)
{
struct net_if_ipv6 *ipv6 = iface->config.ip.ipv6;
int i;

if (!ipv6) {
return NULL;
}

for (i = 0; i < NET_IF_MAX_IPV6_ADDR; i++) {
if (!ipv6->unicast[i].is_used ||
(ipv6->unicast[i].addr_state != NET_ADDR_TENTATIVE &&
ipv6->unicast[i].addr_state != NET_ADDR_PREFERRED) ||
ipv6->unicast[i].address.family != AF_INET6) {
continue;
}

if (!net_ipv6_is_ll_addr(&ipv6->unicast[i].address.in6_addr)) {
return &ipv6->unicast[i].address.in6_addr;
}
}

return NULL;
}

static void join_mcast_nodes(struct net_if *iface, struct in6_addr *addr)
{
enum net_l2_flags flags = 0;
@@ -1890,7 +1865,35 @@ struct in6_addr *net_if_ipv6_get_ll_addr(enum net_addr_state state,
return NULL;
}

struct in6_addr *net_if_ipv6_get_global_addr(struct net_if **iface)
#if defined(CONFIG_NET_IPV6)
static inline struct in6_addr *check_global_addr(struct net_if *iface,
enum net_addr_state state)
{
struct net_if_ipv6 *ipv6 = iface->config.ip.ipv6;
int i;

if (!ipv6) {
return NULL;
}

for (i = 0; i < NET_IF_MAX_IPV6_ADDR; i++) {
if (!ipv6->unicast[i].is_used ||
(ipv6->unicast[i].addr_state != state) ||
ipv6->unicast[i].address.family != AF_INET6) {
continue;
}

if (!net_ipv6_is_ll_addr(&ipv6->unicast[i].address.in6_addr)) {
return &ipv6->unicast[i].address.in6_addr;
}
}

return NULL;
}
#endif

struct in6_addr *net_if_ipv6_get_global_addr(enum net_addr_state state,
struct net_if **iface)
{
#if defined(CONFIG_NET_IPV6)
struct net_if *tmp;
@@ -1902,7 +1905,7 @@ struct in6_addr *net_if_ipv6_get_global_addr(struct net_if **iface)
continue;
}

addr = check_global_addr(tmp);
addr = check_global_addr(tmp, state);
if (addr) {
if (iface) {
*iface = tmp;

0 comments on commit 979aedf

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