@@ -193,14 +193,16 @@ func (d *nicRouted) validateConfig(instConf instance.ConfigReader) error {
193
193
// type: integer
194
194
// shortdesc: The custom policy routing table ID to add IPv4 static routes to (in addition to the main routing table)
195
195
196
- "ipv4.host_table" ,
196
+ "ipv4.host_table" , // deprecated
197
197
// gendoc:generate(entity=devices, group=nic_routed, key=ipv6.host_table)
198
198
//
199
199
// ---
200
200
// type: integer
201
201
// shortdesc: The custom policy routing table ID to add IPv6 static routes to (in addition to the main routing table)
202
202
203
- "ipv6.host_table" ,
203
+ "ipv6.host_table" , // deprecated
204
+ "ipv4.host_tables" ,
205
+ "ipv6.host_tables" ,
204
206
// gendoc:generate(entity=devices, group=nic_routed, key=gvrp)
205
207
//
206
208
// ---
@@ -241,6 +243,10 @@ func (d *nicRouted) validateConfig(instConf instance.ConfigReader) error {
241
243
// shortdesc: Comma-delimited list of IPv6 static addresses to add to the instance
242
244
rules ["ipv6.address" ] = validate .Optional (validate .IsListOf (validate .IsNetworkAddressV6 ))
243
245
246
+ rules ["ipv4.host_tables" ] = validate .Optional (validate .IsListOf (validate .IsInRange (0 , 255 )))
247
+
248
+ rules ["ipv6.host_tables" ] = validate .Optional (validate .IsListOf (validate .IsInRange (0 , 255 )))
249
+
244
250
rules ["gvrp" ] = validate .Optional (validate .IsBool )
245
251
246
252
// gendoc:generate(entity=devices, group=nic_routed, key=ipv4.neighbor_probe)
@@ -584,36 +590,53 @@ func (d *nicRouted) Start() (*deviceConfig.RunConfig, error) {
584
590
}
585
591
}
586
592
587
- table := "main"
588
- if d .config ["vrf" ] != "" {
589
- table = ""
593
+ getTables := func () []string {
594
+ // New plural form – honour exactly what the user gives.
595
+ if v := d .config [fmt .Sprintf ("%s.hosttables" , keyPrefix )]; v != "" {
596
+ tbls := util .SplitNTrimSpace (v , "," , - 1 , true )
597
+ return tbls
598
+ }
599
+
600
+ // Legacy – single key: include it plus 254.
601
+ if v := d .config [fmt .Sprintf ("%s.host_table" , keyPrefix )]; v != "" {
602
+ if v == "254" {
603
+ return []string {"254" } // user asked for main only
604
+ }
605
+
606
+ return []string {v , "254" } // custom + main
607
+ }
608
+
609
+ // Default – main only.
610
+ return []string {"254" }
590
611
}
591
612
613
+ tables := getTables ()
614
+
592
615
// Perform per-address host-side configuration (static routes and neighbour proxy entries).
593
616
for _ , addrStr := range addresses {
594
617
// Apply host-side static routes to main routing table or VRF.
595
- r := ip.Route {
596
- DevName : saveData ["host_name" ],
597
- Route : fmt .Sprintf ("%s/%d" , addrStr , subnetSize ),
598
- Table : table ,
599
- Family : ipFamilyArg ,
600
- VRF : d .config ["vrf" ],
601
- }
618
+ // If a VRF is set we still add a route into the VRF's own table (empty Table value).
619
+ if d .config ["vrf" ] != "" {
620
+ r := ip.Route {
621
+ DevName : saveData ["host_name" ],
622
+ Route : fmt .Sprintf ("%s/%d" , addrStr , subnetSize ),
623
+ Table : "" ,
624
+ Family : ipFamilyArg ,
625
+ VRF : d .config ["vrf" ],
626
+ }
602
627
603
- err = r .Add ()
604
- if err != nil {
605
- return nil , fmt .Errorf ("Failed adding host route %q: %w" , r .Route , err )
628
+ err = r .Add ()
629
+ if err != nil {
630
+ return nil , fmt .Errorf ("Failed adding host route %q: %w" , r .Route , err )
631
+ }
606
632
}
607
633
608
- // Add host-side static routes to instance IPs to custom routing table if specified.
609
- // This is in addition to the static route added to the main routing table, which is still
610
- // critical to ensure that reverse path filtering doesn't kick in blocking traffic from
611
- // the instance.
612
- if d .config [fmt .Sprintf ("%s.host_table" , keyPrefix )] != "" {
634
+ // Add routes to all requested tables.
635
+ for _ , tbl := range tables {
613
636
r := ip.Route {
614
637
DevName : saveData ["host_name" ],
615
638
Route : fmt .Sprintf ("%s/%d" , addrStr , subnetSize ),
616
- Table : d . config [ fmt . Sprintf ( "%s.host_table" , keyPrefix )] ,
639
+ Table : tbl ,
617
640
Family : ipFamilyArg ,
618
641
}
619
642
@@ -651,7 +674,7 @@ func (d *nicRouted) Start() (*deviceConfig.RunConfig, error) {
651
674
r := ip.Route {
652
675
DevName : saveData ["host_name" ],
653
676
Route : routeStr ,
654
- Table : table ,
677
+ Table : "" ,
655
678
Family : ipFamilyArg ,
656
679
Via : addresses [0 ],
657
680
VRF : d .config ["vrf" ],
@@ -720,7 +743,6 @@ func (d *nicRouted) Start() (*deviceConfig.RunConfig, error) {
720
743
}
721
744
722
745
reverter .Success ()
723
-
724
746
return & runConf , nil
725
747
}
726
748
0 commit comments