summaryrefslogtreecommitdiff
path: root/usr.sbin/bgpd/printconf.c
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2018-09-05 17:32:44 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2018-09-05 17:32:44 +0000
commit1774f936b0a0de626710bc738d85222ecf38cd59 (patch)
tree5c288c14bb82bd8cc92ec5f4512703949544542f /usr.sbin/bgpd/printconf.c
parent87b5835785ec1e545166faa845a899cf169947cc (diff)
Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges into a much faster lookup trie for prefix-sets. When printing the config bgpd tries to use the nices way to express the rule: e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32 becomes match from any prefix 18.0.0.0/8 or-longer Apart from that there is no user visible change because of this. OK sthen@
Diffstat (limited to 'usr.sbin/bgpd/printconf.c')
-rw-r--r--usr.sbin/bgpd/printconf.c90
1 files changed, 36 insertions, 54 deletions
diff --git a/usr.sbin/bgpd/printconf.c b/usr.sbin/bgpd/printconf.c
index 49e93e16954..0690679cac2 100644
--- a/usr.sbin/bgpd/printconf.c
+++ b/usr.sbin/bgpd/printconf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: printconf.c,v 1.110 2018/09/05 09:49:57 claudio Exp $ */
+/* $OpenBSD: printconf.c,v 1.111 2018/09/05 17:32:43 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -29,7 +29,7 @@
#include "rde.h"
#include "log.h"
-void print_op(enum comp_ops);
+void print_prefix(struct filter_prefix *p, const char *);
void print_community(int, int);
void print_largecommunity(int64_t, int64_t, int64_t);
void print_extcommunity(struct filter_extcommunity *);
@@ -55,35 +55,47 @@ void print_groups(struct bgpd_config *, struct peer *);
int peer_compare(const void *, const void *);
void
-print_op(enum comp_ops op)
+print_prefix(struct filter_prefix *p, const char *s)
{
- switch (op) {
- case OP_RANGE:
- printf("-");
+ u_int8_t max_len = 0;
+
+ switch (p->addr.aid) {
+ case AID_INET:
+ case AID_VPN_IPv4:
+ max_len = 32;
break;
- case OP_XRANGE:
- printf("><");
+ case AID_INET6:
+ max_len = 128;
+ break;
+ case AID_UNSPEC:
+ /* no prefix to print */
+ return;
+ }
+
+ printf("%s%s/%u ", s, log_addr(&p->addr), p->len);
+
+ switch (p->op) {
+ case OP_NONE:
break;
case OP_EQ:
- printf("=");
+ printf("prefixlen = %u ", p->len_min);
break;
case OP_NE:
- printf("!=");
- break;
- case OP_LE:
- printf("<=");
+ printf("prefixlen != %u ", p->len_min);
break;
- case OP_LT:
- printf("<");
- break;
- case OP_GE:
- printf(">=");
+ case OP_XRANGE:
+ printf("prefixlen %u >< %u ", p->len_min, p->len_max);
break;
- case OP_GT:
- printf(">");
+ case OP_RANGE:
+ if (p->len == p->len_min && p->len_max == max_len)
+ printf("or-longer ");
+ else if (p->len_max == max_len)
+ printf("prefixlen >= %u ", p->len_min);
+ else
+ printf("prefixlen %u - %u ", p->len_min, p->len_max);
break;
default:
- printf("?");
+ printf("prefixlen %u ??? %u ", p->len_min, p->len_max);
break;
}
}
@@ -433,23 +445,8 @@ print_prefixsets(struct prefixset_head *psh)
SIMPLEQ_FOREACH(ps, psh, entry) {
printf("prefix-set \"%s\" { ", ps->name);
- SIMPLEQ_FOREACH(psi, &ps->psitems, entry) {
- if (psi->p.addr.aid)
- printf("%s/%u ", log_addr(&psi->p.addr),
- psi->p.len);
- if (psi->p.op) {
- if (psi->p.op == OP_RANGE ||
- psi->p.op == OP_XRANGE) {
- printf("prefixlen %u ", psi->p.len_min);
- print_op(psi->p.op);
- printf(" %u ", psi->p.len_max);
- } else {
- printf("prefixlen ");
- print_op(psi->p.op);
- printf(" %u ", psi->p.len_min);
- }
- }
- }
+ SIMPLEQ_FOREACH(psi, &ps->psitems, entry)
+ print_prefix(&psi->p, "");
printf(" }\n");
}
}
@@ -676,22 +673,7 @@ print_rule(struct peer *peer_l, struct filter_rule *r)
} else
printf("any ");
- if (r->match.prefix.addr.aid)
- printf("prefix %s/%u ", log_addr(&r->match.prefix.addr),
- r->match.prefix.len);
-
- if (r->match.prefix.op) {
- if (r->match.prefix.op == OP_RANGE ||
- r->match.prefix.op == OP_XRANGE) {
- printf("prefixlen %u ", r->match.prefix.len_min);
- print_op(r->match.prefix.op);
- printf(" %u ", r->match.prefix.len_max);
- } else {
- printf("prefixlen ");
- print_op(r->match.prefix.op);
- printf(" %u ", r->match.prefix.len_min);
- }
- }
+ print_prefix(&r->match.prefix, "prefix ");
if (r->match.prefixset.flags & PREFIXSET_FLAG_FILTER)
printf("prefix-set \"%s\" ", r->match.prefixset.name);