From 310eaa331c2a15243ad96a86949c2d9a7190a9f4 Mon Sep 17 00:00:00 2001 From: Daniel Czerwonk Date: Thu, 7 Dec 2023 13:03:20 +0100 Subject: [PATCH] move responsibility to inherit filter chain to config package, add inheritance for API specific configs --- cmd/bio-rd/bgp.go | 19 ++++--------------- cmd/bio-rd/config/bgp.go | 31 +++++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/cmd/bio-rd/bgp.go b/cmd/bio-rd/bgp.go index d774cb17..a2cb38a0 100644 --- a/cmd/bio-rd/bgp.go +++ b/cmd/bio-rd/bgp.go @@ -7,7 +7,6 @@ import ( "github.com/bio-routing/bio-rd/cmd/bio-rd/config" bgpserver "github.com/bio-routing/bio-rd/protocols/bgp/server" "github.com/bio-routing/bio-rd/routingtable" - "github.com/bio-routing/bio-rd/routingtable/filter" "github.com/bio-routing/bio-rd/routingtable/vrf" ) @@ -82,8 +81,7 @@ func (c *bgpConfigurator) reconfigureModifiedSession(bn *config.BGPNeighbor, bg err := c.srv.ReplaceImportFilterChain( newCfg.VRF, bn.PeerAddressIP, - c.determineFilterChain(bg.ImportFilterChain, bn.ImportFilterChain), - ) + bn.ImportFilterChain) if err != nil { return fmt.Errorf("could not replace import filter: %w", err) } @@ -91,8 +89,7 @@ func (c *bgpConfigurator) reconfigureModifiedSession(bn *config.BGPNeighbor, bg err = c.srv.ReplaceExportFilterChain( newCfg.VRF, bn.PeerAddressIP, - c.determineFilterChain(bg.ExportFilterChain, bn.ExportFilterChain), - ) + bn.ExportFilterChain) if err != nil { return fmt.Errorf("could not replace export filter: %w", err) } @@ -188,8 +185,8 @@ func (c *bgpConfigurator) configureIPv6(bn *config.BGPNeighbor, bg *config.BGPGr func (c *bgpConfigurator) newAFIConfig(bn *config.BGPNeighbor, bg *config.BGPGroup) *bgpserver.AddressFamilyConfig { return &bgpserver.AddressFamilyConfig{ - ImportFilterChain: c.determineFilterChain(bg.ImportFilterChain, bn.ImportFilterChain), - ExportFilterChain: c.determineFilterChain(bg.ExportFilterChain, bn.ExportFilterChain), + ImportFilterChain: bn.ImportFilterChain, + ExportFilterChain: bn.ExportFilterChain, AddPathSend: routingtable.ClientOptions{ BestOnly: true, }, @@ -197,14 +194,6 @@ func (c *bgpConfigurator) newAFIConfig(bn *config.BGPNeighbor, bg *config.BGPGro } } -func (c *bgpConfigurator) determineFilterChain(groupChain filter.Chain, neighChain filter.Chain) filter.Chain { - if len(neighChain) > 0 { - return neighChain - } - - return groupChain -} - func (c *bgpConfigurator) configureAddressFamily(baf *config.AddressFamilyConfig, af *bgpserver.AddressFamilyConfig) { if baf.AddPath != nil { c.configureAddPath(baf.AddPath, af) diff --git a/cmd/bio-rd/config/bgp.go b/cmd/bio-rd/config/bgp.go index 3d5a5de5..6f31e7fa 100644 --- a/cmd/bio-rd/config/bgp.go +++ b/cmd/bio-rd/config/bgp.go @@ -41,10 +41,12 @@ type BGPGroup struct { ImportFilterChain filter.Chain Export []string `yaml:"export"` ExportFilterChain filter.Chain - RouteServerClient bool `yaml:"route_server_client"` - Passive bool `yaml:"passive"` - Neighbors []*BGPNeighbor `yaml:"neighbors"` - RoutingInstance string `yaml:"routing_instance"` + RouteServerClient *bool `yaml:"route_server_client"` + Passive *bool `yaml:"passive"` + Neighbors []*BGPNeighbor `yaml:"neighbors"` + IPv4 *AddressFamilyConfig `yaml:"ipv4"` + IPv6 *AddressFamilyConfig `yaml:"ipv6"` + RoutingInstance string `yaml:"routing_instance"` } func (bg *BGPGroup) load(localAS uint32, policyOptions *PolicyOptions) error { @@ -85,11 +87,11 @@ func (bg *BGPGroup) load(localAS uint32, policyOptions *PolicyOptions) error { for _, bn := range bg.Neighbors { if bn.RouteServerClient == nil { - bn.RouteServerClient = &bg.RouteServerClient + bn.RouteServerClient = bg.RouteServerClient } if bn.Passive == nil { - bn.Passive = &bg.Passive + bn.Passive = bg.Passive } if bn.LocalAddress == "" { @@ -132,6 +134,17 @@ func (bg *BGPGroup) load(localAS uint32, policyOptions *PolicyOptions) error { bn.RoutingInstance = bg.RoutingInstance } + if bn.IPv4 == nil { + bn.IPv4 = bg.IPv4 + } + + if bn.IPv6 == nil { + bn.IPv6 = bg.IPv6 + } + + bn.ImportFilterChain = bg.ImportFilterChain + bn.ExportFilterChain = bg.ExportFilterChain + err := bn.load(policyOptions) if err != nil { return err @@ -199,6 +212,9 @@ func (bn *BGPNeighbor) load(policyOptions *PolicyOptions) error { bn.PeerAddressIP = b.Dedup() bn.HoldTimeDuration = time.Second * time.Duration(bn.HoldTime) + if len(bn.Import) > 0 { + bn.ImportFilterChain = filter.Chain{} + } for i := range bn.Import { f := policyOptions.getPolicyStatementFilter(bn.Import[i]) if f == nil { @@ -208,6 +224,9 @@ func (bn *BGPNeighbor) load(policyOptions *PolicyOptions) error { bn.ImportFilterChain = append(bn.ImportFilterChain, f) } + if len(bn.Export) > 0 { + bn.ExportFilterChain = filter.Chain{} + } for i := range bn.Export { f := policyOptions.getPolicyStatementFilter(bn.Export[i]) if f == nil {