Skip to content

Commit

Permalink
move responsibility to inherit filter chain to config package, add in…
Browse files Browse the repository at this point in the history
…heritance for API specific configs
  • Loading branch information
czerwonk committed Dec 7, 2023
1 parent fc7c203 commit 310eaa3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
19 changes: 4 additions & 15 deletions cmd/bio-rd/bgp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -82,17 +81,15 @@ 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)
}

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)
}
Expand Down Expand Up @@ -188,23 +185,15 @@ 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,
},
AddPathRecv: false,
}
}

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)
Expand Down
31 changes: 25 additions & 6 deletions cmd/bio-rd/config/bgp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 == "" {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 310eaa3

Please sign in to comment.