From d29a1d3572749e08bffe90075257bdd4606b1a63 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Parisot?= <sparisot@iliad-free.fr>
Date: Tue, 12 Aug 2025 14:37:45 +0200
Subject: [PATCH 2/2] L3VPN: Added support for 'import target all' to allow
 routes with any route targets

---
 doc/bird.sgml        | 2 +-
 proto/l3vpn/config.Y | 5 +++--
 proto/l3vpn/l3vpn.c  | 7 +++++--
 proto/l3vpn/l3vpn.h  | 2 ++
 4 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/doc/bird.sgml b/doc/bird.sgml
index 37ad1736..f563a3fe 100644
--- a/doc/bird.sgml
+++ b/doc/bird.sgml
@@ -4557,7 +4557,7 @@ could have up to 5 channels: <cf/ipv4/, <cf/ipv6/, <cf/vpn4/, <cf/vpn6/, and
 	<tag><label id="l3vpn-rd">rd <m/rd/</tag>
 	A shorthand for the option <cf/route distinguisher/.
 
-	<tag><label id="l3vpn-import-target">import target <m/ec/|<m/ec-set/|none</tag>
+	<tag><label id="l3vpn-import-target">import target <m/ec/|<m/ec-set/|none|all</tag>
 	Route target extended communities specifying which routes should be
 	imported. Either one community or a set. A route is imported if there is
 	non-empty intersection between extended communities of the route and the
diff --git a/proto/l3vpn/config.Y b/proto/l3vpn/config.Y
index e49153ff..3ff75251 100644
--- a/proto/l3vpn/config.Y
+++ b/proto/l3vpn/config.Y
@@ -76,9 +76,10 @@ l3vpn_proto_item:
  | mpls_channel
  | RD VPN_RD { L3VPN_CFG->rd = $2; }
  | ROUTE DISTINGUISHER VPN_RD { L3VPN_CFG->rd = $3; }
- | IMPORT TARGET l3vpn_targets { L3VPN_CFG->import_target = $3; }
+ | IMPORT TARGET l3vpn_targets { L3VPN_CFG->import_target = $3; L3VPN_CFG->import_target_all = 0; }
+ | IMPORT TARGET ALL { L3VPN_CFG->import_target = NULL; L3VPN_CFG->import_target_all = 1; }
  | EXPORT TARGET l3vpn_targets { L3VPN_CFG->export_target = $3; }
- | ROUTE TARGET l3vpn_targets { L3VPN_CFG->import_target = L3VPN_CFG->export_target = $3; }
+ | ROUTE TARGET l3vpn_targets { L3VPN_CFG->import_target = L3VPN_CFG->export_target = $3; L3VPN_CFG->import_target_all = 0; }
  ;
 
 l3vpn_proto_opts:
diff --git a/proto/l3vpn/l3vpn.c b/proto/l3vpn/l3vpn.c
index f4b1a587..7c2bad98 100644
--- a/proto/l3vpn/l3vpn.c
+++ b/proto/l3vpn/l3vpn.c
@@ -53,7 +53,6 @@
  * - check for simple nodes in export route
  * - replace pair of channels with shared channel for one address family
  * - improve route comparisons in VRFs
- * - optional import/export target all
  * - optional support for route origins
  * - optional automatic assignment of RDs
  * - MPLS-in-IP encapsulation
@@ -84,6 +83,8 @@ mpls_valid_nexthop(const rta *a)
 static int
 l3vpn_import_targets(struct l3vpn_proto *p, const struct adata *list)
 {
+  if (p->import_target_all)
+    return 1;
   if (!p->import_target)
     return 0;
   return (p->import_target_one) ?
@@ -367,6 +368,7 @@ l3vpn_start(struct proto *P)
 
   p->rd = cf->rd;
   p->import_target = cf->import_target;
+  p->import_target_all = cf->import_target_all;
   p->export_target = cf->export_target;
   p->export_target_data = NULL;
 
@@ -407,11 +409,12 @@ l3vpn_reconfigure(struct proto *P, struct proto_config *CF)
   if (!rd_equal(p->rd, cf->rd))
     return 0;
 
-  int import_changed = !same_tree(p->import_target, cf->import_target);
+  int import_changed = !same_tree(p->import_target, cf->import_target) || !!p->import_target_all != !!cf->import_target_all;
   int export_changed = !same_tree(p->export_target, cf->export_target);
 
   /* Update pointers to config structures */
   p->import_target = cf->import_target;
+  p->import_target_all = cf->import_target_all;
   p->export_target = cf->export_target;
 
   proto_setup_mpls_map(P, RTS_L3VPN, 1);
diff --git a/proto/l3vpn/l3vpn.h b/proto/l3vpn/l3vpn.h
index 1cce28fa..5d0997fe 100644
--- a/proto/l3vpn/l3vpn.h
+++ b/proto/l3vpn/l3vpn.h
@@ -16,6 +16,7 @@ struct l3vpn_config {
   vpn_rd rd;
   struct f_tree *import_target;
   struct f_tree *export_target;
+  uint import_target_all;
 };
 
 struct l3vpn_proto {
@@ -31,6 +32,7 @@ struct l3vpn_proto {
   u32 *export_target_data;
   uint export_target_length;
   uint import_target_one;
+  uint import_target_all;
 };
 
 #endif
-- 
2.39.5

