From 1f053c25c423c79471fbe1d5fb6c618bb67409df Mon Sep 17 00:00:00 2001 From: Wataru Ishida Date: Fri, 5 May 2017 11:19:40 -0400 Subject: *: support remove private as cli ``` $ gobgp n add as remove-private-as (all|replace) ``` config ``` neighbor: config: peer-as: neighbor-address: remove-private-as: all ``` Signed-off-by: Wataru Ishida --- table/path.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'table/path.go') 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 { -- cgit v1.2.3