diff --git a/subsys/net/l2/ethernet/arp.c b/subsys/net/l2/ethernet/arp.c index bdc2c73e2af4..cfed4deb4428 100644 --- a/subsys/net/l2/ethernet/arp.c +++ b/subsys/net/l2/ethernet/arp.c @@ -220,13 +220,12 @@ static inline struct in_addr *if_get_addr(struct net_if *iface, struct in_addr *addr) { struct net_if_ipv4 *ipv4 = iface->config.ip.ipv4; - int i; if (!ipv4) { return NULL; } - for (i = 0; i < NET_IF_MAX_IPV4_ADDR; i++) { + ARRAY_FOR_EACH(ipv4->unicast, i) { if (ipv4->unicast[i].ipv4.is_used && ipv4->unicast[i].ipv4.address.family == AF_INET && ipv4->unicast[i].ipv4.addr_state == NET_ADDR_PREFERRED && diff --git a/subsys/net/lib/config/init.c b/subsys/net/lib/config/init.c index 65b15fcd91c7..6c21232d385b 100644 --- a/subsys/net/lib/config/init.c +++ b/subsys/net/lib/config/init.c @@ -62,13 +62,12 @@ static void ipv4_addr_add_handler(struct net_mgmt_event_callback *cb, #if CONFIG_NET_CONFIG_LOG_LEVEL >= LOG_LEVEL_INF char hr_addr[NET_IPV4_ADDR_LEN]; #endif - int i; if (mgmt_event != NET_EVENT_IPV4_ADDR_ADD) { return; } - for (i = 0; i < NET_IF_MAX_IPV4_ADDR; i++) { + ARRAY_FOR_EACH(iface->config.ip.ipv4->unicast, i) { struct net_if_addr *if_addr = &iface->config.ip.ipv4->unicast[i].ipv4; diff --git a/subsys/net/lib/shell/iface.c b/subsys/net/lib/shell/iface.c index b238846ba19d..5a31c6e8d59e 100644 --- a/subsys/net/lib/shell/iface.c +++ b/subsys/net/lib/shell/iface.c @@ -54,9 +54,8 @@ static void print_supported_ethernet_capabilities( const struct shell *sh, struct net_if *iface) { enum ethernet_hw_caps caps = net_eth_get_hw_capabilities(iface); - int i; - for (i = 0; i < ARRAY_SIZE(eth_hw_caps); i++) { + ARRAY_FOR_EACH(eth_hw_caps, i) { if (caps & eth_hw_caps[i].capability) { PR("\t%s\n", eth_hw_caps[i].description); } @@ -150,7 +149,7 @@ static void iface_cb(struct net_if *iface, void *user_data) #endif const char *extra; #if defined(CONFIG_NET_IP) - int i, count; + int count; #endif if (data->user_data && data->user_data != iface) { @@ -257,7 +256,7 @@ static void iface_cb(struct net_if *iface, void *user_data) if (!ret && params.priority_queues_num) { count = params.priority_queues_num; PR("Priority queues:\n"); - for (i = 0; i < count; ++i) { + for (int i = 0; i < count; ++i) { params.qav_param.queue_id = i; params.qav_param.type = ETHERNET_QAV_PARAM_TYPE_STATUS; @@ -290,7 +289,7 @@ static void iface_cb(struct net_if *iface, void *user_data) eth_ctx = net_if_l2_data(iface); if (eth_ctx->vlan_enabled) { - for (i = 0; i < CONFIG_NET_VLAN_COUNT; i++) { + for (int i = 0; i < CONFIG_NET_VLAN_COUNT; i++) { if (eth_ctx->vlan[i].iface != iface || eth_ctx->vlan[i].tag == NET_VLAN_TAG_UNSPEC) { @@ -316,17 +315,16 @@ static void iface_cb(struct net_if *iface, void *user_data) #if defined(CONFIG_NET_IPV6) count = 0; + ipv6 = iface->config.ip.ipv6; - if (!net_if_flag_is_set(iface, NET_IF_IPV6)) { + if (!net_if_flag_is_set(iface, NET_IF_IPV6) || ipv6 == NULL) { PR("%s not %s for this interface.\n", "IPv6", "enabled"); ipv6 = NULL; goto skip_ipv6; } - ipv6 = iface->config.ip.ipv6; - PR("IPv6 unicast addresses (max %d):\n", NET_IF_MAX_IPV6_ADDR); - for (i = 0; ipv6 && i < NET_IF_MAX_IPV6_ADDR; i++) { + ARRAY_FOR_EACH(ipv6->unicast, i) { unicast = &ipv6->unicast[i]; if (!unicast->is_used) { @@ -349,7 +347,7 @@ static void iface_cb(struct net_if *iface, void *user_data) count = 0; PR("IPv6 multicast addresses (max %d):\n", NET_IF_MAX_IPV6_MADDR); - for (i = 0; ipv6 && i < NET_IF_MAX_IPV6_MADDR; i++) { + ARRAY_FOR_EACH(ipv6->mcast, i) { mcast = &ipv6->mcast[i]; if (!mcast->is_used) { @@ -368,7 +366,7 @@ static void iface_cb(struct net_if *iface, void *user_data) count = 0; PR("IPv6 prefixes (max %d):\n", NET_IF_MAX_IPV6_PREFIX); - for (i = 0; ipv6 && i < NET_IF_MAX_IPV6_PREFIX; i++) { + ARRAY_FOR_EACH(ipv6->prefix, i) { prefix = &ipv6->prefix[i]; if (!prefix->is_used) { @@ -426,17 +424,16 @@ static void iface_cb(struct net_if *iface, void *user_data) } count = 0; + ipv4 = iface->config.ip.ipv4; - if (!net_if_flag_is_set(iface, NET_IF_IPV4)) { + if (!net_if_flag_is_set(iface, NET_IF_IPV4) || ipv4 == NULL) { PR("%s not %s for this interface.\n", "IPv4", "enabled"); ipv4 = NULL; goto skip_ipv4; } - ipv4 = iface->config.ip.ipv4; - PR("IPv4 unicast addresses (max %d):\n", NET_IF_MAX_IPV4_ADDR); - for (i = 0; ipv4 && i < NET_IF_MAX_IPV4_ADDR; i++) { + ARRAY_FOR_EACH(ipv4->unicast, i) { unicast = &ipv4->unicast[i].ipv4; if (!unicast->is_used) { @@ -461,7 +458,7 @@ static void iface_cb(struct net_if *iface, void *user_data) count = 0; PR("IPv4 multicast addresses (max %d):\n", NET_IF_MAX_IPV4_MADDR); - for (i = 0; ipv4 && i < NET_IF_MAX_IPV4_MADDR; i++) { + ARRAY_FOR_EACH(ipv4->mcast, i) { mcast = &ipv4->mcast[i]; if (!mcast->is_used) { diff --git a/subsys/net/lib/shell/ipv4.c b/subsys/net/lib/shell/ipv4.c index 3da6d4777090..cb4d0c7f2138 100644 --- a/subsys/net/lib/shell/ipv4.c +++ b/subsys/net/lib/shell/ipv4.c @@ -20,7 +20,6 @@ static void ip_address_lifetime_cb(struct net_if *iface, void *user_data) const struct shell *sh = data->sh; struct net_if_ipv4 *ipv4 = iface->config.ip.ipv4; const char *extra; - int i; ARG_UNUSED(user_data); @@ -35,7 +34,7 @@ static void ip_address_lifetime_cb(struct net_if *iface, void *user_data) PR("Type \tState \tLifetime (sec)\tAddress\n"); - for (i = 0; i < NET_IF_MAX_IPV4_ADDR; i++) { + ARRAY_FOR_EACH(ipv4->unicast, i) { if (!ipv4->unicast[i].ipv4.is_used || ipv4->unicast[i].ipv4.address.family != AF_INET) { continue; diff --git a/subsys/net/lib/shell/ipv6.c b/subsys/net/lib/shell/ipv6.c index 04efda65d0f8..ef5a90fca70f 100644 --- a/subsys/net/lib/shell/ipv6.c +++ b/subsys/net/lib/shell/ipv6.c @@ -62,7 +62,6 @@ static void address_lifetime_cb(struct net_if *iface, void *user_data) const struct shell *sh = data->sh; struct net_if_ipv6 *ipv6 = iface->config.ip.ipv6; const char *extra; - int i; ARG_UNUSED(user_data); @@ -77,7 +76,7 @@ static void address_lifetime_cb(struct net_if *iface, void *user_data) PR("Type \tState \tLifetime (sec)\tAddress\n"); - for (i = 0; i < NET_IF_MAX_IPV6_ADDR; i++) { + ARRAY_FOR_EACH(ipv6->unicast, i) { struct net_if_ipv6_prefix *prefix; char remaining_str[sizeof("01234567890")]; uint64_t remaining;