From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 8E2145A026F for ; Mon, 9 Oct 2023 10:30:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1696840216; bh=jr7pzdS5R0ER7mILOIrBIegRHVeoB9a78tZ+oTI4bxM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LPgjdV77aqHArGKgbAAVFqT3s/bOkCeKqdgkb9uZAceq23NLBNF+go6hJBnJ3NLmW JQYzCHGy9YbU99Nny/7Gz2Ci04VYnnss3urCYs/Ymo8wSKOooW5FTBDX678+IUEGWo uw7T0cmBCM9aiBJfw/diCsuRNFH2b88zAD/mv7HA= Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4S3sfc4Dmrz4xWb; Mon, 9 Oct 2023 19:30:16 +1100 (AEDT) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH 4/4] pif: Pass originating pif to tap handler functions Date: Mon, 9 Oct 2023 19:30:13 +1100 Message-ID: <20231009083013.2837178-5-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231009083013.2837178-1-david@gibson.dropbear.id.au> References: <20231009083013.2837178-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: RCCY3LWBUK3NLF5MCHAPTTV6YWEKM2OM X-Message-ID-Hash: RCCY3LWBUK3NLF5MCHAPTTV6YWEKM2OM X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: For now, packets passed to the various *_tap_handler() functions always come from the single "tap" interface. We want to allow the possibility to broaden that in future. As preparation for that, have the code in tap.c pass the pif_id of the originating interface to each of those handler functions. Signed-off-by: David Gibson --- icmp.c | 4 +++- icmp.h | 4 ++-- tap.c | 26 ++++++++++++++++---------- tcp.c | 6 +++++- tcp.h | 3 ++- udp.c | 5 ++++- udp.h | 3 ++- 7 files changed, 34 insertions(+), 17 deletions(-) diff --git a/icmp.c b/icmp.c index 41b9f8b..da32ee8 100644 --- a/icmp.c +++ b/icmp.c @@ -148,6 +148,7 @@ void icmpv6_sock_handler(const struct ctx *c, union epoll_ref ref) /** * icmp_tap_handler() - Handle packets from tap * @c: Execution context + * @pif: Pif on which the packet is arriving * @af: Address family, AF_INET or AF_INET6 * @saddr: Source address * @daddr: Destination address @@ -156,13 +157,14 @@ void icmpv6_sock_handler(const struct ctx *c, union epoll_ref ref) * * Return: count of consumed packets (always 1, even if malformed) */ -int icmp_tap_handler(const struct ctx *c, int af, +int icmp_tap_handler(const struct ctx *c, pif_id pif, int af, const void *saddr, const void *daddr, const struct pool *p, const struct timespec *now) { size_t plen; (void)saddr; + (void)pif; if (af == AF_INET) { struct sockaddr_in sa = { diff --git a/icmp.h b/icmp.h index 00d10ea..c6c4b8f 100644 --- a/icmp.h +++ b/icmp.h @@ -12,8 +12,8 @@ struct ctx; void icmp_sock_handler(const struct ctx *c, union epoll_ref ref); void icmpv6_sock_handler(const struct ctx *c, union epoll_ref ref); -int icmp_tap_handler(const struct ctx *c, - int af, const void *saddr, const void *daddr, +int icmp_tap_handler(const struct ctx *c, pif_id pif, int af, + const void *saddr, const void *daddr, const struct pool *p, const struct timespec *now); void icmp_timer(const struct ctx *c, const struct timespec *ts); void icmp_init(void); diff --git a/tap.c b/tap.c index a7f6d8b..3a938f3 100644 --- a/tap.c +++ b/tap.c @@ -645,7 +645,8 @@ resume: tap_packet_debug(iph, NULL, NULL, 0, NULL, 1); packet_add(pkt, l4_len, l4h); - icmp_tap_handler(c, AF_INET, &iph->saddr, &iph->daddr, + icmp_tap_handler(c, PIF_TAP, AF_INET, + &iph->saddr, &iph->daddr, pkt, now); continue; } @@ -719,14 +720,16 @@ append: if (c->no_tcp) continue; for (k = 0; k < p->count; ) - k += tcp_tap_handler(c, AF_INET, &seq->saddr, - &seq->daddr, p, k, now); + k += tcp_tap_handler(c, PIF_TAP, AF_INET, + &seq->saddr, &seq->daddr, + p, k, now); } else if (seq->protocol == IPPROTO_UDP) { if (c->no_udp) continue; for (k = 0; k < p->count; ) - k += udp_tap_handler(c, AF_INET, &seq->saddr, - &seq->daddr, p, k, now); + k += udp_tap_handler(c, PIF_TAP, AF_INET, + &seq->saddr, &seq->daddr, + p, k, now); } } @@ -807,7 +810,8 @@ resume: tap_packet_debug(NULL, ip6h, NULL, proto, NULL, 1); packet_add(pkt, l4_len, l4h); - icmp_tap_handler(c, AF_INET6, saddr, daddr, pkt, now); + icmp_tap_handler(c, PIF_TAP, AF_INET6, + saddr, daddr, pkt, now); continue; } @@ -883,14 +887,16 @@ append: if (c->no_tcp) continue; for (k = 0; k < p->count; ) - k += tcp_tap_handler(c, AF_INET6, &seq->saddr, - &seq->daddr, p, k, now); + k += tcp_tap_handler(c, PIF_TAP, AF_INET6, + &seq->saddr, &seq->daddr, + p, k, now); } else if (seq->protocol == IPPROTO_UDP) { if (c->no_udp) continue; for (k = 0; k < p->count; ) - k += udp_tap_handler(c, AF_INET6, &seq->saddr, - &seq->daddr, p, k, now); + k += udp_tap_handler(c, PIF_TAP, AF_INET6, + &seq->saddr, &seq->daddr, + p, k, now); } } diff --git a/tcp.c b/tcp.c index bad8c38..a921dcd 100644 --- a/tcp.c +++ b/tcp.c @@ -2562,6 +2562,7 @@ static void tcp_conn_from_sock_finish(struct ctx *c, struct tcp_tap_conn *conn, /** * tcp_tap_handler() - Handle packets from tap and state transitions * @c: Execution context + * @pif: Pif on which the packet is arriving * @af: Address family, AF_INET or AF_INET6 * @saddr: Source address * @daddr: Destination address @@ -2571,7 +2572,8 @@ static void tcp_conn_from_sock_finish(struct ctx *c, struct tcp_tap_conn *conn, * * Return: count of consumed packets */ -int tcp_tap_handler(struct ctx *c, int af, const void *saddr, const void *daddr, +int tcp_tap_handler(struct ctx *c, pif_id pif, int af, + const void *saddr, const void *daddr, const struct pool *p, int idx, const struct timespec *now) { struct tcp_tap_conn *conn; @@ -2581,6 +2583,8 @@ int tcp_tap_handler(struct ctx *c, int af, const void *saddr, const void *daddr, char *opts; int count; + (void)pif; + th = packet_get(p, idx, 0, sizeof(*th), &len); if (!th) return 1; diff --git a/tcp.h b/tcp.h index 3f6937c..3872c16 100644 --- a/tcp.h +++ b/tcp.h @@ -17,7 +17,8 @@ void tcp_timer_handler(struct ctx *c, union epoll_ref ref); void tcp_listen_handler(struct ctx *c, union epoll_ref ref, const struct timespec *now); void tcp_sock_handler(struct ctx *c, union epoll_ref ref, uint32_t events); -int tcp_tap_handler(struct ctx *c, int af, const void *saddr, const void *daddr, +int tcp_tap_handler(struct ctx *c, pif_id pif, int af, + const void *saddr, const void *daddr, const struct pool *p, int idx, const struct timespec *now); int tcp_sock_init(const struct ctx *c, sa_family_t af, const void *addr, const char *ifname, in_port_t port); diff --git a/udp.c b/udp.c index ce02979..d838b70 100644 --- a/udp.c +++ b/udp.c @@ -787,6 +787,7 @@ void udp_sock_handler(const struct ctx *c, union epoll_ref ref, uint32_t events, /** * udp_tap_handler() - Handle packets from tap * @c: Execution context + * @pif: Pif on which the packet is arriving * @af: Address family, AF_INET or AF_INET6 * @saddr: Source address * @daddr: Destination address @@ -798,7 +799,8 @@ void udp_sock_handler(const struct ctx *c, union epoll_ref ref, uint32_t events, * * #syscalls sendmmsg */ -int udp_tap_handler(struct ctx *c, int af, const void *saddr, const void *daddr, +int udp_tap_handler(struct ctx *c, pif_id pif, + int af, const void *saddr, const void *daddr, const struct pool *p, int idx, const struct timespec *now) { struct mmsghdr mm[UIO_MAXIOV]; @@ -813,6 +815,7 @@ int udp_tap_handler(struct ctx *c, int af, const void *saddr, const void *daddr, (void)c; (void)saddr; + (void)pif; uh = packet_get(p, idx, 0, sizeof(*uh), NULL); if (!uh) diff --git a/udp.h b/udp.h index 122a3d9..d41932b 100644 --- a/udp.h +++ b/udp.h @@ -10,7 +10,8 @@ void udp_sock_handler(const struct ctx *c, union epoll_ref ref, uint32_t events, const struct timespec *now); -int udp_tap_handler(struct ctx *c, int af, const void *saddr, const void *daddr, +int udp_tap_handler(struct ctx *c, pif_id pif, int af, + const void *saddr, const void *daddr, const struct pool *p, int idx, const struct timespec *now); int udp_sock_init(const struct ctx *c, int ns, sa_family_t af, const void *addr, const char *ifname, in_port_t port); -- 2.41.0