diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2020-12-30 07:31:20 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2020-12-30 07:31:20 +0000 |
commit | 9045574b8eac7108a21b9a4d30203c96517e3766 (patch) | |
tree | fa362cf79cf15403a5621363e777d6f31fe1aa48 | |
parent | bf5844ef63f35037f1f754fe3e17a47b02a553a6 (diff) |
Add 'bgpctl show sets' to display information about the roa-set, as-sets,
and prefix-sets loaded into bgpd.
OK benno@
-rw-r--r-- | usr.sbin/bgpctl/bgpctl.c | 27 | ||||
-rw-r--r-- | usr.sbin/bgpctl/bgpctl.h | 2 | ||||
-rw-r--r-- | usr.sbin/bgpctl/output.c | 23 | ||||
-rw-r--r-- | usr.sbin/bgpctl/output_json.c | 21 | ||||
-rw-r--r-- | usr.sbin/bgpctl/parser.c | 3 | ||||
-rw-r--r-- | usr.sbin/bgpctl/parser.h | 3 |
6 files changed, 74 insertions, 5 deletions
diff --git a/usr.sbin/bgpctl/bgpctl.c b/usr.sbin/bgpctl/bgpctl.c index d74219b2d1e..a35a1ee3ac0 100644 --- a/usr.sbin/bgpctl/bgpctl.c +++ b/usr.sbin/bgpctl/bgpctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpctl.c,v 1.263 2020/05/10 13:38:46 deraadt Exp $ */ +/* $OpenBSD: bgpctl.c,v 1.264 2020/12/30 07:31:19 claudio Exp $ */ /* * Copyright (c) 2003 Henning Brauer <henning@openbsd.org> @@ -213,6 +213,9 @@ main(int argc, char *argv[]) case SHOW_INTERFACE: imsg_compose(ibuf, IMSG_CTL_SHOW_INTERFACE, 0, 0, -1, NULL, 0); break; + case SHOW_SET: + imsg_compose(ibuf, IMSG_CTL_SHOW_SET, 0, 0, -1, NULL, 0); + break; case SHOW_NEIGHBOR: case SHOW_NEIGHBOR_TIMERS: case SHOW_NEIGHBOR_TERSE: @@ -393,6 +396,7 @@ show(struct imsg *imsg, struct parse_result *res) struct ctl_timer *t; struct ctl_show_interface *iface; struct ctl_show_nexthop *nh; + struct ctl_show_set *set; struct kroute_full *kf; struct ktable *kt; struct ctl_show_rib rib; @@ -466,6 +470,10 @@ show(struct imsg *imsg, struct parse_result *res) memcpy(&hash, imsg->data, sizeof(hash)); output->rib_hash(&hash); break; + case IMSG_CTL_SHOW_SET: + set = imsg->data; + output->set(set); + break; case IMSG_CTL_RESULT: if (imsg->hdr.len != IMSG_HEADER_SIZE + sizeof(rescode)) { warnx("got IMSG_CTL_RESULT with wrong len"); @@ -977,6 +985,23 @@ fmt_ext_community(u_int8_t *data) } } +const char * +fmt_set_type(struct ctl_show_set *set) +{ + switch (set->type) { + case ROA_SET: + return "ROA"; + case PREFIX_SET: + return "PREFIX"; + case ORIGIN_SET: + return "ORIGIN"; + case ASNUM_SET: + return "ASNUM"; + default: + return "BULA"; + } +} + void send_filterset(struct imsgbuf *i, struct filter_set_head *set) { diff --git a/usr.sbin/bgpctl/bgpctl.h b/usr.sbin/bgpctl/bgpctl.h index 03d0a16cc7f..a3fe10cc2bb 100644 --- a/usr.sbin/bgpctl/bgpctl.h +++ b/usr.sbin/bgpctl/bgpctl.h @@ -30,6 +30,7 @@ struct output { struct parse_result *); void (*rib_hash)(struct rde_hashstats *); void (*rib_mem)(struct rde_memstats *); + void (*set)(struct ctl_show_set *); void (*result)(u_int); void (*tail)(void); }; @@ -53,3 +54,4 @@ const char *fmt_attr(u_int8_t, int); const char *fmt_community(u_int16_t, u_int16_t); const char *fmt_large_community(u_int32_t, u_int32_t, u_int32_t); const char *fmt_ext_community(u_int8_t *); +const char *fmt_set_type(struct ctl_show_set *); diff --git a/usr.sbin/bgpctl/output.c b/usr.sbin/bgpctl/output.c index d7c23e9f08d..2d49cb3b2e2 100644 --- a/usr.sbin/bgpctl/output.c +++ b/usr.sbin/bgpctl/output.c @@ -1,4 +1,4 @@ -/* $OpenBSD: output.c,v 1.10 2020/10/21 06:52:45 claudio Exp $ */ +/* $OpenBSD: output.c,v 1.11 2020/12/30 07:31:19 claudio Exp $ */ /* * Copyright (c) 2003 Henning Brauer <henning@openbsd.org> @@ -77,6 +77,10 @@ show_head(struct parse_result *res) "flags", "ovs", "destination", "gateway", "lpref", "med", "aspath origin"); break; + case SHOW_SET: + printf("%-6s %-34s %7s %7s %6s %11s\n", "Type", "Name", + "#IPv4", "#IPv6", "#ASnum", "Last Change"); + break; case NETWORK_SHOW: printf("flags: S = Static\n"); printf("flags prio destination gateway\n"); @@ -958,6 +962,22 @@ show_rib_hash(struct rde_hashstats *hash) } static void +show_rib_set(struct ctl_show_set *set) +{ + char buf[64]; + + if (set->type == ASNUM_SET) + snprintf(buf, sizeof(buf), "%7s %7s %6zu", + "-", "-", set->as_cnt); + else + snprintf(buf, sizeof(buf), "%7zu %7zu %6s", + set->v4_cnt, set->v6_cnt, "-"); + + printf("%-6s %-34s %s %11s\n", fmt_set_type(set), set->name, + buf, fmt_monotime(set->lastchange)); +} + +static void show_result(u_int rescode) { if (rescode == 0) @@ -988,6 +1008,7 @@ const struct output show_output = { .rib = show_rib, .rib_mem = show_rib_mem, .rib_hash = show_rib_hash, + .set = show_rib_set, .result = show_result, .tail = show_tail }; diff --git a/usr.sbin/bgpctl/output_json.c b/usr.sbin/bgpctl/output_json.c index 5fb29dec723..3b20533266b 100644 --- a/usr.sbin/bgpctl/output_json.c +++ b/usr.sbin/bgpctl/output_json.c @@ -1,4 +1,4 @@ -/* $OpenBSD: output_json.c,v 1.4 2020/10/21 06:52:45 claudio Exp $ */ +/* $OpenBSD: output_json.c,v 1.5 2020/12/30 07:31:19 claudio Exp $ */ /* * Copyright (c) 2020 Claudio Jeker <claudio@openbsd.org> @@ -919,6 +919,24 @@ json_rib_hash(struct rde_hashstats *hash) } static void +json_rib_set(struct ctl_show_set *set) +{ + json_do_array("sets"); + + json_do_object("set"); + json_do_printf("name", "%s", set->name); + json_do_printf("type", "%s", fmt_set_type(set)); + json_do_printf("last_change", "%s", fmt_monotime(set->lastchange)); + if (set->type == ASNUM_SET) { + json_do_uint("num_ASnum", set->as_cnt); + } else { + json_do_uint("num_IPv4", set->v4_cnt); + json_do_uint("num_IPv6", set->v6_cnt); + } + json_do_end(); +} + +static void json_result(u_int rescode) { if (rescode == 0) @@ -952,6 +970,7 @@ const struct output json_output = { .rib = json_rib, .rib_mem = json_rib_mem, .rib_hash = json_rib_hash, + .set = json_rib_set, .result = json_result, .tail = json_tail }; diff --git a/usr.sbin/bgpctl/parser.c b/usr.sbin/bgpctl/parser.c index f9b6eba5928..7a98e6d65df 100644 --- a/usr.sbin/bgpctl/parser.c +++ b/usr.sbin/bgpctl/parser.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.c,v 1.104 2020/05/12 13:26:02 claudio Exp $ */ +/* $OpenBSD: parser.c,v 1.105 2020/12/30 07:31:19 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -136,6 +136,7 @@ static const struct token t_show[] = { { KEYWORD, "tables", SHOW_FIB_TABLES, NULL}, { KEYWORD, "ip", NONE, t_show_ip}, { KEYWORD, "summary", SHOW_SUMMARY, t_show_summary}, + { KEYWORD, "sets", SHOW_SET, NULL}, { KEYWORD, "mrt", SHOW_MRT, t_show_mrt}, { ENDTOKEN, "", NONE, NULL} }; diff --git a/usr.sbin/bgpctl/parser.h b/usr.sbin/bgpctl/parser.h index 7789bdcc206..2e6350689c9 100644 --- a/usr.sbin/bgpctl/parser.h +++ b/usr.sbin/bgpctl/parser.h @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.h,v 1.38 2020/05/10 13:38:46 deraadt Exp $ */ +/* $OpenBSD: parser.h,v 1.39 2020/12/30 07:31:19 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -32,6 +32,7 @@ enum actions { SHOW_FIB_TABLES, SHOW_RIB, SHOW_MRT, + SHOW_SET, SHOW_RIB_MEM, SHOW_NEXTHOP, SHOW_INTERFACE, |