From: Donatas Abraitis Date: Mon, 10 Apr 2023 19:40:30 +0000 (+0300) Subject: bgpd: Reuse encode_route_target_ip() function X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=8f2a51b7b76eccac7511acb9116cab4c492831bc;p=mirror_frr.git bgpd: Reuse encode_route_target_ip() function Before this patch, this function wasn't used in the code. Let's reuse this since it's uses the same pattern for encoding route-target extcommunity. Also reuse encode_route_target_as[4]() as well. Signed-off-by: Donatas Abraitis --- diff --git a/bgpd/bgp_ecommunity.c b/bgpd/bgp_ecommunity.c index 596c5dbe3..7bf260901 100644 --- a/bgpd/bgp_ecommunity.c +++ b/bgpd/bgp_ecommunity.c @@ -494,32 +494,19 @@ static int ecommunity_encode_internal(uint8_t type, uint8_t sub_type, eval->val[0] |= ECOMMUNITY_FLAG_NON_TRANSITIVE; eval->val[1] = sub_type; if (type == ECOMMUNITY_ENCODE_AS) { - eval->val[2] = (as >> 8) & 0xff; - eval->val[3] = as & 0xff; - eval->val[4] = (val >> 24) & 0xff; - eval->val[5] = (val >> 16) & 0xff; - eval->val[6] = (val >> 8) & 0xff; - eval->val[7] = val & 0xff; + encode_route_target_as(as, val, eval, trans); } else if (type == ECOMMUNITY_ENCODE_IP) { - if (sub_type == ECOMMUNITY_NODE_TARGET) { + if (sub_type == ECOMMUNITY_NODE_TARGET) encode_node_target(ip, eval, trans); - } else { - memcpy(&eval->val[2], ip, sizeof(struct in_addr)); - eval->val[6] = (val >> 8) & 0xff; - eval->val[7] = val & 0xff; - } + else + encode_route_target_ip(ip, val, eval, trans); } else if (type == ECOMMUNITY_ENCODE_TRANS_EXP && sub_type == ECOMMUNITY_FLOWSPEC_REDIRECT_IPV6) { memcpy(&eval6->val[2], ip6, sizeof(struct in6_addr)); eval6->val[18] = (val >> 8) & 0xff; eval6->val[19] = val & 0xff; } else { - eval->val[2] = (as >> 24) & 0xff; - eval->val[3] = (as >> 16) & 0xff; - eval->val[4] = (as >> 8) & 0xff; - eval->val[5] = as & 0xff; - eval->val[6] = (val >> 8) & 0xff; - eval->val[7] = val & 0xff; + encode_route_target_as4(as, val, eval, trans); } return 0; diff --git a/bgpd/bgp_ecommunity.h b/bgpd/bgp_ecommunity.h index 1efb0276d..94a178bbb 100644 --- a/bgpd/bgp_ecommunity.h +++ b/bgpd/bgp_ecommunity.h @@ -159,9 +159,12 @@ struct ecommunity_val_ipv6 { * Encode BGP Route Target AS:nn. */ static inline void encode_route_target_as(as_t as, uint32_t val, - struct ecommunity_val *eval) + struct ecommunity_val *eval, + bool trans) { eval->val[0] = ECOMMUNITY_ENCODE_AS; + if (!trans) + eval->val[0] |= ECOMMUNITY_FLAG_NON_TRANSITIVE; eval->val[1] = ECOMMUNITY_ROUTE_TARGET; eval->val[2] = (as >> 8) & 0xff; eval->val[3] = as & 0xff; @@ -174,12 +177,15 @@ static inline void encode_route_target_as(as_t as, uint32_t val, /* * Encode BGP Route Target IP:nn. */ -static inline void encode_route_target_ip(struct in_addr ip, uint16_t val, - struct ecommunity_val *eval) +static inline void encode_route_target_ip(struct in_addr *ip, uint16_t val, + struct ecommunity_val *eval, + bool trans) { eval->val[0] = ECOMMUNITY_ENCODE_IP; + if (!trans) + eval->val[0] |= ECOMMUNITY_FLAG_NON_TRANSITIVE; eval->val[1] = ECOMMUNITY_ROUTE_TARGET; - memcpy(&eval->val[2], &ip, sizeof(struct in_addr)); + memcpy(&eval->val[2], ip, sizeof(struct in_addr)); eval->val[6] = (val >> 8) & 0xff; eval->val[7] = val & 0xff; } @@ -188,9 +194,12 @@ static inline void encode_route_target_ip(struct in_addr ip, uint16_t val, * Encode BGP Route Target AS4:nn. */ static inline void encode_route_target_as4(as_t as, uint16_t val, - struct ecommunity_val *eval) + struct ecommunity_val *eval, + bool trans) { eval->val[0] = ECOMMUNITY_ENCODE_AS4; + if (!trans) + eval->val[0] |= ECOMMUNITY_FLAG_NON_TRANSITIVE; eval->val[1] = ECOMMUNITY_ROUTE_TARGET; eval->val[2] = (as >> 24) & 0xff; eval->val[3] = (as >> 16) & 0xff; diff --git a/bgpd/bgp_evpn.c b/bgpd/bgp_evpn.c index 81117e94e..87139e9e5 100644 --- a/bgpd/bgp_evpn.c +++ b/bgpd/bgp_evpn.c @@ -577,7 +577,7 @@ static void form_auto_rt(struct bgp *bgp, vni_t vni, struct list *rtl, if (bgp->advertise_autort_rfc8365) vni |= EVPN_AUTORT_VXLAN; - encode_route_target_as((bgp->as & 0xFFFF), vni, &eval); + encode_route_target_as((bgp->as & 0xFFFF), vni, &eval, true); ecomadd = ecommunity_new(); ecommunity_add_val(ecomadd, &eval, false, false); @@ -5168,7 +5168,7 @@ void evpn_rt_delete_auto(struct bgp *bgp, vni_t vni, struct list *rtl, if (bgp->advertise_autort_rfc8365) vni |= EVPN_AUTORT_VXLAN; - encode_route_target_as((bgp->as & 0xFFFF), vni, &eval); + encode_route_target_as((bgp->as & 0xFFFF), vni, &eval, true); ecom_auto = ecommunity_new(); ecommunity_add_val(ecom_auto, &eval, false, false);