summaryrefslogtreecommitdiff
path: root/usr.sbin/bgpd/config.c
diff options
context:
space:
mode:
authorSebastian Benoit <benno@cvs.openbsd.org>2018-09-09 11:00:52 +0000
committerSebastian Benoit <benno@cvs.openbsd.org>2018-09-09 11:00:52 +0000
commitc6764a1531f7d408ef82823f541a3c5791115d8f (patch)
tree32785dd89eb2b0bc20e1e30b69e3457775cee698 /usr.sbin/bgpd/config.c
parent3926e5997298af73f2314c224131235a3ca35a7b (diff)
Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@
Diffstat (limited to 'usr.sbin/bgpd/config.c')
-rw-r--r--usr.sbin/bgpd/config.c51
1 files changed, 50 insertions, 1 deletions
diff --git a/usr.sbin/bgpd/config.c b/usr.sbin/bgpd/config.c
index bf4752b7ba4..1c0984facaf 100644
--- a/usr.sbin/bgpd/config.c
+++ b/usr.sbin/bgpd/config.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: config.c,v 1.72 2018/09/07 05:43:33 claudio Exp $ */
+/* $OpenBSD: config.c,v 1.73 2018/09/09 11:00:51 benno Exp $ */
/*
* Copyright (c) 2003, 2004, 2005 Henning Brauer <henning@openbsd.org>
@@ -497,3 +497,52 @@ get_mpe_label(struct rdomain *r)
r->label = shim.shim_label;
return (0);
}
+
+void
+copy_filterset(struct filter_set_head *source, struct filter_set_head *dest)
+{
+ struct filter_set *s, *t;
+
+ if (source == NULL)
+ return;
+
+ TAILQ_FOREACH(s, source, entry) {
+ if ((t = malloc(sizeof(struct filter_set))) == NULL)
+ fatal(NULL);
+ memcpy(t, s, sizeof(struct filter_set));
+ TAILQ_INSERT_TAIL(dest, t, entry);
+ }
+}
+
+void
+expand_networks(struct bgpd_config *c)
+{
+ struct network *n, *m, *tmp;
+ struct network_head *nw = &c->networks;
+ struct prefixset *ps;
+ struct prefixset_item *psi;
+
+ TAILQ_FOREACH_SAFE(n, nw, entry, tmp) {
+ if (n->net.type == NETWORK_PREFIXSET) {
+ TAILQ_REMOVE(nw, n, entry);
+ if ((ps = find_prefixset(n->net.psname, c->prefixsets))
+ == NULL)
+ fatal("%s: prefixset %s not found", __func__,
+ n->net.psname);
+ SIMPLEQ_FOREACH(psi, &ps->psitems, entry) {
+ if ((m = calloc(1, sizeof(struct network)))
+ == NULL)
+ fatal(NULL);
+ memcpy(&m->net.prefix, &psi->p.addr,
+ sizeof(m->net.prefix));
+ m->net.prefixlen = psi->p.len;
+ TAILQ_INIT(&m->net.attrset);
+ copy_filterset(&n->net.attrset,
+ &m->net.attrset);
+ TAILQ_INSERT_TAIL(nw, m, entry);
+ }
+ filterset_free(&n->net.attrset);
+ free(n);
+ }
+ }
+}