From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 1F39C5A027C for ; Thu, 21 Dec 2023 08:02:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1703142161; bh=qKuXacPPLAzSewcB8wgwo7d6547CRNAY2BKtWVf72CY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TABizEZTaQkIpK63zSh7KLS+c/hwsHKPq+VtFmNoAP8jVI3VPJ81YbAM7YIdJqpKC zr465iqp+XCLRT6GLgT/Vuz8jkeimHyAQv+9ec9mPKeUdBCQiPa0kfvJs+aMKrjAyT wAvCuhiPkv/Z8RsnZkbdwH9YdOWss9KYXIhe99mni8ESNWNad+pCPmk1VE1tI74+Vt UpagQiTcjBbR1LdJXmArPm+eOwtpSgIcdRGYkZfFVGzvcWkM1QMn7jAk0IlEZCMimM a8LMHTojCZ7AKM6q0n5dgJu2/UoVeCfPSdwUgbNtrazY08PmXs5qJUOjFNziqTQ2ET LapSVQCdbY64w== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4SwhFs1Vb0z4xSc; Thu, 21 Dec 2023 18:02:41 +1100 (AEDT) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH v3 14/15] icmp: Merge EPOLL_TYPE_ICMP and EPOLL_TYPE_ICMPV6 Date: Thu, 21 Dec 2023 18:02:36 +1100 Message-ID: <20231221070237.1422557-15-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231221070237.1422557-1-david@gibson.dropbear.id.au> References: <20231221070237.1422557-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: HVAMK6YLVEBZ2O4ZFLXVTS64GYJ3RQFD X-Message-ID-Hash: HVAMK6YLVEBZ2O4ZFLXVTS64GYJ3RQFD 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: We have separate epoll reference types for ICMP and ICMPv6 ping sockets. Now that ping socket references point to a flow table entry, we can easily determine whether we're dealing with ICMP or ICMPv6 from the flow type, making the two epoll types redundant. Merge both types into EPOLL_TYPE_PING. Signed-off-by: David Gibson --- icmp.c | 10 ++++------ icmp.h | 2 +- passt.c | 10 +++------- passt.h | 6 ++---- util.c | 4 +--- 5 files changed, 11 insertions(+), 21 deletions(-) diff --git a/icmp.c b/icmp.c index a073813..272edae 100644 --- a/icmp.c +++ b/icmp.c @@ -57,13 +57,13 @@ static struct icmp_ping_flow *icmp_id_map[IP_VERSIONS][ICMP_NUM_IDS]; /** * icmp_sock_handler() - Handle new data from ICMP or ICMPv6 socket * @c: Execution context - * @af: Address family (AF_INET or AF_INET6) * @ref: epoll reference */ -void icmp_sock_handler(const struct ctx *c, int af, union epoll_ref ref) +void icmp_sock_handler(const struct ctx *c, union epoll_ref ref) { - const char *const pname = af == AF_INET ? "ICMP" : "ICMPv6"; struct icmp_ping_flow *pingf = PINGF(ref.flowside.flow); + int af = pingf->f.type == FLOW_PING4 ? AF_INET : AF_INET6; + const char *const pname = af == AF_INET ? "ICMP" : "ICMPv6"; char buf[USHRT_MAX]; union { struct sockaddr sa; @@ -172,22 +172,20 @@ static struct icmp_ping_flow *icmp_ping_new(const struct ctx *c, { const char *const pname = af == AF_INET ? "ICMP" : "ICMPv6"; uint8_t flowtype = af == AF_INET ? FLOW_PING4 : FLOW_PING6; + union epoll_ref ref = { .type = EPOLL_TYPE_PING }; union flow *flow = flow_alloc(); struct icmp_ping_flow *pingf; const void *bind_addr; const char *bind_if; - union epoll_ref ref; int s; if (!flow) return NULL; if (af == AF_INET) { - ref.type = EPOLL_TYPE_ICMP; bind_addr = &c->ip4.addr_out; bind_if = c->ip4.ifname_out; } else { - ref.type = EPOLL_TYPE_ICMPV6; bind_addr = &c->ip6.addr_out; bind_if = c->ip6.ifname_out; } diff --git a/icmp.h b/icmp.h index 50807c4..5642dda 100644 --- a/icmp.h +++ b/icmp.h @@ -11,7 +11,7 @@ struct ctx; struct icmp_ping_flow; -void icmp_sock_handler(const struct ctx *c, int af, union epoll_ref ref); +void icmp_sock_handler(const struct ctx *c, union epoll_ref ref); int icmp_tap_handler(const struct ctx *c, uint8_t pif, int af, const void *saddr, const void *daddr, const struct pool *p, const struct timespec *now); diff --git a/passt.c b/passt.c index 9191404..eb9f6d8 100644 --- a/passt.c +++ b/passt.c @@ -66,8 +66,7 @@ char *epoll_type_str[] = { [EPOLL_TYPE_TCP_LISTEN] = "listening TCP socket", [EPOLL_TYPE_TCP_TIMER] = "TCP timer", [EPOLL_TYPE_UDP] = "UDP socket", - [EPOLL_TYPE_ICMP] = "ICMP socket", - [EPOLL_TYPE_ICMPV6] = "ICMPv6 socket", + [EPOLL_TYPE_PING] = "ICMP/ICMPv6 ping socket", [EPOLL_TYPE_NSQUIT] = "namespace inotify", [EPOLL_TYPE_TAP_PASTA] = "/dev/net/tun device", [EPOLL_TYPE_TAP_PASST] = "connected qemu socket", @@ -386,11 +385,8 @@ loop: case EPOLL_TYPE_UDP: udp_sock_handler(&c, ref, eventmask, &now); break; - case EPOLL_TYPE_ICMP: - icmp_sock_handler(&c, AF_INET, ref); - break; - case EPOLL_TYPE_ICMPV6: - icmp_sock_handler(&c, AF_INET6, ref); + case EPOLL_TYPE_PING: + icmp_sock_handler(&c, ref); break; default: /* Can't happen */ diff --git a/passt.h b/passt.h index d1ed716..372eb64 100644 --- a/passt.h +++ b/passt.h @@ -61,10 +61,8 @@ enum epoll_type { EPOLL_TYPE_TCP_TIMER, /* UDP sockets */ EPOLL_TYPE_UDP, - /* IPv4 ICMP sockets */ - EPOLL_TYPE_ICMP, - /* ICMPv6 sockets */ - EPOLL_TYPE_ICMPV6, + /* ICMP/ICMPv6 ping sockets */ + EPOLL_TYPE_PING, /* inotify fd watching for end of netns (pasta) */ EPOLL_TYPE_NSQUIT, /* tuntap character device */ diff --git a/util.c b/util.c index 9c7012c..ab08006 100644 --- a/util.c +++ b/util.c @@ -125,10 +125,8 @@ int sock_l4(const struct ctx *c, int af, uint8_t proto, ref.type = EPOLL_TYPE_UDP; break; case IPPROTO_ICMP: - ref.type = EPOLL_TYPE_ICMP; - break; case IPPROTO_ICMPV6: - ref.type = EPOLL_TYPE_ICMPV6; + ref.type = EPOLL_TYPE_PING; break; default: return -EPFNOSUPPORT; /* Not implemented. */ -- 2.43.0