From fe65f56ae2a16494e2efcbdff155730a68117e65 Mon Sep 17 00:00:00 2001 From: claudio Date: Wed, 22 Jun 2022 14:49:51 +0000 Subject: [PATCH] Adjust code after changing struct ctl_show_nexthop to embed a struct kroute_full OK tb@ --- usr.sbin/bgpctl/output.c | 40 +++++++++-------------------------- usr.sbin/bgpctl/output_json.c | 31 ++++++--------------------- 2 files changed, 16 insertions(+), 55 deletions(-) diff --git a/usr.sbin/bgpctl/output.c b/usr.sbin/bgpctl/output.c index a9ea514b2a5..d22e6d0b111 100644 --- a/usr.sbin/bgpctl/output.c +++ b/usr.sbin/bgpctl/output.c @@ -1,4 +1,4 @@ -/* $OpenBSD: output.c,v 1.21 2022/06/15 10:10:50 claudio Exp $ */ +/* $OpenBSD: output.c,v 1.22 2022/06/22 14:49:51 claudio Exp $ */ /* * Copyright (c) 2003 Henning Brauer @@ -480,8 +480,6 @@ show_fib_table(struct ktable *kt) static void show_nexthop(struct ctl_show_nexthop *nh) { - struct kroute *k; - struct kroute6 *k6; char *s; printf("%s %-15s ", nh->valid ? "*" : " ", log_addr(&nh->addr)); @@ -489,33 +487,15 @@ show_nexthop(struct ctl_show_nexthop *nh) printf("\n"); return; } - switch (nh->addr.aid) { - case AID_INET: - k = &nh->kr.kr4; - if (asprintf(&s, "%s/%u", inet_ntoa(k->prefix), - k->prefixlen) == -1) - err(1, NULL); - printf("%-20s", s); - free(s); - printf("%3i %-15s ", k->priority, - k->flags & F_CONNECTED ? "connected" : - inet_ntoa(k->nexthop)); - break; - case AID_INET6: - k6 = &nh->kr.kr6; - if (asprintf(&s, "%s/%u", log_in6addr(&k6->prefix), - k6->prefixlen) == -1) - err(1, NULL); - printf("%-20s", s); - free(s); - printf("%3i %-15s ", k6->priority, - k6->flags & F_CONNECTED ? "connected" : - log_in6addr(&k6->nexthop)); - break; - default: - printf("unknown address family\n"); - return; - } + if (asprintf(&s, "%s/%u", log_addr(&nh->kr.prefix), + nh->kr.prefixlen) == -1) + err(1, NULL); + printf("%-20s", s); + free(s); + printf("%3i %-15s ", nh->kr.priority, + nh->kr.flags & F_CONNECTED ? "connected" : + log_addr(&nh->kr.nexthop)); + if (nh->iface.ifname[0]) { printf("%s (%s, %s)", nh->iface.ifname, nh->iface.is_up ? "UP" : "DOWN", diff --git a/usr.sbin/bgpctl/output_json.c b/usr.sbin/bgpctl/output_json.c index 2b61396fdcd..8e02a1e2a20 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.15 2022/06/15 10:10:50 claudio Exp $ */ +/* $OpenBSD: output_json.c,v 1.16 2022/06/22 14:49:51 claudio Exp $ */ /* * Copyright (c) 2020 Claudio Jeker @@ -414,9 +414,6 @@ json_do_interface(struct ctl_show_interface *iface) static void json_nexthop(struct ctl_show_nexthop *nh) { - struct kroute *k; - struct kroute6 *k6; - json_do_array("nexthops"); json_do_object("nexthop"); @@ -427,27 +424,11 @@ json_nexthop(struct ctl_show_nexthop *nh) if (!nh->krvalid) goto done; - switch (nh->addr.aid) { - case AID_INET: - k = &nh->kr.kr4; - json_do_printf("prefix", "%s/%u", inet_ntoa(k->prefix), - k->prefixlen); - json_do_uint("priority", k->priority); - json_do_bool("connected", k->flags & F_CONNECTED); - json_do_printf("nexthop", "%s", inet_ntoa(k->nexthop)); - break; - case AID_INET6: - k6 = &nh->kr.kr6; - json_do_printf("prefix", "%s/%u", log_in6addr(&k6->prefix), - k6->prefixlen); - json_do_uint("priority", k6->priority); - json_do_bool("connected", k6->flags & F_CONNECTED); - json_do_printf("nexthop", "%s", log_in6addr(&k6->nexthop)); - break; - default: - warnx("nexthop: unknown address family"); - goto done; - } + json_do_printf("prefix", "%s/%u", log_addr(&nh->kr.prefix), + nh->kr.prefixlen); + json_do_uint("priority", nh->kr.priority); + json_do_bool("connected", nh->kr.flags & F_CONNECTED); + json_do_printf("nexthop", "%s", log_addr(&nh->kr.nexthop)); if (nh->iface.ifname[0]) json_do_interface(&nh->iface); done: -- 2.20.1