diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2003-12-27 00:17:27 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2003-12-27 00:17:27 +0000 |
commit | 42812dba4c208c81e988a658871ca9949bd23294 (patch) | |
tree | 979482d4cd733143afb50f3323cdb8be6ebd4956 /usr.sbin | |
parent | 340c4415f98c3e492ebe6da02882d88c12e70574 (diff) |
when a static route is deleted on that a nexthop depends, we re-check
wether there's another (bigger-prefix) non-bgp route suitable to reach the
prefix, and if that is the case change the references over to the new route.
if not, we need to invalidate the nexthop.
unfortunately, we cannot just call kroute_nexthop_insert (whoch does these
checks) again, as it does too much.
factor out the matching and reference adding code from kroute_nexthop_insert
to a new kroute_nexthop_checkmatch(), and make the surrpounding stuff cope.
the kroute parts of "static route addition/deletion affects nexthop-valifity"
work now.
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/bgpd/kroute.c | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/usr.sbin/bgpd/kroute.c b/usr.sbin/bgpd/kroute.c index 325f71be115..ee80339fa9b 100644 --- a/usr.sbin/bgpd/kroute.c +++ b/usr.sbin/bgpd/kroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kroute.c,v 1.36 2003/12/26 23:46:51 henning Exp $ */ +/* $OpenBSD: kroute.c,v 1.37 2003/12/27 00:17:26 henning Exp $ */ /* * Copyright (c) 2003 Henning Brauer <henning@openbsd.org> @@ -56,6 +56,7 @@ u_int8_t mask2prefixlen(in_addr_t); int kroute_fetchtable(void); int kroute_remove(struct kroute_node *); int kroute_nexthop_insert(in_addr_t, struct kroute_nexthop *); +int kroute_nexthop_checkmatch(in_addr_t, struct knexthop_node *); int knexthop_compare(struct knexthop_node *, struct knexthop_node *); @@ -557,11 +558,13 @@ kroute_remove(struct kroute_node *kr) * non-bgp route. if not, notify RDE * that this nexthop is now invalid */ - bzero(&h, sizeof(h)); - if (kroute_nexthop_insert(s->nexthop, &h) == -1) - return (-1); - if (h.valid == 0) /* no alternate route */ + if (!kroute_nexthop_checkmatch(s->nexthop, + s)) { + s->kroute = NULL; + bzero(&h, sizeof(h)); + h.nexthop = s->nexthop; send_nexthop_update(&h); + } } free(kr); return (0); @@ -641,7 +644,6 @@ kroute_nexthop_delete(in_addr_t key) int kroute_nexthop_insert(in_addr_t key, struct kroute_nexthop *nh) { - struct kroute_node *kr; struct knexthop_node *h; if ((h = calloc(1, sizeof(struct knexthop_node))) == NULL) { @@ -651,14 +653,11 @@ kroute_nexthop_insert(in_addr_t key, struct kroute_nexthop *nh) h->nexthop = nh->nexthop = key; - if ((kr = kroute_match(key)) != NULL) - if (kr->flags & F_KERNEL) { /* must be non-bgp! */ - h->kroute = kr; - kr->flags |= F_NEXTHOP; - nh->valid = 1; - nh->connected = kr->flags & F_CONNECTED; - nh->gateway = kr->r.nexthop; - } + if (kroute_nexthop_checkmatch(key, h) == 1) { + nh->valid = 1; + nh->connected = h->kroute->flags & F_CONNECTED; + nh->gateway = h->kroute->r.nexthop; + } if (RB_INSERT(knexthop_tree, &knt, h) != NULL) { logit(LOG_CRIT, "knexthop_tree insert failed for %s", @@ -669,6 +668,21 @@ kroute_nexthop_insert(in_addr_t key, struct kroute_nexthop *nh) } int +kroute_nexthop_checkmatch(in_addr_t key, struct knexthop_node *h) +{ + struct kroute_node *kr; + + if ((kr = kroute_match(key)) != NULL) + if (kr->flags & F_KERNEL) { /* must be non-bgp! */ + h->kroute = kr; + kr->flags |= F_NEXTHOP; + return (1); + } + + return (0); +} + +int knexthop_compare(struct knexthop_node *a, struct knexthop_node *b) { return (b->nexthop - a->nexthop); |