From: claudio Date: Tue, 24 Jul 2018 10:10:58 +0000 (+0000) Subject: Use prefix_nexthop() to access the nexthop instead of dereferencing the X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=3447165f4e5b8907d3007ad71fb1204e11f7d41b;p=openbsd Use prefix_nexthop() to access the nexthop instead of dereferencing the field in asp directly. This is a step to move the prefix from rde_aspath to struct prefix. OK benno@ --- diff --git a/usr.sbin/bgpd/mrt.c b/usr.sbin/bgpd/mrt.c index 446ef558a0f..0f606eb91be 100644 --- a/usr.sbin/bgpd/mrt.c +++ b/usr.sbin/bgpd/mrt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mrt.c,v 1.85 2018/07/17 07:02:11 claudio Exp $ */ +/* $OpenBSD: mrt.c,v 1.86 2018/07/24 10:10:58 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker @@ -310,7 +310,7 @@ mrt_dump_entry_mp(struct mrt *mrt, struct prefix *p, u_int16_t snum, pt_getaddr(p->re->prefix, &addr); - n = prefix_aspath(p)->nexthop; + n = prefix_nexthop(p); if (n == NULL) { bzero(&nexthop, sizeof(struct bgpd_addr)); nexthop.aid = addr.aid; @@ -385,7 +385,7 @@ mrt_dump_entry(struct mrt *mrt, struct prefix *p, u_int16_t snum, return (-1); } - nexthop = prefix_aspath(p)->nexthop; + nexthop = prefix_nexthop(p); if (nexthop == NULL) { bzero(&addr, sizeof(struct bgpd_addr)); addr.aid = p->re->prefix->aid; @@ -501,7 +501,7 @@ mrt_dump_entry_v2(struct mrt *mrt, struct rib_entry *re, u_int32_t snum) struct bgpd_addr *nh; struct ibuf *tbuf; - nexthop = prefix_aspath(p)->nexthop; + nexthop = prefix_nexthop(p); if (nexthop == NULL) { bzero(&addr, sizeof(struct bgpd_addr)); addr.aid = re->prefix->aid; diff --git a/usr.sbin/bgpd/rde.c b/usr.sbin/bgpd/rde.c index 899e45defde..8e51e0541fd 100644 --- a/usr.sbin/bgpd/rde.c +++ b/usr.sbin/bgpd/rde.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.c,v 1.399 2018/07/22 16:59:08 claudio Exp $ */ +/* $OpenBSD: rde.c,v 1.400 2018/07/24 10:10:58 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -2028,10 +2028,10 @@ rde_dump_rib_as(struct prefix *p, struct rde_aspath *asp, pid_t pid, int flags) memcpy(&rib.remote_addr, &prefix_peer(p)->remote_addr, sizeof(rib.remote_addr)); rib.remote_id = prefix_peer(p)->remote_bgpid; - if (asp->nexthop != NULL) { - memcpy(&rib.true_nexthop, &asp->nexthop->true_nexthop, + if (prefix_nexthop(p) != NULL) { + memcpy(&rib.true_nexthop, &prefix_nexthop(p)->true_nexthop, sizeof(rib.true_nexthop)); - memcpy(&rib.exit_nexthop, &asp->nexthop->exit_nexthop, + memcpy(&rib.exit_nexthop, &prefix_nexthop(p)->exit_nexthop, sizeof(rib.exit_nexthop)); } else { /* announced network may have a NULL nexthop */ @@ -2050,7 +2050,8 @@ rde_dump_rib_as(struct prefix *p, struct rde_aspath *asp, pid_t pid, int flags) rib.flags |= F_PREF_INTERNAL; if (asp->flags & F_PREFIX_ANNOUNCED) rib.flags |= F_PREF_ANNOUNCE; - if (asp->nexthop == NULL || asp->nexthop->state == NEXTHOP_REACH) + if (prefix_nexthop(p) == NULL || + prefix_nexthop(p)->state == NEXTHOP_REACH) rib.flags |= F_PREF_ELIGIBLE; if (asp->flags & F_ATTR_LOOP) rib.flags &= ~F_PREF_ELIGIBLE; @@ -2425,7 +2426,7 @@ rde_send_kroute(struct rib *rib, struct prefix *new, struct prefix *old) if (asp->flags & F_NEXTHOP_BLACKHOLE) kr.flags |= F_BLACKHOLE; if (type == IMSG_KROUTE_CHANGE) - memcpy(&kr.nexthop, &asp->nexthop->true_nexthop, + memcpy(&kr.nexthop, &prefix_nexthop(p)->true_nexthop, sizeof(kr.nexthop)); strlcpy(kr.label, rtlabel_id2name(asp->rtlabelid), sizeof(kr.label)); @@ -2442,7 +2443,8 @@ rde_send_kroute(struct rib *rib, struct prefix *new, struct prefix *old) * is chosen */ if (type == IMSG_KROUTE_CHANGE) - memcpy(&kr.nexthop, &asp->nexthop->exit_nexthop, + memcpy(&kr.nexthop, + &prefix_nexthop(p)->exit_nexthop, sizeof(kr.nexthop)); if (imsg_compose(ibuf_main, type, rd->rtableid, 0, -1, &kr, sizeof(kr)) == -1) @@ -3495,11 +3497,11 @@ network_dump_upcall(struct rib_entry *re, void *ptr) bzero(&k, sizeof(k)); memcpy(&k.prefix, &addr, sizeof(k.prefix)); - if (asp->nexthop == NULL || - asp->nexthop->state != NEXTHOP_REACH) + if (prefix_nexthop(p) == NULL || + prefix_nexthop(p)->state != NEXTHOP_REACH) k.nexthop.aid = k.prefix.aid; else - memcpy(&k.nexthop, &asp->nexthop->true_nexthop, + memcpy(&k.nexthop, &prefix_nexthop(p)->true_nexthop, sizeof(k.nexthop)); k.prefixlen = p->re->prefix->prefixlen; k.flags = F_KERNEL; diff --git a/usr.sbin/bgpd/rde_decide.c b/usr.sbin/bgpd/rde_decide.c index 098a0f466fd..37d5a2b4d92 100644 --- a/usr.sbin/bgpd/rde_decide.c +++ b/usr.sbin/bgpd/rde_decide.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_decide.c,v 1.68 2018/06/21 17:26:16 claudio Exp $ */ +/* $OpenBSD: rde_decide.c,v 1.69 2018/07/24 10:10:58 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker @@ -136,9 +136,11 @@ prefix_cmp(struct prefix *p1, struct prefix *p2) return (1); /* 1. check if prefix is eligible a.k.a reachable */ - if (asp2->nexthop != NULL && asp2->nexthop->state != NEXTHOP_REACH) + if (prefix_nexthop(p2) != NULL && + prefix_nexthop(p2)->state != NEXTHOP_REACH) return (1); - if (asp1->nexthop != NULL && asp1->nexthop->state != NEXTHOP_REACH) + if (prefix_nexthop(p1) != NULL && + prefix_nexthop(p1)->state != NEXTHOP_REACH) return (-1); /* 2. local preference of prefix, bigger is better */ @@ -274,8 +276,8 @@ prefix_evaluate(struct prefix *p, struct rib_entry *re) if (xp != NULL) { struct rde_aspath *xasp = prefix_aspath(xp); if (xasp->flags & (F_ATTR_LOOP|F_ATTR_PARSE_ERR) || - (xasp->nexthop != NULL && - xasp->nexthop->state != NEXTHOP_REACH)) + (prefix_nexthop(xp) != NULL && + prefix_nexthop(xp)->state != NEXTHOP_REACH)) /* xp is ineligible */ xp = NULL; }