Skip to content

Commit

Permalink
Merge branch 'main' into feature/bgp-peering
Browse files Browse the repository at this point in the history
  • Loading branch information
chdxD1 committed Feb 20, 2025
2 parents 25e5a40 + fe9e910 commit 7c0a5c3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ Also some special config should be in place:
exit
```
Due to internal parsing of FRR one route-map entry should already be there (default deny). Also mgmt_vrf needs to be part of the list `skipVRFConfig` in the configuration file.
2. The default VRF `router-bgp` config must be marked as `router bgp <ASN> vrf default`. Otherwise a reload will delete it and replace it completely. This will break and crash FRR in the process.

## eBPF

Expand Down
14 changes: 12 additions & 2 deletions pkg/frr/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ var (
rtLinesRe = regexp.MustCompile(`(?m)^\s*route-target.*`)
rtPartsRe = regexp.MustCompile(`(?m)^(\s*route-target\s*(?:import|export)\s*)(.*)`)
rtRe = regexp.MustCompile(`(?m)(\S+)`)

// Regular expression for searching for router bgp <asn> vrf default.
defaultVrfRe = regexp.MustCompile(`(?m)^router bgp (\d+) vrf default`)
)

type templateConfig struct {
Expand Down Expand Up @@ -47,6 +50,8 @@ func (m *Manager) Configure(in Configuration, nm *nl.Manager, nwopCfg *config.Co
}
}

in.HasCommunityDrop = m.hasCommunityDrop

frrConfig, err := m.renderSubtemplates(in, nm)
if err != nil {
return false, err
Expand All @@ -63,10 +68,9 @@ func (m *Manager) Configure(in Configuration, nm *nl.Manager, nwopCfg *config.Co
}

targetConfig = fixRouteTargetReload(targetConfig)
targetConfig = fixDefaultVrf(targetConfig)
targetConfig = applyCfgReplacements(targetConfig, nwopCfg.Replacements)

in.HasCommunityDrop = m.hasCommunityDrop

if !bytes.Equal(currentConfig, targetConfig) {
err = os.WriteFile(m.ConfigPath, targetConfig, frrPermissions)
if err != nil {
Expand Down Expand Up @@ -162,6 +166,12 @@ func fixRouteTargetReload(frrConfig []byte) []byte {
})
}

// fixDefaultVrf is a workaround for a change in FRR, that dropped the vrf default keyword.
// This function removes the vrf default from the router bgp <asn> vrf default command.
func fixDefaultVrf(frrConfig []byte) []byte {
return defaultVrfRe.ReplaceAll(frrConfig, []byte("router bgp $1"))
}

// applyCfgReplacements replaces placeholders in the configuration with the actual values.
func applyCfgReplacements(frrConfig []byte, replacements []config.Replacement) []byte {
for _, replacement := range replacements {
Expand Down
2 changes: 1 addition & 1 deletion pkg/frr/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (m *Manager) Init(mgmtVrf string) error {
}
m.ipv6MgmtRouteMapIn = routeMap

communityDrop, err := hasCommunityDrop(m.ConfigPath)
communityDrop, err := hasCommunityDrop(m.TemplatePath)
if err != nil {
return fmt.Errorf("error checking for community drop in FRR config: %w", err)
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/reconciler/layer3.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (r *reconcile) fetchBGPPeerings(ctx context.Context) ([]networkv1alpha1.BGP
return peerings.Items, nil
}

// nolint: contextcheck // context is not relevant
// nolint: contextcheck,funlen // context is not relevant
func (r *reconcile) reconcileLayer3(data *reconcileData) error {
vrfConfigMap, err := r.createVrfConfigMap(data.l3vnis)
if err != nil {
Expand Down Expand Up @@ -79,6 +79,8 @@ func (r *reconcile) reconcileLayer3(data *reconcileData) error {
return allConfigs[i].VNI < allConfigs[j].VNI
})

time.Sleep(defaultSleep)

// Create FRR configuration and reload it
err = r.configureFRR(allConfigs, defaultVRFPeerings)
if err != nil {
Expand All @@ -99,6 +101,8 @@ func (r *reconcile) reconcileLayer3(data *reconcileData) error {
return err
}

time.Sleep(defaultSleep)

// When a BGP VRF is deleted there is a leftover running configuration after reload
// A second reload fixes this.
if deletedVRF || deletedTaas {
Expand Down

0 comments on commit 7c0a5c3

Please sign in to comment.