Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ipv6: Remove in6addr_any alternatives.

Some code defines the IPv6 wildcard address as a local variable and
use it with memcmp() or ipv6_addr_equal().

Let's use in6addr_any and ipv6_addr_any() instead.

Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Kuniyuki Iwashima and committed by
David S. Miller
8cdc3223 5a8c8b72

+17 -28
+2 -3
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c
··· 98 98 #if IS_ENABLED(CONFIG_INET) && IS_ENABLED(CONFIG_IPV6) 99 99 else if (ip_version == 6) { 100 100 int ipv6_size = MLX5_FLD_SZ_BYTES(ipv6_layout, ipv6); 101 - struct in6_addr zerov6 = {}; 102 101 103 102 daddr = MLX5_ADDR_OF(fte_match_param, spec->match_value, 104 103 outer_headers.dst_ipv4_dst_ipv6.ipv6_layout.ipv6); ··· 105 106 outer_headers.src_ipv4_src_ipv6.ipv6_layout.ipv6); 106 107 memcpy(&tun_attr->dst_ip.v6, daddr, ipv6_size); 107 108 memcpy(&tun_attr->src_ip.v6, saddr, ipv6_size); 108 - if (!memcmp(&tun_attr->dst_ip.v6, &zerov6, sizeof(zerov6)) || 109 - !memcmp(&tun_attr->src_ip.v6, &zerov6, sizeof(zerov6))) 109 + if (ipv6_addr_any(&tun_attr->dst_ip.v6) || 110 + ipv6_addr_any(&tun_attr->src_ip.v6)) 110 111 return 0; 111 112 } 112 113 #endif
+3 -6
include/net/ip6_fib.h
··· 469 469 rcu_read_lock(); 470 470 471 471 from = rcu_dereference(rt->from); 472 - if (from) { 472 + if (from) 473 473 *addr = from->fib6_prefsrc.addr; 474 - } else { 475 - struct in6_addr in6_zero = {}; 476 - 477 - *addr = in6_zero; 478 - } 474 + else 475 + *addr = in6addr_any; 479 476 480 477 rcu_read_unlock(); 481 478 }
+2 -3
include/trace/events/fib.h
··· 36 36 ), 37 37 38 38 TP_fast_assign( 39 - struct in6_addr in6_zero = {}; 40 39 struct net_device *dev; 41 40 struct in6_addr *in6; 42 41 __be32 *p32; ··· 73 74 *p32 = nhc->nhc_gw.ipv4; 74 75 75 76 in6 = (struct in6_addr *)__entry->gw6; 76 - *in6 = in6_zero; 77 + *in6 = in6addr_any; 77 78 } else if (nhc->nhc_gw_family == AF_INET6) { 78 79 p32 = (__be32 *) __entry->gw4; 79 80 *p32 = 0; ··· 86 87 *p32 = 0; 87 88 88 89 in6 = (struct in6_addr *)__entry->gw6; 89 - *in6 = in6_zero; 90 + *in6 = in6addr_any; 90 91 } 91 92 ), 92 93
+1 -4
include/trace/events/fib6.h
··· 68 68 strcpy(__entry->name, "-"); 69 69 } 70 70 if (res->f6i == net->ipv6.fib6_null_entry) { 71 - struct in6_addr in6_zero = {}; 72 - 73 71 in6 = (struct in6_addr *)__entry->gw; 74 - *in6 = in6_zero; 75 - 72 + *in6 = in6addr_any; 76 73 } else if (res->nh) { 77 74 in6 = (struct in6_addr *)__entry->gw; 78 75 *in6 = res->nh->fib_nh_gw6;
+5 -5
net/ethtool/ioctl.c
··· 27 27 #include <linux/net.h> 28 28 #include <linux/pm_runtime.h> 29 29 #include <net/devlink.h> 30 + #include <net/ipv6.h> 30 31 #include <net/xdp_sock_drv.h> 31 32 #include <net/flow_offload.h> 32 33 #include <linux/ethtool_netlink.h> ··· 3128 3127 ethtool_rx_flow_rule_create(const struct ethtool_rx_flow_spec_input *input) 3129 3128 { 3130 3129 const struct ethtool_rx_flow_spec *fs = input->fs; 3131 - static struct in6_addr zero_addr = {}; 3132 3130 struct ethtool_rx_flow_match *match; 3133 3131 struct ethtool_rx_flow_rule *flow; 3134 3132 struct flow_action_entry *act; ··· 3233 3233 3234 3234 v6_spec = &fs->h_u.tcp_ip6_spec; 3235 3235 v6_m_spec = &fs->m_u.tcp_ip6_spec; 3236 - if (memcmp(v6_m_spec->ip6src, &zero_addr, sizeof(zero_addr))) { 3236 + if (!ipv6_addr_any((struct in6_addr *)v6_m_spec->ip6src)) { 3237 3237 memcpy(&match->key.ipv6.src, v6_spec->ip6src, 3238 3238 sizeof(match->key.ipv6.src)); 3239 3239 memcpy(&match->mask.ipv6.src, v6_m_spec->ip6src, 3240 3240 sizeof(match->mask.ipv6.src)); 3241 3241 } 3242 - if (memcmp(v6_m_spec->ip6dst, &zero_addr, sizeof(zero_addr))) { 3242 + if (!ipv6_addr_any((struct in6_addr *)v6_m_spec->ip6dst)) { 3243 3243 memcpy(&match->key.ipv6.dst, v6_spec->ip6dst, 3244 3244 sizeof(match->key.ipv6.dst)); 3245 3245 memcpy(&match->mask.ipv6.dst, v6_m_spec->ip6dst, 3246 3246 sizeof(match->mask.ipv6.dst)); 3247 3247 } 3248 - if (memcmp(v6_m_spec->ip6src, &zero_addr, sizeof(zero_addr)) || 3249 - memcmp(v6_m_spec->ip6dst, &zero_addr, sizeof(zero_addr))) { 3248 + if (!ipv6_addr_any((struct in6_addr *)v6_m_spec->ip6src) || 3249 + !ipv6_addr_any((struct in6_addr *)v6_m_spec->ip6dst)) { 3250 3250 match->dissector.used_keys |= 3251 3251 BIT(FLOW_DISSECTOR_KEY_IPV6_ADDRS); 3252 3252 match->dissector.offset[FLOW_DISSECTOR_KEY_IPV6_ADDRS] =
+4 -7
net/ipv4/inet_hashtables.c
··· 826 826 unsigned short port, int l3mdev, const struct sock *sk) 827 827 { 828 828 #if IS_ENABLED(CONFIG_IPV6) 829 - struct in6_addr addr_any = {}; 830 - 831 829 if (sk->sk_family != tb->family) { 832 830 if (sk->sk_family == AF_INET) 833 831 return net_eq(ib2_net(tb), net) && tb->port == port && 834 832 tb->l3mdev == l3mdev && 835 - ipv6_addr_equal(&tb->v6_rcv_saddr, &addr_any); 833 + ipv6_addr_any(&tb->v6_rcv_saddr); 836 834 837 835 return false; 838 836 } ··· 838 840 if (sk->sk_family == AF_INET6) 839 841 return net_eq(ib2_net(tb), net) && tb->port == port && 840 842 tb->l3mdev == l3mdev && 841 - ipv6_addr_equal(&tb->v6_rcv_saddr, &addr_any); 843 + ipv6_addr_any(&tb->v6_rcv_saddr); 842 844 else 843 845 #endif 844 846 return net_eq(ib2_net(tb), net) && tb->port == port && ··· 864 866 { 865 867 struct inet_hashinfo *hinfo = tcp_or_dccp_get_hashinfo(sk); 866 868 u32 hash; 867 - #if IS_ENABLED(CONFIG_IPV6) 868 - struct in6_addr addr_any = {}; 869 869 870 + #if IS_ENABLED(CONFIG_IPV6) 870 871 if (sk->sk_family == AF_INET6) 871 - hash = ipv6_portaddr_hash(net, &addr_any, port); 872 + hash = ipv6_portaddr_hash(net, &in6addr_any, port); 872 873 else 873 874 #endif 874 875 hash = ipv4_portaddr_hash(net, 0, port);