Skip to content

Commit df1d2c9

Browse files
committed
refactor: replace bird config overrides
1 parent 8530135 commit df1d2c9

File tree

5 files changed

+31
-89
lines changed

5 files changed

+31
-89
lines changed

docs/docs/configuration.md

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ Should default routes be accepted? Setting to false adds 0.0.0.0/0 and ::/0 to t
231231

232232
### `rpki-enable`
233233

234-
Enable RPKI RTR session
234+
Enable RPKI protocol
235235

236236
| Type | Default | Validation |
237237
|------|---------|------------|
@@ -1207,65 +1207,41 @@ Configuration to add to each session before any defined BGP protocols
12071207
|------|---------|------------|
12081208
| string | | |
12091209

1210-
### `pre-import`
1210+
### `pre-import-filter`
12111211

1212-
Configuration to add at the beginning of the import filter
1212+
Configuration to add before the filtering section of the import policy
12131213

12141214
| Type | Default | Validation |
12151215
|------|---------|------------|
12161216
| string | | |
12171217

1218-
### `pre-export`
1219-
1220-
Configuration to add at the beginning of the export filter
1221-
1222-
| Type | Default | Validation |
1223-
|------|---------|------------|
1224-
| string | | |
1225-
1226-
### `pre-import-final`
1227-
1228-
Configuration to add immediately before the final accept/reject on import
1229-
1230-
| Type | Default | Validation |
1231-
|------|---------|------------|
1232-
| string | | |
1233-
1234-
### `pre-export-final`
1218+
### `post-import-filter`
12351219

1236-
Configuration to add immediately before the final accept/reject on export
1220+
Configuration to add after the filtering section of the import filter
12371221

12381222
| Type | Default | Validation |
12391223
|------|---------|------------|
12401224
| string | | |
12411225

1242-
### `pre-import-file`
1226+
### `pre-import-accept`
12431227

1244-
Configuration file to append to pre-import
1228+
Configuration to add immediately before the final accept term import
12451229

12461230
| Type | Default | Validation |
12471231
|------|---------|------------|
12481232
| string | | |
12491233

1250-
### `pre-export-file`
1251-
1252-
Configuration file to append to pre-export
1253-
1254-
| Type | Default | Validation |
1255-
|------|---------|------------|
1256-
| string | | |
1257-
1258-
### `pre-import-final-file`
1234+
### `pre-export`
12591235

1260-
Configuration file to append to pre-import-final
1236+
Configuration to add before the export policy
12611237

12621238
| Type | Default | Validation |
12631239
|------|---------|------------|
12641240
| string | | |
12651241

1266-
### `pre-export-final-file`
1242+
### `pre-export-final`
12671243

1268-
Configuration file to append to pre-export-final
1244+
Configuration to add after the export policy
12691245

12701246
| Type | Default | Validation |
12711247
|------|---------|------------|

internal/embed/templates/peer.tmpl

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ protocol bgp {{ UniqueProtocolName $peer.ProtocolName $af $peer.ASN }} {
8484
import filter {
8585
{{ if $global.NoAccept }}reject;{{ end }}
8686

87-
{{ StrDeref $peer.PreImport }}
87+
{{ StrDeref $peer.PreImportFilter }}
88+
8889
{{ if BoolDeref $peer.FilterBogonRoutes }}reject_bogon_routes();{{ end }}
8990
{{ if BoolDeref $peer.FilterBogonASNs }}reject_bogon_asns();{{ end }}
9091
{{ if BoolDeref $peer.FilterPrefixLength }}reject_out_of_bounds_routes();{{ end }}
@@ -94,6 +95,11 @@ protocol bgp {{ UniqueProtocolName $peer.ProtocolName $af $peer.ASN }} {
9495
{{ if BoolDeref $peer.EnforceFirstAS }}enforce_first_as({{ $peer.ASN }});{{ end }}
9596
{{ if BoolDeref $peer.EnforcePeerNexthop }}enforce_peer_nexthop({{ $neighborNoIface }});{{ end }}
9697
{{ if BoolDeref $peer.FilterTransitASNs }}reject_transit_paths();{{ end }}
98+
{{ if BoolDeref $peer.FilterIRR }}if !(net ~ AS{{ $peer.ASN }}_{{ $peer.ProtocolName }}_PFX_v{{ $af }}) then { _reject("not in IRR prefix set"); }{{ end }}
99+
{{ if BoolDeref $peer.FilterASSet }}if !(bgp_path.first ~ AS{{ $peer.ASN }}_{{ $peer.ProtocolName }}_AS_SET_MEMBERS) then { _reject("not in AS set"); }{{ end }}
100+
101+
{{ StrDeref $peer.PostImportFilter }}
102+
97103
{{ if BoolDeref $peer.ForcePeerNexthop }}bgp_next_hop = {{ $neighborNoIface }};{{ end }}
98104

99105
{{ if StrDeref $peer.ImportNextHop }}
@@ -136,15 +142,7 @@ protocol bgp {{ UniqueProtocolName $peer.ProtocolName $af $peer.ASN }} {
136142
set_blackhole();
137143
{{ end }}
138144

139-
{{ if BoolDeref $peer.FilterIRR }}
140-
if !(net ~ AS{{ $peer.ASN }}_{{ $peer.ProtocolName }}_PFX_v{{ $af }}) then { _reject("not in IRR prefix set"); }
141-
{{ end }}
142-
143-
{{ if BoolDeref $peer.FilterASSet }}
144-
if !(bgp_path.first ~ AS{{ $peer.ASN }}_{{ $peer.ProtocolName }}_AS_SET_MEMBERS) then { _reject("not in AS set"); }
145-
{{ end }}
146-
147-
{{ StrDeref $peer.PreImportFinal }}
145+
{{ StrDeref $peer.PreImportAccept }}
148146
accept;
149147
};
150148

internal/process/process.go

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -234,46 +234,18 @@ func Load(configBlob []byte) (*config.Config, error) {
234234
}
235235
}
236236

237-
// Append snippet files
238-
if peerData.PreImportFile != nil {
239-
content, err := os.ReadFile(*peerData.PreImportFile)
240-
if err != nil {
241-
log.Fatalf("Unable to read pre-import-file: %s", err)
242-
}
243-
*peerData.PreImport += "\n" + string(content)
237+
if peerData.PreImportFilter != nil {
238+
peerData.PreImportFilter = util.Ptr(templateReplacements(*peerData.PreImportFilter, peerData))
244239
}
245-
if peerData.PreExportFile != nil {
246-
content, err := os.ReadFile(*peerData.PreExportFile)
247-
if err != nil {
248-
log.Fatalf("Unable to read pre-export-file: %s", err)
249-
}
250-
*peerData.PreExport += "\n" + string(content)
240+
if peerData.PostImportFilter != nil {
241+
peerData.PostImportFilter = util.Ptr(templateReplacements(*peerData.PostImportFilter, peerData))
251242
}
252-
253-
if peerData.PreImportFinalFile != nil {
254-
content, err := os.ReadFile(*peerData.PreImportFinalFile)
255-
if err != nil {
256-
log.Fatalf("Unable to read pre-import-final-file: %s", err)
257-
}
258-
*peerData.PreImportFinal += "\n" + string(content)
259-
}
260-
if peerData.PreExportFinalFile != nil {
261-
content, err := os.ReadFile(*peerData.PreExportFinalFile)
262-
if err != nil {
263-
log.Fatalf("Unable to read pre-export-final-file: %s", err)
264-
}
265-
*peerData.PreExportFinal += "\n" + string(content)
266-
}
267-
268-
if peerData.PreImport != nil {
269-
peerData.PreImport = util.Ptr(templateReplacements(*peerData.PreImport, peerData))
243+
if peerData.PreImportAccept != nil {
244+
peerData.PreImportAccept = util.Ptr(templateReplacements(*peerData.PreImportAccept, peerData))
270245
}
271246
if peerData.PreExport != nil {
272247
peerData.PreExport = util.Ptr(templateReplacements(*peerData.PreExport, peerData))
273248
}
274-
if peerData.PreImportFinal != nil {
275-
peerData.PreImportFinal = util.Ptr(templateReplacements(*peerData.PreImportFinal, peerData))
276-
}
277249
if peerData.PreExportFinal != nil {
278250
peerData.PreExportFinal = util.Ptr(templateReplacements(*peerData.PreExportFinal, peerData))
279251
}

pkg/config/config.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,11 @@ type Peer struct {
110110
// Custom daemon configuration
111111
SessionGlobal *string `yaml:"session-global" description:"Configuration to add to each session before any defined BGP protocols" default:"-"`
112112

113-
PreImport *string `yaml:"pre-import" description:"Configuration to add at the beginning of the import filter" default:"-"`
114-
PreExport *string `yaml:"pre-export" description:"Configuration to add at the beginning of the export filter" default:"-"`
115-
PreImportFinal *string `yaml:"pre-import-final" description:"Configuration to add immediately before the final accept/reject on import" default:"-"`
116-
PreExportFinal *string `yaml:"pre-export-final" description:"Configuration to add immediately before the final accept/reject on export" default:"-"`
117-
118-
PreImportFile *string `yaml:"pre-import-file" description:"Configuration file to append to pre-import" default:"-"`
119-
PreExportFile *string `yaml:"pre-export-file" description:"Configuration file to append to pre-export" default:"-"`
120-
PreImportFinalFile *string `yaml:"pre-import-final-file" description:"Configuration file to append to pre-import-final" default:"-"`
121-
PreExportFinalFile *string `yaml:"pre-export-final-file" description:"Configuration file to append to pre-export-final" default:"-"`
113+
PreImportFilter *string `yaml:"pre-import-filter" description:"Configuration to add before the filtering section of the import policy" default:"-"`
114+
PostImportFilter *string `yaml:"post-import-filter" description:"Configuration to add after the filtering section of the import filter" default:"-"`
115+
PreImportAccept *string `yaml:"pre-import-accept" description:"Configuration to add immediately before the final accept term import" default:"-"`
116+
PreExport *string `yaml:"pre-export" description:"Configuration to add before the export policy" default:"-"`
117+
PreExportFinal *string `yaml:"pre-export-final" description:"Configuration to add after the export policy" default:"-"`
122118

123119
// Optimizer
124120
OptimizerProbeSources *[]string `yaml:"probe-sources" description:"Optimizer probe source addresses" default:"-"`

tests/generate-complex.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,4 @@ peers:
7878
- 65530
7979
- 65540
8080
filter-as-set: true
81-
pre-import: 'print "Hello from <pathvector.asn>";'
81+
pre-import-accept: 'print "Hello from <pathvector.asn>";'

0 commit comments

Comments
 (0)