More kroute_nexthop cleanup. Mainly use direct assignment instead of
authorclaudio <claudio@openbsd.org>
Wed, 10 Aug 2022 14:17:01 +0000 (14:17 +0000)
committerclaudio <claudio@openbsd.org>
Wed, 10 Aug 2022 14:17:01 +0000 (14:17 +0000)
memcpy(). Additionally replace a bzero() with memset() and remove to
superfluous bzero calls.
OK tb@

usr.sbin/bgpd/bgpd.h
usr.sbin/bgpd/rde.c
usr.sbin/bgpd/rde_rib.c

index 981a442..6c256da 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: bgpd.h,v 1.448 2022/07/28 13:11:48 deraadt Exp $ */
+/*     $OpenBSD: bgpd.h,v 1.449 2022/08/10 14:17:01 claudio Exp $ */
 
 /*
  * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -717,9 +717,9 @@ struct kroute_nexthop {
        struct bgpd_addr        nexthop;
        struct bgpd_addr        gateway;
        struct bgpd_addr        net;
+       uint8_t                 netlen;
        uint8_t                 valid;
        uint8_t                 connected;
-       uint8_t                 netlen;
 };
 
 struct session_dependon {
index ecf201b..b232955 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: rde.c,v 1.561 2022/08/10 11:11:02 claudio Exp $ */
+/*     $OpenBSD: rde.c,v 1.562 2022/08/10 14:17:01 claudio Exp $ */
 
 /*
  * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -2474,7 +2474,7 @@ rde_dump_rib_as(struct prefix *p, struct rde_aspath *asp, pid_t pid, int flags,
 
        nexthop = prefix_nexthop(p);
        peer = prefix_peer(p);
-       bzero(&rib, sizeof(rib));
+       memset(&rib, 0, sizeof(rib));
        rib.age = getmonotime() - p->lastchange;
        rib.local_pref = asp->lpref;
        rib.med = asp->med;
@@ -2484,16 +2484,12 @@ rde_dump_rib_as(struct prefix *p, struct rde_aspath *asp, pid_t pid, int flags,
            sizeof(rib.remote_addr));
        rib.remote_id = peer->remote_bgpid;
        if (nexthop != NULL) {
-               memcpy(&rib.true_nexthop, &nexthop->true_nexthop,
-                   sizeof(rib.true_nexthop));
-               memcpy(&rib.exit_nexthop, &nexthop->exit_nexthop,
-                   sizeof(rib.exit_nexthop));
+               rib.exit_nexthop = nexthop->exit_nexthop;
+               rib.true_nexthop = nexthop->true_nexthop;
        } else {
-               /* announced network may have a NULL nexthop */
-               bzero(&rib.true_nexthop, sizeof(rib.true_nexthop));
-               bzero(&rib.exit_nexthop, sizeof(rib.exit_nexthop));
-               rib.true_nexthop.aid = p->pt->aid;
+               /* announced network can have a NULL nexthop */
                rib.exit_nexthop.aid = p->pt->aid;
+               rib.true_nexthop.aid = p->pt->aid;
        }
        pt_getaddr(p->pt, &rib.prefix);
        rib.prefixlen = p->pt->prefixlen;
index 578d3ac..1519444 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: rde_rib.c,v 1.242 2022/07/28 13:11:51 deraadt Exp $ */
+/*     $OpenBSD: rde_rib.c,v 1.243 2022/08/10 14:17:01 claudio Exp $ */
 
 /*
  * Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org>
@@ -1741,14 +1741,11 @@ nexthop_update(struct kroute_nexthop *msg)
 
        if (msg->connected) {
                nh->flags |= NEXTHOP_CONNECTED;
-               memcpy(&nh->true_nexthop, &nh->exit_nexthop,
-                   sizeof(nh->true_nexthop));
+               nh->true_nexthop = nh->exit_nexthop;
        } else
-               memcpy(&nh->true_nexthop, &msg->gateway,
-                   sizeof(nh->true_nexthop));
+               nh->true_nexthop = msg->gateway;
 
-       memcpy(&nh->nexthop_net, &msg->net,
-           sizeof(nh->nexthop_net));
+       nh->nexthop_net = msg->net;
        nh->nexthop_netlen = msg->netlen;
 
        nh->next_prefix = LIST_FIRST(&nh->prefix_h);