summaryrefslogtreecommitdiffhomepage
path: root/table/path.go
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-07-12 22:45:25 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-07-13 08:56:08 +0900
commitb759f2b1ca7176ea134b3a86d8bfea44509712dd (patch)
treebc0a9f7ca6756d343a2082953ccb5f673b1b1877 /table/path.go
parentf60ce32b8b1f6f161e840e0162bfaf1137d29a0b (diff)
table: iBGP support in PrependAsn()
The length of an aspath attribute's value from iBGP peer can be 0. This patch fixes PrependAsn() to handle such an aspath attribute. Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'table/path.go')
-rw-r--r--table/path.go39
1 files changed, 18 insertions, 21 deletions
diff --git a/table/path.go b/table/path.go
index 75c67a83..f1f92573 100644
--- a/table/path.go
+++ b/table/path.go
@@ -312,41 +312,38 @@ func (path *Path) getAsListofSpecificType(getAsSeq, getAsSet bool) []uint32 {
// into that segment, and places that segment into the AS_PATH.
func (path *Path) PrependAsn(asn uint32, repeat uint8) {
- idx, aspath := path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
+ idx, original := path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
asns := make([]uint32, repeat)
for i, _ := range asns {
asns[i] = asn
}
+ var asPath *bgp.PathAttributeAsPath
if idx < 0 {
- p := bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, asns)
- asPath := bgp.NewPathAttributeAsPath([]bgp.AsPathParamInterface{p})
+ asPath = bgp.NewPathAttributeAsPath([]bgp.AsPathParamInterface{})
path.pathAttrs = append(path.pathAttrs, asPath)
} else {
- aspathClone := cloneAsPath(aspath.(*bgp.PathAttributeAsPath))
- path.pathAttrs[idx] = aspathClone
- fst := aspathClone.Value[0].(*bgp.As4PathParam)
-
- if fst.Type == bgp.BGP_ASPATH_ATTR_TYPE_SEQ && len(fst.AS) < 255 {
+ asPath = cloneAsPath(original.(*bgp.PathAttributeAsPath))
+ path.pathAttrs[idx] = asPath
+ }
- // overflow case
+ if len(asPath.Value) > 0 {
+ fst := asPath.Value[0].(*bgp.As4PathParam)
+ if fst.Type == bgp.BGP_ASPATH_ATTR_TYPE_SEQ {
if len(fst.AS)+int(repeat) > 255 {
- rest := 255 - len(fst.AS)
- fst.AS = append(asns[0:rest], fst.AS...)
- fst.Num = 255
-
- p := bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, asns[rest:])
- aspathClone.Value = append([]bgp.AsPathParamInterface{p}, aspathClone.Value...)
- } else {
- fst.AS = append(asns, fst.AS...)
- fst.Num += repeat
+ repeat = uint8(255 - len(fst.AS))
}
- } else {
- p := bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, asns)
- aspathClone.Value = append([]bgp.AsPathParamInterface{p}, aspathClone.Value...)
+ fst.AS = append(asns[:int(repeat)], fst.AS...)
+ fst.Num += repeat
+ asns = asns[int(repeat):]
}
}
+
+ if len(asns) > 0 {
+ p := bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, asns)
+ asPath.Value = append([]bgp.AsPathParamInterface{p}, asPath.Value...)
+ }
}
func (path *Path) GetCommunities() []uint32 {