Re: bgpd more nexthop cleanup

2022-08-10 Thread Theo Buehler
On Wed, Aug 10, 2022 at 02:54:58PM +0200, Claudio Jeker wrote:
> This is more of what I just did in other places. Use direct assignment
> instead of memcpy(), remove double bzero() calls, switch to memset()
> and order struct kroute_nexthop in a more sensible way.

ok

> There should be no behaviour change from all this.

Agreed.



bgpd more nexthop cleanup

2022-08-10 Thread Claudio Jeker
This is more of what I just did in other places. Use direct assignment
instead of memcpy(), remove double bzero() calls, switch to memset()
and order struct kroute_nexthop in a more sensible way.

There should be no behaviour change from all this.
-- 
:wq Claudio

Index: bgpd.h
===
RCS file: /cvs/src/usr.sbin/bgpd/bgpd.h,v
retrieving revision 1.448
diff -u -p -r1.448 bgpd.h
--- bgpd.h  28 Jul 2022 13:11:48 -  1.448
+++ bgpd.h  10 Aug 2022 12:46:11 -
@@ -717,9 +717,9 @@ struct kroute_nexthop {
struct bgpd_addrnexthop;
struct bgpd_addrgateway;
struct bgpd_addrnet;
+   uint8_t netlen;
uint8_t valid;
uint8_t connected;
-   uint8_t netlen;
 };
 
 struct session_dependon {
Index: rde.c
===
RCS file: /cvs/src/usr.sbin/bgpd/rde.c,v
retrieving revision 1.561
diff -u -p -r1.561 rde.c
--- rde.c   10 Aug 2022 11:11:02 -  1.561
+++ rde.c   10 Aug 2022 12:46:11 -
@@ -2474,7 +2474,7 @@ rde_dump_rib_as(struct prefix *p, struct
 
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
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: rde_rib.c
===
RCS file: /cvs/src/usr.sbin/bgpd/rde_rib.c,v
retrieving revision 1.242
diff -u -p -r1.242 rde_rib.c
--- rde_rib.c   28 Jul 2022 13:11:51 -  1.242
+++ rde_rib.c   10 Aug 2022 12:46:11 -
@@ -1741,14 +1741,11 @@ nexthop_update(struct kroute_nexthop *ms
 
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);