Skip to content

Commit be2644a

Browse files
edumazetdavem330
authored andcommitted
tcp: add ipv6_addr_v4mapped_loopback() helper
tcp_twsk_unique() has a hard coded assumption about ipv4 loopback being 127/8 Lets instead use the standard ipv4_is_loopback() method, in a new ipv6_addr_v4mapped_loopback() helper. Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 5be5515 commit be2644a

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

include/net/ipv6.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,11 @@ static inline bool ipv6_addr_v4mapped(const struct in6_addr *a)
696696
cpu_to_be32(0x0000ffff))) == 0UL;
697697
}
698698

699+
static inline bool ipv6_addr_v4mapped_loopback(const struct in6_addr *a)
700+
{
701+
return ipv6_addr_v4mapped(a) && ipv4_is_loopback(a->s6_addr32[3]);
702+
}
703+
699704
static inline u32 ipv6_portaddr_hash(const struct net *net,
700705
const struct in6_addr *addr6,
701706
unsigned int port)

net/ipv4/tcp_ipv4.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,9 @@ int tcp_twsk_unique(struct sock *sk, struct sock *sktw, void *twp)
121121
#if IS_ENABLED(CONFIG_IPV6)
122122
if (tw->tw_family == AF_INET6) {
123123
if (ipv6_addr_loopback(&tw->tw_v6_daddr) ||
124-
(ipv6_addr_v4mapped(&tw->tw_v6_daddr) &&
125-
(tw->tw_v6_daddr.s6_addr[12] == 127)) ||
124+
ipv6_addr_v4mapped_loopback(&tw->tw_v6_daddr) ||
126125
ipv6_addr_loopback(&tw->tw_v6_rcv_saddr) ||
127-
(ipv6_addr_v4mapped(&tw->tw_v6_rcv_saddr) &&
128-
(tw->tw_v6_rcv_saddr.s6_addr[12] == 127)))
126+
ipv6_addr_v4mapped_loopback(&tw->tw_v6_rcv_saddr))
129127
loopback = true;
130128
} else
131129
#endif

0 commit comments

Comments
 (0)