On Wed, Jul 22, 2009 at 04:37:03PM +0200, Henning Brauer wrote:
> this still removes the interface info I want to see.
> 
> why do you keep ignoring the advice of replaceing the long
> valid/invalid words by some kind of marker like we do in the RIB?
> 
> <[email protected]>  $ bgpctl sh ri as 24640
> flags: * = Valid, > = Selected, I = via IBGP, A = Announced
> 
> can use the same here.
> 
> Nexthop            Route           Gateway     Interface
> *100.200.300.400   62.48.4.0/24    connected   vlan206 UP, Ethernet, active
>  200.200.300.400   62.48.6.0/24    connected   vlan207 UP, Ethernet, no 
> carrier
> 
> voila.
> 

So here is another try:
bgpctl show next | head
Flags: * = nexthop valid

  Nexthop         Route              Prio Gateway         Iface               
* 10.23.0.2       10.23.0.0/16          4 connected       fxp0 (UP, active)
* 10.23.0.3       10.23.0.0/16          4 connected       fxp0 (UP, active)
* 10.23.0.4       10.23.0.0/16          4 connected       fxp0 (UP, active)
...
  10.23.0.5       10.23.0.0/16          4 connected       fxp0 (DOWN, active)
  10.23.0.6       10.23.0.0/16          4 connected       fxp0 (DOWN, active)
...
  10.23.0.7       10.23.0.0/16          4 connected       fxp0 (UP, no carrier)
  10.23.0.8       10.23.0.0/16          4 connected       fxp0 (UP, no carrier)

-- 
:wq Claudio

Index: bgpctl/bgpctl.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpctl/bgpctl.c,v
retrieving revision 1.144
diff -u -p -r1.144 bgpctl.c
--- bgpctl/bgpctl.c     21 Jul 2009 11:49:36 -0000      1.144
+++ bgpctl/bgpctl.c     23 Jul 2009 12:44:30 -0000
@@ -848,35 +848,68 @@ show_fib_msg(struct imsg *imsg)
 void
 show_nexthop_head(void)
 {
-       printf("%-20s %-10s\n", "Nexthop", "State");
+       printf("Flags: * = nexthop valid\n");
+       printf("\n  %-15s %-19s%-4s %-15s %-20s\n", "Nexthop", "Route",
+            "Prio", "Gateway", "Iface");
 }
 
 int
 show_nexthop_msg(struct imsg *imsg)
 {
        struct ctl_show_nexthop *p;
+       struct kroute           *k;
+       struct kroute6          *k6;
+       char                    *s;
        int                      ifms_type;
 
        switch (imsg->hdr.type) {
        case IMSG_CTL_SHOW_NEXTHOP:
                p = imsg->data;
-               printf("%-20s %-10s", log_addr(&p->addr),
-                   p->valid ? "valid" : "invalid");
+               printf("%s %-15s ", p->valid ? "*" : " ", log_addr(&p->addr));
+               if (!p->krvalid) {
+                       printf("\n");
+                       return (0);
+               }
+               switch (p->addr.af) {
+               case AF_INET:
+                       k = &p->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 AF_INET6:
+                       k6 = &p->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 familiy %d\n", p->addr.af);
+                       return (0);
+               }
                if (p->kif.ifname[0]) {
-                       printf("%-8s", p->kif.ifname);
-                       if (p->kif.flags & IFF_UP) {
-                               printf("UP");
-                               ifms_type = ift2ifm(p->kif.media_type);
-                               if (ifms_type != 0)
-                                       printf(", %s, %s",
-                                           get_media_descr(ifms_type),
-                                           get_linkstate(ifms_type,
-                                           p->kif.link_state));
-                               if (p->kif.baudrate) {
-                                       printf(", ");
-                                       print_baudrate(p->kif.baudrate);
-                               }
-                       }
+                       char *s1;
+                       ifms_type = ift2ifm(p->kif.media_type);
+                       if (ifms_type)
+                               if (asprintf(&s1, ", %s", get_linkstate(
+                                   ifms_type, p->kif.link_state)) == -1)
+                                       err(1, NULL);
+                       if (asprintf(&s, "%s (%s%s)", p->kif.ifname, 
+                           p->kif.flags & IFF_UP ? "UP" : "DOWN", s1) == -1)
+                               err(1, NULL);
+                       printf("%-15s", s);
+                       free(s1);
+                       free(s);
                }
                printf("\n");
                break;
Index: bgpd/bgpd.h
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/bgpd.h,v
retrieving revision 1.242
diff -u -p -r1.242 bgpd.h
--- bgpd/bgpd.h 20 Jul 2009 15:03:16 -0000      1.242
+++ bgpd/bgpd.h 22 Jul 2009 11:48:34 -0000
@@ -437,10 +437,13 @@ struct pftable_msg {
 
 struct ctl_show_nexthop {
        struct bgpd_addr        addr;
-       struct bgpd_addr        gateway;
        struct kif              kif;
+       union {
+               struct kroute           kr4;
+               struct kroute6          kr6;
+       } kr;
        u_int8_t                valid;
-       u_int8_t                connected;
+       u_int8_t                krvalid;;
 };
 
 struct ctl_neighbor {
Index: bgpd/kroute.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/kroute.c,v
retrieving revision 1.171
diff -u -p -r1.171 kroute.c
--- bgpd/kroute.c       23 Jul 2009 10:20:44 -0000      1.171
+++ bgpd/kroute.c       23 Jul 2009 11:50:34 -0000
@@ -587,26 +587,17 @@ kr_show_route(struct imsg *imsg)
                                case AF_INET:
                                        kr = h->kroute;
                                        snh.valid = kroute_validate(&kr->r);
-                                       snh.connected =
-                                           kr->r.flags & F_CONNECTED;
-                                       if ((snh.gateway.v4.s_addr =
-                                           kr->r.nexthop.s_addr) != 0)
-                                               snh.gateway.af = AF_INET;
+                                       snh.krvalid = 1;
+                                       memcpy(&snh.kr.kr4, &kr->r,
+                                           sizeof(snh.kr.kr4));
                                        ifindex = kr->r.ifindex;
                                        break;
                                case AF_INET6:
                                        kr6 = h->kroute;
                                        snh.valid = kroute6_validate(&kr6->r);
-                                       snh.connected =
-                                           kr6->r.flags & F_CONNECTED;
-                                       if (memcmp(&kr6->r.nexthop,
-                                           &in6addr_any,
-                                           sizeof(struct in6_addr)) != 0) {
-                                               snh.gateway.af = AF_INET6;
-                                               memcpy(&snh.gateway.v6,
-                                                   &kr6->r.nexthop,
-                                                   sizeof(struct in6_addr));
-                                       }
+                                       snh.krvalid = 1;
+                                       memcpy(&snh.kr.kr6, &kr6->r,
+                                           sizeof(snh.kr.kr6));
                                        ifindex = kr6->r.ifindex;
                                        break;
                                }

Reply via email to