ipv6: Random cleanup for in6addr_any.
Subsystems (8)
cover ipv6: Random cleanup for in6addr_any.
The first patch removes in6addr_any alternatives and the second removes redundant initialisation of a local variable.
Kuniyuki Iwashima (2):
ipv6: Remove in6addr_any alternatives.
6lowpan: Remove redundant initialisation of struct in6_addr.
.../net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c | 5 ++--- include/net/ip6_fib.h | 9 +++------ include/trace/events/fib.h | 5 ++--- include/trace/events/fib6.h | 5 +---- net/6lowpan/iphc.c | 2 +- net/ethtool/ioctl.c | 9 ++++----- net/ipv4/inet_hashtables.c | 11 ++++------- 7 files changed, 17 insertions(+), 29 deletions(-)
Signature · 1 line
2.30.2
PATCH 1/2 ipv6: Remove in6addr_any alternatives.
Some code defines the IPv6 wildcard address as a local variable. Let's use in6addr_any instead.
--- .../net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c | 5 ++--- include/net/ip6_fib.h | 9 +++------ include/trace/events/fib.h | 5 ++--- include/trace/events/fib6.h | 5 +---- net/ethtool/ioctl.c | 9 ++++----- net/ipv4/inet_hashtables.c | 11 ++++------- 6 files changed, 16 insertions(+), 28 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +2 -3
@@ -98,7 +98,6 @@ int mlx5e_tc_set_attr_rx_tun(struct mlx5e_tc_flow *flow,#if IS_ENABLED (CONFIG_INET ) &&IS_ENABLED (CONFIG_IPV6 ) else if (ip_version == 6) {int ipv6_size =MLX5_FLD_SZ_BYTES (ipv6_layout, ipv6); -struct in6_addr zerov6 = {}; daddr =MLX5_ADDR_OF (fte_match_param, spec->match_value, outer_headers.dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
@@ -106,8 +105,8 @@ int mlx5e_tc_set_attr_rx_tun(struct mlx5e_tc_flow *flow, outer_headers.src_ipv4_src_ipv6.ipv6_layout.ipv6);memcpy (&tun_attr->dst_ip.v6, daddr, ipv6_size);memcpy (&tun_attr->src_ip.v6, saddr, ipv6_size); -if (!memcmp (&tun_attr->dst_ip.v6, &zerov6,sizeof (zerov6)) || - !memcmp (&tun_attr->src_ip.v6, &zerov6,sizeof (zerov6))) +if (!memcmp (&tun_attr->dst_ip.v6, &in6addr_any,sizeof (in6addr_any)) || + !memcmp (&tun_attr->src_ip.v6, &in6addr_any,sizeof (in6addr_any))) return 0; }#endif
include/net/ip6_fib.h +3 -6
@@ -472,13 +472,10 @@ void rt6_get_prefsrc(const struct rt6_info *rt, struct in6_addr *addr)rcu_read_lock (); from =rcu_dereference (rt->from); -if (from) { +if (from) *addr = from->fib6_prefsrc.addr; - }else { -struct in6_addr in6_zero = {}; - - *addr = in6_zero; - } +else + *addr = in6addr_any;rcu_read_unlock (); }
include/trace/events/fib.h +2 -3
@@ -36,7 +36,6 @@ TRACE_EVENT(fib_table_lookup, ),TP_fast_assign ( - struct in6_addr in6_zero = {}; struct net_device *dev;struct in6_addr *in6;__be32 *p32;
@@ -74,7 +73,7 @@ TRACE_EVENT(fib_table_lookup, *p32 = nhc->nhc_gw.ipv4; in6 = (struct in6_addr *)__entry->gw6; - *in6 = in6_zero; + *in6 = in6addr_any; }else if (nhc->nhc_gw_family ==AF_INET6 ) { p32 = (__be32 *) __entry->gw4; *p32 =0 ;
@@ -87,7 +86,7 @@ TRACE_EVENT(fib_table_lookup, *p32 =0 ; in6 = (struct in6_addr *)__entry->gw6; - *in6 = in6_zero; + *in6 = in6addr_any; } ),
include/trace/events/fib6.h +1 -4
@@ -68,11 +68,8 @@ TRACE_EVENT(fib6_table_lookup,strcpy (__entry->name,"-" ); }if (res->f6i == net->ipv6.fib6_null_entry) { -struct in6_addr in6_zero = {}; - in6 = (struct in6_addr *)__entry->gw; - *in6 = in6_zero; - + *in6 = in6addr_any; }else if (res->nh) { in6 = (struct in6_addr *)__entry->gw; *in6 = res->nh->fib_nh_gw6;
net/ethtool/ioctl.c +4 -5
@@ -3127,7 +3127,6 @@ struct ethtool_rx_flow_rule * ethtool_rx_flow_rule_create(const struct ethtool_rx_flow_spec_input *input) {const struct ethtool_rx_flow_spec *fs = input->fs; -static struct in6_addr zero_addr = {};struct ethtool_rx_flow_match *match;struct ethtool_rx_flow_rule *flow;struct flow_action_entry *act;
@@ -3233,20 +3232,20 @@ ethtool_rx_flow_rule_create(const struct ethtool_rx_flow_spec_input *input) v6_spec = &fs->h_u.tcp_ip6_spec; v6_m_spec = &fs->m_u.tcp_ip6_spec; -if (memcmp (v6_m_spec->ip6src, &zero_addr,sizeof (zero_addr))) { +if (memcmp (v6_m_spec->ip6src, &in6addr_any,sizeof (in6addr_any))) {memcpy (&match->key.ipv6.src, v6_spec->ip6src,sizeof (match->key.ipv6.src));memcpy (&match->mask.ipv6.src, v6_m_spec->ip6src,sizeof (match->mask.ipv6.src)); } -if (memcmp (v6_m_spec->ip6dst, &zero_addr,sizeof (zero_addr))) { +if (memcmp (v6_m_spec->ip6dst, &in6addr_any,sizeof (in6addr_any))) {memcpy (&match->key.ipv6.dst, v6_spec->ip6dst,sizeof (match->key.ipv6.dst));memcpy (&match->mask.ipv6.dst, v6_m_spec->ip6dst,sizeof (match->mask.ipv6.dst)); } -if (memcmp (v6_m_spec->ip6src, &zero_addr,sizeof (zero_addr)) || -memcmp (v6_m_spec->ip6dst, &zero_addr,sizeof (zero_addr))) { +if (memcmp (v6_m_spec->ip6src, &in6addr_any,sizeof (in6addr_any)) || +memcmp (v6_m_spec->ip6dst, &in6addr_any,sizeof (in6addr_any))) { match->dissector.used_keys |=BIT (FLOW_DISSECTOR_KEY_IPV6_ADDRS ); match->dissector.offset[FLOW_DISSECTOR_KEY_IPV6_ADDRS] =
net/ipv4/inet_hashtables.c +4 -7
@@ -826,13 +826,11 @@ bool inet_bind2_bucket_match_addr_any(const struct inet_bind2_bucket *tb, const unsigned short port, int l3mdev, const struct sock *sk) { #if IS_ENABLED(CONFIG_IPV6) - struct in6_addr addr_any = {}; - if (sk->sk_family != tb->family) { if (sk->sk_family == AF_INET) return net_eq(ib2_net(tb), net) && tb->port == port && tb->l3mdev == l3mdev && -ipv6_addr_equal (&tb->v6_rcv_saddr, &addr_any); + ipv6_addr_equal(&tb->v6_rcv_saddr, &in6addr_any);return false; }
@@ -840,7 +838,7 @@ bool inet_bind2_bucket_match_addr_any(const struct inet_bind2_bucket *tb, constif (sk->sk_family ==AF_INET6 )return net_eq (ib2_net (tb), net) && tb->port == port && tb->l3mdev == l3mdev && -ipv6_addr_equal (&tb->v6_rcv_saddr, &addr_any); +ipv6_addr_equal (&tb->v6_rcv_saddr, &in6addr_any); else#endif return net_eq(ib2_net(tb), net) && tb->port == port &&
@@ -866,11 +864,10 @@ inet_bhash2_addr_any_hashbucket(const struct sock *sk, const struct net *net, in {struct inet_hashinfo *hinfo =tcp_or_dccp_get_hashinfo (sk);u32 hash; -#if IS_ENABLED (CONFIG_IPV6 ) -struct in6_addr addr_any = {}; +#if IS_ENABLED (CONFIG_IPV6 )if (sk->sk_family ==AF_INET6 ) - hash =ipv6_portaddr_hash (net, &addr_any, port); + hash =ipv6_portaddr_hash (net, &in6addr_any, port); else#endif hash =ipv4_portaddr_hash (net,0 , port);
Signature · 1 line
2.30.2
David Ahern
maintainerRe: [PATCH v1 net-next 1/2] ipv6: Remove in6addr_any alternatives.
Quoted 26 lines · Kuniyuki Iwashima
Some code defines the IPv6 wildcard address as a local variable. Let's use
in6addr_anyinstead.Signed-off-by Kuniyuki Iwashima <[email protected]>--- .../net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c | 5 ++--- include/net/ip6_fib.h | 9 +++------ include/trace/events/fib.h | 5 ++--- include/trace/events/fib6.h | 5 +---- net/ethtool/ioctl.c | 9 ++++----- net/ipv4/inet_hashtables.c | 11 ++++------- 6 files changed, 16 insertions(+), 28 deletions(-)drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +0
-1@@ -98,7 +98,6 @@ int mlx5e_tc_set_attr_rx_tun(struct mlx5e_tc_flow *flow,#if IS_ENABLED (CONFIG_INET ) &&IS_ENABLED (CONFIG_IPV6 ) else if (ip_version == 6) {int ipv6_size =MLX5_FLD_SZ_BYTES (ipv6_layout, ipv6); -struct in6_addr zerov6 = {}; daddr =MLX5_ADDR_OF (fte_match_param, spec->match_value, outer_headers.dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c int mlx5e_tc_set_attr_rx_tun(struct mlx5e_tc_flow *flow, · line 109
Quoted 7 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +2
-2@@ -106,8 +105,8 @@ int mlx5e_tc_set_attr_rx_tun(struct mlx5e_tc_flow *flow, outer_headers.src_ipv4_src_ipv6.ipv6_layout.ipv6);memcpy (&tun_attr->dst_ip.v6, daddr, ipv6_size);memcpy (&tun_attr->src_ip.v6, saddr, ipv6_size); -if (!memcmp (&tun_attr->dst_ip.v6, &zerov6,sizeof (zerov6)) || - !memcmp (&tun_attr->src_ip.v6, &zerov6,sizeof (zerov6))) +if (!memcmp (&tun_attr->dst_ip.v6, &in6addr_any,sizeof (in6addr_any)) || + !memcmp (&tun_attr->src_ip.v6, &in6addr_any,sizeof (in6addr_any)))
I think ipv6_addr_any can be used here.
Quoted 18 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +1
-2return 0; }#endif @@ -3233,20 +3232,20 @@ ethtool_rx_flow_rule_create(const struct ethtool_rx_flow_spec_input *input) v6_spec = &fs->h_u.tcp_ip6_spec; v6_m_spec = &fs->m_u.tcp_ip6_spec; -if (memcmp (v6_m_spec->ip6src, &zero_addr,sizeof (zero_addr))) { +if (memcmp (v6_m_spec->ip6src, &in6addr_any,sizeof (in6addr_any))) {memcpy (&match->key.ipv6.src, v6_spec->ip6src,sizeof (match->key.ipv6.src));memcpy (&match->mask.ipv6.src, v6_m_spec->ip6src,sizeof (match->mask.ipv6.src)); } -if (memcmp (v6_m_spec->ip6dst, &zero_addr,sizeof (zero_addr))) {
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c ethtool_rx_flow_rule_create(const struct ethtool_rx_flow_spec_input *input) · line 3248
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +3
-2+if (memcmp (v6_m_spec->ip6dst, &in6addr_any,sizeof (in6addr_any))) {memcpy (&match->key.ipv6.dst, v6_spec->ip6dst,sizeof (match->key.ipv6.dst));memcpy (&match->mask.ipv6.dst, v6_m_spec->ip6dst,sizeof (match->mask.ipv6.dst)); } -if (memcmp (v6_m_spec->ip6src, &zero_addr,sizeof (zero_addr)) || -memcmp (v6_m_spec->ip6dst, &zero_addr,sizeof (zero_addr))) { +if (memcmp (v6_m_spec->ip6src, &in6addr_any,sizeof (in6addr_any)) || +memcmp (v6_m_spec->ip6dst, &in6addr_any,sizeof (in6addr_any))) {
and this group as well.
Quoted 23 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +0
-0match->dissector.used_keys |=BIT (FLOW_DISSECTOR_KEY_IPV6_ADDRS ); match->dissector.offset[FLOW_DISSECTOR_KEY_IPV6_ADDRS] =net/ipv4/inet_hashtables.c +1
-3@@ -826,13 +826,11 @@ bool inet_bind2_bucket_match_addr_any(const struct inet_bind2_bucket *tb, const unsigned short port, int l3mdev, const struct sock *sk) { #if IS_ENABLED(CONFIG_IPV6) - struct in6_addr addr_any = {}; - if (sk->sk_family != tb->family) { if (sk->sk_family == AF_INET) return net_eq(ib2_net(tb), net) && tb->port == port && tb->l3mdev == l3mdev && -ipv6_addr_equal (&tb->v6_rcv_saddr, &addr_any); + ipv6_addr_equal(&tb->v6_rcv_saddr, &in6addr_any);return false; }
net/ipv4/inet_hashtables.c bool inet_bind2_bucket_match_addr_any(const struct inet_bind2_bucket *tb, const · line 844
Quoted 8 lines
net/ipv4/inet_hashtables.c +1
-1@@ -840,7 +838,7 @@ bool inet_bind2_bucket_match_addr_any(const struct inet_bind2_bucket *tb, constif (sk->sk_family ==AF_INET6 )return net_eq (ib2_net (tb), net) && tb->port == port && tb->l3mdev == l3mdev && -ipv6_addr_equal (&tb->v6_rcv_saddr, &addr_any); +ipv6_addr_equal (&tb->v6_rcv_saddr, &in6addr_any); else#endif return net_eq(ib2_net(tb), net) && tb->port == port &&
and these 2.
Re: [PATCH v1 net-next 1/2] ipv6: Remove in6addr_any alternatives.
From: David Ahern <[email protected]> Date: Tue, 21 Mar 2023 20:22:53 -0600
Quoted 24 lines · Kuniyuki Iwashima
Quoted 23 lines
Some code defines the IPv6 wildcard address as a local variable. Let's use
in6addr_anyinstead.Signed-off-by Kuniyuki Iwashima <[email protected]>--- .../net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c | 5 ++--- include/net/ip6_fib.h | 9 +++------ include/trace/events/fib.h | 5 ++--- include/trace/events/fib6.h | 5 +---- net/ethtool/ioctl.c | 9 ++++----- net/ipv4/inet_hashtables.c | 11 ++++------- 6 files changed, 16 insertions(+), 28 deletions(-)drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +0
-1@@ -98,7 +98,6 @@ int mlx5e_tc_set_attr_rx_tun(struct mlx5e_tc_flow *flow,#if IS_ENABLED (CONFIG_INET ) &&IS_ENABLED (CONFIG_IPV6 ) else if (ip_version == 6) {int ipv6_size =MLX5_FLD_SZ_BYTES (ipv6_layout, ipv6); -struct in6_addr zerov6 = {};
Quoted 12 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c int mlx5e_tc_set_attr_rx_tun(struct mlx5e_tc_flow *flow, · line 109
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +2
-2daddr =MLX5_ADDR_OF (fte_match_param, spec->match_value, outer_headers.dst_ipv4_dst_ipv6.ipv6_layout.ipv6);@@ -106,8 +105,8 @@ int mlx5e_tc_set_attr_rx_tun(struct mlx5e_tc_flow *flow, outer_headers.src_ipv4_src_ipv6.ipv6_layout.ipv6);memcpy (&tun_attr->dst_ip.v6, daddr, ipv6_size);memcpy (&tun_attr->src_ip.v6, saddr, ipv6_size); -if (!memcmp (&tun_attr->dst_ip.v6, &zerov6,sizeof (zerov6)) || - !memcmp (&tun_attr->src_ip.v6, &zerov6,sizeof (zerov6))) +if (!memcmp (&tun_attr->dst_ip.v6, &in6addr_any,sizeof (in6addr_any)) || + !memcmp (&tun_attr->src_ip.v6, &in6addr_any,sizeof (in6addr_any)))I think
ipv6_addr_anycan be used here.
Exactly, will fix all in v2.
Thank you!
Quoted 65 lines
Quoted 19 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +1
-2return 0; }#endif @@ -3233,20 +3232,20 @@ ethtool_rx_flow_rule_create(const struct ethtool_rx_flow_spec_input *input) v6_spec = &fs->h_u.tcp_ip6_spec; v6_m_spec = &fs->m_u.tcp_ip6_spec; -if (memcmp (v6_m_spec->ip6src, &zero_addr,sizeof (zero_addr))) { +if (memcmp (v6_m_spec->ip6src, &in6addr_any,sizeof (in6addr_any))) {memcpy (&match->key.ipv6.src, v6_spec->ip6src,sizeof (match->key.ipv6.src));memcpy (&match->mask.ipv6.src, v6_m_spec->ip6src,sizeof (match->mask.ipv6.src)); } -if (memcmp (v6_m_spec->ip6dst, &zero_addr,sizeof (zero_addr))) {drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c ethtool_rx_flow_rule_create(const struct ethtool_rx_flow_spec_input *input) · line 3248
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +3
-2+if (memcmp (v6_m_spec->ip6dst, &in6addr_any,sizeof (in6addr_any))) {memcpy (&match->key.ipv6.dst, v6_spec->ip6dst,sizeof (match->key.ipv6.dst));memcpy (&match->mask.ipv6.dst, v6_m_spec->ip6dst,sizeof (match->mask.ipv6.dst)); } -if (memcmp (v6_m_spec->ip6src, &zero_addr,sizeof (zero_addr)) || -memcmp (v6_m_spec->ip6dst, &zero_addr,sizeof (zero_addr))) { +if (memcmp (v6_m_spec->ip6src, &in6addr_any,sizeof (in6addr_any)) || +memcmp (v6_m_spec->ip6dst, &in6addr_any,sizeof (in6addr_any))) {and this group as well.
Quoted 23 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +0
-0match->dissector.used_keys |=BIT (FLOW_DISSECTOR_KEY_IPV6_ADDRS ); match->dissector.offset[FLOW_DISSECTOR_KEY_IPV6_ADDRS] =net/ipv4/inet_hashtables.c +1
-3@@ -826,13 +826,11 @@ bool inet_bind2_bucket_match_addr_any(const struct inet_bind2_bucket *tb, const unsigned short port, int l3mdev, const struct sock *sk) { #if IS_ENABLED(CONFIG_IPV6) - struct in6_addr addr_any = {}; - if (sk->sk_family != tb->family) { if (sk->sk_family == AF_INET) return net_eq(ib2_net(tb), net) && tb->port == port && tb->l3mdev == l3mdev && -ipv6_addr_equal (&tb->v6_rcv_saddr, &addr_any); + ipv6_addr_equal(&tb->v6_rcv_saddr, &in6addr_any);return false; }net/ipv4/inet_hashtables.c bool inet_bind2_bucket_match_addr_any(const struct inet_bind2_bucket *tb, const · line 844
Quoted 8 lines
net/ipv4/inet_hashtables.c +1
-1@@ -840,7 +838,7 @@ bool inet_bind2_bucket_match_addr_any(const struct inet_bind2_bucket *tb, constif (sk->sk_family ==AF_INET6 )return net_eq (ib2_net (tb), net) && tb->port == port && tb->l3mdev == l3mdev && -ipv6_addr_equal (&tb->v6_rcv_saddr, &addr_any); +ipv6_addr_equal (&tb->v6_rcv_saddr, &in6addr_any); else#endif return net_eq(ib2_net(tb), net) && tb->port == port &&and these 2.
PATCH 2/2 6lowpan: Remove redundant initialisation of struct in6_addr.
In reply to Kuniyuki IwashimaWe'll call memset(&tmp, 0, sizeof(tmp)) later.
--- net/6lowpan/iphc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/6lowpan/iphc.c +1 -1
@@ -848,7 +848,7 @@ static u8 lowpan_compress_ctx_addr(u8 **hc_ptr, const struct net_device *dev,const struct lowpan_iphc_ctx *ctx, const unsigned char *lladdr, bool sam) { - struct in6_addr tmp = {}; + struct in6_addr tmp;u8 dam;switch (lowpan_dev (dev)->lltype) {
Signature · 1 line
2.30.2