summaryrefslogtreecommitdiff
path: root/usr.sbin/bgpd
diff options
context:
space:
mode:
authorHenning Brauer <henning@cvs.openbsd.org>2017-05-28 15:16:34 +0000
committerHenning Brauer <henning@cvs.openbsd.org>2017-05-28 15:16:34 +0000
commitff32495dd086c39ff244188fce0e72948860adc6 (patch)
tree7d460745e4bd91dc5c928d32271e8c1e26e369ec /usr.sbin/bgpd
parented7498b974053da920925eb008a53015769f3c43 (diff)
so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d daemon_rtable) for nexthop verification and as default Adj-RIB-In and Loc-RIB. This allows multiple bgpds in different rdomains on the same machine - bgp router virtualization if you like buzzwords. initial version written under contract more than a year ago, it took us a while to wrap our brains around the bgpd <-> rdomain interactions - 1) RIBs, 2) nexthop verification and 3) tcp sockets. ok & input phessler claudio benno
Diffstat (limited to 'usr.sbin/bgpd')
-rw-r--r--usr.sbin/bgpd/bgpd.c9
-rw-r--r--usr.sbin/bgpd/bgpd.h9
-rw-r--r--usr.sbin/bgpd/config.c3
-rw-r--r--usr.sbin/bgpd/kroute.c13
-rw-r--r--usr.sbin/bgpd/parse.y23
5 files changed, 37 insertions, 20 deletions
diff --git a/usr.sbin/bgpd/bgpd.c b/usr.sbin/bgpd/bgpd.c
index ede5967246a..110f699f0c7 100644
--- a/usr.sbin/bgpd/bgpd.c
+++ b/usr.sbin/bgpd/bgpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bgpd.c,v 1.188 2017/01/24 04:22:42 benno Exp $ */
+/* $OpenBSD: bgpd.c,v 1.189 2017/05/28 15:16:33 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -603,8 +603,8 @@ dispatch_imsg(struct imsgbuf *ibuf, int idx, struct bgpd_config *conf)
else if (imsg.hdr.len != IMSG_HEADER_SIZE +
sizeof(struct bgpd_addr))
log_warnx("wrong imsg len");
- else if (kr_nexthop_add(imsg.hdr.peerid, imsg.data) ==
- -1)
+ else if (kr_nexthop_add(imsg.hdr.peerid, imsg.data,
+ conf) == -1)
rv = -1;
break;
case IMSG_NEXTHOP_REMOVE:
@@ -614,7 +614,8 @@ dispatch_imsg(struct imsgbuf *ibuf, int idx, struct bgpd_config *conf)
sizeof(struct bgpd_addr))
log_warnx("wrong imsg len");
else
- kr_nexthop_delete(imsg.hdr.peerid, imsg.data);
+ kr_nexthop_delete(imsg.hdr.peerid, imsg.data,
+ conf);
break;
case IMSG_PFTABLE_ADD:
if (idx != PFD_PIPE_ROUTE)
diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h
index 8f1cd1e123b..3bb4602e6a4 100644
--- a/usr.sbin/bgpd/bgpd.h
+++ b/usr.sbin/bgpd/bgpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: bgpd.h,v 1.305 2017/05/28 12:21:36 claudio Exp $ */
+/* $OpenBSD: bgpd.h,v 1.306 2017/05/28 15:16:33 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -220,6 +220,7 @@ struct bgpd_config {
char *rcsock;
int flags;
int log;
+ u_int default_tableid;
u_int32_t bgpid;
u_int32_t clusterid;
u_int32_t as;
@@ -1011,8 +1012,10 @@ void kr_fib_decouple(u_int, u_int8_t);
void kr_fib_decouple_all(u_int8_t);
void kr_fib_update_prio_all(u_int8_t);
int kr_dispatch_msg(void);
-int kr_nexthop_add(u_int32_t, struct bgpd_addr *);
-void kr_nexthop_delete(u_int32_t, struct bgpd_addr *);
+int kr_nexthop_add(u_int32_t, struct bgpd_addr *,
+ struct bgpd_config *);
+void kr_nexthop_delete(u_int32_t, struct bgpd_addr *,
+ struct bgpd_config *);
void kr_show_route(struct imsg *);
void kr_ifinfo(char *);
int kr_net_reload(u_int, struct network_head *);
diff --git a/usr.sbin/bgpd/config.c b/usr.sbin/bgpd/config.c
index adbfaf380ee..8d0f34e2653 100644
--- a/usr.sbin/bgpd/config.c
+++ b/usr.sbin/bgpd/config.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: config.c,v 1.65 2017/01/24 04:22:42 benno Exp $ */
+/* $OpenBSD: config.c,v 1.66 2017/05/28 15:16:33 henning Exp $ */
/*
* Copyright (c) 2003, 2004, 2005 Henning Brauer <henning@openbsd.org>
@@ -52,6 +52,7 @@ new_config(void)
conf->min_holdtime = MIN_HOLDTIME;
conf->bgpid = get_bgpid();
conf->fib_priority = RTP_BGP;
+ conf->default_tableid = getrtable();
if ((conf->csock = strdup(SOCKET_NAME)) == NULL)
fatal(NULL);
diff --git a/usr.sbin/bgpd/kroute.c b/usr.sbin/bgpd/kroute.c
index 36926dd2fd5..138f7684a2d 100644
--- a/usr.sbin/bgpd/kroute.c
+++ b/usr.sbin/bgpd/kroute.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kroute.c,v 1.212 2017/03/28 05:04:09 claudio Exp $ */
+/* $OpenBSD: kroute.c,v 1.213 2017/05/28 15:16:33 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -875,11 +875,14 @@ kr_dispatch_msg(void)
}
int
-kr_nexthop_add(u_int rtableid, struct bgpd_addr *addr)
+kr_nexthop_add(u_int rtableid, struct bgpd_addr *addr, struct bgpd_config *conf)
{
struct ktable *kt;
struct knexthop_node *h;
+ if (rtableid == 0)
+ rtableid = conf->default_tableid;
+
if ((kt = ktable_get(rtableid)) == NULL) {
log_warnx("kr_nexthop_add: non-existent rtableid %d", rtableid);
return (0);
@@ -902,11 +905,15 @@ kr_nexthop_add(u_int rtableid, struct bgpd_addr *addr)
}
void
-kr_nexthop_delete(u_int rtableid, struct bgpd_addr *addr)
+kr_nexthop_delete(u_int rtableid, struct bgpd_addr *addr,
+ struct bgpd_config *conf)
{
struct ktable *kt;
struct knexthop_node *kn;
+ if (rtableid == 0)
+ rtableid = conf->default_tableid;
+
if ((kt = ktable_get(rtableid)) == NULL) {
log_warnx("kr_nexthop_delete: non-existent rtableid %d",
rtableid);
diff --git a/usr.sbin/bgpd/parse.y b/usr.sbin/bgpd/parse.y
index ad567092cc1..44a9df6597a 100644
--- a/usr.sbin/bgpd/parse.y
+++ b/usr.sbin/bgpd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.305 2017/05/27 18:12:23 phessler Exp $ */
+/* $OpenBSD: parse.y,v 1.306 2017/05/28 15:16:33 henning Exp $ */
/*
* Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -454,7 +454,7 @@ conf_main : AS as4number {
conf->flags &= ~BGPD_FLAG_NO_EVALUATE;
}
| RDE RIB STRING {
- if (add_rib($3, 0, F_RIB_NOFIB)) {
+ if (add_rib($3, conf->default_tableid, F_RIB_NOFIB)) {
free($3);
YYERROR;
}
@@ -466,7 +466,8 @@ conf_main : AS as4number {
yyerror("bad rde rib definition");
YYERROR;
}
- if (add_rib($3, 0, F_RIB_NOFIB | F_RIB_NOEVALUATE)) {
+ if (add_rib($3, conf->default_tableid,
+ F_RIB_NOFIB | F_RIB_NOEVALUATE)) {
free($3);
YYERROR;
}
@@ -2823,8 +2824,9 @@ parse_config(char *filename, struct bgpd_config *xconf, struct peer **xpeers)
netconf = &conf->networks;
- add_rib("Adj-RIB-In", 0, F_RIB_NOFIB | F_RIB_NOEVALUATE);
- add_rib("Loc-RIB", 0, F_RIB_LOCAL);
+ add_rib("Adj-RIB-In", conf->default_tableid,
+ F_RIB_NOFIB | F_RIB_NOEVALUATE);
+ add_rib("Loc-RIB", conf->default_tableid, F_RIB_LOCAL);
if ((file = pushfile(filename, 1)) == NULL) {
free(conf);
@@ -3373,7 +3375,7 @@ int
add_rib(char *name, u_int rtableid, u_int16_t flags)
{
struct rde_rib *rr;
- u_int rdom;
+ u_int rdom, default_rdom;
if ((rr = find_rib(name)) == NULL) {
if ((rr = calloc(1, sizeof(*rr))) == NULL) {
@@ -3394,9 +3396,12 @@ add_rib(char *name, u_int rtableid, u_int16_t flags)
free(rr);
return (-1);
}
- if (rdom != 0) {
- yyerror("rtable %u does not belong to rdomain 0",
- rtableid);
+ if (ktable_exists(conf->default_tableid, &default_rdom) != 1)
+ fatal("default rtable %u does not exist",
+ conf->default_tableid);
+ if (rdom != default_rdom) {
+ log_warnx("rtable %u does not belong to rdomain %u",
+ rtableid, default_rdom);
free(rr);
return (-1);
}