From d31277e292281aa7e61d3785f56af1c956520786 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Wed, 28 Feb 2024 22:25:01 +1100 Subject: inany: Helper to test for various address types Add helpers to determine if an inany is loopback, unspecified or multicast, regardless of whether it's a "true" IPv6 address or an IPv4 address represented as v4-mapped. Use the loopback helper to simplify tcp_splice_conn_from_sock() slightly. Signed-off-by: David Gibson Signed-off-by: Stefano Brivio --- tcp_splice.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'tcp_splice.c') diff --git a/tcp_splice.c b/tcp_splice.c index 5b38a82..cdc09a4 100644 --- a/tcp_splice.c +++ b/tcp_splice.c @@ -449,29 +449,20 @@ bool tcp_splice_conn_from_sock(const struct ctx *c, struct tcp_splice_conn *conn, int s, const struct sockaddr *sa) { - const struct in_addr *a4; union inany_addr aany; in_port_t port; ASSERT(c->mode == MODE_PASTA); inany_from_sockaddr(&aany, &port, sa); - a4 = inany_v4(&aany); - - if (a4) { - if (!IN4_IS_ADDR_LOOPBACK(a4)) - return false; - conn->flags = 0; - } else { - if (!IN6_IS_ADDR_LOOPBACK(&aany.a6)) - return false; - conn->flags = SPLICE_V6; - } + if (!inany_is_loopback(&aany)) + return false; if (setsockopt(s, SOL_TCP, TCP_QUICKACK, &((int){ 1 }), sizeof(int))) flow_trace(conn, "failed to set TCP_QUICKACK on %i", s); conn->f.type = FLOW_TCP_SPLICE; + conn->flags = inany_v4(&aany) ? 0 : SPLICE_V6; conn->s[0] = s; if (tcp_splice_new(c, conn, ref.port, ref.pif)) -- cgit v1.2.3