From 013a9b91fe495371cbf9a5690613de45b634e3af Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sat, 13 Feb 1999 20:46:03 +0000 Subject: [PATCH] When shutting down, remove all routes (except for RTS_INHERIT and RTS_DEVICE routes) from kernel routing tables unless the "persist" switch is set. --- sysdep/unix/Modules | 1 + sysdep/unix/krt-set.Y | 29 +++++++++++++++++++++++++++++ sysdep/unix/krt-set.c | 26 ++++++++++++++++++++++++++ sysdep/unix/krt-set.h | 1 + sysdep/unix/krt.h | 1 + sysdep/unix/sync-rt.c | 1 + 6 files changed, 59 insertions(+) create mode 100644 sysdep/unix/krt-set.Y diff --git a/sysdep/unix/Modules b/sysdep/unix/Modules index f6db6d35..2969ee45 100644 --- a/sysdep/unix/Modules +++ b/sysdep/unix/Modules @@ -9,5 +9,6 @@ krt.Y krt.h krt-set.c krt-set.h +krt-set.Y krt-iface.h krt-iface.Y diff --git a/sysdep/unix/krt-set.Y b/sysdep/unix/krt-set.Y new file mode 100644 index 00000000..551ee16d --- /dev/null +++ b/sysdep/unix/krt-set.Y @@ -0,0 +1,29 @@ +/* + * BIRD -- UNIX Kernel Syncer Configuration + * + * (c) 1998--1999 Martin Mares + * + * Can be freely distributed and used under the terms of the GNU GPL. + */ + +CF_HDR + +#include "lib/krt-scan.h" + +CF_DECLS + +CF_KEYWORDS(PERSIST) + +CF_GRAMMAR + +CF_ADDTO(kern_proto, kern_proto krt_set_item ';') + +krt_set_item: + PERSIST bool { + ((struct krt_config *) this_proto)->setopt.persist = $2; + } + ; + +CF_CODE + +CF_END diff --git a/sysdep/unix/krt-set.c b/sysdep/unix/krt-set.c index 2f0abe66..e77015b3 100644 --- a/sysdep/unix/krt-set.c +++ b/sysdep/unix/krt-set.c @@ -133,3 +133,29 @@ void krt_set_preconfig(struct krt_config *c) { } + +void +krt_set_shutdown(struct krt_proto *x) +{ + struct rtable *t = &master_table; + + if (((struct krt_config *) x->p.cf)->setopt.persist) + return; + DBG("Flushing kernel routes...\n"); + while (t && t->tos) + t = t->sibling; + if (!t) + return; + FIB_WALK(&t->fib, f) + { + net *n = (net *) f; + rte *e = n->routes; + if (e) + { + rta *a = e->attrs; + if (a->source != RTS_DEVICE && a->source != RTS_INHERIT) + krt_remove_route(e); + } + } + FIB_WALK_END; +} diff --git a/sysdep/unix/krt-set.h b/sysdep/unix/krt-set.h index 53b11464..ec96e652 100644 --- a/sysdep/unix/krt-set.h +++ b/sysdep/unix/krt-set.h @@ -10,6 +10,7 @@ #define _BIRD_KRT_SET_H_ struct krt_set_params { + int persist; }; struct krt_set_status { diff --git a/sysdep/unix/krt.h b/sysdep/unix/krt.h index 5631bc5c..9b630b27 100644 --- a/sysdep/unix/krt.h +++ b/sysdep/unix/krt.h @@ -52,6 +52,7 @@ void krt_scan_ifaces_done(struct krt_proto *); void krt_set_preconfig(struct krt_config *); void krt_set_start(struct krt_proto *); +void krt_set_shutdown(struct krt_proto *); /* sync-if.c */ diff --git a/sysdep/unix/sync-rt.c b/sysdep/unix/sync-rt.c index 094da1c2..99ef92a0 100644 --- a/sysdep/unix/sync-rt.c +++ b/sysdep/unix/sync-rt.c @@ -43,6 +43,7 @@ krt_shutdown(struct proto *p) krt_scan_shutdown(k); krt_if_shutdown(k); + krt_set_shutdown(k); return PS_DOWN; }