From: henning Date: Sun, 9 Sep 2018 10:07:38 +0000 (+0000) Subject: provide rtable_empty(), returns 1 if the rtable doesn't contain any routes X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=c58a9139a71b1d9be6642aef1a21c1d432f2c797;p=openbsd provide rtable_empty(), returns 1 if the rtable doesn't contain any routes ok bluhm --- 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);