diff options
author | Donatas Abraitis <donatas@opensourcerouting.org> | 2022-06-27 08:57:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-27 08:57:29 +0200 |
commit | f646c17a4349a2439230980bdae70b58b34b862c (patch) | |
tree | 6beff29af33de5b06454a45ad4f73868ce70a633 /bgpd/bgp_route.c | |
parent | Merge pull request #11477 from LabNConsulting/chopps/fix-config-load (diff) | |
parent | bgpd: update topotests for role mismatch (diff) | |
download | frr-f646c17a4349a2439230980bdae70b58b34b862c.tar.xz frr-f646c17a4349a2439230980bdae70b58b34b862c.zip |
Merge pull request #11426 from error2407/open_policy
bgpd: Add RFC9234 implementation
Diffstat (limited to 'bgpd/bgp_route.c')
-rw-r--r-- | bgpd/bgp_route.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index f94f5db51..b35cbeb21 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -1561,6 +1561,48 @@ static bool bgp_cluster_filter(struct peer *peer, struct attr *attr) return false; } +static bool bgp_otc_filter(struct peer *peer, struct attr *attr) +{ + if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_OTC)) { + if (peer->local_role == ROLE_PROVIDER || + peer->local_role == ROLE_RS_SERVER) + return true; + if (peer->local_role == ROLE_PEER && attr->otc != peer->as) + return true; + return false; + } + if (peer->local_role == ROLE_CUSTOMER || + peer->local_role == ROLE_PEER || + peer->local_role == ROLE_RS_CLIENT) { + attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_OTC); + attr->otc = peer->as; + } + return false; +} + +static bool bgp_otc_egress(struct peer *peer, struct attr *attr) +{ + if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_OTC)) { + if (peer->local_role == ROLE_CUSTOMER || + peer->local_role == ROLE_RS_CLIENT || + peer->local_role == ROLE_PEER) + return true; + return false; + } + if (peer->local_role == ROLE_PROVIDER || + peer->local_role == ROLE_PEER || + peer->local_role == ROLE_RS_SERVER) { + attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_OTC); + attr->otc = peer->bgp->as; + } + return false; +} + +static bool bgp_check_role_applicability(afi_t afi, safi_t safi) +{ + return ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST); +} + static int bgp_input_modifier(struct peer *peer, const struct prefix *p, struct attr *attr, afi_t afi, safi_t safi, const char *rmap_name, mpls_label_t *label, @@ -2165,6 +2207,10 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi, memset(&attr->mp_nexthop_local, 0, IPV6_MAX_BYTELEN); } + if (bgp_check_role_applicability(afi, safi) && + bgp_otc_egress(peer, attr)) + return false; + bgp_peer_remove_private_as(bgp, afi, safi, peer, attr); bgp_peer_as_override(bgp, afi, safi, peer, attr); @@ -3961,6 +4007,12 @@ int bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id, goto filtered; } + if (bgp_check_role_applicability(afi, safi) && + bgp_otc_filter(peer, &new_attr)) { + reason = "failing otc validation"; + bgp_attr_flush(&new_attr); + goto filtered; + } /* The flag BGP_NODE_FIB_INSTALL_PENDING is for the following * condition : * Suppress fib is enabled @@ -10434,6 +10486,13 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn, vty_out(vty, ", atomic-aggregate"); } + if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_OTC)) { + if (json_paths) + json_object_int_add(json_path, "otc", attr->otc); + else + vty_out(vty, ", otc %u", attr->otc); + } + if (CHECK_FLAG(path->flags, BGP_PATH_MULTIPATH) || (CHECK_FLAG(path->flags, BGP_PATH_SELECTED) && bgp_path_info_mpath_count(path))) { |