]> git.proxmox.com Git - mirror_frr.git/blobdiff - ospfd/ospf_lsa.c
Merge pull request #5468 from qlyoung/bgpd-remove-bgp-attr-dup
[mirror_frr.git] / ospfd / ospf_lsa.c
index bf46d22031762a375253d6a84a368d8860faee89..6eec87c93ea87931096cdc5560df1939cd2c2611 100644 (file)
@@ -290,7 +290,7 @@ void ospf_lsa_data_free(struct lsa_header *lsah)
 
 const char *dump_lsa_key(struct ospf_lsa *lsa)
 {
-       static char buf[] = {"Type255,id(255.255.255.255),ar(255.255.255.255)"};
+       static char buf[sizeof("Type255,id(255.255.255.255),ar(255.255.255.255)")+1];
        struct lsa_header *lsah;
 
        if (lsa != NULL && (lsah = lsa->data) != NULL) {
@@ -1979,6 +1979,13 @@ struct ospf_lsa *ospf_external_lsa_originate(struct ospf *ospf,
 
           */
 
+       if (ospf->router_id.s_addr == 0) {
+               if (IS_DEBUG_OSPF_EVENT)
+                       zlog_debug("LSA[Type5:%pI4]: deferring AS-external-LSA origination, router ID is zero",
+                                  &ei->p.prefix);
+               return NULL;
+       }
+
        /* Check the AS-external-LSA should be originated. */
        if (!ospf_redistribute_check(ospf, ei, NULL))
                return NULL;
@@ -2019,50 +2026,6 @@ struct ospf_lsa *ospf_external_lsa_originate(struct ospf *ospf,
        return new;
 }
 
-/* Originate AS-external-LSA from external info with initial flag. */
-int ospf_external_lsa_originate_timer(struct thread *thread)
-{
-       struct ospf *ospf = THREAD_ARG(thread);
-       struct route_node *rn;
-       struct external_info *ei;
-       struct route_table *rt;
-       int type = THREAD_VAL(thread);
-       struct list *ext_list;
-       struct listnode *node;
-       struct ospf_external *ext;
-
-       ospf->t_external_lsa = NULL;
-
-       ext_list = ospf->external[type];
-       if (!ext_list)
-               return 0;
-
-       for (ALL_LIST_ELEMENTS_RO(ext_list, node, ext)) {
-               /* Originate As-external-LSA from all type of distribute source.
-                */
-               rt = ext->external_info;
-               if (!rt)
-                       continue;
-
-               for (rn = route_top(rt); rn; rn = route_next(rn)) {
-                       ei = rn->info;
-
-                       if (!ei)
-                               continue;
-
-                       if (is_prefix_default((struct prefix_ipv4 *)&ei->p))
-                               continue;
-
-                       if (!ospf_external_lsa_originate(ospf, ei))
-                               flog_warn(
-                                       EC_OSPF_LSA_INSTALL_FAILURE,
-                                       "LSA: AS-external-LSA was not originated.");
-               }
-       }
-
-       return 0;
-}
-
 static struct external_info *ospf_default_external_info(struct ospf *ospf)
 {
        int type;
@@ -2102,31 +2065,52 @@ static struct external_info *ospf_default_external_info(struct ospf *ospf)
        return NULL;
 }
 
-int ospf_default_originate_timer(struct thread *thread)
+void ospf_external_lsa_rid_change(struct ospf *ospf)
 {
-       struct prefix_ipv4 p;
-       struct in_addr nexthop;
        struct external_info *ei;
-       struct ospf *ospf;
+       int type;
 
-       ospf = THREAD_ARG(thread);
+       for (type = 0; type < ZEBRA_ROUTE_MAX; type++) {
+               struct route_node *rn;
+               struct route_table *rt;
+               struct list *ext_list;
+               struct listnode *node;
+               struct ospf_external *ext;
 
-       p.family = AF_INET;
-       p.prefix.s_addr = 0;
-       p.prefixlen = 0;
+               ext_list = ospf->external[type];
+               if (!ext_list)
+                       continue;
 
-       if (ospf->default_originate == DEFAULT_ORIGINATE_ALWAYS) {
-               /* If there is no default route via redistribute,
-                  then originate AS-external-LSA with nexthop 0 (self). */
-               nexthop.s_addr = 0;
-               ospf_external_info_add(ospf, DEFAULT_ROUTE, 0, p, 0, nexthop,
-                                      0);
-       }
+               for (ALL_LIST_ELEMENTS_RO(ext_list, node, ext)) {
+                       /* Originate As-external-LSA from all type of
+                        * distribute source.
+                        */
+                       rt = ext->external_info;
+                       if (!rt)
+                               continue;
 
-       if ((ei = ospf_default_external_info(ospf)))
-               ospf_external_lsa_originate(ospf, ei);
+                       for (rn = route_top(rt); rn; rn = route_next(rn)) {
+                               ei = rn->info;
 
-       return 0;
+                               if (!ei)
+                                       continue;
+
+                               if (is_prefix_default(
+                                               (struct prefix_ipv4 *)&ei->p))
+                                       continue;
+
+                               if (!ospf_external_lsa_originate(ospf, ei))
+                                       flog_warn(EC_OSPF_LSA_INSTALL_FAILURE,
+                                               "LSA: AS-external-LSA was not originated.");
+                       }
+               }
+       }
+
+       ei = ospf_default_external_info(ospf);
+       if (ei && !ospf_external_lsa_originate(ospf, ei)) {
+               flog_warn(EC_OSPF_LSA_INSTALL_FAILURE,
+                       "LSA: AS-external-LSA for default route was not originated.");
+       }
 }
 
 /* Flush any NSSA LSAs for given prefix */
@@ -2218,44 +2202,20 @@ void ospf_external_lsa_refresh_default(struct ospf *ospf)
        ei = ospf_default_external_info(ospf);
        lsa = ospf_external_info_find_lsa(ospf, &p);
 
-       if (ei) {
-               if (lsa) {
-                       if (IS_DEBUG_OSPF_EVENT)
-                               zlog_debug(
-                                       "LSA[Type5:0.0.0.0]: Refresh AS-external-LSA %p",
-                                       (void *)lsa);
-                       ospf_external_lsa_refresh(ospf, lsa, ei,
-                                                 LSA_REFRESH_FORCE);
-               } else {
-                       if (IS_DEBUG_OSPF_EVENT)
-                               zlog_debug(
-                                       "LSA[Type5:0.0.0.0]: Originate AS-external-LSA");
-                       ospf_external_lsa_originate(ospf, ei);
-               }
-       } else {
-               if (lsa) {
-                       if (IS_DEBUG_OSPF_EVENT)
-                               zlog_debug(
-                                       "LSA[Type5:0.0.0.0]: Flush AS-external-LSA");
-                       ospf_refresher_unregister_lsa(ospf, lsa);
-                       ospf_lsa_flush_as(ospf, lsa);
-               }
-       }
-}
-
-void ospf_default_originate_lsa_update(struct ospf *ospf)
-{
-       struct prefix_ipv4 p;
-       struct ospf_lsa *lsa;
-
-       p.family = AF_INET;
-       p.prefixlen = 0;
-       p.prefix.s_addr = 0;
-
-       lsa = ospf_external_info_find_lsa(ospf, &p);
-       if (lsa && IS_LSA_MAXAGE(lsa)) {
-               ospf_discard_from_db(ospf, lsa->lsdb, lsa);
-               ospf_lsdb_delete(lsa->lsdb, lsa);
+       if (ei && lsa) {
+               if (IS_DEBUG_OSPF_EVENT)
+                       zlog_debug("LSA[Type5:0.0.0.0]: Refresh AS-external-LSA %p",
+                                  (void *)lsa);
+               ospf_external_lsa_refresh(ospf, lsa, ei, LSA_REFRESH_FORCE);
+       } else if (ei && !lsa) {
+               if (IS_DEBUG_OSPF_EVENT)
+                       zlog_debug(
+                               "LSA[Type5:0.0.0.0]: Originate AS-external-LSA");
+               ospf_external_lsa_originate(ospf, ei);
+       } else if (lsa) {
+               if (IS_DEBUG_OSPF_EVENT)
+                       zlog_debug("LSA[Type5:0.0.0.0]: Flush AS-external-LSA");
+               ospf_external_lsa_flush(ospf, DEFAULT_ROUTE, &p, 0);
        }
 }
 
@@ -2477,7 +2437,7 @@ static struct ospf_lsa *ospf_summary_asbr_lsa_install(struct ospf *ospf,
 #if 0
       /* These don't exist yet... */
       ospf_summary_incremental_update(new);
-      /* Isn't this done by the above call? 
+      /* Isn't this done by the above call?
         - RFC 2328 Section 16.5 implies it should be */
       /* ospf_ase_calculate_schedule(); */
 #else  /* #if 0 */
@@ -3242,45 +3202,6 @@ int ospf_lsa_different(struct ospf_lsa *l1, struct ospf_lsa *l2)
        return 0;
 }
 
-#ifdef ORIGINAL_CODING
-void ospf_lsa_flush_self_originated(struct ospf_neighbor *nbr,
-                                   struct ospf_lsa *self, struct ospf_lsa *new)
-{
-       uint32_t seqnum;
-
-       /* Adjust LS Sequence Number. */
-       seqnum = ntohl(new->data->ls_seqnum) + 1;
-       self->data->ls_seqnum = htonl(seqnum);
-
-       /* Recalculate LSA checksum. */
-       ospf_lsa_checksum(self->data);
-
-       /* Reflooding LSA. */
-       /*  RFC2328  Section 13.3
-                 On non-broadcast networks, separate   Link State Update
-                 packets must be sent, as unicasts, to each adjacent   neighbor
-                 (i.e., those in state Exchange or greater).    The destination
-                 IP addresses for these packets are the neighbors' IP
-                 addresses.   */
-       if (nbr->oi->type == OSPF_IFTYPE_NBMA) {
-               struct route_node *rn;
-               struct ospf_neighbor *onbr;
-
-               for (rn = route_top(nbr->oi->nbrs); rn; rn = route_next(rn))
-                       if ((onbr = rn->info) != NULL)
-                               if (onbr != nbr->oi->nbr_self
-                                   && onbr->status >= NSM_Exchange)
-                                       ospf_ls_upd_send_lsa(
-                                               onbr, self,
-                                               OSPF_SEND_PACKET_DIRECT);
-       } else
-               ospf_ls_upd_send_lsa(nbr, self, OSPF_SEND_PACKET_INDIRECT);
-
-       if (IS_DEBUG_OSPF(lsa, LSA_GENERATE))
-               zlog_debug("LSA[Type%d:%s]: Flush self-originated LSA",
-                          self->data->type, inet_ntoa(self->data->id));
-}
-#else  /* ORIGINAL_CODING */
 int ospf_lsa_flush_schedule(struct ospf *ospf, struct ospf_lsa *lsa)
 {
        if (lsa == NULL || !IS_LSA_SELF(lsa))
@@ -3385,7 +3306,6 @@ void ospf_flush_self_originated_lsas_now(struct ospf *ospf)
 
        return;
 }
-#endif /* ORIGINAL_CODING */
 
 /* If there is self-originated LSA, then return 1, otherwise return 0. */
 /* An interface-independent version of ospf_lsa_is_self_originated */