cli: fix mrt to drop MP_REACH attribute when injecting

The GoBGP API gives an error with a path having multiple nlris MP_REACH attribute.

Signed-off-by: FUJITA Tomonori <[email protected]>
This commit is contained in:
FUJITA Tomonori
2018-01-13 12:38:01 +09:00
parent c75aec72ec
commit c6b44ccd8a
+16 -1
View File
@@ -22,6 +22,7 @@ import (
"strconv"
"time"
"github.com/osrg/gobgp/packet/bgp"
"github.com/osrg/gobgp/packet/mrt"
"github.com/osrg/gobgp/table"
"github.com/spf13/cobra"
@@ -116,7 +117,21 @@ func injectMrt() error {
ID: peers[e.PeerIndex].BgpId,
}
t := time.Unix(int64(e.OriginatedTime), 0)
paths = append(paths, table.NewPath(source, nlri, false, e.PathAttributes, t, false))
if subType != mrt.RIB_IPV4_UNICAST || subType != mrt.RIB_IPV4_UNICAST_ADDPATH {
attrs := make([]bgp.PathAttributeInterface, 0, len(e.PathAttributes))
for _, attr := range e.PathAttributes {
if attr.GetType() != bgp.BGP_ATTR_TYPE_MP_REACH_NLRI {
attrs = append(attrs, attr)
} else {
a := attr.(*bgp.PathAttributeMpReachNLRI)
attrs = append(attrs, bgp.NewPathAttributeMpReachNLRI(a.Nexthop.String(), []bgp.AddrPrefixInterface{nlri}))
}
}
paths = append(paths, table.NewPath(source, nlri, false, attrs, t, false))
} else {
paths = append(paths, table.NewPath(source, nlri, false, e.PathAttributes, t, false))
}
}
if mrtOpts.NextHop != nil {
for _, p := range paths {