]> git.puffer.fish Git - matthieu/frr.git/commitdiff
ospf6d: Add logic to change the status of router to ASBR
authorYash Ranjan <ranjany@vmware.com>
Wed, 10 Feb 2021 06:44:44 +0000 (22:44 -0800)
committerYash Ranjan <ranjany@vmware.com>
Mon, 29 Mar 2021 13:37:10 +0000 (06:37 -0700)
Signed-off-by: Yash Ranjan <ranjany@vmware.com>
ospf6d/ospf6_asbr.c
ospf6d/ospf6_spf.h
ospf6d/ospf6_top.c
ospf6d/ospf6_top.h
ospf6d/ospf6d.h

index 62ce74718bb6d81e6ce6f123434e0fd1d619178b..cb6359300ab460f42b2b2271307bd7e62a044c16 100644 (file)
@@ -37,6 +37,7 @@
 #include "ospf6_route.h"
 #include "ospf6_zebra.h"
 #include "ospf6_message.h"
+#include "ospf6_spf.h"
 
 #include "ospf6_top.h"
 #include "ospf6_area.h"
@@ -1051,6 +1052,7 @@ static struct ospf6_redist *ospf6_redist_add(struct ospf6 *ospf6, int type,
        ROUTEMAP(red) = NULL;
 
        listnode_add(ospf6->redist[type], red);
+       ospf6->redistribute++;
 
        return red;
 }
@@ -1064,6 +1066,7 @@ static void ospf6_redist_del(struct ospf6 *ospf6, struct ospf6_redist *red,
                        list_delete(&ospf6->redist[type]);
                }
                XFREE(MTYPE_OSPF6_REDISTRIBUTE, red);
+               ospf6->redistribute--;
        }
 }
 
@@ -1131,6 +1134,35 @@ void ospf6_asbr_remove_externals_from_area(struct ospf6_area *oa)
        }
 }
 
+/* Update ASBR status. */
+static void ospf6_asbr_status_update(struct ospf6 *ospf6, uint8_t status)
+{
+       struct listnode *lnode, *lnnode;
+       struct ospf6_area *oa;
+
+       zlog_info("ASBR[%s:Status:%d]: Update", ospf6->name, status);
+
+       if (status) {
+               if (IS_OSPF6_ASBR(ospf6)) {
+                       zlog_info("ASBR[%s:Status:%d]: Already ASBR",
+                                 ospf6->name, status);
+                       return;
+               }
+               SET_FLAG(ospf6->flag, OSPF6_FLAG_ASBR);
+       } else {
+               if (!IS_OSPF6_ASBR(ospf6)) {
+                       zlog_info("ASBR[%s:Status:%d]: Already non ASBR",
+                                 ospf6->name, status);
+                       return;
+               }
+               UNSET_FLAG(ospf6->flag, OSPF6_FLAG_ASBR);
+       }
+
+       ospf6_spf_schedule(ospf6, OSPF6_SPF_FLAGS_ASBR_STATUS_CHANGE);
+       for (ALL_LIST_ELEMENTS(ospf6->area_list, lnode, lnnode, oa))
+               OSPF6_ROUTER_LSA_SCHEDULE(oa);
+}
+
 void ospf6_asbr_redistribute_add(int type, ifindex_t ifindex,
                                 struct prefix *prefix,
                                 unsigned int nexthop_num,
@@ -1145,8 +1177,6 @@ void ospf6_asbr_redistribute_add(int type, ifindex_t ifindex,
        struct prefix prefix_id;
        struct route_node *node;
        char ibuf[16];
-       struct listnode *lnode, *lnnode;
-       struct ospf6_area *oa;
        struct ospf6_redist *red;
 
        red = ospf6_redist_lookup(ospf6, type, 0);
@@ -1236,6 +1266,7 @@ void ospf6_asbr_redistribute_add(int type, ifindex_t ifindex,
 
                match->path.origin.id = htonl(info->id);
                ospf6_as_external_lsa_originate(match, ospf6);
+               ospf6_asbr_status_update(ospf6, ospf6->redistribute);
                return;
        }
 
@@ -1289,10 +1320,7 @@ void ospf6_asbr_redistribute_add(int type, ifindex_t ifindex,
 
        route->path.origin.id = htonl(info->id);
        ospf6_as_external_lsa_originate(route, ospf6);
-
-       /* Router-Bit (ASBR Flag) may have to be updated */
-       for (ALL_LIST_ELEMENTS(ospf6->area_list, lnode, lnnode, oa))
-               OSPF6_ROUTER_LSA_SCHEDULE(oa);
+       ospf6_asbr_status_update(ospf6, ospf6->redistribute);
 }
 
 void ospf6_asbr_redistribute_remove(int type, ifindex_t ifindex,
@@ -1304,8 +1332,6 @@ void ospf6_asbr_redistribute_remove(int type, ifindex_t ifindex,
        struct ospf6_lsa *lsa;
        struct prefix prefix_id;
        char ibuf[16];
-       struct listnode *lnode, *lnnode;
-       struct ospf6_area *oa;
 
        match = ospf6_route_lookup(prefix, ospf6->external_table);
        if (match == NULL) {
@@ -1346,9 +1372,7 @@ void ospf6_asbr_redistribute_remove(int type, ifindex_t ifindex,
        ospf6_route_remove(match, ospf6->external_table);
        XFREE(MTYPE_OSPF6_EXTERNAL_INFO, info);
 
-       /* Router-Bit (ASBR Flag) may have to be updated */
-       for (ALL_LIST_ELEMENTS(ospf6->area_list, lnode, lnnode, oa))
-               OSPF6_ROUTER_LSA_SCHEDULE(oa);
+       ospf6_asbr_status_update(ospf6, ospf6->redistribute);
 }
 
 DEFUN (ospf6_redistribute,
index 523b318d5bbeaf15797dcd412e0fde2ed18ba446..4660bfd05db9f391eae4b27dc2a7897a1da2f650 100644 (file)
@@ -90,6 +90,7 @@ struct ospf6_vertex {
 #define OSPF6_SPF_FLAGS_ROUTER_LSA_ORIGINATED    (1 << 6)
 #define OSPF6_SPF_FLAGS_NETWORK_LSA_ORIGINATED   (1 << 7)
 #define OSPF6_SPF_FLAGS_CONFIG_CHANGE            (1 << 8)
+#define OSPF6_SPF_FLAGS_ASBR_STATUS_CHANGE       (1 << 9)
 
 static inline void ospf6_set_spf_reason(struct ospf6 *ospf, unsigned int reason)
 {
index 8be84ec2b4fa715dbb0f2028478f855c74c3b358..e2cd5c259de9cf04305a9fa3aa8796a9ee3fa4ef 100644 (file)
@@ -248,6 +248,7 @@ static struct ospf6 *ospf6_create(const char *name)
        o->spf_hold_multiplier = 1;
 
        o->default_originate = DEFAULT_ORIGINATE_NONE;
+       o->redistribute = 0;
        /* LSA timers value init */
        o->lsa_minarrival = OSPF_MIN_LS_ARRIVAL;
 
index eb683956e14f279ba98008f8ba3c7579cc3c87dc..08b884f23a99a7fb9059ab499cdba577280f67bb 100644 (file)
@@ -96,6 +96,8 @@ struct ospf6 {
 
        uint8_t flag;
 
+       int redistribute; /* Num of redistributed protocols. */
+
        /* Configuration bitmask, refer to enum above */
        uint8_t config_flags;
        int default_originate; /* Default information originate. */
@@ -150,6 +152,7 @@ DECLARE_QOBJ_TYPE(ospf6);
 
 #define OSPF6_DISABLED    0x01
 #define OSPF6_STUB_ROUTER 0x02
+#define OSPF6_FLAG_ASBR   0x04
 
 /* global pointer for OSPF top data structure */
 extern struct ospf6 *ospf6;
index 3f9461c7f0be8b65d82e654336a11a2c28ac0d33..dfac57aa2f5d4ef47faa2bb55bae4e259e352817 100644 (file)
@@ -95,6 +95,7 @@ extern struct thread_master *master;
                return CMD_SUCCESS;                                            \
        }
 
+#define IS_OSPF6_ASBR(O) ((O)->flag & OSPF6_FLAG_ASBR)
 extern struct zebra_privs_t ospf6d_privs;
 
 /* Function Prototypes */