Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Add gateway parameter in peers #205

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,14 @@ Accept prefixes up to /24 and /48 from covering parent IRR objects
|------|---------|------------|
| bool | false | |

### `gateway`

The mode in which the gateway is defined for received routes (direct|recursive).

| Type | Default | Validation |
|------|---------|------------|
| string | | |

### `add-on-import`

List of communities to add to all imported routes
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ type Peer struct {
DisableAfterError *bool `yaml:"disable-after-error" description:"Disable peer after error" default:"false"`
PreferOlderRoutes *bool `yaml:"prefer-older-routes" description:"Prefer older routes instead of comparing router IDs (RFC 5004)" default:"false"`
IRRAcceptChildPrefixes *bool `yaml:"irr-accept-child-prefixes" description:"Accept prefixes up to /24 and /48 from covering parent IRR objects" default:"false"`
Gateway *string `yaml:"gateway" description:"The mode in which the gateway is defined for received routes (direct|recursive)." default:"-"`

ImportCommunities *[]string `yaml:"add-on-import" description:"List of communities to add to all imported routes" default:"-"`
ExportCommunities *[]string `yaml:"add-on-export" description:"List of communities to add to all exported routes" default:"-"`
Expand Down
1 change: 1 addition & 0 deletions pkg/embed/templates/peer.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ protocol bgp {{ UniqueProtocolName $peer.ProtocolName $peerName $af $peer.ASN $p
{{ if BoolDeref $peer.AddPathRx }}add paths rx;{{ end }}
{{ if BoolDeref $peer.AdvertiseHostname }}advertise hostname on;{{ end }}
{{ if BoolDeref $peer.DisableAfterError }}disable after error on;{{ end }}
{{ if StrDeref $peer.Gateway }}gateway "{{ StrDeref $peer.Gateway }}";{{ end }}
import filter {
{{ if $global.NoAccept }}reject; # no-accept: true{{ end }}
{{ if (not (BoolDeref $peer.Import)) }}reject; # import: false{{ end }}
Expand Down
6 changes: 6 additions & 0 deletions pkg/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,12 @@ func Load(configBlob []byte) (*config.Config, error) {
}
}

if peerData.Gateway != nil {
peerData.Gateway = util.Ptr(strings.ReplaceAll(*peerData.Gateway, "-", "_"))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we refactor to assign directly rather than with a util.Ptr call? That's really just a helper function for constants.

*peerData.Gateway = strings.ReplaceAll(*peerData.Gateway, "-", "_")

if *peerData.Gateway != "direct" && *peerData.Gateway != "recursive" {
return nil, errors.New("invalid gateway type")
}
}
// Check for no originated prefixes but announce-originated enabled
if len(c.Prefixes) < 1 && *peerData.AnnounceOriginated {
// No locally originated prefixes are defined, so there's nothing to originate
Expand Down