diff options
author | Wataru Ishida <ishida.wataru@lab.ntt.co.jp> | 2017-05-05 11:19:40 -0400 |
---|---|---|
committer | Wataru Ishida <ishida.wataru@lab.ntt.co.jp> | 2017-05-10 08:05:47 +0000 |
commit | 1f053c25c423c79471fbe1d5fb6c618bb67409df (patch) | |
tree | ba3c43da6df3e1163a754ff742f25a64d819d6e2 /table/path.go | |
parent | 540d77319c6eaa1eefd7b52df2a4771c7ee565ac (diff) |
*: support remove private as
cli
```
$ gobgp n add <neighbor-addr> as <asn> remove-private-as (all|replace)
```
config
```
neighbor:
config:
peer-as: <asn>
neighbor-address: <neighbor-addr>
remove-private-as: all
```
Signed-off-by: Wataru Ishida <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'table/path.go')
-rw-r--r-- | table/path.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/table/path.go b/table/path.go index ef63d720..3b0fc40d 100644 --- a/table/path.go +++ b/table/path.go @@ -188,6 +188,9 @@ func UpdatePathAttrs(global *config.Global, peer *config.Neighbor, info *PeerInf path.SetNexthop(localAddress) } + // remove-private-as handling + path.RemovePrivateAS(peer.Config.LocalAs, peer.State.RemovePrivateAs) + // AS_PATH handling path.PrependAsn(peer.Config.LocalAs, 1) @@ -677,6 +680,39 @@ func (path *Path) PrependAsn(asn uint32, repeat uint8) { path.setPathAttr(asPath) } +func isPrivateAS(as uint32) bool { + return (64512 <= as && as <= 65534) || (4200000000 <= as && as <= 4294967294) +} + +func (path *Path) RemovePrivateAS(localAS uint32, option config.RemovePrivateAsOption) { + original := path.GetAsPath() + if original == nil { + return + } + switch option { + case config.REMOVE_PRIVATE_AS_OPTION_ALL, config.REMOVE_PRIVATE_AS_OPTION_REPLACE: + newASParams := make([]bgp.AsPathParamInterface, 0, len(original.Value)) + for _, param := range original.Value { + asParam := param.(*bgp.As4PathParam) + newASParam := make([]uint32, 0, len(asParam.AS)) + for _, as := range asParam.AS { + if isPrivateAS(as) { + if option == config.REMOVE_PRIVATE_AS_OPTION_REPLACE { + newASParam = append(newASParam, localAS) + } + } else { + newASParam = append(newASParam, as) + } + } + if len(newASParam) > 0 { + newASParams = append(newASParams, bgp.NewAs4PathParam(asParam.Type, newASParam)) + } + } + path.setPathAttr(bgp.NewPathAttributeAsPath(newASParams)) + } + return +} + func (path *Path) GetCommunities() []uint32 { communityList := []uint32{} if attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_COMMUNITIES); attr != nil { |