diff options
author | Sebastian Benoit <benno@cvs.openbsd.org> | 2018-08-08 06:54:51 +0000 |
---|---|---|
committer | Sebastian Benoit <benno@cvs.openbsd.org> | 2018-08-08 06:54:51 +0000 |
commit | 1b5ce4208bb6da6e31351920a33c1bf239023b82 (patch) | |
tree | 8f45b22cbdbd4569fdf08bcb48db7e92d95e8150 /usr.sbin/bgpd | |
parent | 9a78f3f40369e5ba28e96371c9c5f406ba245836 (diff) |
hide rib[] internals in new rib_valid() function
ok claudio@
Diffstat (limited to 'usr.sbin/bgpd')
-rw-r--r-- | usr.sbin/bgpd/rde.c | 20 | ||||
-rw-r--r-- | usr.sbin/bgpd/rde.h | 10 | ||||
-rw-r--r-- | usr.sbin/bgpd/rde_rib.c | 4 |
3 files changed, 21 insertions, 13 deletions
diff --git a/usr.sbin/bgpd/rde.c b/usr.sbin/bgpd/rde.c index 0257653069f..79cf5a42545 100644 --- a/usr.sbin/bgpd/rde.c +++ b/usr.sbin/bgpd/rde.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.c,v 1.411 2018/08/06 15:59:01 claudio Exp $ */ +/* $OpenBSD: rde.c,v 1.412 2018/08/08 06:54:50 benno Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -773,7 +773,7 @@ rde_dispatch_imsg_parent(struct imsgbuf *ibuf) fatal(NULL); memcpy(nconf, imsg.data, sizeof(struct bgpd_config)); for (rid = 0; rid < rib_size; rid++) { - if (*ribs[rid].name == '\0') + if (!rib_valid(rid)) break; ribs[rid].state = RECONF_DELETE; } @@ -1320,7 +1320,7 @@ rde_update_update(struct rde_peer *peer, struct filterstate *in, fatalx("rde_update_update: no prefix in Adj-RIB-In"); for (i = RIB_LOC_START; i < rib_size; i++) { - if (*ribs[i].name == '\0') + if (!rib_valid(i)) break; rde_filterstate_prep(&state, &in->aspath, in->nexthop, in->nhflags); @@ -1352,7 +1352,7 @@ rde_update_withdraw(struct rde_peer *peer, struct bgpd_addr *prefix, u_int16_t i; for (i = RIB_LOC_START; i < rib_size; i++) { - if (*ribs[i].name == '\0') + if (!rib_valid(i)) break; if (prefix_remove(&ribs[i].rib, peer, prefix, prefixlen, 0)) rde_update_log("withdraw", i, peer, NULL, prefix, @@ -2799,7 +2799,7 @@ rde_reload_done(void) } /* bring ribs in sync */ for (rid = 0; rid < rib_size; rid++) { - if (*ribs[rid].name == '\0') + if (!rib_valid(rid)) continue; rde_filter_calc_skip_steps(ribs[rid].in_rules_tmp); @@ -2868,7 +2868,7 @@ rde_softreconfig_done(void *arg) filterlist_free(out_rules_tmp); out_rules_tmp = NULL; for (rid = 0; rid < rib_size; rid++) { - if (*ribs[rid].name == '\0') + if (!rib_valid(rid)) continue; ribs[rid].state = RECONF_NONE; } @@ -2904,7 +2904,7 @@ rde_softreconfig_in(struct rib_entry *re, void *bula) rib = &ribs[i]; if (rib->state != RECONF_RELOAD) continue; - if (*rib->name == '\0') + if (!rib_valid(i)) break; rde_filterstate_prep(&state, asp, prefix_nexthop(p), @@ -3486,7 +3486,7 @@ network_add(struct network_config *nc, int flagstatic) nc->prefixlen, 0)) peerself->prefix_cnt++; for (i = RIB_LOC_START; i < rib_size; i++) { - if (*ribs[i].name == '\0') + if (!rib_valid(i)) break; rde_update_log("announce", i, peerself, state.nexthop ? &state.nexthop->exit_nexthop : NULL, @@ -3538,7 +3538,7 @@ network_delete(struct network_config *nc, int flagstatic) } for (i = RIB_LOC_START; i < rib_size; i++) { - if (*ribs[i].name == '\0') + if (!rib_valid(i)) break; if (prefix_remove(&ribs[i].rib, peerself, &nc->prefix, nc->prefixlen, flags)) @@ -3607,7 +3607,7 @@ rde_shutdown(void) /* free filters */ filterlist_free(out_rules); for (i = 0; i < rib_size; i++) { - if (*ribs[i].name == '\0') + if (!rib_valid(i)) break; filterlist_free(ribs[i].in_rules); } diff --git a/usr.sbin/bgpd/rde.h b/usr.sbin/bgpd/rde.h index 7fcf39daec6..0e30e476559 100644 --- a/usr.sbin/bgpd/rde.h +++ b/usr.sbin/bgpd/rde.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.h,v 1.184 2018/08/06 08:13:31 claudio Exp $ */ +/* $OpenBSD: rde.h,v 1.185 2018/08/08 06:54:50 benno Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> and @@ -466,6 +466,14 @@ re_rib(struct rib_entry *re) return (struct rib *)((intptr_t)re->__rib & ~1); } +static inline int +rib_valid(u_int16_t rid) +{ + if (rid >= rib_size || *ribs[rid].name == '\0') + return 0; + return 1; +} + void path_init(u_int32_t); void path_init(u_int32_t); void path_shutdown(void); diff --git a/usr.sbin/bgpd/rde_rib.c b/usr.sbin/bgpd/rde_rib.c index 5b973ae2abc..80ca3d609e0 100644 --- a/usr.sbin/bgpd/rde_rib.c +++ b/usr.sbin/bgpd/rde_rib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_rib.c,v 1.174 2018/08/06 08:13:31 claudio Exp $ */ +/* $OpenBSD: rde_rib.c,v 1.175 2018/08/08 06:54:50 benno Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> @@ -86,7 +86,7 @@ rib_new(char *name, u_int rtableid, u_int16_t flags) u_int16_t id; for (id = 0; id < rib_size; id++) { - if (*ribs[id].name == '\0') + if (!rib_valid(id)) break; } |