On Mon, Jan 04, 2021 at 10:46:39AM +0100, Claudio Jeker wrote:
> 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);

Perhaps I haven't yet had enough coffee this year, but I'm unsure
whether it is actually guaranteed that addr2sa() is called before the
second len in this line is passed to log_sockaddr().

>       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;
> 

Reply via email to