Index | Thread | Search

From:
Claudio Jeker <cjeker@diehard.n-r-g.com>
Subject:
bgpd: add ring buffer to log_sockaddr
To:
tech@openbsd.org
Date:
Wed, 29 May 2024 11:10:58 +0200

Download raw body.

Thread
  • Claudio Jeker:

    bgpd: add ring buffer to log_sockaddr

It is annoying to print an address in a log_peer_warnx() call since
that results in two calls to log_addr() and log_sockaddr() and one of
those calls clobbers the other.
It is fairly common to print more than one IP in a log message so
introduce a ring buffer in log_sockaddr() (which is called by log_addr)
this way less hoops are required to print IPs.

-- 
:wq Claudio

Index: util.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/util.c,v
diff -u -p -r1.85 util.c
--- util.c	22 Mar 2024 15:41:34 -0000	1.85
+++ util.c	29 May 2024 08:59:45 -0000
@@ -98,13 +98,15 @@ log_in6addr(const struct in6_addr *addr)
 const char *
 log_sockaddr(struct sockaddr *sa, socklen_t len)
 {
-	static char	buf[NI_MAXHOST];
+	static char	buf[4][NI_MAXHOST];
+	static int	bufidx;
 
-	if (sa == NULL || getnameinfo(sa, len, buf, sizeof(buf), NULL, 0,
-	    NI_NUMERICHOST))
+	bufidx = (bufidx + 1) % 4;
+	if (sa == NULL || getnameinfo(sa, len, buf[bufidx], sizeof(buf[0]),
+	    NULL, 0, NI_NUMERICHOST))
 		return ("(unknown)");
 	else
-		return (buf);
+		return (buf[bufidx]);
 }
 
 const char *