summaryrefslogtreecommitdiff
path: root/usr.sbin/bgpd
diff options
context:
space:
mode:
authorSebastian Benoit <benno@cvs.openbsd.org>2018-07-11 14:08:47 +0000
committerSebastian Benoit <benno@cvs.openbsd.org>2018-07-11 14:08:47 +0000
commit147ec7f1bab0a28b69d988dd06f8eb988d105b99 (patch)
tree8e85c556c283cb35df37c125b85fa84348e73cac /usr.sbin/bgpd
parent0726135f93f01511a571fe5e567593a966eb77e1 (diff)
add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority. For example to import all ospfd/ospf6d routes into bgp. tested by remi@ ok remi@ henning@ and maybe a little claudio@
Diffstat (limited to 'usr.sbin/bgpd')
-rw-r--r--usr.sbin/bgpd/bgpd.conf.514
-rw-r--r--usr.sbin/bgpd/bgpd.h6
-rw-r--r--usr.sbin/bgpd/kroute.c10
-rw-r--r--usr.sbin/bgpd/parse.y39
-rw-r--r--usr.sbin/bgpd/printconf.c6
5 files changed, 67 insertions, 8 deletions
diff --git a/usr.sbin/bgpd/bgpd.conf.5 b/usr.sbin/bgpd/bgpd.conf.5
index d49a239ca22..9c0629004f1 100644
--- a/usr.sbin/bgpd/bgpd.conf.5
+++ b/usr.sbin/bgpd/bgpd.conf.5
@@ -1,4 +1,4 @@
-.\" $OpenBSD: bgpd.conf.5,v 1.170 2018/07/05 19:51:35 jmc Exp $
+.\" $OpenBSD: bgpd.conf.5,v 1.171 2018/07/11 14:08:46 benno Exp $
.\"
.\" Copyright (c) 2004 Claudio Jeker <claudio@openbsd.org>
.\" Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -16,7 +16,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: July 5 2018 $
+.Dd $Mdocdate: July 11 2018 $
.Dt BGPD.CONF 5
.Os
.Sh NAME
@@ -273,6 +273,11 @@ Log received and sent updates.
.Pq Ic inet Ns | Ns Ic inet6
.Ic rtlabel Ar label Op Ic set ...\&
.Xc
+.It Xo
+.Ic network
+.Pq Ic inet Ns | Ns Ic inet6
+.Ic priority Ar number Op Ic set ...\&
+.Xc
.\" NOT IMPLEMENTED. DO WE WANT THIS?
.\" .It Xo
.\" .Ic network prefix-set
@@ -291,6 +296,11 @@ If set to
routes with the specified
.Ar label
will be announced.
+If set to
+.Ic priority ,
+routes with the specified
+.Ar priority
+will be announced.
.Bd -literal -offset indent
network 192.168.7.0/24
.Ed
diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h
index 5d53b019d97..9c9902ba4ad 100644
--- a/usr.sbin/bgpd/bgpd.h
+++ b/usr.sbin/bgpd/bgpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: bgpd.h,v 1.322 2018/07/10 13:06:28 benno Exp $ */
+/* $OpenBSD: bgpd.h,v 1.323 2018/07/11 14:08:46 benno Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -344,7 +344,8 @@ enum network_type {
NETWORK_STATIC,
NETWORK_CONNECTED,
NETWORK_RTLABEL,
- NETWORK_MRTCLONE
+ NETWORK_MRTCLONE,
+ NETWORK_PRIORITY
};
struct network_config {
@@ -355,6 +356,7 @@ struct network_config {
u_int16_t rtlabel;
enum network_type type;
u_int8_t prefixlen;
+ u_int8_t priority;
u_int8_t old; /* used for reloading */
};
diff --git a/usr.sbin/bgpd/kroute.c b/usr.sbin/bgpd/kroute.c
index be4811d132a..ed5405db314 100644
--- a/usr.sbin/bgpd/kroute.c
+++ b/usr.sbin/bgpd/kroute.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kroute.c,v 1.218 2018/07/10 13:06:28 benno Exp $ */
+/* $OpenBSD: kroute.c,v 1.219 2018/07/11 14:08:46 benno Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -1127,6 +1127,10 @@ kr_net_match(struct ktable *kt, struct kroute *kr)
case NETWORK_MRTCLONE:
/* can not happen */
break;
+ case NETWORK_PRIORITY:
+ if (kr->priority == xn->net.priority)
+ return (xn);
+ break;
}
}
return (NULL);
@@ -1163,6 +1167,10 @@ kr_net_match6(struct ktable *kt, struct kroute6 *kr6)
case NETWORK_MRTCLONE:
/* can not happen */
break;
+ case NETWORK_PRIORITY:
+ if (kr6->priority == xn->net.priority)
+ return (xn);
+ break;
}
}
return (NULL);
diff --git a/usr.sbin/bgpd/parse.y b/usr.sbin/bgpd/parse.y
index 2257473f7ce..f71441bf88e 100644
--- a/usr.sbin/bgpd/parse.y
+++ b/usr.sbin/bgpd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.327 2018/07/10 12:40:41 benno Exp $ */
+/* $OpenBSD: parse.y,v 1.328 2018/07/11 14:08:46 benno Exp $ */
/*
* Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -211,7 +211,7 @@ typedef struct {
%token COMMUNITY EXTCOMMUNITY LARGECOMMUNITY
%token PREFIX PREFIXLEN PREFIXSET SOURCEAS TRANSITAS PEERAS DELETE MAXASLEN
%token MAXASSEQ SET LOCALPREF MED METRIC NEXTHOP REJECT BLACKHOLE NOMODIFY SELF
-%token PREPEND_SELF PREPEND_PEER PFTABLE WEIGHT RTLABEL ORIGIN
+%token PREPEND_SELF PREPEND_PEER PFTABLE WEIGHT RTLABEL ORIGIN PRIORITY
%token ERROR INCLUDE
%token IPSEC ESP AH SPI IKE
%token IPV4 IPV6
@@ -794,6 +794,30 @@ network : NETWORK prefix filter_set {
TAILQ_INSERT_TAIL(netconf, n, entry);
}
+ | NETWORK family PRIORITY NUMBER filter_set {
+ struct network *n;
+ if ($4 < RTP_LOCAL && $4 > RTP_MAX) {
+ yyerror("priority %lld > max %d or < min %d", $4,
+ RTP_MAX, RTP_LOCAL);
+ YYERROR;
+ }
+
+ if ((n = calloc(1, sizeof(struct network))) == NULL)
+ fatal("new_network");
+ if (afi2aid($2, SAFI_UNICAST, &n->net.prefix.aid) ==
+ -1) {
+ yyerror("unknown family");
+ filterset_free($5);
+ free($5);
+ YYERROR;
+ }
+ n->net.type = NETWORK_PRIORITY;
+ n->net.priority = $4;
+ filterset_move($5, &n->net.attrset);
+ free($5);
+
+ TAILQ_INSERT_TAIL(netconf, n, entry);
+ }
| NETWORK family nettype filter_set {
struct network *n;
@@ -2576,6 +2600,7 @@ lookup(char *s)
{ "prefixlen", PREFIXLEN},
{ "prepend-neighbor", PREPEND_PEER},
{ "prepend-self", PREPEND_SELF},
+ { "priority", PRIORITY},
{ "qualify", QUALIFY},
{ "quick", QUICK},
{ "rd", RD},
@@ -2972,6 +2997,7 @@ parse_config(char *filename, struct bgpd_config *xconf, struct peer **xpeers)
struct sym *sym, *next;
struct peer *p, *pnext;
struct rde_rib *rr;
+ struct network *n;
int errors = 0;
conf = new_config();
@@ -3010,6 +3036,15 @@ parse_config(char *filename, struct bgpd_config *xconf, struct peer **xpeers)
errors = file->errors;
popfile();
+ /* check that we dont try to announce our own routes */
+ TAILQ_FOREACH(n, netconf, entry)
+ if (n->net.priority == conf->fib_priority) {
+ errors++;
+ logit(LOG_CRIT, "network priority %d == fib-priority "
+ "%d is not allowed.",
+ n->net.priority, conf->fib_priority);
+ }
+
/* Free macros and check which have not been used. */
TAILQ_FOREACH_SAFE(sym, &symhead, entry, next) {
if ((cmd_opts & BGPD_OPT_VERBOSE2) && !sym->used)
diff --git a/usr.sbin/bgpd/printconf.c b/usr.sbin/bgpd/printconf.c
index df0b6e5ab78..6cae947f8ba 100644
--- a/usr.sbin/bgpd/printconf.c
+++ b/usr.sbin/bgpd/printconf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: printconf.c,v 1.108 2018/06/13 09:33:51 claudio Exp $ */
+/* $OpenBSD: printconf.c,v 1.109 2018/07/11 14:08:46 benno Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -410,6 +410,10 @@ print_network(struct network_config *n, const char *c)
printf("%snetwork %s rtlabel \"%s\"", c,
print_af(n->prefix.aid), rtlabel_id2name(n->rtlabel));
break;
+ case NETWORK_PRIORITY:
+ printf("%snetwork %s priority %d", c,
+ print_af(n->prefix.aid), n->priority);
+ break;
default:
printf("%snetwork %s/%u", c, log_addr(&n->prefix),
n->prefixlen);