Adjust code after changing struct ctl_show_nexthop to embed a struct kroute_full
authorclaudio <claudio@openbsd.org>
Wed, 22 Jun 2022 14:49:51 +0000 (14:49 +0000)
committerclaudio <claudio@openbsd.org>
Wed, 22 Jun 2022 14:49:51 +0000 (14:49 +0000)
OK tb@

usr.sbin/bgpctl/output.c
usr.sbin/bgpctl/output_json.c

index a9ea514..d22e6d0 100644 (file)
@@ -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 <henning@openbsd.org>
@@ -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",
index 2b61396..8e02a1e 100644 (file)
@@ -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 <claudio@openbsd.org>
@@ -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: