In bgpd most prefixes and addresses are stored as struct bgpd_addr. When
it is printed it uses inet_ntop() which is not ideal since it does not
handle IPv6 scoped_id. Instead convert to a struct sockaddr and use
log_sockaddr() which in turn uses getnameinfo.
Ideally the same should be done for the VPN address types but that is a
bit more complex.
--
:wq Claudio
Index: bgpd.h
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/bgpd.h,v
retrieving revision 1.408
diff -u -p -r1.408 bgpd.h
--- bgpd.h 30 Dec 2020 07:29:56 -0000 1.408
+++ bgpd.h 4 Jan 2021 09:34:44 -0000
@@ -1371,7 +1371,7 @@ int aid2afi(u_int8_t, u_int16_t *, u_i
int afi2aid(u_int16_t, u_int8_t, u_int8_t *);
sa_family_t aid2af(u_int8_t);
int af2aid(sa_family_t, u_int8_t, u_int8_t *);
-struct sockaddr *addr2sa(struct bgpd_addr *, u_int16_t, socklen_t *);
+struct sockaddr *addr2sa(const struct bgpd_addr *, u_int16_t, socklen_t
*);
void sa2addr(struct sockaddr *, struct bgpd_addr *, u_int16_t *);
const char * get_baudrate(unsigned long long, char *);
Index: util.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/util.c,v
retrieving revision 1.55
diff -u -p -r1.55 util.c
--- util.c 21 Oct 2020 06:53:54 -0000 1.55
+++ util.c 4 Jan 2021 09:33:30 -0000
@@ -39,14 +39,12 @@ log_addr(const struct bgpd_addr *addr)
{
static char buf[74];
char tbuf[40];
+ socklen_t len;
switch (addr->aid) {
case AID_INET:
case AID_INET6:
- if (inet_ntop(aid2af(addr->aid), &addr->ba, buf,
- sizeof(buf)) == NULL)
- return ("?");
- return (buf);
+ return log_sockaddr(addr2sa(addr, 0, &len), len);
case AID_VPN_IPv4:
if (inet_ntop(AF_INET, &addr->vpn4.addr, tbuf,
sizeof(tbuf)) == NULL)
@@ -838,7 +836,7 @@ af2aid(sa_family_t af, u_int8_t safi, u_
}
struct sockaddr *
-addr2sa(struct bgpd_addr *addr, u_int16_t port, socklen_t *len)
+addr2sa(const struct bgpd_addr *addr, u_int16_t port, socklen_t *len)
{
static struct sockaddr_storage ss;
struct sockaddr_in *sa_in = (struct sockaddr_in *)&ss;