ospf6d: assorted code cleanup

This commits consists of several changes that positively impact
code reability without introducing any logical change.

Summary of the changes:
* Return earlier in ospf6_abr_range_update() in order to reduce one
  level of indentation;
* Remove ospf6_translated_nssa_originate() since it's nothing other
  than a useless wrapper around ospf6_lsa_translated_nssa_new();
* Change ospf6_abr_translate_nssa() to return void;
* Change ospf6_abr_process_nssa_translates() checking for NSSA areas
  before anything else;
* Remove ospf6_abr_remove_unapproved_translates_apply() since it's a
  small function that is only called in one place;
* Change ospf6_abr_check_translate_nssa() to avoid an LSDB lookup when
  the router isn't an ABR.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
This commit is contained in:
Renato Westphal 2021-10-05 21:25:55 -03:00
parent 7270e0edf3
commit 8ee9d58b0d
3 changed files with 42 additions and 80 deletions

View File

@ -681,34 +681,31 @@ void ospf6_abr_range_update(struct ospf6_route *range, struct ospf6 *ospf6)
* if there * if there
* were active ranges. * were active ranges.
*/ */
if (!ospf6_abr_range_summary_needs_update(range, cost))
return;
if (ospf6_abr_range_summary_needs_update(range, cost)) { if (IS_OSPF6_DEBUG_ABR)
if (IS_OSPF6_DEBUG_ABR) zlog_debug("%s: range %pFX update", __func__, &range->prefix);
zlog_debug("%s: range %pFX update", __func__,
&range->prefix);
for (ALL_LIST_ELEMENTS(ospf6->area_list, node, nnode, oa))
summary_orig +=
ospf6_abr_originate_summary_to_area(range, oa);
if (CHECK_FLAG(range->flag, OSPF6_ROUTE_ACTIVE_SUMMARY) for (ALL_LIST_ELEMENTS(ospf6->area_list, node, nnode, oa))
&& summary_orig) { summary_orig += ospf6_abr_originate_summary_to_area(range, oa);
if (!CHECK_FLAG(range->flag,
OSPF6_ROUTE_BLACKHOLE_ADDED)) {
if (IS_OSPF6_DEBUG_ABR)
zlog_debug("Add discard route");
ospf6_zebra_add_discard(range, ospf6); if (CHECK_FLAG(range->flag, OSPF6_ROUTE_ACTIVE_SUMMARY)
} && summary_orig) {
} else { if (!CHECK_FLAG(range->flag, OSPF6_ROUTE_BLACKHOLE_ADDED)) {
/* Summary removed or no summary generated as no if (IS_OSPF6_DEBUG_ABR)
* specifics exist */ zlog_debug("Add discard route");
if (CHECK_FLAG(range->flag,
OSPF6_ROUTE_BLACKHOLE_ADDED)) {
if (IS_OSPF6_DEBUG_ABR)
zlog_debug("Delete discard route");
ospf6_zebra_delete_discard(range, ospf6); ospf6_zebra_add_discard(range, ospf6);
} }
} else {
/* Summary removed or no summary generated as no
* specifics exist */
if (CHECK_FLAG(range->flag, OSPF6_ROUTE_BLACKHOLE_ADDED)) {
if (IS_OSPF6_DEBUG_ABR)
zlog_debug("Delete discard route");
ospf6_zebra_delete_discard(range, ospf6);
} }
} }
} }

View File

@ -596,27 +596,7 @@ struct ospf6_lsa *ospf6_translated_nssa_refresh(struct ospf6_area *area,
return new; return new;
} }
/* Originate Translated Type-5 for supplied Type-7 NSSA LSA */ static void ospf6_abr_translate_nssa(struct ospf6_area *area, struct ospf6_lsa *lsa)
struct ospf6_lsa *ospf6_translated_nssa_originate(struct ospf6_area *oa,
struct ospf6_lsa *type7)
{
struct ospf6_lsa *new;
if (ntohs(type7->header->type) != OSPF6_LSTYPE_TYPE_7)
return NULL;
if ((new = ospf6_lsa_translated_nssa_new(oa, type7)) == NULL) {
if (IS_OSPF6_DEBUG_NSSA)
zlog_debug(
"%s : Could not translate Type-7, Id %pI4, to Type-5",
__func__, &type7->header->id);
return NULL;
}
return new;
}
int ospf6_abr_translate_nssa(struct ospf6_area *area, struct ospf6_lsa *lsa)
{ {
/* Incoming Type-7 or later aggregated Type-7 /* Incoming Type-7 or later aggregated Type-7
* *
@ -645,7 +625,7 @@ int ospf6_abr_translate_nssa(struct ospf6_area *area, struct ospf6_lsa *lsa)
zlog_debug( zlog_debug(
"%s : LSA Id %pI4, P-bit off, NO Translation", "%s : LSA Id %pI4, P-bit off, NO Translation",
__func__, &lsa->header->id); __func__, &lsa->header->id);
return 1; return;
} }
if (IS_OSPF6_DEBUG_NSSA) if (IS_OSPF6_DEBUG_NSSA)
@ -662,7 +642,7 @@ int ospf6_abr_translate_nssa(struct ospf6_area *area, struct ospf6_lsa *lsa)
zlog_debug( zlog_debug(
"%s : LSA Id %pI4, Forward address is 0, NO Translation", "%s : LSA Id %pI4, Forward address is 0, NO Translation",
__func__, &lsa->header->id); __func__, &lsa->header->id);
return 1; return;
} }
/* Find the existing AS-External LSA for this prefix */ /* Find the existing AS-External LSA for this prefix */
@ -705,16 +685,14 @@ int ospf6_abr_translate_nssa(struct ospf6_area *area, struct ospf6_lsa *lsa)
* originate translated LSA * originate translated LSA
*/ */
if (ospf6_translated_nssa_originate(area, lsa) == NULL) { if (ospf6_lsa_translated_nssa_new(area, lsa) == NULL) {
if (IS_OSPF6_DEBUG_NSSA) if (IS_OSPF6_DEBUG_NSSA)
zlog_debug( zlog_debug(
"%s : Could not translate Type-7 for %pI4 to Type-5", "%s : Could not translate Type-7 for %pI4 to Type-5",
__func__, &lsa->header->id); __func__, &lsa->header->id);
return 1; return;
} }
} }
return 0;
} }
static void ospf6_abr_process_nssa_translates(struct ospf6 *ospf6) static void ospf6_abr_process_nssa_translates(struct ospf6 *ospf6)
@ -734,6 +712,8 @@ static void ospf6_abr_process_nssa_translates(struct ospf6 *ospf6)
zlog_debug("%s : Start", __func__); zlog_debug("%s : Start", __func__);
for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, node, oa)) { for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, node, oa)) {
if (!IS_AREA_NSSA(oa))
continue;
/* skip if not translator */ /* skip if not translator */
if (oa->NSSATranslatorState == OSPF6_NSSA_TRANSLATE_DISABLED) { if (oa->NSSATranslatorState == OSPF6_NSSA_TRANSLATE_DISABLED) {
@ -743,13 +723,6 @@ static void ospf6_abr_process_nssa_translates(struct ospf6 *ospf6)
continue; continue;
} }
/* skip if not Nssa Area */
if (!IS_AREA_NSSA(oa)) {
zlog_debug("%s area %pI4 Flag %x", __func__,
&oa->area_id, oa->flag);
continue;
}
if (IS_OSPF6_DEBUG_NSSA) if (IS_OSPF6_DEBUG_NSSA)
zlog_debug("%s : looking at area %pI4", __func__, zlog_debug("%s : looking at area %pI4", __func__,
&oa->area_id); &oa->area_id);
@ -767,20 +740,6 @@ static void ospf6_abr_process_nssa_translates(struct ospf6 *ospf6)
zlog_debug("%s : Stop", __func__); zlog_debug("%s : Stop", __func__);
} }
/*Flood max age LSA's for the unapproved LSA's */
static int ospf6_abr_remove_unapproved_translates_apply(struct ospf6_lsa *lsa)
{
if (CHECK_FLAG(lsa->flag, OSPF6_LSA_LOCAL_XLT)
&& CHECK_FLAG(lsa->flag, OSPF6_LSA_UNAPPROVED)) {
zlog_debug("%s : removing unapproved translates, lsa : %s",
__func__, lsa->name);
/* FLUSH THROUGHOUT AS */
ospf6_lsa_premature_aging(lsa);
}
return 0;
}
static void ospf6_abr_remove_unapproved_translates(struct ospf6 *ospf6) static void ospf6_abr_remove_unapproved_translates(struct ospf6 *ospf6)
{ {
struct ospf6_lsa *lsa; struct ospf6_lsa *lsa;
@ -792,8 +751,16 @@ static void ospf6_abr_remove_unapproved_translates(struct ospf6 *ospf6)
zlog_debug("ospf6_abr_remove_unapproved_translates(): Start"); zlog_debug("ospf6_abr_remove_unapproved_translates(): Start");
type = htons(OSPF6_LSTYPE_AS_EXTERNAL); type = htons(OSPF6_LSTYPE_AS_EXTERNAL);
for (ALL_LSDB_TYPED(ospf6->lsdb, type, lsa)) for (ALL_LSDB_TYPED(ospf6->lsdb, type, lsa)) {
ospf6_abr_remove_unapproved_translates_apply(lsa); if (CHECK_FLAG(lsa->flag, OSPF6_LSA_LOCAL_XLT)
&& CHECK_FLAG(lsa->flag, OSPF6_LSA_UNAPPROVED)) {
zlog_debug(
"%s : removing unapproved translates, lsa : %s",
__func__, lsa->name);
ospf6_lsa_premature_aging(lsa);
}
}
if (IS_OSPF6_DEBUG_NSSA) if (IS_OSPF6_DEBUG_NSSA)
zlog_debug("ospf_abr_remove_unapproved_translates(): Stop"); zlog_debug("ospf_abr_remove_unapproved_translates(): Stop");
@ -1268,11 +1235,13 @@ void ospf6_abr_check_translate_nssa(struct ospf6_area *area,
if (IS_OSPF6_DEBUG_NSSA) if (IS_OSPF6_DEBUG_NSSA)
zlog_debug("%s : start", __func__); zlog_debug("%s : start", __func__);
if (!ospf6_check_and_set_router_abr(ospf6))
return;
type5 = ospf6_lsdb_lookup(htons(OSPF6_LSTYPE_AS_EXTERNAL), type5 = ospf6_lsdb_lookup(htons(OSPF6_LSTYPE_AS_EXTERNAL),
lsa->external_lsa_id, ospf6->router_id, lsa->external_lsa_id, ospf6->router_id,
ospf6->lsdb); ospf6->lsdb);
if (!type5) {
if (ospf6_check_and_set_router_abr(ospf6) && (type5 == NULL)) {
if (IS_OSPF6_DEBUG_NSSA) if (IS_OSPF6_DEBUG_NSSA)
zlog_debug("%s : Originating type5 LSA", __func__); zlog_debug("%s : Originating type5 LSA", __func__);
ospf6_lsa_translated_nssa_new(area, lsa); ospf6_lsa_translated_nssa_new(area, lsa);

View File

@ -55,8 +55,6 @@ extern void ospf6_nssa_lsa_flush(struct ospf6 *ospf6, struct prefix_ipv6 *p);
extern struct ospf6_lsa *ospf6_translated_nssa_refresh(struct ospf6_area *oa, extern struct ospf6_lsa *ospf6_translated_nssa_refresh(struct ospf6_area *oa,
struct ospf6_lsa *type7, struct ospf6_lsa *type7,
struct ospf6_lsa *type5); struct ospf6_lsa *type5);
extern struct ospf6_lsa *
ospf6_translated_nssa_originate(struct ospf6_area *oa, struct ospf6_lsa *type7);
extern void ospf6_asbr_nssa_redist_task(struct ospf6 *ospf6); extern void ospf6_asbr_nssa_redist_task(struct ospf6 *ospf6);
@ -69,8 +67,6 @@ extern void install_element_ospf6_debug_nssa(void);
extern void ospf6_abr_nssa_type_7_defaults(struct ospf6 *osof6); extern void ospf6_abr_nssa_type_7_defaults(struct ospf6 *osof6);
int ospf6_redistribute_check(struct ospf6 *ospf6, struct ospf6_route *route, int ospf6_redistribute_check(struct ospf6 *ospf6, struct ospf6_route *route,
int type); int type);
extern int ospf6_abr_translate_nssa(struct ospf6_area *area,
struct ospf6_lsa *lsa);
extern void ospf6_abr_check_translate_nssa(struct ospf6_area *area, extern void ospf6_abr_check_translate_nssa(struct ospf6_area *area,
struct ospf6_lsa *lsa); struct ospf6_lsa *lsa);
extern void ospf6_abr_nssa_check_status(struct ospf6 *ospf6); extern void ospf6_abr_nssa_check_status(struct ospf6 *ospf6);