net: if: Check IPv4 pointers properly in TTL setters/getters

We must make sure that IPv4 configuration pointer is valid
so that the TTL can be set for a given interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
This commit is contained in:
Jukka Rissanen 2024-02-07 09:52:29 +02:00 committed by Alberto Escolar
parent dceff4a98f
commit e7b1d6d8aa

View file

@ -3165,6 +3165,10 @@ uint8_t net_if_ipv4_get_ttl(struct net_if *iface)
net_if_lock(iface);
if (net_if_config_ipv4_get(iface, NULL) < 0) {
goto out;
}
if (!iface->config.ip.ipv4) {
goto out;
}
@ -3186,6 +3190,10 @@ void net_if_ipv4_set_ttl(struct net_if *iface, uint8_t ttl)
#if defined(CONFIG_NET_NATIVE_IPV4)
net_if_lock(iface);
if (net_if_config_ipv4_get(iface, NULL) < 0) {
goto out;
}
if (!iface->config.ip.ipv4) {
goto out;
}
@ -3206,6 +3214,10 @@ uint8_t net_if_ipv4_get_mcast_ttl(struct net_if *iface)
net_if_lock(iface);
if (net_if_config_ipv4_get(iface, NULL) < 0) {
goto out;
}
if (!iface->config.ip.ipv4) {
goto out;
}
@ -3227,6 +3239,10 @@ void net_if_ipv4_set_mcast_ttl(struct net_if *iface, uint8_t ttl)
#if defined(CONFIG_NET_NATIVE_IPV4)
net_if_lock(iface);
if (net_if_config_ipv4_get(iface, NULL) < 0) {
goto out;
}
if (!iface->config.ip.ipv4) {
goto out;
}