From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stefano Brivio To: passt-dev@passt.top Subject: [PATCH 09/24] dhcpv6, tap, tcp: Use IN6_ARE_ADDR_EQUAL instead of open-coded memcmp() Date: Fri, 25 Mar 2022 23:52:45 +0100 Message-ID: <20220325225300.2803584-10-sbrivio@redhat.com> In-Reply-To: <20220325225300.2803584-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============7229464194190736368==" --===============7229464194190736368== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Signed-off-by: Stefano Brivio --- dhcpv6.c | 2 +- tap.c | 4 ++-- tcp.c | 12 ++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/dhcpv6.c b/dhcpv6.c index b79a8e9..375ba79 100644 --- a/dhcpv6.c +++ b/dhcpv6.c @@ -354,7 +354,7 @@ ia_ta: =20 req_addr =3D (struct in6_addr *)(ia_addr + 1); =20 - if (memcmp(addr, req_addr, sizeof(*addr))) { + if (!IN6_ARE_ADDR_EQUAL(addr, req_addr)) { info("DHCPv6: requested address %s not on link", inet_ntop(AF_INET6, req_addr, buf, sizeof(buf))); diff --git a/tap.c b/tap.c index e1854fb..a1ccfc1 100644 --- a/tap.c +++ b/tap.c @@ -542,8 +542,8 @@ resume: #define L4_MATCH(ip6h, proto, uh, seq) \ (seq->protocol =3D=3D proto && \ seq->source =3D=3D uh->source && seq->dest =3D=3D uh->dest && \ - !memcmp(&seq->saddr, &ip6h->saddr, sizeof(seq->saddr)) && \ - !memcmp(&seq->daddr, &ip6h->daddr, sizeof(seq->daddr))) + IN6_ARE_ADDR_EQUAL(&seq->saddr, &ip6h->saddr) && \ + IN6_ARE_ADDR_EQUAL(&seq->daddr, &ip6h->daddr)) =20 #define L4_SET(ip6h, proto, uh, seq) \ do { \ diff --git a/tcp.c b/tcp.c index 968db97..539d415 100644 --- a/tcp.c +++ b/tcp.c @@ -853,7 +853,7 @@ static int tcp_rtt_dst_low(struct tcp_conn *conn) int i; =20 for (i =3D 0; i < LOW_RTT_TABLE_SIZE; i++) - if (!memcmp(&conn->a.a6, low_rtt_dst + i, sizeof(conn->a.a6))) + if (IN6_ARE_ADDR_EQUAL(&conn->a.a6, low_rtt_dst + i)) return 1; =20 return 0; @@ -874,7 +874,7 @@ static void tcp_rtt_dst_check(struct tcp_conn *conn, stru= ct tcp_info *tinfo) return; =20 for (i =3D 0; i < LOW_RTT_TABLE_SIZE; i++) { - if (!memcmp(&conn->a.a6, low_rtt_dst + i, sizeof(conn->a.a6))) + if (IN6_ARE_ADDR_EQUAL(&conn->a.a6, low_rtt_dst + i)) return; if (hole =3D=3D -1 && IN6_IS_ADDR_UNSPECIFIED(low_rtt_dst + i)) hole =3D i; @@ -1181,7 +1181,7 @@ static int tcp_hash_match(struct tcp_conn *conn, int af= , void *addr, return 1; =20 if (af =3D=3D AF_INET6 && - !memcmp(&conn->a.a6, addr, sizeof(conn->a.a6)) && + IN6_ARE_ADDR_EQUAL(&conn->a.a6, addr) && conn->tap_port =3D=3D tap_port && conn->sock_port =3D=3D sock_port) return 1; =20 @@ -2047,7 +2047,7 @@ static void tcp_conn_from_tap(struct ctx *c, int af, vo= id *addr, if (!c->no_map_gw) { if (af =3D=3D AF_INET && addr4.sin_addr.s_addr =3D=3D c->gw4) addr4.sin_addr.s_addr =3D htonl(INADDR_LOOPBACK); - if (af =3D=3D AF_INET6 && !memcmp(addr, &c->gw6, sizeof(c->gw6))) + if (af =3D=3D AF_INET6 && IN6_ARE_ADDR_EQUAL(addr, &c->gw6)) addr6.sin6_addr =3D in6addr_loopback; } =20 @@ -2697,8 +2697,8 @@ static void tcp_conn_from_sock(struct ctx *c, union epo= ll_ref ref, memcpy(&sa6, &sa, sizeof(sa6)); =20 if (IN6_IS_ADDR_LOOPBACK(&sa6.sin6_addr) || - !memcmp(&sa6.sin6_addr, &c->addr6_seen, sizeof(c->gw6)) || - !memcmp(&sa6.sin6_addr, &c->addr6, sizeof(c->gw6))) { + IN6_ARE_ADDR_EQUAL(&sa6.sin6_addr, &c->addr6_seen) || + IN6_ARE_ADDR_EQUAL(&sa6.sin6_addr, &c->addr6)) { struct in6_addr *src; =20 if (IN6_IS_ADDR_LINKLOCAL(&c->gw6)) --=20 2.35.1 --===============7229464194190736368==--