2 * Copyright (C) 2000 Kunihiro Ishiguro <kunihiro@zebra.org>
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
34 #include "bgpd/bgpd.h"
35 #include "bgpd/bgp_debug.h"
36 #include "bgpd/bgp_table.h"
37 #include "bgpd/bgp_route.h"
38 #include "bgpd/bgp_attr.h"
39 #include "bgpd/bgp_label.h"
40 #include "bgpd/bgp_mplsvpn.h"
41 #include "bgpd/bgp_packet.h"
42 #include "bgpd/bgp_vty.h"
43 #include "bgpd/bgp_vpn.h"
44 #include "bgpd/bgp_ecommunity.h"
45 #include "bgpd/bgp_zebra.h"
46 #include "bgpd/bgp_nexthop.h"
47 #include "bgpd/bgp_nht.h"
50 #include "bgpd/rfapi/rfapi_backend.h"
54 * Definitions and external declarations.
56 extern struct zclient
*zclient
;
58 extern int argv_find_and_parse_vpnvx(struct cmd_token
**argv
, int argc
,
59 int *index
, afi_t
*afi
)
62 if (argv_find(argv
, argc
, "vpnv4", index
)) {
66 } else if (argv_find(argv
, argc
, "vpnv6", index
)) {
74 uint32_t decode_label(mpls_label_t
*label_pnt
)
77 uint8_t *pnt
= (uint8_t *)label_pnt
;
79 l
= ((uint32_t)*pnt
++ << 12);
80 l
|= (uint32_t)*pnt
++ << 4;
81 l
|= (uint32_t)((*pnt
& 0xf0) >> 4);
85 void encode_label(mpls_label_t label
, mpls_label_t
*label_pnt
)
87 uint8_t *pnt
= (uint8_t *)label_pnt
;
90 *pnt
++ = (label
>> 12) & 0xff;
91 *pnt
++ = (label
>> 4) & 0xff;
92 *pnt
++ = ((label
<< 4) + 1) & 0xff; /* S=1 */
95 int bgp_nlri_parse_vpn(struct peer
*peer
, struct attr
*attr
,
96 struct bgp_nlri
*packet
)
106 struct prefix_rd prd
;
107 mpls_label_t label
= {0};
114 prd
.family
= AF_UNSPEC
;
118 lim
= pnt
+ packet
->length
;
124 (CHECK_FLAG(peer
->af_cap
[afi
][safi
], PEER_CAP_ADDPATH_AF_RX_ADV
)
125 && CHECK_FLAG(peer
->af_cap
[afi
][safi
],
126 PEER_CAP_ADDPATH_AF_TX_RCV
));
128 #define VPN_PREFIXLEN_MIN_BYTES (3 + 8) /* label + RD */
129 for (; pnt
< lim
; pnt
+= psize
) {
130 /* Clear prefix structure. */
131 memset(&p
, 0, sizeof(struct prefix
));
133 if (addpath_encoded
) {
135 /* When packet overflow occurs return immediately. */
136 if (pnt
+ BGP_ADDPATH_ID_LEN
> lim
)
139 addpath_id
= ntohl(*((uint32_t *)pnt
));
140 pnt
+= BGP_ADDPATH_ID_LEN
;
143 /* Fetch prefix length. */
145 p
.family
= afi2family(packet
->afi
);
146 psize
= PSIZE(prefixlen
);
148 if (prefixlen
< VPN_PREFIXLEN_MIN_BYTES
* 8) {
150 "%s [Error] Update packet error / VPN (prefix length %d less than VPN min length)",
151 peer
->host
, prefixlen
);
155 /* sanity check against packet data */
156 if ((pnt
+ psize
) > lim
) {
158 "%s [Error] Update packet error / VPN (prefix length %d exceeds packet size %u)",
159 peer
->host
, prefixlen
, (uint
)(lim
- pnt
));
163 /* sanity check against storage for the IP address portion */
164 if ((psize
- VPN_PREFIXLEN_MIN_BYTES
) > (ssize_t
)sizeof(p
.u
)) {
166 "%s [Error] Update packet error / VPN (psize %d exceeds storage size %zu)",
168 prefixlen
- VPN_PREFIXLEN_MIN_BYTES
* 8,
173 /* Sanity check against max bitlen of the address family */
174 if ((psize
- VPN_PREFIXLEN_MIN_BYTES
) > prefix_blen(&p
)) {
176 "%s [Error] Update packet error / VPN (psize %d exceeds family (%u) max byte len %u)",
178 prefixlen
- VPN_PREFIXLEN_MIN_BYTES
* 8,
179 p
.family
, prefix_blen(&p
));
183 /* Copy label to prefix. */
184 memcpy(&label
, pnt
, BGP_LABEL_BYTES
);
185 bgp_set_valid_label(&label
);
187 /* Copy routing distinguisher to rd. */
188 memcpy(&prd
.val
, pnt
+ BGP_LABEL_BYTES
, 8);
190 /* Decode RD type. */
191 type
= decode_rd_type(pnt
+ BGP_LABEL_BYTES
);
195 decode_rd_as(pnt
+ 5, &rd_as
);
199 decode_rd_as4(pnt
+ 5, &rd_as
);
203 decode_rd_ip(pnt
+ 5, &rd_ip
);
207 case RD_TYPE_VNC_ETH
:
212 zlog_err("Unknown RD type %d", type
);
213 break; /* just report */
218 - VPN_PREFIXLEN_MIN_BYTES
* 8; /* exclude label & RD */
219 memcpy(&p
.u
.prefix
, pnt
+ VPN_PREFIXLEN_MIN_BYTES
,
220 psize
- VPN_PREFIXLEN_MIN_BYTES
);
223 bgp_update(peer
, &p
, addpath_id
, attr
, packet
->afi
,
224 SAFI_MPLS_VPN
, ZEBRA_ROUTE_BGP
,
225 BGP_ROUTE_NORMAL
, &prd
, &label
, 1, 0, NULL
);
227 bgp_withdraw(peer
, &p
, addpath_id
, attr
, packet
->afi
,
228 SAFI_MPLS_VPN
, ZEBRA_ROUTE_BGP
,
229 BGP_ROUTE_NORMAL
, &prd
, &label
, 1, NULL
);
232 /* Packet length consistency check. */
235 "%s [Error] Update packet error / VPN (%zu data remaining after parsing)",
236 peer
->host
, lim
- pnt
);
241 #undef VPN_PREFIXLEN_MIN_BYTES
245 * This function informs zebra of the label this vrf sets on routes
246 * leaked to VPN. Zebra should install this label in the kernel with
247 * an action of "pop label and then use this vrf's IP FIB to route the PDU."
249 * Sending this vrf-label association is qualified by a) whether vrf->vpn
250 * exporting is active ("export vpn" is enabled, vpn-policy RD and RT list
251 * are set) and b) whether vpn-policy label is set.
253 * If any of these conditions do not hold, then we send MPLS_LABEL_NONE
254 * for this vrf, which zebra interprets to mean "delete this vrf-label
257 void vpn_leak_zebra_vrf_label_update(struct bgp
*bgp
, afi_t afi
)
259 mpls_label_t label
= MPLS_LABEL_NONE
;
260 int debug
= BGP_DEBUG(vpn
, VPN_LEAK_LABEL
);
262 if (bgp
->vrf_id
== VRF_UNKNOWN
) {
265 "%s: vrf %s: afi %s: vrf_id not set, "
266 "can't set zebra vrf label",
267 __func__
, bgp
->name_pretty
, afi2str(afi
));
272 if (vpn_leak_to_vpn_active(bgp
, afi
, NULL
)) {
273 label
= bgp
->vpn_policy
[afi
].tovpn_label
;
277 zlog_debug("%s: vrf %s: afi %s: setting label %d for vrf id %d",
278 __func__
, bgp
->name_pretty
, afi2str(afi
), label
,
282 zclient_send_vrf_label(zclient
, bgp
->vrf_id
, afi
, label
, ZEBRA_LSP_BGP
);
283 bgp
->vpn_policy
[afi
].tovpn_zebra_vrf_label_last_sent
= label
;
287 * If zebra tells us vrf has become unconfigured, tell zebra not to
288 * use this label to forward to the vrf anymore
290 void vpn_leak_zebra_vrf_label_withdraw(struct bgp
*bgp
, afi_t afi
)
292 mpls_label_t label
= MPLS_LABEL_NONE
;
293 int debug
= BGP_DEBUG(vpn
, VPN_LEAK_LABEL
);
295 if (bgp
->vrf_id
== VRF_UNKNOWN
) {
298 "%s: vrf_id not set, can't delete zebra vrf label",
305 zlog_debug("%s: deleting label for vrf %s (id=%d)", __func__
,
306 bgp
->name_pretty
, bgp
->vrf_id
);
309 zclient_send_vrf_label(zclient
, bgp
->vrf_id
, afi
, label
, ZEBRA_LSP_BGP
);
310 bgp
->vpn_policy
[afi
].tovpn_zebra_vrf_label_last_sent
= label
;
313 int vpn_leak_label_callback(
318 struct vpn_policy
*vp
= (struct vpn_policy
*)labelid
;
319 int debug
= BGP_DEBUG(vpn
, VPN_LEAK_LABEL
);
322 zlog_debug("%s: label=%u, allocated=%d",
323 __func__
, label
, allocated
);
327 * previously-allocated label is now invalid
329 if (CHECK_FLAG(vp
->flags
, BGP_VPN_POLICY_TOVPN_LABEL_AUTO
) &&
330 (vp
->tovpn_label
!= MPLS_LABEL_NONE
)) {
332 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN
,
333 vp
->afi
, bgp_get_default(), vp
->bgp
);
334 vp
->tovpn_label
= MPLS_LABEL_NONE
;
335 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN
,
336 vp
->afi
, bgp_get_default(), vp
->bgp
);
342 * New label allocation
344 if (!CHECK_FLAG(vp
->flags
, BGP_VPN_POLICY_TOVPN_LABEL_AUTO
)) {
347 * not currently configured for auto label, reject allocation
352 if (vp
->tovpn_label
!= MPLS_LABEL_NONE
) {
353 if (label
== vp
->tovpn_label
) {
354 /* already have same label, accept but do nothing */
357 /* Shouldn't happen: different label allocation */
358 zlog_err("%s: %s had label %u but got new assignment %u",
359 __func__
, vp
->bgp
->name_pretty
, vp
->tovpn_label
, label
);
363 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN
,
364 vp
->afi
, bgp_get_default(), vp
->bgp
);
365 vp
->tovpn_label
= label
;
366 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN
,
367 vp
->afi
, bgp_get_default(), vp
->bgp
);
372 static int ecom_intersect(struct ecommunity
*e1
, struct ecommunity
*e2
)
380 for (i
= 0; i
< e1
->size
; ++i
) {
381 for (j
= 0; j
< e2
->size
; ++j
) {
382 if (!memcmp(e1
->val
+ (i
* ECOMMUNITY_SIZE
),
383 e2
->val
+ (j
* ECOMMUNITY_SIZE
),
393 static bool labels_same(struct bgp_info
*bi
, mpls_label_t
*label
, uint32_t n
)
404 if (n
!= bi
->extra
->num_labels
)
407 for (i
= 0; i
< n
; ++i
) {
408 if (label
[i
] != bi
->extra
->label
[i
])
415 * make encoded route labels match specified encoded label set
417 static void setlabels(
419 mpls_label_t
*label
, /* array of labels */
424 assert(num_labels
<= BGP_MAX_LABELS
);
428 bi
->extra
->num_labels
= 0;
432 struct bgp_info_extra
*extra
= bgp_info_extra_get(bi
);
435 for (i
= 0; i
< num_labels
; ++i
) {
436 extra
->label
[i
] = label
[i
];
437 if (!bgp_is_valid_label(&label
[i
])) {
438 bgp_set_valid_label(&extra
->label
[i
]);
441 extra
->num_labels
= num_labels
;
445 * returns pointer to new bgp_info upon success
447 static struct bgp_info
*
449 struct bgp
*bgp
, /* destination bgp instance */
451 struct attr
*new_attr
, /* already interned */
454 struct bgp_info
*source_bi
,
458 struct bgp
*bgp_orig
,
459 struct prefix
*nexthop_orig
,
460 int nexthop_self_flag
,
463 struct prefix
*p
= &bn
->p
;
465 struct bgp_info
*new;
466 char buf_prefix
[PREFIX_STRLEN
];
469 prefix2str(&bn
->p
, buf_prefix
, sizeof(buf_prefix
));
470 zlog_debug("%s: entry: leak-to=%s, p=%s, type=%d, sub_type=%d",
471 __func__
, bgp
->name_pretty
, buf_prefix
,
472 source_bi
->type
, source_bi
->sub_type
);
478 for (bi
= bn
->info
; bi
; bi
= bi
->next
) {
479 if (bi
->extra
&& bi
->extra
->parent
== parent
)
484 bool labelssame
= labels_same(bi
, label
, num_labels
);
486 if (attrhash_cmp(bi
->attr
, new_attr
)
488 && !CHECK_FLAG(bi
->flags
, BGP_INFO_REMOVED
)) {
490 bgp_attr_unintern(&new_attr
);
493 "%s: ->%s: %s: Found route, no change",
494 __func__
, bgp
->name_pretty
,
499 /* attr is changed */
500 bgp_info_set_flag(bn
, bi
, BGP_INFO_ATTR_CHANGED
);
502 /* Rewrite BGP route information. */
503 if (CHECK_FLAG(bi
->flags
, BGP_INFO_REMOVED
))
504 bgp_info_restore(bn
, bi
);
506 bgp_aggregate_decrement(bgp
, p
, bi
, afi
, safi
);
507 bgp_attr_unintern(&bi
->attr
);
509 bi
->uptime
= bgp_clock();
515 setlabels(bi
, label
, num_labels
);
517 if (nexthop_self_flag
)
518 bgp_info_set_flag(bn
, bi
, BGP_INFO_ANNC_NH_SELF
);
520 struct bgp
*bgp_nexthop
= bgp
;
523 if (bi
->extra
&& bi
->extra
->bgp_orig
)
524 bgp_nexthop
= bi
->extra
->bgp_orig
;
526 /* No nexthop tracking for redistributed routes */
527 if (source_bi
->sub_type
== BGP_ROUTE_REDISTRIBUTE
)
531 * TBD do we need to do anything about the
532 * 'connected' parameter?
534 nh_valid
= bgp_find_or_add_nexthop(
539 zlog_debug("%s: nexthop is %svalid (in vrf %s)",
540 __func__
, (nh_valid
? "" : "not "),
541 bgp_nexthop
->name_pretty
);
544 bgp_info_set_flag(bn
, bi
, BGP_INFO_VALID
);
546 /* Process change. */
547 bgp_aggregate_increment(bgp
, p
, bi
, afi
, safi
);
548 bgp_process(bgp
, bn
, afi
, safi
);
552 zlog_debug("%s: ->%s: %s Found route, changed attr",
553 __func__
, bgp
->name_pretty
, buf_prefix
);
558 new = info_make(ZEBRA_ROUTE_BGP
, BGP_ROUTE_IMPORTED
, 0,
559 bgp
->peer_self
, new_attr
, bn
);
561 if (nexthop_self_flag
)
562 bgp_info_set_flag(bn
, new, BGP_INFO_ANNC_NH_SELF
);
565 setlabels(new, label
, num_labels
);
567 bgp_info_extra_get(new);
568 new->extra
->parent
= parent
;
571 new->extra
->bgp_orig
= bgp_orig
;
573 new->extra
->nexthop_orig
= *nexthop_orig
;
576 * nexthop tracking for unicast routes
578 struct bgp
*bgp_nexthop
= bgp
;
581 if (new->extra
&& new->extra
->bgp_orig
)
582 bgp_nexthop
= new->extra
->bgp_orig
;
585 * No nexthop tracking for redistributed routes because
586 * their originating protocols will do the tracking and
587 * withdraw those routes if the nexthops become unreachable
589 if (source_bi
->sub_type
== BGP_ROUTE_REDISTRIBUTE
)
593 * TBD do we need to do anything about the
594 * 'connected' parameter?
596 nh_valid
= bgp_find_or_add_nexthop(bgp
, bgp_nexthop
,
600 zlog_debug("%s: nexthop is %svalid (in vrf %s)",
601 __func__
, (nh_valid
? "" : "not "),
602 bgp_nexthop
->name_pretty
);
604 bgp_info_set_flag(bn
, new, BGP_INFO_VALID
);
606 bgp_aggregate_increment(bgp
, p
, new, afi
, safi
);
607 bgp_info_add(bn
, new);
610 bgp_process(bgp
, bn
, afi
, safi
);
613 zlog_debug("%s: ->%s: %s: Added new route", __func__
,
614 bgp
->name_pretty
, buf_prefix
);
619 /* cf vnc_import_bgp_add_route_mode_nvegroup() and add_vnc_route() */
620 void vpn_leak_from_vrf_update(struct bgp
*bgp_vpn
, /* to */
621 struct bgp
*bgp_vrf
, /* from */
622 struct bgp_info
*info_vrf
) /* route */
624 int debug
= BGP_DEBUG(vpn
, VPN_LEAK_FROM_VRF
);
625 struct prefix
*p
= &info_vrf
->net
->p
;
626 afi_t afi
= family2afi(p
->family
);
627 struct attr static_attr
= {0};
628 struct attr
*new_attr
= NULL
;
629 safi_t safi
= SAFI_MPLS_VPN
;
630 mpls_label_t label_val
;
633 const char *debugmsg
;
634 int nexthop_self_flag
= 0;
637 zlog_debug("%s: from vrf %s", __func__
, bgp_vrf
->name_pretty
);
639 if (debug
&& info_vrf
->attr
->ecommunity
) {
640 char *s
= ecommunity_ecom2str(info_vrf
->attr
->ecommunity
,
641 ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
643 zlog_debug("%s: %s info_vrf->type=%d, EC{%s}", __func__
,
644 bgp_vrf
->name
, info_vrf
->type
, s
);
645 XFREE(MTYPE_ECOMMUNITY_STR
, s
);
653 zlog_debug("%s: can't get afi of prefix", __func__
);
657 /* loop check - should not be an imported route. */
658 if (info_vrf
->extra
&& info_vrf
->extra
->bgp_orig
)
662 if (!vpn_leak_to_vpn_active(bgp_vrf
, afi
, &debugmsg
)) {
664 zlog_debug("%s: %s skipping: %s", __func__
,
665 bgp_vrf
->name
, debugmsg
);
669 bgp_attr_dup(&static_attr
, info_vrf
->attr
); /* shallow copy */
674 if (bgp_vrf
->vpn_policy
[afi
].rmap
[BGP_VPN_POLICY_DIR_TOVPN
]) {
675 struct bgp_info info
;
676 route_map_result_t ret
;
678 memset(&info
, 0, sizeof(info
));
679 info
.peer
= bgp_vpn
->peer_self
;
680 info
.attr
= &static_attr
;
681 ret
= route_map_apply(
682 bgp_vrf
->vpn_policy
[afi
].rmap
[BGP_VPN_POLICY_DIR_TOVPN
],
684 if (RMAP_DENYMATCH
== ret
) {
685 bgp_attr_flush(&static_attr
); /* free any added parts */
688 "%s: vrf %s route map \"%s\" says DENY, returning",
689 __func__
, bgp_vrf
->name_pretty
,
690 bgp_vrf
->vpn_policy
[afi
]
691 .rmap
[BGP_VPN_POLICY_DIR_TOVPN
]
697 if (debug
&& static_attr
.ecommunity
) {
698 char *s
= ecommunity_ecom2str(static_attr
.ecommunity
,
699 ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
701 zlog_debug("%s: post route map static_attr.ecommunity{%s}",
703 XFREE(MTYPE_ECOMMUNITY_STR
, s
);
707 * Add the vpn-policy rt-list
709 struct ecommunity
*old_ecom
;
710 struct ecommunity
*new_ecom
;
712 old_ecom
= static_attr
.ecommunity
;
714 new_ecom
= ecommunity_merge(
715 ecommunity_dup(old_ecom
),
716 bgp_vrf
->vpn_policy
[afi
]
717 .rtlist
[BGP_VPN_POLICY_DIR_TOVPN
]);
718 if (!old_ecom
->refcnt
)
719 ecommunity_free(&old_ecom
);
721 new_ecom
= ecommunity_dup(
722 bgp_vrf
->vpn_policy
[afi
]
723 .rtlist
[BGP_VPN_POLICY_DIR_TOVPN
]);
725 static_attr
.ecommunity
= new_ecom
;
726 SET_FLAG(static_attr
.flag
, ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
));
728 if (debug
&& static_attr
.ecommunity
) {
729 char *s
= ecommunity_ecom2str(static_attr
.ecommunity
,
730 ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
732 zlog_debug("%s: post merge static_attr.ecommunity{%s}",
734 XFREE(MTYPE_ECOMMUNITY_STR
, s
);
738 /* if policy nexthop not set, use 0 */
739 if (CHECK_FLAG(bgp_vrf
->vpn_policy
[afi
].flags
,
740 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET
)) {
741 struct prefix
*nexthop
=
742 &bgp_vrf
->vpn_policy
[afi
].tovpn_nexthop
;
744 switch (nexthop
->family
) {
746 /* prevent mp_nexthop_global_in <- self in bgp_route.c
748 static_attr
.nexthop
.s_addr
= nexthop
->u
.prefix4
.s_addr
;
750 static_attr
.mp_nexthop_global_in
= nexthop
->u
.prefix4
;
751 static_attr
.mp_nexthop_len
= 4;
755 static_attr
.mp_nexthop_global
= nexthop
->u
.prefix6
;
756 static_attr
.mp_nexthop_len
= 16;
763 if (!CHECK_FLAG(bgp_vrf
->af_flags
[afi
][SAFI_UNICAST
],
764 BGP_CONFIG_VRF_TO_VRF_EXPORT
)) {
767 * For ipv4, copy to multiprotocol
770 static_attr
.mp_nexthop_global_in
=
772 static_attr
.mp_nexthop_len
= 4;
774 * XXX Leave static_attr.nexthop
778 ~ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
781 /* Update based on next-hop family to account for
782 * RFC 5549 (BGP unnumbered) scenario. Note that
783 * specific action is only needed for the case of
784 * IPv4 nexthops as the attr has been copied
788 !BGP_ATTR_NEXTHOP_AFI_IP6(info_vrf
->attr
)) {
789 static_attr
.mp_nexthop_global_in
.s_addr
=
790 static_attr
.nexthop
.s_addr
;
791 static_attr
.mp_nexthop_len
= 4;
793 ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
796 nexthop_self_flag
= 1;
799 label_val
= bgp_vrf
->vpn_policy
[afi
].tovpn_label
;
800 if (label_val
== MPLS_LABEL_NONE
) {
801 encode_label(MPLS_LABEL_IMPLICIT_NULL
, &label
);
803 encode_label(label_val
, &label
);
806 /* Set originator ID to "me" */
807 SET_FLAG(static_attr
.flag
, ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
));
808 static_attr
.originator_id
= bgp_vpn
->router_id
;
811 new_attr
= bgp_attr_intern(
812 &static_attr
); /* hashed refcounted everything */
813 bgp_attr_flush(&static_attr
); /* free locally-allocated parts */
815 if (debug
&& new_attr
->ecommunity
) {
816 char *s
= ecommunity_ecom2str(new_attr
->ecommunity
,
817 ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
819 zlog_debug("%s: new_attr->ecommunity{%s}", __func__
, s
);
820 XFREE(MTYPE_ECOMMUNITY_STR
, s
);
823 /* Now new_attr is an allocated interned attr */
825 bn
= bgp_afi_node_get(bgp_vpn
->rib
[afi
][safi
], afi
, safi
, p
,
826 &(bgp_vrf
->vpn_policy
[afi
].tovpn_rd
));
828 struct bgp_info
*new_info
;
830 new_info
= leak_update(bgp_vpn
, bn
, new_attr
, afi
, safi
, info_vrf
,
831 &label
, 1, info_vrf
, bgp_vrf
, NULL
,
832 nexthop_self_flag
, debug
);
835 * Routes actually installed in the vpn RIB must also be
836 * offered to all vrfs (because now they originate from
839 * Acceptance into other vrfs depends on rt-lists.
840 * Originating vrf will not accept the looped back route
841 * because of loop checking.
844 vpn_leak_to_vrf_update(bgp_vrf
, new_info
);
847 void vpn_leak_from_vrf_withdraw(struct bgp
*bgp_vpn
, /* to */
848 struct bgp
*bgp_vrf
, /* from */
849 struct bgp_info
*info_vrf
) /* route */
851 int debug
= BGP_DEBUG(vpn
, VPN_LEAK_FROM_VRF
);
852 struct prefix
*p
= &info_vrf
->net
->p
;
853 afi_t afi
= family2afi(p
->family
);
854 safi_t safi
= SAFI_MPLS_VPN
;
857 const char *debugmsg
;
858 char buf_prefix
[PREFIX_STRLEN
];
861 prefix2str(p
, buf_prefix
, sizeof(buf_prefix
));
863 "%s: entry: leak-from=%s, p=%s, type=%d, sub_type=%d",
864 __func__
, bgp_vrf
->name_pretty
, buf_prefix
,
865 info_vrf
->type
, info_vrf
->sub_type
);
868 if (info_vrf
->sub_type
!= BGP_ROUTE_NORMAL
869 && info_vrf
->sub_type
!= BGP_ROUTE_STATIC
870 && info_vrf
->sub_type
!= BGP_ROUTE_REDISTRIBUTE
) {
873 zlog_debug("%s: wrong sub_type %d", __func__
,
882 zlog_debug("%s: can't get afi of prefix", __func__
);
886 if (!vpn_leak_to_vpn_active(bgp_vrf
, afi
, &debugmsg
)) {
888 zlog_debug("%s: skipping: %s", __func__
, debugmsg
);
893 zlog_debug("%s: withdrawing (info_vrf=%p)", __func__
, info_vrf
);
895 bn
= bgp_afi_node_get(bgp_vpn
->rib
[afi
][safi
], afi
, safi
, p
,
896 &(bgp_vrf
->vpn_policy
[afi
].tovpn_rd
));
900 * match original bi imported from
902 for (bi
= (bn
? bn
->info
: NULL
); bi
; bi
= bi
->next
) {
903 if (bi
->extra
&& bi
->extra
->parent
== info_vrf
) {
909 /* withdraw from looped vrfs as well */
910 vpn_leak_to_vrf_withdraw(bgp_vpn
, bi
);
912 bgp_aggregate_decrement(bgp_vpn
, p
, bi
, afi
, safi
);
913 bgp_info_delete(bn
, bi
);
914 bgp_process(bgp_vpn
, bn
, afi
, safi
);
919 void vpn_leak_from_vrf_withdraw_all(struct bgp
*bgp_vpn
, /* to */
920 struct bgp
*bgp_vrf
, /* from */
923 int debug
= BGP_DEBUG(vpn
, VPN_LEAK_FROM_VRF
);
924 struct bgp_node
*prn
;
925 safi_t safi
= SAFI_MPLS_VPN
;
928 * Walk vpn table, delete bi with bgp_orig == bgp_vrf
930 for (prn
= bgp_table_top(bgp_vpn
->rib
[afi
][safi
]); prn
;
931 prn
= bgp_route_next(prn
)) {
933 struct bgp_table
*table
;
937 /* This is the per-RD table of prefixes */
943 for (bn
= bgp_table_top(table
); bn
; bn
= bgp_route_next(bn
)) {
945 char buf
[PREFIX2STR_BUFFER
];
947 if (debug
&& bn
->info
) {
949 "%s: looking at prefix %s", __func__
,
950 prefix2str(&bn
->p
, buf
, sizeof(buf
)));
953 for (bi
= bn
->info
; bi
; bi
= bi
->next
) {
955 zlog_debug("%s: type %d, sub_type %d",
958 if (bi
->sub_type
!= BGP_ROUTE_IMPORTED
)
962 if ((struct bgp
*)bi
->extra
->bgp_orig
966 zlog_debug("%s: deleting it\n",
968 bgp_aggregate_decrement(bgp_vpn
, &bn
->p
,
970 bgp_info_delete(bn
, bi
);
971 bgp_process(bgp_vpn
, bn
, afi
, safi
);
978 void vpn_leak_from_vrf_update_all(struct bgp
*bgp_vpn
, /* to */
979 struct bgp
*bgp_vrf
, /* from */
984 int debug
= BGP_DEBUG(vpn
, VPN_LEAK_FROM_VRF
);
987 zlog_debug("%s: entry, afi=%d, vrf=%s", __func__
, afi
,
988 bgp_vrf
->name_pretty
);
990 for (bn
= bgp_table_top(bgp_vrf
->rib
[afi
][SAFI_UNICAST
]); bn
;
991 bn
= bgp_route_next(bn
)) {
994 zlog_debug("%s: node=%p", __func__
, bn
);
996 for (bi
= bn
->info
; bi
; bi
= bi
->next
) {
999 "%s: calling vpn_leak_from_vrf_update",
1001 vpn_leak_from_vrf_update(bgp_vpn
, bgp_vrf
, bi
);
1006 static void vpn_leak_to_vrf_update_onevrf(struct bgp
*bgp_vrf
, /* to */
1007 struct bgp
*bgp_vpn
, /* from */
1008 struct bgp_info
*info_vpn
) /* route */
1010 struct prefix
*p
= &info_vpn
->net
->p
;
1011 afi_t afi
= family2afi(p
->family
);
1013 struct attr static_attr
= {0};
1014 struct attr
*new_attr
= NULL
;
1015 struct bgp_node
*bn
;
1016 safi_t safi
= SAFI_UNICAST
;
1017 const char *debugmsg
;
1018 struct prefix nexthop_orig
;
1019 mpls_label_t
*pLabels
= NULL
;
1020 uint32_t num_labels
= 0;
1021 int nexthop_self_flag
= 1;
1022 struct bgp_info
*bi_ultimate
= NULL
;
1023 int origin_local
= 0;
1024 struct bgp
*src_vrf
;
1026 int debug
= BGP_DEBUG(vpn
, VPN_LEAK_TO_VRF
);
1028 if (!vpn_leak_from_vpn_active(bgp_vrf
, afi
, &debugmsg
)) {
1030 zlog_debug("%s: skipping: %s", __func__
, debugmsg
);
1034 /* Check for intersection of route targets */
1035 if (!ecom_intersect(
1036 bgp_vrf
->vpn_policy
[afi
].rtlist
[BGP_VPN_POLICY_DIR_FROMVPN
],
1037 info_vpn
->attr
->ecommunity
)) {
1043 zlog_debug("%s: updating to vrf %s", __func__
,
1044 bgp_vrf
->name_pretty
);
1046 bgp_attr_dup(&static_attr
, info_vpn
->attr
); /* shallow copy */
1049 * Nexthop: stash and clear
1051 * Nexthop is valid in context of VPN core, but not in destination vrf.
1052 * Stash it for later label resolution by vrf ingress path and then
1053 * overwrite with 0, i.e., "me", for the sake of vrf advertisement.
1055 uint8_t nhfamily
= NEXTHOP_FAMILY(info_vpn
->attr
->mp_nexthop_len
);
1057 memset(&nexthop_orig
, 0, sizeof(nexthop_orig
));
1058 nexthop_orig
.family
= nhfamily
;
1063 nexthop_orig
.u
.prefix4
= info_vpn
->attr
->mp_nexthop_global_in
;
1064 nexthop_orig
.prefixlen
= 32;
1066 if (CHECK_FLAG(bgp_vrf
->af_flags
[afi
][safi
],
1067 BGP_CONFIG_VRF_TO_VRF_IMPORT
)) {
1068 static_attr
.nexthop
.s_addr
=
1069 nexthop_orig
.u
.prefix4
.s_addr
;
1071 static_attr
.mp_nexthop_global_in
=
1072 info_vpn
->attr
->mp_nexthop_global_in
;
1073 static_attr
.mp_nexthop_len
=
1074 info_vpn
->attr
->mp_nexthop_len
;
1076 static_attr
.flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1080 nexthop_orig
.u
.prefix6
= info_vpn
->attr
->mp_nexthop_global
;
1081 nexthop_orig
.prefixlen
= 128;
1083 if (CHECK_FLAG(bgp_vrf
->af_flags
[afi
][safi
],
1084 BGP_CONFIG_VRF_TO_VRF_IMPORT
)) {
1085 static_attr
.mp_nexthop_global
= nexthop_orig
.u
.prefix6
;
1091 * route map handling
1093 if (bgp_vrf
->vpn_policy
[afi
].rmap
[BGP_VPN_POLICY_DIR_FROMVPN
]) {
1094 struct bgp_info info
;
1095 route_map_result_t ret
;
1097 memset(&info
, 0, sizeof(info
));
1098 info
.peer
= bgp_vrf
->peer_self
;
1099 info
.attr
= &static_attr
;
1100 ret
= route_map_apply(bgp_vrf
->vpn_policy
[afi
]
1101 .rmap
[BGP_VPN_POLICY_DIR_FROMVPN
],
1102 p
, RMAP_BGP
, &info
);
1103 if (RMAP_DENYMATCH
== ret
) {
1104 bgp_attr_flush(&static_attr
); /* free any added parts */
1107 "%s: vrf %s vpn-policy route map \"%s\" says DENY, returning",
1108 __func__
, bgp_vrf
->name_pretty
,
1109 bgp_vrf
->vpn_policy
[afi
]
1110 .rmap
[BGP_VPN_POLICY_DIR_FROMVPN
]
1115 * if route-map changed nexthop, don't nexthop-self on output
1117 if (!CHECK_FLAG(static_attr
.rmap_change_flags
,
1118 BATTR_RMAP_NEXTHOP_UNCHANGED
))
1119 nexthop_self_flag
= 0;
1122 new_attr
= bgp_attr_intern(&static_attr
);
1123 bgp_attr_flush(&static_attr
);
1125 bn
= bgp_afi_node_get(bgp_vrf
->rib
[afi
][safi
], afi
, safi
, p
, NULL
);
1128 * ensure labels are copied
1130 * However, there is a special case: if the route originated in
1131 * another local VRF (as opposed to arriving via VPN), then the
1132 * nexthop is reached by hairpinning through this router (me)
1133 * using IP forwarding only (no LSP). Therefore, the route
1134 * imported to the VRF should not have labels attached. Note
1135 * that nexthop tracking is also involved: eliminating the
1136 * labels for these routes enables the non-labeled nexthops
1137 * from the originating VRF to be considered valid for this route.
1139 if (!CHECK_FLAG(bgp_vrf
->af_flags
[afi
][safi
],
1140 BGP_CONFIG_VRF_TO_VRF_IMPORT
)) {
1141 /* work back to original route */
1142 for (bi_ultimate
= info_vpn
;
1143 bi_ultimate
->extra
&& bi_ultimate
->extra
->parent
;
1144 bi_ultimate
= bi_ultimate
->extra
->parent
)
1148 * if original route was unicast,
1149 * then it did not arrive over vpn
1151 if (bi_ultimate
->net
) {
1152 struct bgp_table
*table
;
1154 table
= bgp_node_table(bi_ultimate
->net
);
1155 if (table
&& (table
->safi
== SAFI_UNICAST
))
1160 if (!origin_local
&&
1161 info_vpn
->extra
&& info_vpn
->extra
->num_labels
) {
1162 num_labels
= info_vpn
->extra
->num_labels
;
1163 if (num_labels
> BGP_MAX_LABELS
)
1164 num_labels
= BGP_MAX_LABELS
;
1165 pLabels
= info_vpn
->extra
->label
;
1170 char buf_prefix
[PREFIX_STRLEN
];
1171 prefix2str(p
, buf_prefix
, sizeof(buf_prefix
));
1172 zlog_debug("%s: pfx %s: num_labels %d", __func__
, buf_prefix
,
1177 * For VRF-2-VRF route-leaking,
1178 * the source will be the originating VRF.
1180 if (info_vpn
->extra
&& info_vpn
->extra
->bgp_orig
)
1181 src_vrf
= info_vpn
->extra
->bgp_orig
;
1185 leak_update(bgp_vrf
, bn
, new_attr
, afi
, safi
, info_vpn
,
1186 pLabels
, num_labels
,
1187 info_vpn
, /* parent */
1188 src_vrf
, &nexthop_orig
, nexthop_self_flag
, debug
);
1191 void vpn_leak_to_vrf_update(struct bgp
*bgp_vpn
, /* from */
1192 struct bgp_info
*info_vpn
) /* route */
1194 struct listnode
*mnode
, *mnnode
;
1197 int debug
= BGP_DEBUG(vpn
, VPN_LEAK_TO_VRF
);
1200 zlog_debug("%s: start (info_vpn=%p)", __func__
, info_vpn
);
1202 /* Loop over VRFs */
1203 for (ALL_LIST_ELEMENTS(bm
->bgp
, mnode
, mnnode
, bgp
)) {
1205 if (!info_vpn
->extra
1206 || info_vpn
->extra
->bgp_orig
!= bgp
) { /* no loop */
1207 vpn_leak_to_vrf_update_onevrf(bgp
, bgp_vpn
, info_vpn
);
1212 void vpn_leak_to_vrf_withdraw(struct bgp
*bgp_vpn
, /* from */
1213 struct bgp_info
*info_vpn
) /* route */
1217 safi_t safi
= SAFI_UNICAST
;
1219 struct listnode
*mnode
, *mnnode
;
1220 struct bgp_node
*bn
;
1221 struct bgp_info
*bi
;
1222 const char *debugmsg
;
1223 char buf_prefix
[PREFIX_STRLEN
];
1225 int debug
= BGP_DEBUG(vpn
, VPN_LEAK_TO_VRF
);
1228 prefix2str(&info_vpn
->net
->p
, buf_prefix
, sizeof(buf_prefix
));
1229 zlog_debug("%s: entry: p=%s, type=%d, sub_type=%d",
1230 __func__
, buf_prefix
,
1231 info_vpn
->type
, info_vpn
->sub_type
);
1235 zlog_debug("%s: start (info_vpn=%p)", __func__
, info_vpn
);
1237 if (!info_vpn
->net
) {
1239 /* BGP_ROUTE_RFP routes do not have info_vpn->net set (yet) */
1240 if (info_vpn
->type
== ZEBRA_ROUTE_BGP
&&
1241 info_vpn
->sub_type
== BGP_ROUTE_RFP
) {
1247 zlog_debug("%s: info_vpn->net unexpectedly NULL, no prefix, bailing",
1252 p
= &info_vpn
->net
->p
;
1253 afi
= family2afi(p
->family
);
1255 /* Loop over VRFs */
1256 for (ALL_LIST_ELEMENTS(bm
->bgp
, mnode
, mnnode
, bgp
)) {
1257 if (!vpn_leak_from_vpn_active(bgp
, afi
, &debugmsg
)) {
1259 zlog_debug("%s: skipping: %s", __func__
,
1264 /* Check for intersection of route targets */
1265 if (!ecom_intersect(bgp
->vpn_policy
[afi
]
1266 .rtlist
[BGP_VPN_POLICY_DIR_FROMVPN
],
1267 info_vpn
->attr
->ecommunity
)) {
1273 zlog_debug("%s: withdrawing from vrf %s", __func__
,
1276 bn
= bgp_afi_node_get(bgp
->rib
[afi
][safi
], afi
, safi
, p
, NULL
);
1277 for (bi
= (bn
? bn
->info
: NULL
); bi
; bi
= bi
->next
) {
1279 && (struct bgp_info
*)bi
->extra
->parent
1287 zlog_debug("%s: deleting bi %p", __func__
, bi
);
1288 bgp_aggregate_decrement(bgp
, p
, bi
, afi
, safi
);
1289 bgp_info_delete(bn
, bi
);
1290 bgp_process(bgp
, bn
, afi
, safi
);
1292 bgp_unlock_node(bn
);
1296 void vpn_leak_to_vrf_withdraw_all(struct bgp
*bgp_vrf
, /* to */
1299 struct bgp_node
*bn
;
1300 struct bgp_info
*bi
;
1301 safi_t safi
= SAFI_UNICAST
;
1302 int debug
= BGP_DEBUG(vpn
, VPN_LEAK_TO_VRF
);
1305 zlog_debug("%s: entry", __func__
);
1307 * Walk vrf table, delete bi with bgp_orig in a different vrf
1309 for (bn
= bgp_table_top(bgp_vrf
->rib
[afi
][safi
]); bn
;
1310 bn
= bgp_route_next(bn
)) {
1312 for (bi
= bn
->info
; bi
; bi
= bi
->next
) {
1313 if (bi
->extra
&& bi
->extra
->bgp_orig
!= bgp_vrf
) {
1316 bgp_aggregate_decrement(bgp_vrf
, &bn
->p
, bi
,
1318 bgp_info_delete(bn
, bi
);
1319 bgp_process(bgp_vrf
, bn
, afi
, safi
);
1325 void vpn_leak_to_vrf_update_all(struct bgp
*bgp_vrf
, /* to */
1326 struct bgp
*bgp_vpn
, /* from */
1329 struct prefix_rd prd
;
1330 struct bgp_node
*prn
;
1331 safi_t safi
= SAFI_MPLS_VPN
;
1336 for (prn
= bgp_table_top(bgp_vpn
->rib
[afi
][safi
]); prn
;
1337 prn
= bgp_route_next(prn
)) {
1339 struct bgp_table
*table
;
1340 struct bgp_node
*bn
;
1341 struct bgp_info
*bi
;
1343 memset(&prd
, 0, sizeof(prd
));
1344 prd
.family
= AF_UNSPEC
;
1346 memcpy(prd
.val
, prn
->p
.u
.val
, 8);
1348 /* This is the per-RD table of prefixes */
1354 for (bn
= bgp_table_top(table
); bn
; bn
= bgp_route_next(bn
)) {
1356 for (bi
= bn
->info
; bi
; bi
= bi
->next
) {
1358 if (bi
->extra
&& bi
->extra
->bgp_orig
== bgp_vrf
)
1361 vpn_leak_to_vrf_update_onevrf(bgp_vrf
, bgp_vpn
,
1369 * This function is called for definition/deletion/change to a route-map
1371 static void vpn_policy_routemap_update(struct bgp
*bgp
, const char *rmap_name
)
1373 int debug
= BGP_DEBUG(vpn
, VPN_LEAK_RMAP_EVENT
);
1375 struct route_map
*rmap
;
1377 if (bgp
->inst_type
!= BGP_INSTANCE_TYPE_DEFAULT
1378 && bgp
->inst_type
!= BGP_INSTANCE_TYPE_VRF
) {
1383 rmap
= route_map_lookup_by_name(rmap_name
); /* NULL if deleted */
1385 for (afi
= 0; afi
< AFI_MAX
; ++afi
) {
1387 if (bgp
->vpn_policy
[afi
].rmap_name
[BGP_VPN_POLICY_DIR_TOVPN
]
1388 && !strcmp(rmap_name
,
1389 bgp
->vpn_policy
[afi
]
1390 .rmap_name
[BGP_VPN_POLICY_DIR_TOVPN
])) {
1394 "%s: rmap \"%s\" matches vrf-policy tovpn for as %d afi %s",
1395 __func__
, rmap_name
, bgp
->as
,
1398 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN
, afi
,
1399 bgp_get_default(), bgp
);
1401 zlog_debug("%s: after vpn_leak_prechange",
1404 /* in case of definition/deletion */
1405 bgp
->vpn_policy
[afi
].rmap
[BGP_VPN_POLICY_DIR_TOVPN
] =
1408 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN
, afi
,
1409 bgp_get_default(), bgp
);
1412 zlog_debug("%s: after vpn_leak_postchange",
1416 if (bgp
->vpn_policy
[afi
].rmap_name
[BGP_VPN_POLICY_DIR_FROMVPN
]
1417 && !strcmp(rmap_name
,
1418 bgp
->vpn_policy
[afi
]
1419 .rmap_name
[BGP_VPN_POLICY_DIR_FROMVPN
])) {
1422 zlog_debug("%s: rmap \"%s\" matches vrf-policy fromvpn for as %d afi %s",
1423 __func__
, rmap_name
, bgp
->as
,
1427 vpn_leak_prechange(BGP_VPN_POLICY_DIR_FROMVPN
, afi
,
1428 bgp_get_default(), bgp
);
1430 /* in case of definition/deletion */
1431 bgp
->vpn_policy
[afi
].rmap
[BGP_VPN_POLICY_DIR_FROMVPN
] =
1434 vpn_leak_postchange(BGP_VPN_POLICY_DIR_FROMVPN
, afi
,
1435 bgp_get_default(), bgp
);
1440 void vpn_policy_routemap_event(const char *rmap_name
)
1442 int debug
= BGP_DEBUG(vpn
, VPN_LEAK_RMAP_EVENT
);
1443 struct listnode
*mnode
, *mnnode
;
1447 zlog_debug("%s: entry", __func__
);
1449 if (bm
->bgp
== NULL
) /* may be called during cleanup */
1452 for (ALL_LIST_ELEMENTS(bm
->bgp
, mnode
, mnnode
, bgp
))
1453 vpn_policy_routemap_update(bgp
, rmap_name
);
1456 void vrf_import_from_vrf(struct bgp
*to_bgp
, struct bgp
*from_bgp
,
1457 afi_t afi
, safi_t safi
)
1459 const char *export_name
;
1460 vpn_policy_direction_t idir
, edir
;
1463 struct ecommunity
*ecom
;
1464 bool first_export
= false;
1466 export_name
= to_bgp
->name
? to_bgp
->name
: BGP_DEFAULT_NAME
;
1467 idir
= BGP_VPN_POLICY_DIR_FROMVPN
;
1468 edir
= BGP_VPN_POLICY_DIR_TOVPN
;
1471 * Cross-ref both VRFs. Also, note if this is the first time
1472 * any VRF is importing from "import_vrf".
1474 vname
= (from_bgp
->name
? XSTRDUP(MTYPE_TMP
, from_bgp
->name
)
1475 : XSTRDUP(MTYPE_TMP
, BGP_DEFAULT_NAME
));
1477 listnode_add(to_bgp
->vpn_policy
[afi
].import_vrf
, vname
);
1479 if (!listcount(from_bgp
->vpn_policy
[afi
].export_vrf
))
1480 first_export
= true;
1481 vname
= XSTRDUP(MTYPE_TMP
, export_name
);
1482 listnode_add(from_bgp
->vpn_policy
[afi
].export_vrf
, vname
);
1484 /* Update import RT for current VRF using export RT of the VRF we're
1485 * importing from. First though, make sure "import_vrf" has that
1489 form_auto_rd(from_bgp
->router_id
, from_bgp
->vrf_rd_id
,
1490 &from_bgp
->vrf_prd_auto
);
1491 from_bgp
->vpn_policy
[afi
].tovpn_rd
= from_bgp
->vrf_prd_auto
;
1492 SET_FLAG(from_bgp
->vpn_policy
[afi
].flags
,
1493 BGP_VPN_POLICY_TOVPN_RD_SET
);
1494 prefix_rd2str(&from_bgp
->vpn_policy
[afi
].tovpn_rd
,
1496 from_bgp
->vpn_policy
[afi
].rtlist
[edir
] =
1497 ecommunity_str2com(buf
, ECOMMUNITY_ROUTE_TARGET
, 0);
1498 SET_FLAG(from_bgp
->af_flags
[afi
][safi
],
1499 BGP_CONFIG_VRF_TO_VRF_EXPORT
);
1501 ecom
= from_bgp
->vpn_policy
[afi
].rtlist
[edir
];
1502 if (to_bgp
->vpn_policy
[afi
].rtlist
[idir
])
1503 to_bgp
->vpn_policy
[afi
].rtlist
[idir
] =
1504 ecommunity_merge(to_bgp
->vpn_policy
[afi
]
1505 .rtlist
[idir
], ecom
);
1507 to_bgp
->vpn_policy
[afi
].rtlist
[idir
] = ecommunity_dup(ecom
);
1508 SET_FLAG(to_bgp
->af_flags
[afi
][safi
], BGP_CONFIG_VRF_TO_VRF_IMPORT
);
1510 /* Does "import_vrf" first need to export its routes or that
1511 * is already done and we just need to import those routes
1512 * from the global table?
1515 vpn_leak_postchange(edir
, afi
, bgp_get_default(), from_bgp
);
1517 vpn_leak_postchange(idir
, afi
, bgp_get_default(), to_bgp
);
1520 void vrf_unimport_from_vrf(struct bgp
*to_bgp
, struct bgp
*from_bgp
,
1521 afi_t afi
, safi_t safi
)
1523 const char *export_name
, *tmp_name
;
1524 vpn_policy_direction_t idir
, edir
;
1526 struct ecommunity
*ecom
;
1527 struct listnode
*node
;
1529 export_name
= to_bgp
->name
? to_bgp
->name
: BGP_DEFAULT_NAME
;
1530 tmp_name
= from_bgp
->name
? from_bgp
->name
: BGP_DEFAULT_NAME
;
1531 idir
= BGP_VPN_POLICY_DIR_FROMVPN
;
1532 edir
= BGP_VPN_POLICY_DIR_TOVPN
;
1534 /* Were we importing from "import_vrf"? */
1535 for (ALL_LIST_ELEMENTS_RO(to_bgp
->vpn_policy
[afi
].import_vrf
, node
,
1537 if (strcmp(vname
, tmp_name
) == 0)
1542 * We do not check in the cli if the passed in bgp
1543 * instance is actually imported into us before
1544 * we call this function. As such if we do not
1545 * find this in the import_vrf list than
1546 * we just need to return safely.
1551 /* Remove "import_vrf" from our import list. */
1552 listnode_delete(to_bgp
->vpn_policy
[afi
].import_vrf
, vname
);
1553 XFREE(MTYPE_TMP
, vname
);
1555 /* Remove routes imported from "import_vrf". */
1556 /* TODO: In the current logic, we have to first remove all
1557 * imported routes and then (if needed) import back routes
1559 vpn_leak_prechange(idir
, afi
, bgp_get_default(), to_bgp
);
1561 if (to_bgp
->vpn_policy
[afi
].import_vrf
->count
== 0) {
1562 UNSET_FLAG(to_bgp
->af_flags
[afi
][safi
],
1563 BGP_CONFIG_VRF_TO_VRF_IMPORT
);
1564 ecommunity_free(&to_bgp
->vpn_policy
[afi
].rtlist
[idir
]);
1566 ecom
= from_bgp
->vpn_policy
[afi
].rtlist
[edir
];
1567 ecommunity_del_val(to_bgp
->vpn_policy
[afi
].rtlist
[idir
],
1568 (struct ecommunity_val
*)ecom
->val
);
1569 vpn_leak_postchange(idir
, afi
, bgp_get_default(), to_bgp
);
1574 * So SA is assuming that since the ALL_LIST_ELEMENTS_RO
1575 * below is checking for NULL that export_vrf can be
1576 * NULL, consequently it is complaining( like a cabbage )
1577 * that we could dereference and crash in the listcount(..)
1579 * So make it happy, under protest, with liberty and justice
1582 assert(from_bgp
->vpn_policy
[afi
].export_vrf
);
1584 /* Remove us from "import_vrf's" export list. If no other VRF
1585 * is importing from "import_vrf", cleanup appropriately.
1587 for (ALL_LIST_ELEMENTS_RO(from_bgp
->vpn_policy
[afi
].export_vrf
,
1589 if (strcmp(vname
, export_name
) == 0)
1594 * If we have gotten to this point then the vname must
1595 * exist. If not, we are in a world of trouble and
1596 * have slag sitting around.
1598 * import_vrf and export_vrf must match in having
1599 * the in/out names as appropriate.
1603 listnode_delete(from_bgp
->vpn_policy
[afi
].export_vrf
, vname
);
1604 XFREE(MTYPE_TMP
, vname
);
1606 if (!listcount(from_bgp
->vpn_policy
[afi
].export_vrf
)) {
1607 vpn_leak_prechange(edir
, afi
, bgp_get_default(), from_bgp
);
1608 ecommunity_free(&from_bgp
->vpn_policy
[afi
].rtlist
[edir
]);
1609 UNSET_FLAG(from_bgp
->af_flags
[afi
][safi
],
1610 BGP_CONFIG_VRF_TO_VRF_EXPORT
);
1611 memset(&from_bgp
->vpn_policy
[afi
].tovpn_rd
, 0,
1612 sizeof(struct prefix_rd
));
1613 UNSET_FLAG(from_bgp
->vpn_policy
[afi
].flags
,
1614 BGP_VPN_POLICY_TOVPN_RD_SET
);
1618 /* For testing purpose, static route of MPLS-VPN. */
1619 DEFUN (vpnv4_network
,
1621 "network A.B.C.D/M rd ASN:NN_OR_IP-ADDRESS:NN <tag|label> (0-1048575)",
1622 "Specify a network to announce via BGP\n"
1624 "Specify Route Distinguisher\n"
1625 "VPN Route Distinguisher\n"
1626 "VPN NLRI label (tag)\n"
1627 "VPN NLRI label (tag)\n"
1630 int idx_ipv4_prefixlen
= 1;
1631 int idx_ext_community
= 3;
1633 return bgp_static_set_safi(
1634 AFI_IP
, SAFI_MPLS_VPN
, vty
, argv
[idx_ipv4_prefixlen
]->arg
,
1635 argv
[idx_ext_community
]->arg
, argv
[idx_label
]->arg
, NULL
, 0,
1636 NULL
, NULL
, NULL
, NULL
);
1639 DEFUN (vpnv4_network_route_map
,
1640 vpnv4_network_route_map_cmd
,
1641 "network A.B.C.D/M rd ASN:NN_OR_IP-ADDRESS:NN <tag|label> (0-1048575) route-map WORD",
1642 "Specify a network to announce via BGP\n"
1644 "Specify Route Distinguisher\n"
1645 "VPN Route Distinguisher\n"
1646 "VPN NLRI label (tag)\n"
1647 "VPN NLRI label (tag)\n"
1652 int idx_ipv4_prefixlen
= 1;
1653 int idx_ext_community
= 3;
1656 return bgp_static_set_safi(
1657 AFI_IP
, SAFI_MPLS_VPN
, vty
, argv
[idx_ipv4_prefixlen
]->arg
,
1658 argv
[idx_ext_community
]->arg
, argv
[idx_label
]->arg
,
1659 argv
[idx_word_2
]->arg
, 0, NULL
, NULL
, NULL
, NULL
);
1662 /* For testing purpose, static route of MPLS-VPN. */
1663 DEFUN (no_vpnv4_network
,
1664 no_vpnv4_network_cmd
,
1665 "no network A.B.C.D/M rd ASN:NN_OR_IP-ADDRESS:NN <tag|label> (0-1048575)",
1667 "Specify a network to announce via BGP\n"
1669 "Specify Route Distinguisher\n"
1670 "VPN Route Distinguisher\n"
1671 "VPN NLRI label (tag)\n"
1672 "VPN NLRI label (tag)\n"
1675 int idx_ipv4_prefixlen
= 2;
1676 int idx_ext_community
= 4;
1678 return bgp_static_unset_safi(AFI_IP
, SAFI_MPLS_VPN
, vty
,
1679 argv
[idx_ipv4_prefixlen
]->arg
,
1680 argv
[idx_ext_community
]->arg
,
1681 argv
[idx_label
]->arg
, 0, NULL
, NULL
, NULL
);
1684 DEFUN (vpnv6_network
,
1686 "network X:X::X:X/M rd ASN:NN_OR_IP-ADDRESS:NN <tag|label> (0-1048575) [route-map WORD]",
1687 "Specify a network to announce via BGP\n"
1688 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
1689 "Specify Route Distinguisher\n"
1690 "VPN Route Distinguisher\n"
1691 "VPN NLRI label (tag)\n"
1692 "VPN NLRI label (tag)\n"
1697 int idx_ipv6_prefix
= 1;
1698 int idx_ext_community
= 3;
1702 return bgp_static_set_safi(
1703 AFI_IP6
, SAFI_MPLS_VPN
, vty
, argv
[idx_ipv6_prefix
]->arg
,
1704 argv
[idx_ext_community
]->arg
, argv
[idx_label
]->arg
,
1705 argv
[idx_word_2
]->arg
, 0, NULL
, NULL
, NULL
, NULL
);
1707 return bgp_static_set_safi(
1708 AFI_IP6
, SAFI_MPLS_VPN
, vty
, argv
[idx_ipv6_prefix
]->arg
,
1709 argv
[idx_ext_community
]->arg
, argv
[idx_label
]->arg
,
1710 NULL
, 0, NULL
, NULL
, NULL
, NULL
);
1713 /* For testing purpose, static route of MPLS-VPN. */
1714 DEFUN (no_vpnv6_network
,
1715 no_vpnv6_network_cmd
,
1716 "no network X:X::X:X/M rd ASN:NN_OR_IP-ADDRESS:NN <tag|label> (0-1048575)",
1718 "Specify a network to announce via BGP\n"
1719 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
1720 "Specify Route Distinguisher\n"
1721 "VPN Route Distinguisher\n"
1722 "VPN NLRI label (tag)\n"
1723 "VPN NLRI label (tag)\n"
1726 int idx_ipv6_prefix
= 2;
1727 int idx_ext_community
= 4;
1729 return bgp_static_unset_safi(AFI_IP6
, SAFI_MPLS_VPN
, vty
,
1730 argv
[idx_ipv6_prefix
]->arg
,
1731 argv
[idx_ext_community
]->arg
,
1732 argv
[idx_label
]->arg
, 0, NULL
, NULL
, NULL
);
1735 int bgp_show_mpls_vpn(struct vty
*vty
, afi_t afi
, struct prefix_rd
*prd
,
1736 enum bgp_show_type type
, void *output_arg
, int tags
,
1740 struct bgp_table
*table
;
1742 bgp
= bgp_get_default();
1745 vty_out(vty
, "No BGP process is configured\n");
1747 vty_out(vty
, "{}\n");
1750 table
= bgp
->rib
[afi
][SAFI_MPLS_VPN
];
1751 return bgp_show_table_rd(vty
, bgp
, SAFI_MPLS_VPN
, table
, prd
, type
,
1752 output_arg
, use_json
);
1755 DEFUN (show_bgp_ip_vpn_all_rd
,
1756 show_bgp_ip_vpn_all_rd_cmd
,
1757 "show bgp "BGP_AFI_CMD_STR
" vpn all [rd ASN:NN_OR_IP-ADDRESS:NN] [json]",
1761 "Display VPN NLRI specific information\n"
1762 "Display VPN NLRI specific information\n"
1763 "Display information for a route distinguisher\n"
1764 "VPN Route Distinguisher\n"
1768 struct prefix_rd prd
;
1772 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
1773 if (argv_find(argv
, argc
, "rd", &idx
)) {
1774 ret
= str2prefix_rd(argv
[idx
+ 1]->arg
, &prd
);
1777 "%% Malformed Route Distinguisher\n");
1780 return bgp_show_mpls_vpn(vty
, afi
, &prd
,
1781 bgp_show_type_normal
, NULL
, 0,
1782 use_json(argc
, argv
));
1784 return bgp_show_mpls_vpn(vty
, afi
, NULL
,
1785 bgp_show_type_normal
, NULL
, 0,
1786 use_json(argc
, argv
));
1792 ALIAS(show_bgp_ip_vpn_all_rd
,
1793 show_bgp_ip_vpn_rd_cmd
,
1794 "show bgp "BGP_AFI_CMD_STR
" vpn rd ASN:NN_OR_IP-ADDRESS:NN [json]",
1798 "Display VPN NLRI specific information\n"
1799 "Display information for a route distinguisher\n"
1800 "VPN Route Distinguisher\n"
1803 #ifdef KEEP_OLD_VPN_COMMANDS
1804 DEFUN (show_ip_bgp_vpn_rd
,
1805 show_ip_bgp_vpn_rd_cmd
,
1806 "show ip bgp "BGP_AFI_CMD_STR
" vpn rd ASN:NN_OR_IP-ADDRESS:NN",
1811 "Address Family modifier\n"
1812 "Display information for a route distinguisher\n"
1813 "VPN Route Distinguisher\n")
1815 int idx_ext_community
= argc
- 1;
1817 struct prefix_rd prd
;
1821 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
1822 ret
= str2prefix_rd(argv
[idx_ext_community
]->arg
, &prd
);
1824 vty_out(vty
, "%% Malformed Route Distinguisher\n");
1827 return bgp_show_mpls_vpn(vty
, afi
, &prd
, bgp_show_type_normal
,
1833 DEFUN (show_ip_bgp_vpn_all
,
1834 show_ip_bgp_vpn_all_cmd
,
1835 "show [ip] bgp <vpnv4|vpnv6>",
1844 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
))
1845 return bgp_show_mpls_vpn(vty
, afi
, NULL
, bgp_show_type_normal
,
1850 DEFUN (show_ip_bgp_vpn_all_tags
,
1851 show_ip_bgp_vpn_all_tags_cmd
,
1852 "show [ip] bgp <vpnv4|vpnv6> all tags",
1857 "Display information about all VPNv4/VPNV6 NLRIs\n"
1858 "Display BGP tags for prefixes\n")
1863 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
))
1864 return bgp_show_mpls_vpn(vty
, afi
, NULL
, bgp_show_type_normal
,
1869 DEFUN (show_ip_bgp_vpn_rd_tags
,
1870 show_ip_bgp_vpn_rd_tags_cmd
,
1871 "show [ip] bgp <vpnv4|vpnv6> rd ASN:NN_OR_IP-ADDRESS:NN tags",
1876 "Display information for a route distinguisher\n"
1877 "VPN Route Distinguisher\n"
1878 "Display BGP tags for prefixes\n")
1880 int idx_ext_community
= 5;
1882 struct prefix_rd prd
;
1886 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
1887 ret
= str2prefix_rd(argv
[idx_ext_community
]->arg
, &prd
);
1889 vty_out(vty
, "%% Malformed Route Distinguisher\n");
1892 return bgp_show_mpls_vpn(vty
, afi
, &prd
, bgp_show_type_normal
,
1898 DEFUN (show_ip_bgp_vpn_all_neighbor_routes
,
1899 show_ip_bgp_vpn_all_neighbor_routes_cmd
,
1900 "show [ip] bgp <vpnv4|vpnv6> all neighbors A.B.C.D routes [json]",
1905 "Display information about all VPNv4/VPNv6 NLRIs\n"
1906 "Detailed information on TCP and BGP neighbor connections\n"
1907 "Neighbor to display information about\n"
1908 "Display routes learned from neighbor\n"
1915 uint8_t uj
= use_json(argc
, argv
);
1919 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
1920 ret
= str2sockunion(argv
[idx_ipv4
]->arg
, &su
);
1923 json_object
*json_no
= NULL
;
1924 json_no
= json_object_new_object();
1925 json_object_string_add(json_no
, "warning",
1926 "Malformed address");
1927 vty_out(vty
, "%s\n",
1928 json_object_to_json_string(json_no
));
1929 json_object_free(json_no
);
1931 vty_out(vty
, "Malformed address: %s\n",
1932 argv
[idx_ipv4
]->arg
);
1936 peer
= peer_lookup(NULL
, &su
);
1937 if (!peer
|| !peer
->afc
[afi
][SAFI_MPLS_VPN
]) {
1939 json_object
*json_no
= NULL
;
1940 json_no
= json_object_new_object();
1941 json_object_string_add(
1943 "No such neighbor or address family");
1944 vty_out(vty
, "%s\n",
1945 json_object_to_json_string(json_no
));
1946 json_object_free(json_no
);
1949 "%% No such neighbor or address family\n");
1953 return bgp_show_mpls_vpn(vty
, afi
, NULL
, bgp_show_type_neighbor
,
1959 DEFUN (show_ip_bgp_vpn_rd_neighbor_routes
,
1960 show_ip_bgp_vpn_rd_neighbor_routes_cmd
,
1961 "show [ip] bgp <vpnv4|vpnv6> rd ASN:NN_OR_IP-ADDRESS:NN neighbors A.B.C.D routes [json]",
1966 "Display information for a route distinguisher\n"
1967 "VPN Route Distinguisher\n"
1968 "Detailed information on TCP and BGP neighbor connections\n"
1969 "Neighbor to display information about\n"
1970 "Display routes learned from neighbor\n"
1973 int idx_ext_community
= 5;
1978 struct prefix_rd prd
;
1979 uint8_t uj
= use_json(argc
, argv
);
1983 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
1984 ret
= str2prefix_rd(argv
[idx_ext_community
]->arg
, &prd
);
1987 json_object
*json_no
= NULL
;
1988 json_no
= json_object_new_object();
1989 json_object_string_add(
1991 "Malformed Route Distinguisher");
1992 vty_out(vty
, "%s\n",
1993 json_object_to_json_string(json_no
));
1994 json_object_free(json_no
);
1997 "%% Malformed Route Distinguisher\n");
2001 ret
= str2sockunion(argv
[idx_ipv4
]->arg
, &su
);
2004 json_object
*json_no
= NULL
;
2005 json_no
= json_object_new_object();
2006 json_object_string_add(json_no
, "warning",
2007 "Malformed address");
2008 vty_out(vty
, "%s\n",
2009 json_object_to_json_string(json_no
));
2010 json_object_free(json_no
);
2012 vty_out(vty
, "Malformed address: %s\n",
2013 argv
[idx_ext_community
]->arg
);
2017 peer
= peer_lookup(NULL
, &su
);
2018 if (!peer
|| !peer
->afc
[afi
][SAFI_MPLS_VPN
]) {
2020 json_object
*json_no
= NULL
;
2021 json_no
= json_object_new_object();
2022 json_object_string_add(
2024 "No such neighbor or address family");
2025 vty_out(vty
, "%s\n",
2026 json_object_to_json_string(json_no
));
2027 json_object_free(json_no
);
2030 "%% No such neighbor or address family\n");
2034 return bgp_show_mpls_vpn(vty
, afi
, &prd
, bgp_show_type_neighbor
,
2040 DEFUN (show_ip_bgp_vpn_all_neighbor_advertised_routes
,
2041 show_ip_bgp_vpn_all_neighbor_advertised_routes_cmd
,
2042 "show [ip] bgp <vpnv4|vpnv6> all neighbors A.B.C.D advertised-routes [json]",
2047 "Display information about all VPNv4/VPNv6 NLRIs\n"
2048 "Detailed information on TCP and BGP neighbor connections\n"
2049 "Neighbor to display information about\n"
2050 "Display the routes advertised to a BGP neighbor\n"
2057 uint8_t uj
= use_json(argc
, argv
);
2061 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
2062 ret
= str2sockunion(argv
[idx_ipv4
]->arg
, &su
);
2065 json_object
*json_no
= NULL
;
2066 json_no
= json_object_new_object();
2067 json_object_string_add(json_no
, "warning",
2068 "Malformed address");
2069 vty_out(vty
, "%s\n",
2070 json_object_to_json_string(json_no
));
2071 json_object_free(json_no
);
2073 vty_out(vty
, "Malformed address: %s\n",
2074 argv
[idx_ipv4
]->arg
);
2077 peer
= peer_lookup(NULL
, &su
);
2078 if (!peer
|| !peer
->afc
[afi
][SAFI_MPLS_VPN
]) {
2080 json_object
*json_no
= NULL
;
2081 json_no
= json_object_new_object();
2082 json_object_string_add(
2084 "No such neighbor or address family");
2085 vty_out(vty
, "%s\n",
2086 json_object_to_json_string(json_no
));
2087 json_object_free(json_no
);
2090 "%% No such neighbor or address family\n");
2093 return show_adj_route_vpn(vty
, peer
, NULL
, AFI_IP
,
2099 DEFUN (show_ip_bgp_vpn_rd_neighbor_advertised_routes
,
2100 show_ip_bgp_vpn_rd_neighbor_advertised_routes_cmd
,
2101 "show [ip] bgp <vpnv4|vpnv6> rd ASN:NN_OR_IP-ADDRESS:NN neighbors A.B.C.D advertised-routes [json]",
2106 "Display information for a route distinguisher\n"
2107 "VPN Route Distinguisher\n"
2108 "Detailed information on TCP and BGP neighbor connections\n"
2109 "Neighbor to display information about\n"
2110 "Display the routes advertised to a BGP neighbor\n"
2113 int idx_ext_community
= 5;
2117 struct prefix_rd prd
;
2119 uint8_t uj
= use_json(argc
, argv
);
2123 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
2124 ret
= str2sockunion(argv
[idx_ipv4
]->arg
, &su
);
2127 json_object
*json_no
= NULL
;
2128 json_no
= json_object_new_object();
2129 json_object_string_add(json_no
, "warning",
2130 "Malformed address");
2131 vty_out(vty
, "%s\n",
2132 json_object_to_json_string(json_no
));
2133 json_object_free(json_no
);
2135 vty_out(vty
, "Malformed address: %s\n",
2136 argv
[idx_ext_community
]->arg
);
2139 peer
= peer_lookup(NULL
, &su
);
2140 if (!peer
|| !peer
->afc
[afi
][SAFI_MPLS_VPN
]) {
2142 json_object
*json_no
= NULL
;
2143 json_no
= json_object_new_object();
2144 json_object_string_add(
2146 "No such neighbor or address family");
2147 vty_out(vty
, "%s\n",
2148 json_object_to_json_string(json_no
));
2149 json_object_free(json_no
);
2152 "%% No such neighbor or address family\n");
2156 ret
= str2prefix_rd(argv
[idx_ext_community
]->arg
, &prd
);
2159 json_object
*json_no
= NULL
;
2160 json_no
= json_object_new_object();
2161 json_object_string_add(
2163 "Malformed Route Distinguisher");
2164 vty_out(vty
, "%s\n",
2165 json_object_to_json_string(json_no
));
2166 json_object_free(json_no
);
2169 "%% Malformed Route Distinguisher\n");
2173 return show_adj_route_vpn(vty
, peer
, &prd
, AFI_IP
,
2178 #endif /* KEEP_OLD_VPN_COMMANDS */
2180 void bgp_mplsvpn_init(void)
2182 install_element(BGP_VPNV4_NODE
, &vpnv4_network_cmd
);
2183 install_element(BGP_VPNV4_NODE
, &vpnv4_network_route_map_cmd
);
2184 install_element(BGP_VPNV4_NODE
, &no_vpnv4_network_cmd
);
2186 install_element(BGP_VPNV6_NODE
, &vpnv6_network_cmd
);
2187 install_element(BGP_VPNV6_NODE
, &no_vpnv6_network_cmd
);
2189 install_element(VIEW_NODE
, &show_bgp_ip_vpn_all_rd_cmd
);
2190 install_element(VIEW_NODE
, &show_bgp_ip_vpn_rd_cmd
);
2191 #ifdef KEEP_OLD_VPN_COMMANDS
2192 install_element(VIEW_NODE
, &show_ip_bgp_vpn_rd_cmd
);
2193 install_element(VIEW_NODE
, &show_ip_bgp_vpn_all_cmd
);
2194 install_element(VIEW_NODE
, &show_ip_bgp_vpn_all_tags_cmd
);
2195 install_element(VIEW_NODE
, &show_ip_bgp_vpn_rd_tags_cmd
);
2196 install_element(VIEW_NODE
, &show_ip_bgp_vpn_all_neighbor_routes_cmd
);
2197 install_element(VIEW_NODE
, &show_ip_bgp_vpn_rd_neighbor_routes_cmd
);
2198 install_element(VIEW_NODE
,
2199 &show_ip_bgp_vpn_all_neighbor_advertised_routes_cmd
);
2200 install_element(VIEW_NODE
,
2201 &show_ip_bgp_vpn_rd_neighbor_advertised_routes_cmd
);
2202 #endif /* KEEP_OLD_VPN_COMMANDS */
2205 vrf_id_t
get_first_vrf_for_redirect_with_rt(struct ecommunity
*eckey
)
2207 struct listnode
*mnode
, *mnnode
;
2210 for (ALL_LIST_ELEMENTS(bm
->bgp
, mnode
, mnnode
, bgp
)) {
2211 struct ecommunity
*ec
;
2213 if (bgp
->inst_type
!= BGP_INSTANCE_TYPE_VRF
)
2216 ec
= bgp
->vpn_policy
[AFI_IP
].import_redirect_rtlist
;
2218 if (ecom_intersect(ec
, eckey
))