diff options
| author | Donald Sharp <donaldsharp72@gmail.com> | 2023-07-20 10:16:46 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-20 10:16:46 -0400 |
| commit | d8525635f335a3b7ffacea7cd65040c39742c079 (patch) | |
| tree | 9c639c1616bf3fc208cc20d3400f63cb1fb5f29a | |
| parent | 46b47720a23d3615bebda73d92867d4075fa1be4 (diff) | |
| parent | 725f61150eac3afe2341213190e75563ea646b7e (diff) | |
Merge pull request #14003 from iqras23/coverity
bgpd: Fix coverity for EVPN
| -rw-r--r-- | lib/prefix.c | 38 | ||||
| -rw-r--r-- | lib/prefix.h | 1 |
2 files changed, 37 insertions, 2 deletions
diff --git a/lib/prefix.c b/lib/prefix.c index b8cad910f4..0b8664411d 100644 --- a/lib/prefix.c +++ b/lib/prefix.c @@ -355,6 +355,41 @@ void prefix_copy(union prefixptr udest, union prefixconstptr usrc) } } +bool evpn_addr_same(const struct evpn_addr *e1, const struct evpn_addr *e2) +{ + if (e1->route_type != e2->route_type) + return false; + if (e1->route_type == BGP_EVPN_AD_ROUTE) + return (!memcmp(&e1->ead_addr.esi.val, + &e2->ead_addr.esi.val, ESI_BYTES) && + e1->ead_addr.eth_tag == e2->ead_addr.eth_tag && + !ipaddr_cmp(&e1->ead_addr.ip, &e2->ead_addr.ip)); + if (e1->route_type == BGP_EVPN_MAC_IP_ROUTE) + return (e1->macip_addr.eth_tag == e2->macip_addr.eth_tag && + e1->macip_addr.ip_prefix_length + == e2->macip_addr.ip_prefix_length && + !memcmp(&e1->macip_addr.mac, + &e2->macip_addr.mac, ETH_ALEN) && + !ipaddr_cmp(&e1->macip_addr.ip, &e2->macip_addr.ip)); + if (e1->route_type == BGP_EVPN_IMET_ROUTE) + return (e1->imet_addr.eth_tag == e2->imet_addr.eth_tag && + e1->imet_addr.ip_prefix_length + == e2->imet_addr.ip_prefix_length && + !ipaddr_cmp(&e1->imet_addr.ip, &e2->imet_addr.ip)); + if (e1->route_type == BGP_EVPN_ES_ROUTE) + return (!memcmp(&e1->es_addr.esi.val, + &e2->es_addr.esi.val, ESI_BYTES) && + e1->es_addr.ip_prefix_length + == e2->es_addr.ip_prefix_length && + !ipaddr_cmp(&e1->es_addr.ip, &e2->es_addr.ip)); + if (e1->route_type == BGP_EVPN_IP_PREFIX_ROUTE) + return (e1->prefix_addr.eth_tag == e2->prefix_addr.eth_tag && + e1->prefix_addr.ip_prefix_length + == e2->prefix_addr.ip_prefix_length && + !ipaddr_cmp(&e1->prefix_addr.ip, &e2->prefix_addr.ip)); + return true; +} + /* * Return 1 if the address/netmask contained in the prefix structure * is the same, and else return 0. For this routine, 'same' requires @@ -387,8 +422,7 @@ int prefix_same(union prefixconstptr up1, union prefixconstptr up2) sizeof(struct ethaddr))) return 1; if (p1->family == AF_EVPN) - if (!memcmp(&p1->u.prefix_evpn, &p2->u.prefix_evpn, - sizeof(struct evpn_addr))) + if (evpn_addr_same(&p1->u.prefix_evpn, &p2->u.prefix_evpn)) return 1; if (p1->family == AF_FLOWSPEC) { if (p1->u.prefix_flowspec.family != diff --git a/lib/prefix.h b/lib/prefix.h index 90b792b33c..7ca525e762 100644 --- a/lib/prefix.h +++ b/lib/prefix.h @@ -427,6 +427,7 @@ extern int prefix_cmp(union prefixconstptr ua, union prefixconstptr ub); extern int prefix_common_bits(union prefixconstptr ua, union prefixconstptr ub); extern void prefix_copy(union prefixptr udst, union prefixconstptr usrc); extern void apply_mask(union prefixptr pu); +extern bool evpn_addr_same(const struct evpn_addr *e1, const struct evpn_addr *e2); #ifdef __clang_analyzer__ /* clang-SA doesn't understand transparent unions, making it think that the |
