From 3c8af4819e677e5ae5298604edbd544887cf964a Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Mon, 10 May 2021 07:50:35 +0200 Subject: passt: Don't use getprotobynumber() in debug build With glibc, we can't reliably build a static binary with getprotobynumber(), which is currently used with -DDEBUG. Replace that with a small array of protocol strings. Signed-off-by: Stefano Brivio --- passt.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'passt.c') diff --git a/passt.c b/passt.c index 4b0497c..73f3a48 100644 --- a/passt.c +++ b/passt.c @@ -65,6 +65,20 @@ static char pkt_buf [PKT_BUF_BYTES]; #define TIMER_INTERVAL MIN(TCP_TIMER_INTERVAL, UDP_TIMER_INTERVAL) +#ifdef DEBUG +static char *ip_proto_str[IPPROTO_SCTP + 1] = { + [IPPROTO_ICMP] = "ICMP", + [IPPROTO_TCP] = "TCP", + [IPPROTO_UDP] = "UDP", + [IPPROTO_ICMPV6] = "ICMPV6", + [IPPROTO_SCTP] = "SCTP", +}; + +#define IP_PROTO_STR(n) \ + (((n) <= IPPROTO_SCTP && ip_proto_str[(n)]) ? ip_proto_str[(n)] : "?") + +#endif + /** * sock_unix() - Create and bind AF_UNIX socket, add to epoll list * @@ -394,7 +408,7 @@ static int tap4_handler(struct ctx *c, struct tap_msg *msg, size_t count, return 1; debug("%s from tap: %s:%i -> %s:%i (%i packet%s)", - getprotobynumber(iph->protocol)->p_name, + IP_PROTO_STR(iph->protocol), inet_ntop(AF_INET, &iph->saddr, buf_s, sizeof(buf_s)), ntohs(uh->source), inet_ntop(AF_INET, &iph->daddr, buf_d, sizeof(buf_d)), @@ -513,7 +527,7 @@ static int tap6_handler(struct ctx *c, struct tap_msg *msg, size_t count, return 1; debug("%s from tap: [%s]:%i\n\t-> [%s]:%i (%i packet%s)", - getprotobynumber(proto)->p_name, + IP_PROTO_STR(proto), inet_ntop(AF_INET6, &ip6h->saddr, buf_s, sizeof(buf_s)), ntohs(uh->source), inet_ntop(AF_INET6, &ip6h->daddr, buf_d, sizeof(buf_d)), @@ -658,7 +672,7 @@ static void sock_handler(struct ctx *c, int s, uint32_t events, return; } - debug("%s: packet from socket %i", getprotobynumber(proto)->p_name, s); + debug("%s: packet from socket %i", IP_PROTO_STR(proto), s); if (proto == IPPROTO_ICMP || proto == IPPROTO_ICMPV6) icmp_sock_handler(c, s, events, pkt_buf, now); -- cgit v1.2.3