From c58a9139a71b1d9be6642aef1a21c1d432f2c797 Mon Sep 17 00:00:00 2001 From: henning Date: Sun, 9 Sep 2018 10:07:38 +0000 Subject: [PATCH] provide rtable_empty(), returns 1 if the rtable doesn't contain any routes ok bluhm --- sys/net/rtable.c | 23 ++++++++++++++++++++++- sys/net/rtable.h | 3 ++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/sys/net/rtable.c b/sys/net/rtable.c index b16499ccd79..9dd3e2ee542 100644 --- a/sys/net/rtable.c +++ b/sys/net/rtable.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtable.c,v 1.63 2017/09/05 11:15:39 mpi Exp $ */ +/* $OpenBSD: rtable.c,v 1.64 2018/09/09 10:07:38 henning Exp $ */ /* * Copyright (c) 2014-2016 Martin Pieuchot @@ -278,6 +278,27 @@ rtable_exists(unsigned int rtableid) return (0); } +int +rtable_empty(unsigned int rtableid) +{ + struct domain *dp; + int i; + struct art_root *tbl; + + for (i = 0; (dp = domains[i]) != NULL; i++) { + if (dp->dom_rtoffset == 0) + continue; + + tbl = rtable_get(rtableid, dp->dom_family); + if (tbl == NULL) + continue; + if (tbl->ar_root.ref != NULL) + return (0); + } + + return (1); +} + unsigned int rtable_l2(unsigned int rtableid) { diff --git a/sys/net/rtable.h b/sys/net/rtable.h index 6df75dd040a..57093723d4f 100644 --- a/sys/net/rtable.h +++ b/sys/net/rtable.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rtable.h,v 1.20 2017/08/02 08:38:28 mpi Exp $ */ +/* $OpenBSD: rtable.h,v 1.21 2018/09/09 10:07:38 henning Exp $ */ /* * Copyright (c) 2014-2016 Martin Pieuchot @@ -49,6 +49,7 @@ int rtable_satoplen(sa_family_t, struct sockaddr *); void rtable_init(void); int rtable_exists(unsigned int); +int rtable_empty(unsigned int); int rtable_add(unsigned int); unsigned int rtable_l2(unsigned int); unsigned int rtable_loindex(unsigned int); -- 2.20.1