From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202512 header.b=Z7AXG8JS; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id D385D5A004E for ; Thu, 15 Jan 2026 09:50:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202512; t=1768467049; bh=EYCUT9J3lG2IbgJ2O3gcARwGE8XcUZygBH98eUh2zng=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z7AXG8JSEKPQo/uAC/e8L8tlbwvKP/Ce/6mMUg5bb64sGCEzz5kWVuQe82n/SFqij d/87jMMEO546IJIyCJRa7r+MrnrjZTeCvikzmI2SJCwRsFUZe2ZcIJ1F5hWhONlRnw +jdOEfaDjJyKjbWgw9ybGZLnT6mP9VDLp6Jes3zC5Fw1d9gwn+Uec/mtkrEC6IyCcr 3oJvSjInqcxQ6qipz91YDX1byRSuck1mB5F9gP5UeefQWfM9x4ZfDPR+ZEm0DKMr/7 B6zUQ7reI8qgGtUqkeOPtDEQlw4QW8mpZsLhLhU4A12MxLhrVvF30KBJITkEEdCPjl rDOSJGAH8YMuw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4dsGsj3Z8Hz4wMK; Thu, 15 Jan 2026 19:50:49 +1100 (AEDT) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH v4 06/14] ip: Add ipproto_name() function Date: Thu, 15 Jan 2026 19:50:37 +1100 Message-ID: <20260115085045.3309818-7-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260115085045.3309818-1-david@gibson.dropbear.id.au> References: <20260115085045.3309818-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: WW6CATRQRU55TX6XIUAWFN2E64ACP3HU X-Message-ID-Hash: WW6CATRQRU55TX6XIUAWFN2E64ACP3HU 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 , Laurent Vivier 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: Add a function to get the name of an IP protocol from its number. Usually this would be done by getprotobynumber(), but that requires access to /etc/protocols and might allocate. We can't do either of those once we've self-isolated. Signed-off-by: David Gibson Reviewed-by: Laurent Vivier --- ip.c | 27 +++++++++++++++++++++++++++ ip.h | 1 + 2 files changed, 28 insertions(+) diff --git a/ip.c b/ip.c index 9a7f4c54..f1d224bd 100644 --- a/ip.c +++ b/ip.c @@ -67,3 +67,30 @@ found: *proto = nh; return true; } + +/** + * ipproto_name() - Get IP protocol name from number + * @proto: IP protocol number + * + * Return: pointer to name of protocol @proto + * + * Usually this would be done with getprotobynumber(3) but that reads + * /etc/protocols and might allocate, which isn't possible for us once + * self-isolated. + */ +/* cppcheck-suppress unusedFunction */ +const char *ipproto_name(uint8_t proto) +{ + switch (proto) { + case IPPROTO_ICMP: + return "ICMP"; + case IPPROTO_TCP: + return "TCP"; + case IPPROTO_UDP: + return "UDP"; + case IPPROTO_ICMPV6: + return "ICMPv6"; + default: + return ""; + } +} diff --git a/ip.h b/ip.h index 5830b923..a8043c2d 100644 --- a/ip.h +++ b/ip.h @@ -116,6 +116,7 @@ static inline uint32_t ip6_get_flow_lbl(const struct ipv6hdr *ip6h) } bool ipv6_l4hdr(struct iov_tail *data, uint8_t *proto, size_t *dlen); +const char *ipproto_name(uint8_t proto); /* IPv6 link-local all-nodes multicast address, ff02::1 */ static const struct in6_addr in6addr_ll_all_nodes = { -- 2.52.0