summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorclaudio <claudio@openbsd.org>2020-12-30 07:29:56 +0000
committerclaudio <claudio@openbsd.org>2020-12-30 07:29:56 +0000
commit7ff9bf356d37ace0e7f546136e69b380fd1889c1 (patch)
treeb72a37e0add667be7922ebaebf7f86519f7c8ad0
parentUse correct IMSG type in fatal message. Also reformat some not so long lines. (diff)
downloadwireguard-openbsd-7ff9bf356d37ace0e7f546136e69b380fd1889c1.tar.xz
wireguard-openbsd-7ff9bf356d37ace0e7f546136e69b380fd1889c1.zip
Implement IMSG_CTL_SHOW_SET to get information about roa-set, as-sets and
prefix-sets loaded into the RDE. For now only the number of prefixes or asnumbers are shown plus the time since the last change was done to the table. OK benno@
-rw-r--r--usr.sbin/bgpd/bgpd.h22
-rw-r--r--usr.sbin/bgpd/control.c4
-rw-r--r--usr.sbin/bgpd/rde.c61
-rw-r--r--usr.sbin/bgpd/rde_filter.c14
-rw-r--r--usr.sbin/bgpd/rde_sets.c13
-rw-r--r--usr.sbin/bgpd/rde_trie.c8
-rw-r--r--usr.sbin/bgpd/session.c3
7 files changed, 110 insertions, 15 deletions
diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h
index e84fedf11b8..15d96345a1b 100644
--- a/usr.sbin/bgpd/bgpd.h
+++ b/usr.sbin/bgpd/bgpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: bgpd.h,v 1.407 2020/12/29 15:30:34 claudio Exp $ */
+/* $OpenBSD: bgpd.h,v 1.408 2020/12/30 07:29:56 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -254,12 +254,15 @@ struct trie_head {
struct tentry_v6 *root_v6;
int match_default_v4;
int match_default_v6;
+ size_t v4_cnt;
+ size_t v6_cnt;
};
struct rde_prefixset {
char name[SET_NAME_LEN];
struct trie_head th;
SIMPLEQ_ENTRY(rde_prefixset) entry;
+ time_t lastchange;
int dirty;
};
SIMPLEQ_HEAD(rde_prefixset_head, rde_prefixset);
@@ -480,6 +483,7 @@ enum imsg_type {
IMSG_CTL_SHOW_TIMER,
IMSG_CTL_LOG_VERBOSE,
IMSG_CTL_SHOW_FIB_TABLES,
+ IMSG_CTL_SHOW_SET,
IMSG_CTL_TERMINATE,
IMSG_NETWORK_ADD,
IMSG_NETWORK_ASPATH,
@@ -711,6 +715,20 @@ struct ctl_show_nexthop {
u_int8_t krvalid;
};
+struct ctl_show_set {
+ char name[SET_NAME_LEN];
+ time_t lastchange;
+ size_t v4_cnt;
+ size_t v6_cnt;
+ size_t as_cnt;
+ enum {
+ ASNUM_SET,
+ PREFIX_SET,
+ ORIGIN_SET,
+ ROA_SET,
+ } type;
+};
+
struct ctl_neighbor {
struct bgpd_addr addr;
char descr[PEER_DESCR_LEN];
@@ -1064,6 +1082,7 @@ struct as_set {
char name[SET_NAME_LEN];
SIMPLEQ_ENTRY(as_set) entry;
struct set_table *set;
+ time_t lastchange;
int dirty;
};
@@ -1299,6 +1318,7 @@ void set_prep(struct set_table *);
void *set_match(const struct set_table *, u_int32_t);
int set_equal(const struct set_table *,
const struct set_table *);
+size_t set_nmemb(const struct set_table *);
/* rde_trie.c */
int trie_add(struct trie_head *, struct bgpd_addr *, u_int8_t, u_int8_t,
diff --git a/usr.sbin/bgpd/control.c b/usr.sbin/bgpd/control.c
index 5c1cfba2e13..4430362547c 100644
--- a/usr.sbin/bgpd/control.c
+++ b/usr.sbin/bgpd/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.102 2020/12/11 12:00:01 claudio Exp $ */
+/* $OpenBSD: control.c,v 1.103 2020/12/30 07:29:56 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -280,6 +280,7 @@ control_dispatch_msg(struct pollfd *pfd, struct peer_head *peers)
case IMSG_CTL_SHOW_NETWORK:
case IMSG_CTL_SHOW_RIB:
case IMSG_CTL_SHOW_RIB_PREFIX:
+ case IMSG_CTL_SHOW_SET:
break;
default:
/* clear imsg type to prevent processing */
@@ -498,6 +499,7 @@ control_dispatch_msg(struct pollfd *pfd, struct peer_head *peers)
c->terminate = 1;
/* FALLTHROUGH */
case IMSG_CTL_SHOW_RIB_MEM:
+ case IMSG_CTL_SHOW_SET:
c->ibuf.pid = imsg.hdr.pid;
imsg_ctl_rde(imsg.hdr.type, imsg.hdr.pid,
imsg.data, imsg.hdr.len - IMSG_HEADER_SIZE);
diff --git a/usr.sbin/bgpd/rde.c b/usr.sbin/bgpd/rde.c
index 3b004c14029..177046b8a69 100644
--- a/usr.sbin/bgpd/rde.c
+++ b/usr.sbin/bgpd/rde.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde.c,v 1.509 2020/12/30 07:02:10 claudio Exp $ */
+/* $OpenBSD: rde.c,v 1.510 2020/12/30 07:29:56 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -345,12 +345,15 @@ rde_dispatch_imsg_session(struct imsgbuf *ibuf)
struct imsg imsg;
struct peer p;
struct peer_config pconf;
+ struct ctl_show_set cset;
struct ctl_show_rib csr;
struct ctl_show_rib_request req;
struct rde_peer *peer;
struct rde_aspath *asp;
struct rde_hashstats rdehash;
struct filter_set *s;
+ struct as_set *aset;
+ struct rde_prefixset *pset;
u_int8_t *asdata;
ssize_t n;
size_t aslen;
@@ -572,6 +575,53 @@ badnetdel:
imsg_compose(ibuf_se_ctl, IMSG_CTL_END, 0, imsg.hdr.pid,
-1, NULL, 0);
break;
+ case IMSG_CTL_SHOW_SET:
+ /* first roa set */
+ pset = &conf->rde_roa;
+ memset(&cset, 0, sizeof(cset));
+ cset.type = ROA_SET;
+ strlcpy(cset.name, "RPKI ROA", sizeof(cset.name));
+ cset.lastchange = pset->lastchange;
+ cset.v4_cnt = pset->th.v4_cnt;
+ cset.v6_cnt = pset->th.v6_cnt;
+ imsg_compose(ibuf_se_ctl, IMSG_CTL_SHOW_SET, 0,
+ imsg.hdr.pid, -1, &cset, sizeof(cset));
+
+ SIMPLEQ_FOREACH(aset, &conf->as_sets, entry) {
+ memset(&cset, 0, sizeof(cset));
+ cset.type = ASNUM_SET;
+ strlcpy(cset.name, aset->name,
+ sizeof(cset.name));
+ cset.lastchange = aset->lastchange;
+ cset.as_cnt = set_nmemb(aset->set);
+ imsg_compose(ibuf_se_ctl, IMSG_CTL_SHOW_SET, 0,
+ imsg.hdr.pid, -1, &cset, sizeof(cset));
+ }
+ SIMPLEQ_FOREACH(pset, &conf->rde_prefixsets, entry) {
+ memset(&cset, 0, sizeof(cset));
+ cset.type = PREFIX_SET;
+ strlcpy(cset.name, pset->name,
+ sizeof(cset.name));
+ cset.lastchange = pset->lastchange;
+ cset.v4_cnt = pset->th.v4_cnt;
+ cset.v6_cnt = pset->th.v6_cnt;
+ imsg_compose(ibuf_se_ctl, IMSG_CTL_SHOW_SET, 0,
+ imsg.hdr.pid, -1, &cset, sizeof(cset));
+ }
+ SIMPLEQ_FOREACH(pset, &conf->rde_originsets, entry) {
+ memset(&cset, 0, sizeof(cset));
+ cset.type = ORIGIN_SET;
+ strlcpy(cset.name, pset->name,
+ sizeof(cset.name));
+ cset.lastchange = pset->lastchange;
+ cset.v4_cnt = pset->th.v4_cnt;
+ cset.v6_cnt = pset->th.v6_cnt;
+ imsg_compose(ibuf_se_ctl, IMSG_CTL_SHOW_SET, 0,
+ imsg.hdr.pid, -1, &cset, sizeof(cset));
+ }
+ imsg_compose(ibuf_se_ctl, IMSG_CTL_END, 0, imsg.hdr.pid,
+ -1, NULL, 0);
+ break;
case IMSG_CTL_LOG_VERBOSE:
/* already checked by SE */
memcpy(&verbose, imsg.data, sizeof(verbose));
@@ -3100,6 +3150,7 @@ rde_reload_done(void)
SIMPLEQ_CONCAT(&conf->as_sets, &nconf->as_sets);
conf->rde_roa = nconf->rde_roa;
+ conf->rde_roa.lastchange = roa_old.lastchange;
memset(&nconf->rde_roa, 0, sizeof(nconf->rde_roa));
/* apply new set of l3vpn, sync will be done later */
@@ -3123,8 +3174,10 @@ rde_reload_done(void)
if (trie_equal(&conf->rde_roa.th, &roa_old.th) == 0) {
log_debug("roa change: reloading Adj-RIB-In");
conf->rde_roa.dirty = 1;
+ conf->rde_roa.lastchange = getmonotime();
reload++; /* run softreconf in */
}
+
trie_free(&roa_old.th); /* old roa no longer needed */
rde_mark_prefixsets_dirty(&prefixsets_old, &conf->rde_prefixsets);
@@ -3855,9 +3908,13 @@ rde_mark_prefixsets_dirty(struct rde_prefixset_head *psold,
if ((psold == NULL) ||
(old = rde_find_prefixset(new->name, psold)) == NULL) {
new->dirty = 1;
+ new->lastchange = getmonotime();
} else {
- if (trie_equal(&new->th, &old->th) == 0)
+ if (trie_equal(&new->th, &old->th) == 0) {
new->dirty = 1;
+ new->lastchange = getmonotime();
+ } else
+ new->lastchange = old->lastchange;
}
}
}
diff --git a/usr.sbin/bgpd/rde_filter.c b/usr.sbin/bgpd/rde_filter.c
index d37cacb4533..3a394555dc3 100644
--- a/usr.sbin/bgpd/rde_filter.c
+++ b/usr.sbin/bgpd/rde_filter.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde_filter.c,v 1.125 2020/12/03 11:53:34 claudio Exp $ */
+/* $OpenBSD: rde_filter.c,v 1.126 2020/12/30 07:29:56 claudio Exp $ */
/*
* Copyright (c) 2004 Claudio Jeker <claudio@openbsd.org>
@@ -55,8 +55,8 @@ rde_apply_set(struct filter_set_head *sh, struct rde_peer *peer,
state->aspath.lpref +=
set->action.relative;
} else {
- if ((u_int32_t)-set->action.relative >
- state->aspath.lpref)
+ if (state->aspath.lpref <
+ 0U - set->action.relative)
state->aspath.lpref = 0;
else
state->aspath.lpref +=
@@ -77,8 +77,8 @@ rde_apply_set(struct filter_set_head *sh, struct rde_peer *peer,
state->aspath.med +=
set->action.relative;
} else {
- if ((u_int32_t)-set->action.relative >
- state->aspath.med)
+ if (state->aspath.med <
+ 0U - set->action.relative)
state->aspath.med = 0;
else
state->aspath.med +=
@@ -97,8 +97,8 @@ rde_apply_set(struct filter_set_head *sh, struct rde_peer *peer,
state->aspath.weight +=
set->action.relative;
} else {
- if ((u_int32_t)-set->action.relative >
- state->aspath.weight)
+ if (state->aspath.weight <
+ 0U - set->action.relative)
state->aspath.weight = 0;
else
state->aspath.weight +=
diff --git a/usr.sbin/bgpd/rde_sets.c b/usr.sbin/bgpd/rde_sets.c
index 2a8b393d0e4..764a9cf0d4b 100644
--- a/usr.sbin/bgpd/rde_sets.c
+++ b/usr.sbin/bgpd/rde_sets.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde_sets.c,v 1.9 2019/08/05 08:46:55 claudio Exp $ */
+/* $OpenBSD: rde_sets.c,v 1.10 2020/12/30 07:29:56 claudio Exp $ */
/*
* Copyright (c) 2018 Claudio Jeker <claudio@openbsd.org>
@@ -93,8 +93,11 @@ as_sets_mark_dirty(struct as_set_head *old, struct as_set_head *new)
SIMPLEQ_FOREACH(n, new, entry) {
if (old == NULL || (o = as_sets_lookup(old, n->name)) == NULL ||
- !set_equal(n->set, o->set))
+ !set_equal(n->set, o->set)) {
n->dirty = 1;
+ n->lastchange = getmonotime();
+ } else
+ n->lastchange = o->lastchange;
}
}
@@ -224,3 +227,9 @@ set_equal(const struct set_table *a, const struct set_table *b)
return 0;
return 1;
}
+
+size_t
+set_nmemb(const struct set_table *set)
+{
+ return set->nmemb;
+}
diff --git a/usr.sbin/bgpd/rde_trie.c b/usr.sbin/bgpd/rde_trie.c
index 15dc624508a..9f9b736fd1c 100644
--- a/usr.sbin/bgpd/rde_trie.c
+++ b/usr.sbin/bgpd/rde_trie.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde_trie.c,v 1.11 2020/12/29 15:30:34 claudio Exp $ */
+/* $OpenBSD: rde_trie.c,v 1.12 2020/12/30 07:29:56 claudio Exp $ */
/*
* Copyright (c) 2018 Claudio Jeker <claudio@openbsd.org>
@@ -189,6 +189,8 @@ trie_add_v4(struct trie_head *th, struct in_addr *prefix, u_int8_t plen)
if (n->plen == plen) {
/* matching node, adjust */
+ if (n->node == 0)
+ th->v4_cnt++;
n->node = 1;
return n;
}
@@ -204,6 +206,7 @@ trie_add_v4(struct trie_head *th, struct in_addr *prefix, u_int8_t plen)
/* create new node */
if ((new = calloc(1, sizeof(*new))) == NULL)
return NULL;
+ th->v4_cnt++;
rdemem.pset_cnt++;
rdemem.pset_size += sizeof(*new);
new->addr = p;
@@ -269,6 +272,8 @@ trie_add_v6(struct trie_head *th, struct in6_addr *prefix, u_int8_t plen)
if (n->plen == plen) {
/* matching node, adjust */
+ if (n->node == 0)
+ th->v6_cnt++;
n->node = 1;
return n;
}
@@ -284,6 +289,7 @@ trie_add_v6(struct trie_head *th, struct in6_addr *prefix, u_int8_t plen)
/* create new node */
if ((new = calloc(1, sizeof(*new))) == NULL)
return NULL;
+ th->v6_cnt++;
rdemem.pset_cnt++;
rdemem.pset_size += sizeof(*new);
new->addr = p;
diff --git a/usr.sbin/bgpd/session.c b/usr.sbin/bgpd/session.c
index 2018c45dd1d..c0406c71b62 100644
--- a/usr.sbin/bgpd/session.c
+++ b/usr.sbin/bgpd/session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: session.c,v 1.408 2020/12/29 09:49:04 claudio Exp $ */
+/* $OpenBSD: session.c,v 1.409 2020/12/30 07:29:56 claudio Exp $ */
/*
* Copyright (c) 2003, 2004, 2005 Henning Brauer <henning@openbsd.org>
@@ -2841,6 +2841,7 @@ session_dispatch_imsg(struct imsgbuf *ibuf, int idx, u_int *listener_cnt)
case IMSG_CTL_SHOW_RIB_HASH:
case IMSG_CTL_SHOW_NETWORK:
case IMSG_CTL_SHOW_NEIGHBOR:
+ case IMSG_CTL_SHOW_SET:
if (idx != PFD_PIPE_ROUTE_CTL)
fatalx("ctl rib request not from RDE");
control_imsg_relay(&imsg);