summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorclaudio <claudio@openbsd.org>2010-05-03 13:11:41 +0000
committerclaudio <claudio@openbsd.org>2010-05-03 13:11:41 +0000
commit7f410e5ebd93e4b0117a24553fd1da48456e00a8 (patch)
tree5b9f6e598db3f077c8686782d97d8dd3691897db
parentMake it possible to load multiple routing tables at the same time and use (diff)
downloadwireguard-openbsd-7f410e5ebd93e4b0117a24553fd1da48456e00a8.tar.xz
wireguard-openbsd-7f410e5ebd93e4b0117a24553fd1da48456e00a8.zip
Adjustments for multiple kroute table support. This adds a few new command
arguments (show tables and show fib table 1, etc). Tested by sthen@, OK to move on by henning@
-rw-r--r--usr.sbin/bgpctl/bgpctl.836
-rw-r--r--usr.sbin/bgpctl/bgpctl.c63
-rw-r--r--usr.sbin/bgpctl/parser.c45
-rw-r--r--usr.sbin/bgpctl/parser.h6
4 files changed, 111 insertions, 39 deletions
diff --git a/usr.sbin/bgpctl/bgpctl.8 b/usr.sbin/bgpctl/bgpctl.8
index 11ae0ebd177..27a296a12e2 100644
--- a/usr.sbin/bgpctl/bgpctl.8
+++ b/usr.sbin/bgpctl/bgpctl.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: bgpctl.8,v 1.52 2009/11/03 08:09:15 jmc Exp $
+.\" $OpenBSD: bgpctl.8,v 1.53 2010/05/03 13:11:41 claudio Exp $
.\"
.\" Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
.\"
@@ -14,7 +14,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: November 3 2009 $
+.Dd $Mdocdate: May 3 2010 $
.Dt BGPCTL 8
.Os
.Sh NAME
@@ -53,11 +53,19 @@ to communicate with
.Pp
The commands are as follows:
.Bl -tag -width xxxxxx
-.It Cm fib couple
-Insert the learned routes into the Forwarding Information Base
+.It Xo
+.Cm fib
+.Op Cm table Ar number
+.Cm couple
+.Xc
+Insert the learned routes into the specified Forwarding Information Base
a.k.a. the kernel routing table.
-.It Cm fib decouple
-Remove the learned routes from the Forwarding Information Base
+.It Xo
+.Cm fib
+.Op Cm table Ar number
+.Cm decouple
+.Xc
+Remove the learned routes from the specified Forwarding Information Base
a.k.a. the kernel routing table.
.It Xo
.Cm irrfilter
@@ -106,8 +114,10 @@ Note that the neighbor is not obliged to re-send all routes, or any routes at
all, even if it announced the route refresh capability.
.Ar peer
may be the neighbor's address or description.
-.It Cm network add Ar prefix
+.It Cm network add Ar prefix Op Ar arguments
Add the specified prefix to the list of announced networks.
+It is possible to set various path attributes with additional
+.Ar arguments .
.It Cm network delete Ar prefix
Remove the specified prefix from the list of announced networks.
.It Cm network flush
@@ -130,7 +140,7 @@ view of the Forwarding Information Base.
can be an IP address, in which case the route to this address is shown,
or a flag:
.Pp
-.Bl -tag -width connected -compact
+.Bl -tag -width tableXnumber -compact
.It Cm connected
Show only connected routes.
.It Cm static
@@ -141,6 +151,14 @@ Show only routes originating from
itself.
.It Cm nexthop
Show only routes required to reach a BGP nexthop.
+.It Cm inet
+Show only IPv4 routes.
+.It Cm inet6
+Show only IPv6 routes.
+.It Cm table Ar number
+Show the routing table with ID
+.Ar number
+instead of the default routing table with ID 0.
.El
.It Cm show interfaces
Show the interface states.
@@ -251,6 +269,8 @@ and message counters.
.It Cm show summary terse
Show a list of all neighbors, including information about the session state,
in a terse format.
+.It Cm show tables
+Show a list of all currently loaded fib routing tables.
.El
.Sh FILES
.Bl -tag -width "/var/run/bgpd.sockXXX" -compact
diff --git a/usr.sbin/bgpctl/bgpctl.c b/usr.sbin/bgpctl/bgpctl.c
index ae9a9e8befc..a4e80febba7 100644
--- a/usr.sbin/bgpctl/bgpctl.c
+++ b/usr.sbin/bgpctl/bgpctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bgpctl.c,v 1.158 2010/04/13 09:10:50 claudio Exp $ */
+/* $OpenBSD: bgpctl.c,v 1.159 2010/05/03 13:11:41 claudio Exp $ */
/*
* Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
@@ -56,6 +56,7 @@ void print_timer(const char *, time_t);
static char *fmt_timeframe(time_t t);
static char *fmt_timeframe_core(time_t t);
void show_fib_head(void);
+void show_fib_tables_head(void);
void show_network_head(void);
void show_fib_flags(u_int16_t);
int show_fib_msg(struct imsg *);
@@ -171,8 +172,9 @@ main(int argc, char *argv[])
sa_family_t af;
af = aid2af(res->aid);
- if ((msg = imsg_create(ibuf, IMSG_CTL_KROUTE, 0, 0,
- sizeof(res->flags) + sizeof(af))) == NULL)
+ if ((msg = imsg_create(ibuf, IMSG_CTL_KROUTE,
+ res->rtableid, 0, sizeof(res->flags) +
+ sizeof(af))) == NULL)
errx(1, "imsg_create failure");
if (imsg_add(msg, &res->flags, sizeof(res->flags)) ==
-1 ||
@@ -180,12 +182,17 @@ main(int argc, char *argv[])
errx(1, "imsg_add failure");
imsg_close(ibuf, msg);
} else
- imsg_compose(ibuf, IMSG_CTL_KROUTE_ADDR, 0, 0, -1,
- &res->addr, sizeof(res->addr));
+ imsg_compose(ibuf, IMSG_CTL_KROUTE_ADDR, res->rtableid,
+ 0, -1, &res->addr, sizeof(res->addr));
show_fib_head();
break;
+ case SHOW_FIB_TABLES:
+ imsg_compose(ibuf, IMSG_CTL_SHOW_FIB_TABLES, 0, 0, -1, NULL, 0);
+ show_fib_tables_head();
+ break;
case SHOW_NEXTHOP:
- imsg_compose(ibuf, IMSG_CTL_SHOW_NEXTHOP, 0, 0, -1, NULL, 0);
+ imsg_compose(ibuf, IMSG_CTL_SHOW_NEXTHOP, res->rtableid, 0, -1,
+ NULL, 0);
show_nexthop_head();
break;
case SHOW_INTERFACE:
@@ -241,12 +248,14 @@ main(int argc, char *argv[])
errx(1, "action==FIB");
break;
case FIB_COUPLE:
- imsg_compose(ibuf, IMSG_CTL_FIB_COUPLE, 0, 0, -1, NULL, 0);
+ imsg_compose(ibuf, IMSG_CTL_FIB_COUPLE, res->rtableid, 0, -1,
+ NULL, 0);
printf("couple request sent.\n");
done = 1;
break;
case FIB_DECOUPLE:
- imsg_compose(ibuf, IMSG_CTL_FIB_DECOUPLE, 0, 0, -1, NULL, 0);
+ imsg_compose(ibuf, IMSG_CTL_FIB_DECOUPLE, res->rtableid, 0, -1,
+ NULL, 0);
printf("decouple request sent.\n");
done = 1;
break;
@@ -342,6 +351,8 @@ main(int argc, char *argv[])
done = show_summary_terse_msg(&imsg, nodescr);
break;
case SHOW_FIB:
+ case SHOW_FIB_TABLES:
+ case NETWORK_SHOW:
done = show_fib_msg(&imsg);
break;
case SHOW_NEXTHOP:
@@ -369,9 +380,6 @@ main(int argc, char *argv[])
case SHOW_RIB_MEM:
done = show_rib_memory_msg(&imsg);
break;
- case NETWORK_SHOW:
- done = show_fib_msg(&imsg);
- break;
case NEIGHBOR:
case NEIGHBOR_UP:
case NEIGHBOR_DOWN:
@@ -761,6 +769,12 @@ show_fib_head(void)
}
void
+show_fib_tables_head(void)
+{
+ printf("%-5s %-20s %-8s\n", "Table", "Description", "State");
+}
+
+void
show_network_head(void)
{
printf("flags: S = Static\n");
@@ -805,6 +819,7 @@ int
show_fib_msg(struct imsg *imsg)
{
struct kroute_full *kf;
+ struct ktable *kt;
char *p;
switch (imsg->hdr.type) {
@@ -829,6 +844,16 @@ show_fib_msg(struct imsg *imsg)
printf("\n");
break;
+ case IMSG_CTL_SHOW_FIB_TABLES:
+ if (imsg->hdr.len < IMSG_HEADER_SIZE + sizeof(*kt))
+ errx(1, "wrong imsg len");
+ kt = imsg->data;
+
+ printf("%5i %-20s %-8s%s\n", kt->rtableid, kt->descr,
+ kt->fib_sync ? "coupled" : "decoupled",
+ kt->fib_sync != kt->fib_conf ? "*" : "");
+
+ break;
case IMSG_CTL_END:
return (1);
default:
@@ -1071,26 +1096,26 @@ print_flags(u_int8_t flags, int sum)
char *p = flagstr;
if (sum) {
- if (flags & F_RIB_ANNOUNCE)
+ if (flags & F_PREF_ANNOUNCE)
*p++ = 'A';
- if (flags & F_RIB_INTERNAL)
+ if (flags & F_PREF_INTERNAL)
*p++ = 'I';
- if (flags & F_RIB_ELIGIBLE)
+ if (flags & F_PREF_ELIGIBLE)
*p++ = '*';
- if (flags & F_RIB_ACTIVE)
+ if (flags & F_PREF_ACTIVE)
*p++ = '>';
*p = '\0';
printf("%-5s ", flagstr);
} else {
- if (flags & F_RIB_INTERNAL)
+ if (flags & F_PREF_INTERNAL)
printf("internal");
else
printf("external");
- if (flags & F_RIB_ELIGIBLE)
+ if (flags & F_PREF_ELIGIBLE)
printf(", valid");
- if (flags & F_RIB_ACTIVE)
+ if (flags & F_PREF_ACTIVE)
printf(", best");
- if (flags & F_RIB_ANNOUNCE)
+ if (flags & F_PREF_ANNOUNCE)
printf(", announced");
}
}
diff --git a/usr.sbin/bgpctl/parser.c b/usr.sbin/bgpctl/parser.c
index f1f560d97d0..1854b7d0f60 100644
--- a/usr.sbin/bgpctl/parser.c
+++ b/usr.sbin/bgpctl/parser.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.c,v 1.61 2010/03/08 17:02:19 claudio Exp $ */
+/* $OpenBSD: parser.c,v 1.62 2010/05/03 13:11:41 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -52,7 +52,8 @@ enum token_type {
PREPSELF,
WEIGHT,
FAMILY,
- GETOPT
+ GETOPT,
+ RTABLE
};
enum getopts {
@@ -98,6 +99,8 @@ static const struct token t_weight[];
static const struct token t_irrfilter[];
static const struct token t_irrfilter_opts[];
static const struct token t_log[];
+static const struct token t_fib_table[];
+static const struct token t_show_fib_table[];
static const struct token t_main[] = {
{ KEYWORD, "reload", RELOAD, NULL},
@@ -118,6 +121,7 @@ static const struct token t_show[] = {
{ KEYWORD, "network", NETWORK_SHOW, t_network_show},
{ KEYWORD, "nexthop", SHOW_NEXTHOP, NULL},
{ KEYWORD, "rib", SHOW_RIB, t_show_rib},
+ { KEYWORD, "tables", SHOW_FIB_TABLES, NULL},
{ KEYWORD, "ip", NONE, t_show_ip},
{ KEYWORD, "summary", SHOW_SUMMARY, t_show_summary},
{ ENDTOKEN, "", NONE, NULL}
@@ -130,14 +134,15 @@ static const struct token t_show_summary[] = {
};
static const struct token t_show_fib[] = {
- { NOTOKEN, "", NONE, NULL},
- { FLAG, "connected", F_CONNECTED, t_show_fib},
- { FLAG, "static", F_STATIC, t_show_fib},
- { FLAG, "bgp", F_BGPD_INSERTED, t_show_fib},
- { FLAG, "nexthop", F_NEXTHOP, t_show_fib},
- { FAMILY, "", NONE, t_show_fib},
- { ADDRESS, "", NONE, NULL},
- { ENDTOKEN, "", NONE, NULL}
+ { NOTOKEN, "", NONE, NULL},
+ { FLAG, "connected", F_CONNECTED, t_show_fib},
+ { FLAG, "static", F_STATIC, t_show_fib},
+ { FLAG, "bgp", F_BGPD_INSERTED, t_show_fib},
+ { FLAG, "nexthop", F_NEXTHOP, t_show_fib},
+ { KEYWORD, "table", NONE, t_show_fib_table},
+ { FAMILY, "", NONE, t_show_fib},
+ { ADDRESS, "", NONE, NULL},
+ { ENDTOKEN, "", NONE, NULL}
};
static const struct token t_show_rib[] = {
@@ -189,6 +194,7 @@ static const struct token t_show_neighbor_modifiers[] = {
static const struct token t_fib[] = {
{ KEYWORD, "couple", FIB_COUPLE, NULL},
{ KEYWORD, "decouple", FIB_DECOUPLE, NULL},
+ { KEYWORD, "table", NONE, t_fib_table},
{ ENDTOKEN, "", NONE, NULL}
};
@@ -319,6 +325,16 @@ static const struct token t_log[] = {
{ ENDTOKEN, "", NONE, NULL}
};
+static const struct token t_fib_table[] = {
+ { RTABLE, "", NONE, t_fib},
+ { ENDTOKEN, "", NONE, NULL}
+};
+
+static const struct token t_show_fib_table[] = {
+ { RTABLE, "", NONE, t_show_fib},
+ { ENDTOKEN, "", NONE, NULL}
+};
+
static struct parse_result res;
const struct token *match_token(int *argc, char **argv[],
@@ -500,6 +516,7 @@ match_token(int *argc, char **argv[], const struct token table[])
case PREPNBR:
case PREPSELF:
case WEIGHT:
+ case RTABLE:
if (word != NULL && strlen(word) > 0 &&
parse_number(word, &res, table[i].type)) {
match++;
@@ -592,6 +609,9 @@ show_valid_args(const struct token table[])
case WEIGHT:
fprintf(stderr, " <number>\n");
break;
+ case RTABLE:
+ fprintf(stderr, " <rtableid>\n");
+ break;
case NEXTHOP:
fprintf(stderr, " <address>\n");
break;
@@ -739,6 +759,11 @@ parse_number(const char *word, struct parse_result *r, enum token_type type)
errx(1, "number is %s: %s", errstr, word);
/* number was parseable */
+ if (type == RTABLE) {
+ r->rtableid = uval;
+ return (1);
+ }
+
if ((fs = calloc(1, sizeof(struct filter_set))) == NULL)
err(1, NULL);
switch (type) {
diff --git a/usr.sbin/bgpctl/parser.h b/usr.sbin/bgpctl/parser.h
index 2b7da598a32..3b6ce758a41 100644
--- a/usr.sbin/bgpctl/parser.h
+++ b/usr.sbin/bgpctl/parser.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.h,v 1.21 2010/01/10 00:16:23 claudio Exp $ */
+/* $OpenBSD: parser.h,v 1.22 2010/05/03 13:11:41 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -29,6 +29,7 @@ enum actions {
SHOW_NEIGHBOR_TIMERS,
SHOW_NEIGHBOR_TERSE,
SHOW_FIB,
+ SHOW_FIB_TABLES,
SHOW_RIB,
SHOW_RIB_MEM,
SHOW_NEXTHOP,
@@ -61,7 +62,8 @@ struct parse_result {
char rib[PEER_DESCR_LEN];
char *irr_outdir;
int flags;
- enum actions action;
+ u_int rtableid;
+ enum actions action;
u_int8_t prefixlen;
u_int8_t aid;
};