diff options
author | Rafael Zalamena <rzalamena@opensourcerouting.org> | 2021-07-08 19:09:20 +0200 |
---|---|---|
committer | Rafael Zalamena <rzalamena@opensourcerouting.org> | 2021-07-09 12:55:25 +0200 |
commit | 1fe59b44fc94337f0b508bc762a401a9dbe9c1a3 (patch) | |
tree | 8a525db11e5c2b61c3b8cb29b9eb55c4ed9bd6f5 /ospfd | |
parent | Merge pull request #8978 from kssoman/ospf_new (diff) | |
download | frr-1fe59b44fc94337f0b508bc762a401a9dbe9c1a3.tar.xz frr-1fe59b44fc94337f0b508bc762a401a9dbe9c1a3.zip |
lib,ospfd,ospf6d: remove duplicated function
Move `is_default_prefix` variations to `lib/prefix.h` and make the code
use the library version instead of implementing it again.
NOTE
----
The function was split into per family versions to cover all types.
Using `union prefixconstptr` is not possible due to static analyzer
warnings which cause CI to fail.
The specific cases that would cause this failure were:
- Caller used `struct prefix_ipv4` and called the generic function.
- `is_default_prefix` with signature using `const struct prefix *` or
`union prefixconstptr`.
The compiler would complain about reading bytes outside of the memory
bounds even though it did not take into account the `prefix->family`
part.
Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
Diffstat (limited to 'ospfd')
-rw-r--r-- | ospfd/ospf_asbr.c | 4 | ||||
-rw-r--r-- | ospfd/ospf_flood.c | 12 | ||||
-rw-r--r-- | ospfd/ospf_lsa.c | 20 | ||||
-rw-r--r-- | ospfd/ospf_lsa.h | 1 | ||||
-rw-r--r-- | ospfd/ospf_vty.c | 8 | ||||
-rw-r--r-- | ospfd/ospf_zebra.c | 14 |
6 files changed, 23 insertions, 36 deletions
diff --git a/ospfd/ospf_asbr.c b/ospfd/ospf_asbr.c index 192dbe4fc..53d2ec538 100644 --- a/ospfd/ospf_asbr.c +++ b/ospfd/ospf_asbr.c @@ -334,7 +334,7 @@ void ospf_redistribute_withdraw(struct ospf *ospf, uint8_t type, struct ospf_external_aggr_rt *aggr; - if (is_prefix_default(&ei->p) + if (is_default_prefix4(&ei->p) && ospf->default_originate != DEFAULT_ORIGINATE_NONE) continue; @@ -862,7 +862,7 @@ static void ospf_handle_external_aggr_add(struct ospf *ospf) continue; ei = rn->info; - if (is_prefix_default(&ei->p)) + if (is_default_prefix4(&ei->p)) continue; /* Check the AS-external-LSA diff --git a/ospfd/ospf_flood.c b/ospfd/ospf_flood.c index 6c1ac6761..55bcaebd6 100644 --- a/ospfd/ospf_flood.c +++ b/ospfd/ospf_flood.c @@ -98,14 +98,14 @@ struct external_info *ospf_external_info_check(struct ospf *ospf, int redist_on = 0; redist_on = - is_prefix_default(&p) + is_default_prefix4(&p) ? vrf_bitmap_check( - zclient->default_information[AFI_IP], - ospf->vrf_id) + zclient->default_information[AFI_IP], + ospf->vrf_id) : (zclient->mi_redist[AFI_IP][type].enabled || vrf_bitmap_check( - zclient->redist[AFI_IP][type], - ospf->vrf_id)); + zclient->redist[AFI_IP][type], + ospf->vrf_id)); // Pending: check for MI above. if (redist_on) { ext_list = ospf->external[type]; @@ -128,7 +128,7 @@ struct external_info *ospf_external_info_check(struct ospf *ospf, } } - if (is_prefix_default(&p) && ospf->external[DEFAULT_ROUTE]) { + if (is_default_prefix4(&p) && ospf->external[DEFAULT_ROUTE]) { ext_list = ospf->external[DEFAULT_ROUTE]; for (ALL_LIST_ELEMENTS_RO(ext_list, node, ext)) { diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c index c850df55b..c7c9fa2d6 100644 --- a/ospfd/ospf_lsa.c +++ b/ospfd/ospf_lsa.c @@ -1551,8 +1551,8 @@ static void ospf_external_lsa_body_set(struct stream *s, stream_put_ipv4(s, mask.s_addr); /* If prefix is default, specify DEFAULT_ROUTE. */ - type = is_prefix_default(&ei->p) ? DEFAULT_ROUTE : ei->type; - instance = is_prefix_default(&ei->p) ? 0 : ei->instance; + type = is_default_prefix4(&ei->p) ? DEFAULT_ROUTE : ei->type; + instance = is_default_prefix4(&ei->p) ? 0 : ei->instance; mtype = (ROUTEMAP_METRIC_TYPE(ei) != -1) ? ROUTEMAP_METRIC_TYPE(ei) @@ -1947,17 +1947,6 @@ struct ospf_lsa *ospf_translated_nssa_refresh(struct ospf *ospf, return new; } -int is_prefix_default(struct prefix_ipv4 *p) -{ - struct prefix_ipv4 q; - - q.family = AF_INET; - q.prefix.s_addr = INADDR_ANY; - q.prefixlen = 0; - - return prefix_same((struct prefix *)p, (struct prefix *)&q); -} - /* Originate an AS-external-LSA, install and flood. */ struct ospf_lsa *ospf_external_lsa_originate(struct ospf *ospf, struct external_info *ei) @@ -2113,8 +2102,7 @@ void ospf_external_lsa_rid_change(struct ospf *ospf) if (!ei) continue; - if (is_prefix_default( - (struct prefix_ipv4 *)&ei->p)) + if (is_default_prefix4(&ei->p)) continue; lsa = ospf_external_info_find_lsa(ospf, &ei->p); @@ -2284,7 +2272,7 @@ void ospf_external_lsa_refresh_type(struct ospf *ospf, uint8_t type, rn = route_next(rn)) { ei = rn->info; if (ei) { - if (!is_prefix_default(&ei->p)) { + if (!is_default_prefix4(&ei->p)) { struct ospf_lsa *lsa; struct ospf_external_aggr_rt *aggr; diff --git a/ospfd/ospf_lsa.h b/ospfd/ospf_lsa.h index 3808700cc..d01dc720b 100644 --- a/ospfd/ospf_lsa.h +++ b/ospfd/ospf_lsa.h @@ -331,7 +331,6 @@ extern void ospf_lsa_maxage_delete(struct ospf *, struct ospf_lsa *); extern void ospf_discard_from_db(struct ospf *, struct ospf_lsdb *, struct ospf_lsa *); -extern int is_prefix_default(struct prefix_ipv4 *); extern int metric_type(struct ospf *, uint8_t, unsigned short); extern int metric_value(struct ospf *, uint8_t, unsigned short); diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index db8e961b8..946d19cfd 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -10027,7 +10027,7 @@ DEFUN (ospf_external_route_aggregation, str2prefix_ipv4(argv[idx]->arg, &p); - if (is_prefix_default(&p)) { + if (is_default_prefix4(&p)) { vty_out(vty, "Default address shouldn't be configured as summary address.\n"); return CMD_SUCCESS; @@ -10068,7 +10068,7 @@ DEFUN (no_ospf_external_route_aggregation, str2prefix_ipv4(argv[idx]->arg, &p); - if (is_prefix_default(&p)) { + if (is_default_prefix4(&p)) { vty_out(vty, "Default address shouldn't be configured as summary address.\n"); return CMD_SUCCESS; @@ -10361,7 +10361,7 @@ DEFUN (ospf_external_route_aggregation_no_adrvertise, str2prefix_ipv4(argv[idx]->arg, &p); - if (is_prefix_default(&p)) { + if (is_default_prefix4(&p)) { vty_out(vty, "Default address shouldn't be configured as summary address.\n"); return CMD_SUCCESS; @@ -10397,7 +10397,7 @@ DEFUN (no_ospf_external_route_aggregation_no_adrvertise, str2prefix_ipv4(argv[idx]->arg, &p); - if (is_prefix_default(&p)) { + if (is_default_prefix4(&p)) { vty_out(vty, "Default address shouldn't be configured as summary address.\n"); return CMD_SUCCESS; diff --git a/ospfd/ospf_zebra.c b/ospfd/ospf_zebra.c index 017915e0e..387bbc0ce 100644 --- a/ospfd/ospf_zebra.c +++ b/ospfd/ospf_zebra.c @@ -933,7 +933,7 @@ static int ospf_external_lsa_originate_check(struct ospf *ospf, } /* Take care of default-originate. */ - if (is_prefix_default(&ei->p)) + if (is_default_prefix4(&ei->p)) if (ospf->default_originate == DEFAULT_ORIGINATE_NONE) { zlog_info( "LSA[Type5:0.0.0.0]: Not originate AS-external-LSA for default"); @@ -1089,8 +1089,8 @@ int ospf_redistribute_check(struct ospf *ospf, struct external_info *ei, struct route_map_set_values save_values; struct prefix_ipv4 *p = &ei->p; struct ospf_redist *red; - uint8_t type = is_prefix_default(&ei->p) ? DEFAULT_ROUTE : ei->type; - unsigned short instance = is_prefix_default(&ei->p) ? 0 : ei->instance; + uint8_t type = is_default_prefix4(&ei->p) ? DEFAULT_ROUTE : ei->type; + unsigned short instance = is_default_prefix4(&ei->p) ? 0 : ei->instance; route_tag_t saved_tag = 0; /* Default is handled differently. */ @@ -1213,7 +1213,7 @@ static int ospf_zebra_read_route(ZAPI_CALLBACK_ARGS) * originate)ZEBRA_ROUTE_MAX is used to delete the ex-info. * Resolved this inconsistency by maintaining same route type. */ - if (is_prefix_default(&p)) + if (is_default_prefix4(&p)) rt_type = DEFAULT_ROUTE; if (IS_DEBUG_OSPF(zebra, ZEBRA_REDISTRIBUTE)) @@ -1252,7 +1252,7 @@ static int ospf_zebra_read_route(ZAPI_CALLBACK_ARGS) return 0; } if (ospf->router_id.s_addr != INADDR_ANY) { - if (is_prefix_default(&p)) + if (is_default_prefix4(&p)) ospf_external_lsa_refresh_default(ospf); else { struct ospf_external_aggr_rt *aggr; @@ -1374,7 +1374,7 @@ static int ospf_zebra_read_route(ZAPI_CALLBACK_ARGS) ospf_external_info_delete(ospf, rt_type, api.instance, p); - if (is_prefix_default(&p)) + if (is_default_prefix4(&p)) ospf_external_lsa_refresh_default(ospf); else ospf_external_lsa_flush(ospf, rt_type, &p, @@ -1471,7 +1471,7 @@ static int ospf_distribute_list_update_timer(struct thread *thread) if (!ei) continue; - if (is_prefix_default(&ei->p)) + if (is_default_prefix4(&ei->p)) default_refresh = 1; else { struct ospf_external_aggr_rt *aggr; |