Skip to content

Commit

Permalink
net: if: Check IPv4 pointers properly in TTL setters/getters
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
jukkar authored and aescolar committed Feb 26, 2024
1 parent dceff4a commit e7b1d6d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions subsys/net/ip/net_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit e7b1d6d

Please sign in to comment.