From: claudio Date: Sun, 4 Feb 2018 05:08:16 +0000 (+0000) Subject: Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=62894d8285b10c56744dc91ca09aac538d5192b5;p=openbsd Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and Adj-RIB-Out and use them consistently. Makes code easier to read. OK benno@ --- diff --git a/usr.sbin/bgpd/parse.y b/usr.sbin/bgpd/parse.y index 0015d259e90..a1eacce3e40 100644 --- a/usr.sbin/bgpd/parse.y +++ b/usr.sbin/bgpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.316 2017/10/19 06:52:55 jsg Exp $ */ +/* $OpenBSD: parse.y,v 1.317 2018/02/04 05:08:16 claudio Exp $ */ /* * Copyright (c) 2002, 2003, 2004 Henning Brauer @@ -2824,8 +2824,8 @@ parse_config(char *filename, struct bgpd_config *xconf, struct peer **xpeers) netconf = &conf->networks; - add_rib("Adj-RIB-In", conf->default_tableid, - F_RIB_NOFIB | F_RIB_NOEVALUATE); + add_rib("Adj-RIB-In", 0, F_RIB_NOFIB | F_RIB_NOEVALUATE); + add_rib("Adj-RIB-Out", 0, F_RIB_NOFIB | F_RIB_NOEVALUATE); add_rib("Loc-RIB", conf->default_tableid, F_RIB_LOCAL); if ((file = pushfile(filename, 1)) == NULL) { diff --git a/usr.sbin/bgpd/rde.c b/usr.sbin/bgpd/rde.c index 03d8b9f3bb7..bb44bbd2ae5 100644 --- a/usr.sbin/bgpd/rde.c +++ b/usr.sbin/bgpd/rde.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.c,v 1.373 2017/11/14 22:04:50 claudio Exp $ */ +/* $OpenBSD: rde.c,v 1.374 2018/02/04 05:08:16 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -225,6 +225,10 @@ rde_main(int debug, int verbose) nexthop_init(nexthophashsize); peer_init(peerhashsize); + /* make sure the default RIBs are setup */ + rib_new("Adj-RIB-In", 0, F_RIB_NOFIB | F_RIB_NOEVALUATE); + rib_new("Adj-RIB-Out", 0, F_RIB_NOFIB | F_RIB_NOEVALUATE); + out_rules = calloc(1, sizeof(struct filter_head)); if (out_rules == NULL) fatal(NULL); @@ -1330,10 +1334,10 @@ rde_update_update(struct rde_peer *peer, struct rde_aspath *asp, peer->prefix_rcvd_update++; /* add original path to the Adj-RIB-In */ - if (path_update(&ribs[0].rib, peer, asp, prefix, prefixlen)) + if (path_update(&ribs[RIB_ADJ_IN].rib, peer, asp, prefix, prefixlen)) peer->prefix_cnt++; - for (i = 1; i < rib_size; i++) { + for (i = RIB_LOC_START; i < rib_size; i++) { if (*ribs[i].name == '\0') break; /* input filter */ @@ -1366,7 +1370,7 @@ rde_update_withdraw(struct rde_peer *peer, struct bgpd_addr *prefix, { u_int16_t i; - for (i = 1; i < rib_size; i++) { + for (i = RIB_LOC_START; i < rib_size; i++) { if (*ribs[i].name == '\0') break; if (prefix_remove(&ribs[i].rib, peer, prefix, prefixlen, 0)) { @@ -1376,7 +1380,7 @@ rde_update_withdraw(struct rde_peer *peer, struct bgpd_addr *prefix, } /* remove original path form the Adj-RIB-In */ - if (prefix_remove(&ribs[0].rib, peer, prefix, prefixlen, 0)) + if (prefix_remove(&ribs[RIB_ADJ_IN].rib, peer, prefix, prefixlen, 0)) peer->prefix_cnt--; peer->prefix_rcvd_withdraw++; @@ -2957,8 +2961,8 @@ rde_reload_done(void) ribs[rid].state = RECONF_RELOAD; /* FALLTHROUGH */ case RECONF_REINIT: - rib_dump(&ribs[0].rib, rde_softreconfig_in, &ribs[rid], - AID_UNSPEC); + rib_dump(&ribs[RIB_ADJ_IN].rib, rde_softreconfig_in, + &ribs[rid], AID_UNSPEC); break; case RECONF_RELOAD: log_warnx("Bad rib reload state"); @@ -3599,7 +3603,7 @@ network_add(struct network_config *nc, int flagstatic) rde_apply_set(asp, &nc->attrset, nc->prefix.aid, peerself, peerself); if (vpnset) rde_apply_set(asp, vpnset, nc->prefix.aid, peerself, peerself); - for (i = 1; i < rib_size; i++) { + for (i = RIB_LOC_START; i < rib_size; i++) { if (*ribs[i].name == '\0') break; path_update(&ribs[i].rib, peerself, asp, &nc->prefix, @@ -3647,7 +3651,7 @@ network_delete(struct network_config *nc, int flagstatic) } } - for (i = 1; i < rib_size; i++) { + for (i = RIB_LOC_START; i < rib_size; i++) { if (*ribs[i].name == '\0') break; prefix_remove(&ribs[i].rib, peerself, &nc->prefix, diff --git a/usr.sbin/bgpd/rde.h b/usr.sbin/bgpd/rde.h index 5df5ff2ed8d..3b333d79df0 100644 --- a/usr.sbin/bgpd/rde.h +++ b/usr.sbin/bgpd/rde.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.h,v 1.162 2017/05/30 18:08:15 benno Exp $ */ +/* $OpenBSD: rde.h,v 1.163 2018/02/04 05:08:16 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker and @@ -301,6 +301,10 @@ struct rib_desc { enum reconf_action state; }; +#define RIB_ADJ_IN 0 +#define RIB_ADJ_OUT 1 +#define RIB_LOC_START 2 + struct prefix { LIST_ENTRY(prefix) rib_l, path_l; struct rde_aspath *aspath; diff --git a/usr.sbin/bgpd/rde_rib.c b/usr.sbin/bgpd/rde_rib.c index 68604f0b285..afceee32f85 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.154 2017/05/28 12:21:36 claudio Exp $ */ +/* $OpenBSD: rde_rib.c,v 1.155 2018/02/04 05:08:16 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker @@ -114,8 +114,9 @@ rib_find(char *name) { u_int16_t id; + /* no name returns the first Loc-RIB */ if (name == NULL || *name == '\0') - return (&ribs[1].rib); /* no name returns the Loc-RIB */ + return (&ribs[RIB_LOC_START].rib); for (id = 0; id < rib_size; id++) { if (!strcmp(ribs[id].name, name)) @@ -537,7 +538,7 @@ path_remove_stale(struct rde_aspath *asp, u_int8_t aid) } /* only count Adj-RIB-In */ - if (re_rib(p->re) == &ribs[0].rib) + if (re_rib(p->re) == &ribs[RIB_ADJ_IN].rib) rprefixes++; prefix_destroy(p); diff --git a/usr.sbin/bgpd/rde_update.c b/usr.sbin/bgpd/rde_update.c index 0fa7b50073b..96dfa3c6b40 100644 --- a/usr.sbin/bgpd/rde_update.c +++ b/usr.sbin/bgpd/rde_update.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_update.c,v 1.86 2017/05/30 18:08:15 benno Exp $ */ +/* $OpenBSD: rde_update.c,v 1.87 2018/02/04 05:08:16 claudio Exp $ */ /* * Copyright (c) 2004 Claudio Jeker @@ -484,14 +484,14 @@ up_generate_default(struct filter_head *rules, struct rde_peer *peer, return; } - /* generate update */ - if (fasp != NULL) - up_generate(peer, fasp, &addr, 0); - else - up_generate(peer, asp, &addr, 0); + if (fasp == NULL) + fasp = asp; + + up_generate(peer, fasp, &addr, 0); /* no longer needed */ - path_put(fasp); + if (fasp != asp) + path_put(fasp); path_put(asp); }