net: if: Add locking when setting/getting hoplimit or ttl
Locking was missing when setting or getting IPv6 hop limit or IPv4 time-to-live values. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
parent
b07ba6db85
commit
97bf53fdcf
2 changed files with 86 additions and 45 deletions
|
@ -1289,18 +1289,7 @@ bool net_if_ipv6_router_rm(struct net_if_router *router);
|
||||||
*
|
*
|
||||||
* @return Hop limit
|
* @return Hop limit
|
||||||
*/
|
*/
|
||||||
static inline uint8_t net_if_ipv6_get_hop_limit(struct net_if *iface)
|
uint8_t net_if_ipv6_get_hop_limit(struct net_if *iface);
|
||||||
{
|
|
||||||
#if defined(CONFIG_NET_NATIVE_IPV6)
|
|
||||||
if (!iface->config.ip.ipv6) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return iface->config.ip.ipv6->hop_limit;
|
|
||||||
#else
|
|
||||||
return 0;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the default IPv6 hop limit of a given interface.
|
* @brief Set the default IPv6 hop limit of a given interface.
|
||||||
|
@ -1308,17 +1297,7 @@ static inline uint8_t net_if_ipv6_get_hop_limit(struct net_if *iface)
|
||||||
* @param iface Network interface
|
* @param iface Network interface
|
||||||
* @param hop_limit New hop limit
|
* @param hop_limit New hop limit
|
||||||
*/
|
*/
|
||||||
static inline void net_ipv6_set_hop_limit(struct net_if *iface,
|
void net_ipv6_set_hop_limit(struct net_if *iface, uint8_t hop_limit);
|
||||||
uint8_t hop_limit)
|
|
||||||
{
|
|
||||||
#if defined(CONFIG_NET_NATIVE_IPV6)
|
|
||||||
if (!iface->config.ip.ipv6) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
iface->config.ip.ipv6->hop_limit = hop_limit;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set IPv6 reachable time for a given interface
|
* @brief Set IPv6 reachable time for a given interface
|
||||||
|
@ -1540,18 +1519,7 @@ int net_if_config_ipv4_put(struct net_if *iface);
|
||||||
*
|
*
|
||||||
* @return Time-to-live
|
* @return Time-to-live
|
||||||
*/
|
*/
|
||||||
static inline uint8_t net_if_ipv4_get_ttl(struct net_if *iface)
|
uint8_t net_if_ipv4_get_ttl(struct net_if *iface);
|
||||||
{
|
|
||||||
#if defined(CONFIG_NET_NATIVE_IPV4)
|
|
||||||
if (!iface->config.ip.ipv4) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return iface->config.ip.ipv4->ttl;
|
|
||||||
#else
|
|
||||||
return 0;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set IPv4 time-to-live value specified to a given interface
|
* @brief Set IPv4 time-to-live value specified to a given interface
|
||||||
|
@ -1559,16 +1527,7 @@ static inline uint8_t net_if_ipv4_get_ttl(struct net_if *iface)
|
||||||
* @param iface Network interface
|
* @param iface Network interface
|
||||||
* @param ttl Time-to-live value
|
* @param ttl Time-to-live value
|
||||||
*/
|
*/
|
||||||
static inline void net_if_ipv4_set_ttl(struct net_if *iface, uint8_t ttl)
|
void net_if_ipv4_set_ttl(struct net_if *iface, uint8_t ttl);
|
||||||
{
|
|
||||||
#if defined(CONFIG_NET_NATIVE_IPV4)
|
|
||||||
if (!iface->config.ip.ipv4) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
iface->config.ip.ipv4->ttl = ttl;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Check if this IPv4 address belongs to one of the interfaces.
|
* @brief Check if this IPv4 address belongs to one of the interfaces.
|
||||||
|
|
|
@ -2473,6 +2473,47 @@ bool net_if_ipv6_router_rm(struct net_if_router *router)
|
||||||
return iface_router_rm(router);
|
return iface_router_rm(router);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t net_if_ipv6_get_hop_limit(struct net_if *iface)
|
||||||
|
{
|
||||||
|
#if defined(CONFIG_NET_NATIVE_IPV6)
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
k_mutex_lock(&lock, K_FOREVER);
|
||||||
|
|
||||||
|
if (!iface->config.ip.ipv6) {
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = iface->config.ip.ipv6->hop_limit;
|
||||||
|
out:
|
||||||
|
k_mutex_unlock(&lock);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
#else
|
||||||
|
ARG_UNUSED(iface);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void net_ipv6_set_hop_limit(struct net_if *iface, uint8_t hop_limit)
|
||||||
|
{
|
||||||
|
#if defined(CONFIG_NET_NATIVE_IPV6)
|
||||||
|
k_mutex_lock(&lock, K_FOREVER);
|
||||||
|
|
||||||
|
if (!iface->config.ip.ipv6) {
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
iface->config.ip.ipv6->hop_limit = hop_limit;
|
||||||
|
out:
|
||||||
|
k_mutex_unlock(&lock);
|
||||||
|
#else
|
||||||
|
ARG_UNUSED(iface);
|
||||||
|
ARG_UNUSED(hop_limit);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
struct in6_addr *net_if_ipv6_get_ll(struct net_if *iface,
|
struct in6_addr *net_if_ipv6_get_ll(struct net_if *iface,
|
||||||
enum net_addr_state addr_state)
|
enum net_addr_state addr_state)
|
||||||
{
|
{
|
||||||
|
@ -2887,6 +2928,47 @@ out:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t net_if_ipv4_get_ttl(struct net_if *iface)
|
||||||
|
{
|
||||||
|
#if defined(CONFIG_NET_NATIVE_IPV4)
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
k_mutex_lock(&lock, K_FOREVER);
|
||||||
|
|
||||||
|
if (!iface->config.ip.ipv4) {
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = iface->config.ip.ipv4->ttl;
|
||||||
|
out:
|
||||||
|
k_mutex_unlock(&lock);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
#else
|
||||||
|
ARG_UNUSED(iface);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void net_if_ipv4_set_ttl(struct net_if *iface, uint8_t ttl)
|
||||||
|
{
|
||||||
|
#if defined(CONFIG_NET_NATIVE_IPV4)
|
||||||
|
k_mutex_lock(&lock, K_FOREVER);
|
||||||
|
|
||||||
|
if (!iface->config.ip.ipv4) {
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
iface->config.ip.ipv4->ttl = ttl;
|
||||||
|
out:
|
||||||
|
k_mutex_unlock(&lock);
|
||||||
|
#else
|
||||||
|
ARG_UNUSED(iface);
|
||||||
|
ARG_UNUSED(ttl);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
struct net_if_router *net_if_ipv4_router_lookup(struct net_if *iface,
|
struct net_if_router *net_if_ipv4_router_lookup(struct net_if *iface,
|
||||||
struct in_addr *addr)
|
struct in_addr *addr)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue