net: IP address lookup functions return interface

When checking the IP address from network interface, return
also the used network interface.

Change-Id: If7b8385193da4cb1b469f697e219cfae3b6477dd
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
Jukka Rissanen 2016-06-22 15:34:47 +03:00
commit 2658ac7a73
5 changed files with 43 additions and 14 deletions

View file

@ -410,10 +410,12 @@ struct net_if *net_if_get_default(void);
* @brief Check if this IPv6 address belongs to one of the interfaces.
*
* @param addr IPv6 address
* @param iface Pointer to interface is returned
*
* @return Pointer to interface address, NULL if not found.
*/
struct net_if_addr *net_if_ipv6_addr_lookup(struct in6_addr *addr);
struct net_if_addr *net_if_ipv6_addr_lookup(const struct in6_addr *addr,
struct net_if **iface);
/**
* @brief Check if this IPv6 address belongs to this specific interfaces.
@ -496,10 +498,12 @@ bool net_if_ipv6_maddr_rm(struct net_if *iface, struct in6_addr *addr);
* @brief Check if this IPv6 multicast address belongs to one of the interfaces.
*
* @param addr IPv6 address
* @param iface Pointer to interface is returned
*
* @return Pointer to interface multicast address, NULL if not found.
*/
struct net_if_mcast_addr *net_if_ipv6_maddr_lookup(struct in6_addr *addr);
struct net_if_mcast_addr *net_if_ipv6_maddr_lookup(const struct in6_addr *addr,
struct net_if **iface);
/**
* @brief Check if this IPv6 prefix belongs to this interface
@ -723,10 +727,12 @@ static inline uint8_t net_if_ipv4_get_ttl(struct net_if *iface)
* @brief Check if this IPv4 address belongs to one of the interfaces.
*
* @param addr IPv4 address
* @param iface Interface is returned
*
* @return Pointer to interface address, NULL if not found.
*/
struct net_if_addr *net_if_ipv4_addr_lookup(struct in_addr *addr);
struct net_if_addr *net_if_ipv4_addr_lookup(const struct in_addr *addr,
struct net_if **iface);
/**
* @brief Add a IPv4 address to an interface

View file

@ -244,7 +244,10 @@ static inline bool net_is_ipv6_addr_mcast(struct in6_addr *addr)
return addr->s6_addr[0] == 0xFF;
}
extern struct net_if_addr *net_if_ipv6_addr_lookup(struct in6_addr *addr);
struct net_if;
extern struct net_if_addr *net_if_ipv6_addr_lookup(const struct in6_addr *addr,
struct net_if **iface);
/**
* @brief Check if IPv6 address is found in one of the network interfaces.
@ -255,10 +258,11 @@ extern struct net_if_addr *net_if_ipv6_addr_lookup(struct in6_addr *addr);
*/
static inline bool net_is_my_ipv6_addr(struct in6_addr *addr)
{
return net_if_ipv6_addr_lookup(addr) != NULL;
return net_if_ipv6_addr_lookup(addr, NULL) != NULL;
}
extern struct net_if_mcast_addr *net_if_ipv6_maddr_lookup(struct in6_addr *addr);
extern struct net_if_mcast_addr *net_if_ipv6_maddr_lookup(const struct in6_addr *addr,
struct net_if **iface);
/**
* @brief Check if IPv6 multicast address is found in one of the
@ -270,7 +274,7 @@ extern struct net_if_mcast_addr *net_if_ipv6_maddr_lookup(struct in6_addr *addr)
*/
static inline bool net_is_my_ipv6_maddr(struct in6_addr *maddr)
{
return net_if_ipv6_maddr_lookup(maddr) != NULL;
return net_if_ipv6_maddr_lookup(maddr, NULL) != NULL;
}
/**
@ -302,7 +306,8 @@ static inline bool net_is_ipv6_prefix(uint8_t *addr1, uint8_t *addr2,
(addr2[16 - bytes] & ((8 - remain) << 8)));
}
extern struct net_if_addr *net_if_ipv4_addr_lookup(struct in_addr *addr);
extern struct net_if_addr *net_if_ipv4_addr_lookup(const struct in_addr *addr,
struct net_if **iface);
/**
* @brief Check if the IPv4 address is assigned to any network interface
@ -315,7 +320,7 @@ extern struct net_if_addr *net_if_ipv4_addr_lookup(struct in_addr *addr);
*/
static inline bool net_is_my_ipv4_addr(struct in_addr *addr)
{
return net_if_ipv4_addr_lookup(addr) != NULL;
return net_if_ipv4_addr_lookup(addr, NULL) != NULL;
}
/**

View file

@ -1085,7 +1085,7 @@ static inline void handle_prefix_autonomous(struct net_buf *buf,
net_ipv6_addr_create_iid(&addr,
net_if_get_link_addr(net_nbuf_iface(buf)));
ifaddr = net_if_ipv6_addr_lookup(&addr);
ifaddr = net_if_ipv6_addr_lookup(&addr, NULL);
if (ifaddr && ifaddr->addr_type == NET_ADDR_AUTOCONF) {
if (prefix_info->valid_lifetime ==
NET_IPV6_ND_INFINITE_LIFETIME) {

View file

@ -190,7 +190,8 @@ void net_if_start_rs(struct net_if *iface)
}
#endif /* CONFIG_NET_IPV6_ND */
struct net_if_addr *net_if_ipv6_addr_lookup(struct in6_addr *addr)
struct net_if_addr *net_if_ipv6_addr_lookup(const struct in6_addr *addr,
struct net_if **ret)
{
struct net_if *iface;
@ -206,6 +207,11 @@ struct net_if_addr *net_if_ipv6_addr_lookup(struct in6_addr *addr)
if (net_is_ipv6_prefix(addr->s6_addr,
iface->ipv6.unicast[i].address.in6_addr.s6_addr,
128)) {
if (ret) {
*ret = iface;
}
return &iface->ipv6.unicast[i];
}
}
@ -339,7 +345,8 @@ bool net_if_ipv6_maddr_rm(struct net_if *iface, struct in6_addr *addr)
return false;
}
struct net_if_mcast_addr *net_if_ipv6_maddr_lookup(struct in6_addr *maddr)
struct net_if_mcast_addr *net_if_ipv6_maddr_lookup(const struct in6_addr *maddr,
struct net_if **ret)
{
struct net_if *iface;
@ -355,6 +362,11 @@ struct net_if_mcast_addr *net_if_ipv6_maddr_lookup(struct in6_addr *maddr)
if (net_is_ipv6_prefix(maddr->s6_addr,
iface->ipv6.mcast[i].address.in6_addr.s6_addr,
128)) {
if (ret) {
*ret = iface;
}
return &iface->ipv6.mcast[i];
}
}
@ -733,7 +745,8 @@ bool net_if_ipv4_addr_mask_cmp(struct net_if *iface,
return false;
}
struct net_if_addr *net_if_ipv4_addr_lookup(struct in_addr *addr)
struct net_if_addr *net_if_ipv4_addr_lookup(const struct in_addr *addr,
struct net_if **ret)
{
struct net_if *iface;
@ -748,6 +761,11 @@ struct net_if_addr *net_if_ipv4_addr_lookup(struct in_addr *addr)
if (addr->s4_addr32[0] ==
iface->ipv4.unicast[i].address.in_addr.s_addr[0]) {
if (ret) {
*ret = iface;
}
return &iface->ipv4.unicast[i];
}
}

View file

@ -252,7 +252,7 @@ void main(void)
return;
}
ifaddr2 = net_if_ipv6_addr_lookup(&addr6);
ifaddr2 = net_if_ipv6_addr_lookup(&addr6, NULL);
if (ifaddr1 != ifaddr2) {
printk("IPv6 interface address mismatch\n");
return;