Skip to content
Permalink
Browse files

net/iface: Add a function to get IPv4 global address

As for IPv6, let's create the same function on IPv4 side.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
  • Loading branch information...
tbursztyka authored and jukkar committed May 14, 2019
1 parent 979aedf commit 426764ebcfff5a28562edebbd92092a424e1c80f
Showing with 39 additions and 5 deletions.
  1. +12 −0 include/net/net_if.h
  2. +27 −5 subsys/net/ip/net_if.c
@@ -1563,6 +1563,18 @@ const struct in_addr *net_if_ipv4_select_src_addr(struct net_if *iface,
struct in_addr *net_if_ipv4_get_ll(struct net_if *iface,
enum net_addr_state addr_state);

/**
* @brief Get a IPv4 global address in a given state.
*
* @param iface Interface to use. Must be a valid pointer to an interface.
* @param addr_state IPv4 address state (preferred, tentative, deprecated)
*
* @return Pointer to link local IPv4 address, NULL if no proper IPv4 address
* could be found.
*/
struct in_addr *net_if_ipv4_get_global_addr(struct net_if *iface,
enum net_addr_state addr_state);

/**
* @brief Set IPv4 netmask for an interface.
*
@@ -2332,10 +2332,10 @@ static struct in_addr *net_if_ipv4_get_best_match(struct net_if *iface,
}
#endif /* CONFIG_NET_IPV4 */

struct in_addr *net_if_ipv4_get_ll(struct net_if *iface,
enum net_addr_state addr_state)
{
#if defined(CONFIG_NET_IPV4)
static struct in_addr *if_ipv4_get_addr(struct net_if *iface,
enum net_addr_state addr_state, bool ll)
{
struct net_if_ipv4 *ipv4 = iface->config.ip.ipv4;
int i;

@@ -2352,13 +2352,35 @@ struct in_addr *net_if_ipv4_get_ll(struct net_if *iface,
}

if (net_ipv4_is_ll_addr(&ipv4->unicast[i].address.in_addr)) {
return &ipv4->unicast[i].address.in_addr;
if (!ll) {
continue;
}
} else {
if (ll) {
continue;
}
}

return &ipv4->unicast[i].address.in_addr;
}
#endif

return NULL;
}
#else
#define if_ipv4_get_addr(...) NULL
#endif

struct in_addr *net_if_ipv4_get_ll(struct net_if *iface,
enum net_addr_state addr_state)
{
return if_ipv4_get_addr(iface, addr_state, true);
}

struct in_addr *net_if_ipv4_get_global_addr(struct net_if *iface,
enum net_addr_state addr_state)
{
return if_ipv4_get_addr(iface, addr_state, false);
}

const struct in_addr *net_if_ipv4_select_src_addr(struct net_if *dst_iface,
const struct in_addr *dst)

0 comments on commit 426764e

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