Fix logic in network_dump_upcall()
authorclaudio <claudio@openbsd.org>
Wed, 10 Aug 2022 11:11:02 +0000 (11:11 +0000)
committerclaudio <claudio@openbsd.org>
Wed, 10 Aug 2022 11:11:02 +0000 (11:11 +0000)
The nexthop can be valid but still a NULL pointer. In that case just set
the aid like it is done for invalid nexthops. If the nexthop is set by
explicitly specifying one then include the exit_nexthop, that is the
nexthop that is relevant for BGP. Further cleanup the function as usual.
OK tb@

usr.sbin/bgpd/rde.c

index f08b23a..ecf201b 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: rde.c,v 1.560 2022/07/28 13:11:50 deraadt Exp $ */
+/*     $OpenBSD: rde.c,v 1.561 2022/08/10 11:11:02 claudio Exp $ */
 
 /*
  * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -4247,14 +4247,13 @@ network_dump_upcall(struct rib_entry *re, void *ptr)
                        continue;
                pt_getaddr(p->pt, &addr);
 
-               bzero(&kf, sizeof(kf));
-               memcpy(&kf.prefix, &addr, sizeof(kf.prefix));
-               if (prefix_nhvalid(p))
-                       kf.nexthop.aid = kf.prefix.aid;
-               else
-                       memcpy(&kf.nexthop, &prefix_nexthop(p)->true_nexthop,
-                           sizeof(kf.nexthop));
+               memset(&kf, 0, sizeof(kf));
+               kf.prefix = addr;
                kf.prefixlen = p->pt->prefixlen;
+               if (prefix_nhvalid(p) && prefix_nexthop(p) != NULL)
+                       kf.nexthop = prefix_nexthop(p)->true_nexthop;
+               else
+                       kf.nexthop.aid = kf.prefix.aid;
                if ((asp->flags & F_ANN_DYNAMIC) == 0)
                        kf.flags = F_STATIC;
                if (imsg_compose(ibuf_se_ctl, IMSG_CTL_SHOW_NETWORK, 0,