Browse Source

zebra: configure static routes in any VRF

Introduce new commands to configure static routes in any VRF, by
appending the old static route commands with a new parameter
"vrf N".

A new parameter "const char *vrf_id_str" is added to the functions
zebra_static_ipv4() and static_ipv6_func() to get the configured
VRF ID.

A new member "vrf_id" is added to the "struct static_ipv4" and
"struct static_ipv6", indicating which VRF this static route is
configured in.

But till now, no interface can exist in any non-default VRF. So
these static routes in non-default VRFs are kept inactive.

Signed-off-by: Feng Lu <lu.feng@6wind.com>
Reviewed-by: Alain Ritoux <alain.ritoux@6wind.com>
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Acked-by: Vincent JARDIN <vincent.jardin@6wind.com>
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Feng Lu 6 years ago
parent
commit
7aaf4ea990
3 changed files with 604 additions and 108 deletions
  1. 6 0
      zebra/rib.h
  2. 8 6
      zebra/zebra_rib.c
  3. 590 102
      zebra/zebra_vty.c

+ 6 - 0
zebra/rib.h

@@ -173,6 +173,9 @@ struct static_ipv4
   struct static_ipv4 *prev;
   struct static_ipv4 *next;
 
+  /* VRF identifier. */
+  vrf_id_t vrf_id;
+
   /* Administrative distance. */
   u_char distance;
 
@@ -205,6 +208,9 @@ struct static_ipv6
   struct static_ipv6 *prev;
   struct static_ipv6 *next;
 
+  /* VRF identifier. */
+  vrf_id_t vrf_id;
+
   /* Administrative distance. */
   u_char distance;
 

+ 8 - 6
zebra/zebra_rib.c

@@ -2290,7 +2290,7 @@ static_install_ipv4 (safi_t safi, struct prefix *p, struct static_ipv4 *si)
   struct route_table *table;
 
   /* Lookup table.  */
-  table = zebra_vrf_table (AFI_IP, safi, VRF_DEFAULT);
+  table = zebra_vrf_table (AFI_IP, safi, si->vrf_id);
   if (! table)
     return;
 
@@ -2332,7 +2332,7 @@ static_install_ipv4 (safi_t safi, struct prefix *p, struct static_ipv4 *si)
       rib->type = ZEBRA_ROUTE_STATIC;
       rib->distance = si->distance;
       rib->metric = 0;
-      rib->vrf_id = VRF_DEFAULT;
+      rib->vrf_id = si->vrf_id;
       rib->table = zebrad.rtm_table_default;
       rib->nexthop_num = 0;
 
@@ -2384,7 +2384,7 @@ static_uninstall_ipv4 (safi_t safi, struct prefix *p, struct static_ipv4 *si)
   struct route_table *table;
 
   /* Lookup table.  */
-  table = zebra_vrf_table (AFI_IP, safi, VRF_DEFAULT);
+  table = zebra_vrf_table (AFI_IP, safi, si->vrf_id);
   if (! table)
     return;
   
@@ -2490,6 +2490,7 @@ static_add_ipv4_safi (safi_t safi, struct prefix *p, struct in_addr *gate,
   si->type = type;
   si->distance = distance;
   si->flags = flags;
+  si->vrf_id = vrf_id;
 
   if (gate)
     si->gate.ipv4 = *gate;
@@ -2836,7 +2837,7 @@ static_install_ipv6 (struct prefix *p, struct static_ipv6 *si)
   struct route_node *rn;
 
   /* Lookup table.  */
-  table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
+  table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, si->vrf_id);
   if (! table)
     return;
 
@@ -2879,7 +2880,7 @@ static_install_ipv6 (struct prefix *p, struct static_ipv6 *si)
       rib->type = ZEBRA_ROUTE_STATIC;
       rib->distance = si->distance;
       rib->metric = 0;
-      rib->vrf_id = VRF_DEFAULT;
+      rib->vrf_id = si->vrf_id;
       rib->table = zebrad.rtm_table_default;
       rib->nexthop_num = 0;
 
@@ -2932,7 +2933,7 @@ static_uninstall_ipv6 (struct prefix *p, struct static_ipv6 *si)
   struct nexthop *nexthop;
 
   /* Lookup table.  */
-  table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
+  table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, si->vrf_id);
   if (! table)
     return;
 
@@ -3031,6 +3032,7 @@ static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
   si->type = type;
   si->distance = distance;
   si->flags = flags;
+  si->vrf_id = vrf_id;
 
   switch (type)
     {

File diff suppressed because it is too large
+ 590 - 102
zebra/zebra_vty.c


Some files were not shown because too many files changed in this diff