]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgp_route.c
Merge pull request #12646 from pguibert6WIND/mpls_alloc_per_nh
[mirror_frr.git] / bgpd / bgp_route.c
index 40ecdbb670dc9c9532787007324dbe7b7fc7d4fd..f5ead66f25b75fe9882ed8c0e210f88f6633970b 100644 (file)
@@ -3087,10 +3087,13 @@ static bool bgp_lu_need_null_label(struct bgp *bgp,
 need_null_label:
        if (label == NULL)
                return true;
-       if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LU_EXPLICIT_NULL))
-               /* Disable PHP : explicit-null */
-               *label = afi == AFI_IP ? MPLS_LABEL_IPV4_EXPLICIT_NULL
-                                      : MPLS_LABEL_IPV6_EXPLICIT_NULL;
+       /* Disable PHP : explicit-null */
+       if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LU_IPV4_EXPLICIT_NULL) &&
+           afi == AFI_IP)
+               *label = MPLS_LABEL_IPV4_EXPLICIT_NULL;
+       else if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LU_IPV6_EXPLICIT_NULL) &&
+                afi == AFI_IP6)
+               *label = MPLS_LABEL_IPV6_EXPLICIT_NULL;
        else
                /* Enforced PHP popping: implicit-null */
                *label = MPLS_LABEL_IMPLICIT_NULL;
@@ -4173,6 +4176,21 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
                goto filtered;
        }
 
+       /* If the route has Node Target Extended Communities, check
+        * if it's allowed to be installed locally.
+        */
+       if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))) {
+               struct ecommunity *ecomm = bgp_attr_get_ecommunity(attr);
+
+               if (ecommunity_lookup(ecomm, ECOMMUNITY_ENCODE_IP,
+                                     ECOMMUNITY_NODE_TARGET) &&
+                   !ecommunity_node_target_match(ecomm, &peer->local_id)) {
+                       reason =
+                               "Node-Target Extended Communities do not contain own BGP Identifier;";
+                       goto filtered;
+               }
+       }
+
        /* RFC 8212 to prevent route leaks.
         * This specification intends to improve this situation by requiring the
         * explicit configuration of both BGP Import and Export Policies for any
@@ -8658,12 +8676,16 @@ void bgp_redistribute_add(struct bgp *bgp, struct prefix *p,
         */
        assert(attr.aspath);
 
+       if (p->family == AF_INET6)
+               UNSET_FLAG(attr.flag, ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP));
+
        switch (nhtype) {
        case NEXTHOP_TYPE_IFINDEX:
                switch (p->family) {
                case AF_INET:
                        attr.nexthop.s_addr = INADDR_ANY;
                        attr.mp_nexthop_len = BGP_ATTR_NHLEN_IPV4;
+                       attr.mp_nexthop_global_in.s_addr = INADDR_ANY;
                        break;
                case AF_INET6:
                        memset(&attr.mp_nexthop_global, 0,
@@ -8676,6 +8698,7 @@ void bgp_redistribute_add(struct bgp *bgp, struct prefix *p,
        case NEXTHOP_TYPE_IPV4_IFINDEX:
                attr.nexthop = nexthop->ipv4;
                attr.mp_nexthop_len = BGP_ATTR_NHLEN_IPV4;
+               attr.mp_nexthop_global_in = nexthop->ipv4;
                break;
        case NEXTHOP_TYPE_IPV6:
        case NEXTHOP_TYPE_IPV6_IFINDEX:
@@ -8687,6 +8710,7 @@ void bgp_redistribute_add(struct bgp *bgp, struct prefix *p,
                case AF_INET:
                        attr.nexthop.s_addr = INADDR_ANY;
                        attr.mp_nexthop_len = BGP_ATTR_NHLEN_IPV4;
+                       attr.mp_nexthop_global_in.s_addr = INADDR_ANY;
                        break;
                case AF_INET6:
                        memset(&attr.mp_nexthop_global, 0,
@@ -14262,7 +14286,6 @@ show_adj_route(struct vty *vty, struct peer *peer, struct bgp_table *table,
                        for (ain = dest->adj_in; ain; ain = ain->next) {
                                if (ain->peer != peer)
                                        continue;
-
                                show_adj_route_header(vty, peer, table, header1,
                                                      header2, json, json_scode,
                                                      json_ocode, wide, detail);
@@ -14313,9 +14336,23 @@ show_adj_route(struct vty *vty, struct peer *peer, struct bgp_table *table,
                                        if (use_json)
                                                json_net =
                                                        json_object_new_object();
+
+                                       struct bgp_path_info bpi;
+                                       struct bgp_dest buildit = *dest;
+                                       struct bgp_dest *pass_in;
+
+                                       if (route_filtered ||
+                                           ret == RMAP_DENY) {
+                                               bpi.attr = &attr;
+                                               bpi.peer = peer;
+                                               buildit.info = &bpi;
+
+                                               pass_in = &buildit;
+                                       } else
+                                               pass_in = dest;
                                        bgp_show_path_info(
-                                               NULL /* prefix_rd */, dest, vty,
-                                               bgp, afi, safi, json_net,
+                                               NULL, pass_in, vty, bgp, afi,
+                                               safi, json_net,
                                                BGP_PATH_SHOW_ALL, &display,
                                                RPKI_NOT_BEING_USED);
                                        if (use_json)