diff options
author | Faicker Mo <faicker.mo@ucloud.cn> | 2019-11-08 09:34:00 +0800 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@gmail.com> | 2021-03-03 09:47:50 +0900 |
commit | cd5671baee534da4a4e4d70f7597919b315b04bf (patch) | |
tree | 484efa1d6ad127349eaee3856d12e0ccc9ed13a4 /internal | |
parent | 2d73cf8eba6a8c978442dccc2d4c1ad9538ca1a9 (diff) |
policy: add nexthop unchanged
Support config set-next-hop = "unchanged" and also cli command.
Signed-off-by: Faicker Mo <faicker.mo@ucloud.cn>
Diffstat (limited to 'internal')
-rw-r--r-- | internal/pkg/table/policy.go | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/internal/pkg/table/policy.go b/internal/pkg/table/policy.go index f4bcf0a4..2909c199 100644 --- a/internal/pkg/table/policy.go +++ b/internal/pkg/table/policy.go @@ -2566,8 +2566,9 @@ func NewAsPathPrependAction(action config.SetAsPathPrepend) (*AsPathPrependActio } type NexthopAction struct { - value net.IP - self bool + value net.IP + self bool + unchanged bool } func (a *NexthopAction) Type() ActionType { @@ -2581,6 +2582,12 @@ func (a *NexthopAction) Apply(path *Path, options *PolicyOptions) *Path { } return path } + if a.unchanged { + if options != nil && options.OldNextHop != nil { + path.SetNexthop(options.OldNextHop) + } + return path + } path.SetNexthop(a.value) return path } @@ -2589,6 +2596,9 @@ func (a *NexthopAction) ToConfig() config.BgpNextHopType { if a.self { return config.BgpNextHopType("self") } + if a.unchanged { + return config.BgpNextHopType("unchanged") + } return config.BgpNextHopType(a.value.String()) } @@ -2608,6 +2618,10 @@ func NewNexthopAction(c config.BgpNextHopType) (*NexthopAction, error) { return &NexthopAction{ self: true, }, nil + case "unchanged": + return &NexthopAction{ + unchanged: true, + }, nil } addr := net.ParseIP(string(c)) if addr == nil { @@ -4049,6 +4063,11 @@ func toStatementApi(s *config.Statement) *api.Statement { Self: true, } } + if string(s.Actions.BgpActions.SetNextHop) == "unchanged" { + return &api.NexthopAction{ + Unchanged: true, + } + } return &api.NexthopAction{ Address: string(s.Actions.BgpActions.SetNextHop), } |