]> git.proxmox.com Git - mirror_frr.git/blobdiff - ospfd/ospf_spf.c
zebra: Allow ns delete to happen after under/over flow checks
[mirror_frr.git] / ospfd / ospf_spf.c
index 891088ecc2da46dd7ad5030fa772bc212f6379e8..9c223facd354b4326175c11d5ece75814c4eab7e 100644 (file)
@@ -46,6 +46,8 @@
 #include "ospfd/ospf_ase.h"
 #include "ospfd/ospf_abr.h"
 #include "ospfd/ospf_dump.h"
+#include "ospfd/ospf_sr.h"
+#include "ospfd/ospf_errors.h"
 
 /* Variables to ensure a SPF scheduled log message is printed only once */
 
@@ -153,9 +155,6 @@ static struct vertex_parent *vertex_parent_new(struct vertex *v, int backlink,
 
        new = XMALLOC(MTYPE_OSPF_VERTEX_PARENT, sizeof(struct vertex_parent));
 
-       if (new == NULL)
-               return NULL;
-
        new->parent = v;
        new->backlink = backlink;
        new->nexthop = hop;
@@ -210,12 +209,10 @@ static void ospf_vertex_free(void *data)
        // assert (listcount (v->parents) == 0);
 
        if (v->children)
-               list_delete(v->children);
-       v->children = NULL;
+               list_delete(&v->children);
 
        if (v->parents)
-               list_delete(v->parents);
-       v->parents = NULL;
+               list_delete(&v->parents);
 
        v->lsa = NULL;
 
@@ -361,23 +358,23 @@ static struct router_lsa_link *
 ospf_get_next_link(struct vertex *v, struct vertex *w,
                   struct router_lsa_link *prev_link)
 {
-       u_char *p;
-       u_char *lim;
-       u_char lsa_type = LSA_LINK_TYPE_TRANSIT;
+       uint8_t *p;
+       uint8_t *lim;
+       uint8_t lsa_type = LSA_LINK_TYPE_TRANSIT;
        struct router_lsa_link *l;
 
        if (w->type == OSPF_VERTEX_ROUTER)
                lsa_type = LSA_LINK_TYPE_POINTOPOINT;
 
        if (prev_link == NULL)
-               p = ((u_char *)v->lsa) + OSPF_LSA_HEADER_SIZE + 4;
+               p = ((uint8_t *)v->lsa) + OSPF_LSA_HEADER_SIZE + 4;
        else {
-               p = (u_char *)prev_link;
+               p = (uint8_t *)prev_link;
                p += (OSPF_ROUTER_LSA_LINK_SIZE
                      + (prev_link->m[0].tos_count * OSPF_ROUTER_LSA_TOS_SIZE));
        }
 
-       lim = ((u_char *)v->lsa) + ntohs(v->lsa->length);
+       lim = ((uint8_t *)v->lsa) + ntohs(v->lsa->length);
 
        while (p < lim) {
                l = (struct router_lsa_link *)p;
@@ -781,12 +778,12 @@ static unsigned int ospf_nexthop_calculation(struct ospf_area *area,
  * of candidates with any vertices not already on the list.  If a lower-cost
  * path is found to a vertex already on the candidate list, store the new cost.
  */
-static void ospf_spf_next(struct vertex *v, struct ospf_area *area,
-                         struct pqueue *candidate)
+static void ospf_spf_next(struct vertex *v, struct ospf *ospf,
+                         struct ospf_area *area, struct pqueue *candidate)
 {
        struct ospf_lsa *w_lsa = NULL;
-       u_char *p;
-       u_char *lim;
+       uint8_t *p;
+       uint8_t *lim;
        struct router_lsa_link *l = NULL;
        struct in_addr *r;
        int type = 0, lsa_pos = -1, lsa_pos_next = 0;
@@ -803,8 +800,8 @@ static void ospf_spf_next(struct vertex *v, struct ospf_area *area,
                           v->type == OSPF_VERTEX_ROUTER ? "Router" : "Network",
                           inet_ntoa(v->lsa->id));
 
-       p = ((u_char *)v->lsa) + OSPF_LSA_HEADER_SIZE + 4;
-       lim = ((u_char *)v->lsa) + ntohs(v->lsa->length);
+       p = ((uint8_t *)v->lsa) + OSPF_LSA_HEADER_SIZE + 4;
+       lim = ((uint8_t *)v->lsa) + ntohs(v->lsa->length);
 
        while (p < lim) {
                struct vertex *w;
@@ -841,7 +838,8 @@ static void ospf_spf_next(struct vertex *v, struct ospf_area *area,
                                                        inet_ntoa(l->link_id));
                                }
 
-                               w_lsa = ospf_lsa_lookup(area, OSPF_ROUTER_LSA,
+                               w_lsa = ospf_lsa_lookup(ospf, area,
+                                                       OSPF_ROUTER_LSA,
                                                        l->link_id, l->link_id);
                                if (w_lsa) {
                                        if (IS_DEBUG_OSPF_EVENT)
@@ -862,7 +860,8 @@ static void ospf_spf_next(struct vertex *v, struct ospf_area *area,
                                                zlog_debug("found the LSA");
                                break;
                        default:
-                               zlog_warn("Invalid LSA link type %d", type);
+                               flog_warn(EC_OSPF_LSA,
+                                         "Invalid LSA link type %d", type);
                                continue;
                        }
                } else {
@@ -1017,8 +1016,8 @@ static void ospf_spf_process_stubs(struct ospf_area *area, struct vertex *v,
                zlog_debug("ospf_process_stub():processing stubs for area %s",
                           inet_ntoa(area->area_id));
        if (v->type == OSPF_VERTEX_ROUTER) {
-               u_char *p;
-               u_char *lim;
+               uint8_t *p;
+               uint8_t *lim;
                struct router_lsa_link *l;
                struct router_lsa *rlsa;
                int lsa_pos = 0;
@@ -1034,8 +1033,8 @@ static void ospf_spf_process_stubs(struct ospf_area *area, struct vertex *v,
                        zlog_debug(
                                "ospf_process_stubs(): we have %d links to process",
                                ntohs(rlsa->links));
-               p = ((u_char *)v->lsa) + OSPF_LSA_HEADER_SIZE + 4;
-               lim = ((u_char *)v->lsa) + ntohs(v->lsa->length);
+               p = ((uint8_t *)v->lsa) + OSPF_LSA_HEADER_SIZE + 4;
+               lim = ((uint8_t *)v->lsa) + ntohs(v->lsa->length);
 
                while (p < lim) {
                        l = (struct router_lsa_link *)p;
@@ -1087,7 +1086,7 @@ void ospf_rtrs_free(struct route_table *rtrs)
                        for (ALL_LIST_ELEMENTS(or_list, node, nnode, or))
                                ospf_route_free(or);
 
-                       list_delete(or_list);
+                       list_delete(&or_list);
 
                        /* Unlock the node. */
                        rn->info = NULL;
@@ -1159,7 +1158,7 @@ ospf_rtrs_print (struct route_table *rtrs)
 #endif
 
 /* Calculating the shortest-path tree for an area. */
-static void ospf_spf_calculate(struct ospf_area *area,
+static void ospf_spf_calculate(struct ospf *ospf, struct ospf_area *area,
                               struct route_table *new_table,
                               struct route_table *new_rtrs)
 {
@@ -1209,7 +1208,7 @@ static void ospf_spf_calculate(struct ospf_area *area,
 
        for (;;) {
                /* RFC2328 16.1. (2). */
-               ospf_spf_next(v, area, candidate);
+               ospf_spf_next(v, ospf, area, candidate);
 
                /* RFC2328 16.1. (3). */
                /* If at this step the candidate list is empty, the shortest-
@@ -1307,13 +1306,13 @@ static int ospf_spf_calculate_timer(struct thread *thread)
                if (ospf->backbone && ospf->backbone == area)
                        continue;
 
-               ospf_spf_calculate(area, new_table, new_rtrs);
+               ospf_spf_calculate(ospf, area, new_table, new_rtrs);
                areas_processed++;
        }
 
        /* SPF for backbone, if required */
        if (ospf->backbone) {
-               ospf_spf_calculate(ospf->backbone, new_table, new_rtrs);
+               ospf_spf_calculate(ospf, ospf->backbone, new_table, new_rtrs);
                areas_processed++;
        }
 
@@ -1339,6 +1338,11 @@ static int ospf_spf_calculate_timer(struct thread *thread)
 
        ospf_ase_calculate_timer_add(ospf);
 
+       if (IS_DEBUG_OSPF_EVENT)
+               zlog_debug(
+                       "%s: ospf install new route, vrf %s id %u new_table count %lu",
+                       __PRETTY_FUNCTION__, ospf_vrf_id_to_name(ospf->vrf_id),
+                       ospf->vrf_id, new_table->count);
        /* Update routing table. */
        monotime(&start_time);
        ospf_route_install(ospf, new_table);
@@ -1360,6 +1364,9 @@ static int ospf_spf_calculate_timer(struct thread *thread)
                ospf_abr_task(ospf);
        abr_time = monotime_since(&start_time, NULL);
 
+       /* Schedule Segment Routing update */
+       ospf_sr_update_timer_add(ospf);
+
        total_spf_time =
                monotime_since(&spf_start_time, &ospf->ts_spf_duration);
 
@@ -1457,9 +1464,7 @@ void ospf_spf_calculate_schedule(struct ospf *ospf, ospf_spf_reason_t reason)
        }
 
        if (IS_DEBUG_OSPF_EVENT)
-               zlog_debug("SPF: calculation timer delay = %ld", delay);
-
-       zlog_info("SPF: Scheduled in %ld msec", delay);
+               zlog_debug("SPF: calculation timer delay = %ld msec", delay);
 
        ospf->t_spf_calc = NULL;
        thread_add_timer_msec(master, ospf_spf_calculate_timer, ospf, delay,