Handle connected routes as ospfd(8) does.

(diff to ospf6d and ospf6ctl)

Index: ospf6ctl/ospf6ctl.c
===================================================================
RCS file: /cvs/src/usr.sbin/ospf6ctl/ospf6ctl.c,v
retrieving revision 1.50
diff -u -p -r1.50 ospf6ctl.c
--- ospf6ctl/ospf6ctl.c 26 May 2019 09:27:09 -0000      1.50
+++ ospf6ctl/ospf6ctl.c 1 Apr 2020 18:16:12 -0000
@@ -1103,10 +1103,10 @@ show_rib_msg(struct imsg *imsg)
                        errx(1, "Invalid route type");
                }
 
-               printf("%-20s %-17s %-12s %-9s %-7d %s\n", dstnet,
+               printf("%-20s %-16s%s %-12s %-9s %-7d %s\n", dstnet,
                    log_in6addr_scope(&rt->nexthop, rt->ifindex),
-                   path_type_name(rt->p_type), dst_type_name(rt->d_type),
-                   rt->cost,
+                   rt->connected ? "C" : " ", path_type_name(rt->p_type),
+                   dst_type_name(rt->d_type), rt->cost,
                    rt->uptime == 0 ? "-" : fmt_timeframe_core(rt->uptime));
                free(dstnet);
                break;
Index: ospf6d/ospf6d.h
===================================================================
RCS file: /cvs/src/usr.sbin/ospf6d/ospf6d.h,v
retrieving revision 1.45
diff -u -p -r1.45 ospf6d.h
--- ospf6d/ospf6d.h     21 Jan 2020 20:38:52 -0000      1.45
+++ ospf6d/ospf6d.h     1 Apr 2020 18:16:12 -0000
@@ -483,6 +483,7 @@ struct ctl_rt {
        enum dst_type            d_type;
        u_int8_t                 flags;
        u_int8_t                 prefixlen;
+       u_int8_t                 connected;
 };
 
 struct ctl_sum {
Index: ospf6d/rde.c
===================================================================
RCS file: /cvs/src/usr.sbin/ospf6d/rde.c,v
retrieving revision 1.85
diff -u -p -r1.85 rde.c
--- ospf6d/rde.c        29 Mar 2020 11:59:11 -0000      1.85
+++ ospf6d/rde.c        1 Apr 2020 18:16:12 -0000
@@ -886,6 +886,9 @@ rde_send_change_kroute(struct rt_node *r
        TAILQ_FOREACH(rn, &r->nexthop, entry) {
                if (rn->invalid)
                        continue;
+               if (rn->connected)
+                       /* skip self-originated routes */
+                       continue;
                krcount++;
 
                bzero(&kr, sizeof(kr));
@@ -899,8 +902,12 @@ rde_send_change_kroute(struct rt_node *r
                kr.ext_tag = r->ext_tag;
                imsg_add(wbuf, &kr, sizeof(kr));
        }
-       if (krcount == 0)
-               fatalx("rde_send_change_kroute: no valid nexthop found");
+       if (krcount == 0) {
+               /* no valid nexthop or self originated, so remove */
+               ibuf_free(wbuf);
+               rde_send_delete_kroute(r);
+               return;
+       }
 
        imsg_close(&iev_main->ibuf, wbuf);
        imsg_event_add(iev_main);
Index: ospf6d/rde_spf.c
===================================================================
RCS file: /cvs/src/usr.sbin/ospf6d/rde_spf.c,v
retrieving revision 1.27
diff -u -p -r1.27 rde_spf.c
--- ospf6d/rde_spf.c    29 Mar 2020 11:59:11 -0000      1.27
+++ ospf6d/rde_spf.c    1 Apr 2020 18:16:12 -0000
@@ -897,7 +897,9 @@ rt_nexthop_add(struct rt_node *r, struct
                rn->ifindex = vn->ifindex;
                rn->adv_rtr.s_addr = adv_rtr.s_addr;
                rn->uptime = now.tv_sec;
-               rn->connected = vn->prev == spf_root;
+               rn->connected = (type == LSA_TYPE_NETWORK &&
+                   vn->prev == spf_root) ||
+                   (IN6_IS_ADDR_UNSPECIFIED(&vn->nexthop));
                rn->invalid = 0;
 
                r->invalid = 0;
@@ -952,21 +954,24 @@ rt_dump(struct in_addr area, pid_t pid, 
                        fatalx("rt_dump: invalid RIB type");
                }
 
+               memset(&rtctl, 0, sizeof(rtctl));
+               rtctl.prefix = r->prefix;
+               rtctl.area.s_addr = r->area.s_addr;
+               rtctl.cost = r->cost;
+               rtctl.cost2 = r->cost2;
+               rtctl.p_type = r->p_type;
+               rtctl.d_type = r->d_type;
+               rtctl.flags = r->flags;
+               rtctl.prefixlen = r->prefixlen;
+
                TAILQ_FOREACH(rn, &r->nexthop, entry) {
                        if (rn->invalid)
                                continue;
 
-                       rtctl.prefix = r->prefix;
+                       rtctl.connected = rn->connected;
                        rtctl.nexthop = rn->nexthop;
                        rtctl.ifindex = rn->ifindex;
-                       rtctl.area.s_addr = r->area.s_addr;
                        rtctl.adv_rtr.s_addr = rn->adv_rtr.s_addr;
-                       rtctl.cost = r->cost;
-                       rtctl.cost2 = r->cost2;
-                       rtctl.p_type = r->p_type;
-                       rtctl.d_type = r->d_type;
-                       rtctl.flags = r->flags;
-                       rtctl.prefixlen = r->prefixlen;
                        rtctl.uptime = now.tv_sec - rn->uptime;
 
                        rde_imsg_compose_ospfe(IMSG_CTL_SHOW_RIB, 0, pid,

Reply via email to