diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-03-27 16:34:09 +0000 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-03-31 10:55:44 +0900 |
commit | 4cd999438493d101f8d5d300a901ce6544e58e6c (patch) | |
tree | 16156636fcb74bbb3cc9f04d62a7491033d9c376 | |
parent | ce2c4a1fd29c9f4e1e0f132272d61386517bdf0e (diff) |
table: fix nexthop path attribute updating for normal BGP
Paths whose route family are other than ipv4 have nexthop information in
a mp_reach_nlri path attribute instead of a nexthop path attribute.
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
-rw-r--r-- | table/path.go | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/table/path.go b/table/path.go index e4daa9de..468da2f2 100644 --- a/table/path.go +++ b/table/path.go @@ -106,12 +106,26 @@ func (pd *PathDefault) updatePathAttrs(global *config.Global, peer *config.Neigh if peer.PeerType == config.PEER_TYPE_EXTERNAL { // NEXTHOP handling - idx, _ := pd.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) - if idx < 0 { - log.Fatal("missing NEXTHOP mandatory attribute") + switch pd.routeFamily { + case bgp.RF_IPv4_UC: + idx, _ := pd.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) + if idx < 0 { + log.Warn("missing NEXTHOP mandatory attribute, check MP_REACH_NLRI instead.") + } else { + newNexthop := bgp.NewPathAttributeNextHop(peer.LocalAddress.String()) + pd.pathAttrs[idx] = newNexthop + break + } + fallthrough + default: + idx, attr := pd.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI) + if attr == nil { + log.Fatal("missing MP_REACH_NLRI mandatory attribute") + } + oldNlri := attr.(*bgp.PathAttributeMpReachNLRI) + newNlri := bgp.NewPathAttributeMpReachNLRI(peer.LocalAddress.String(), oldNlri.Value) + pd.pathAttrs[idx] = newNlri } - newNexthop := bgp.NewPathAttributeNextHop(peer.LocalAddress.String()) - newPathAttrs[idx] = newNexthop // AS_PATH handling // @@ -140,7 +154,7 @@ func (pd *PathDefault) updatePathAttrs(global *config.Global, peer *config.Neigh log.Fatal("missing AS_PATH mandatory attribute") } asPath := cloneAsPath(originalAsPath.(*bgp.PathAttributeAsPath)) - newPathAttrs[idx] = asPath + pd.pathAttrs[idx] = asPath fst := asPath.Value[0].(*bgp.As4PathParam) if len(asPath.Value) > 0 && fst.Type == bgp.BGP_ASPATH_ATTR_TYPE_SEQ && fst.ASLen() < 255 { @@ -154,7 +168,7 @@ func (pd *PathDefault) updatePathAttrs(global *config.Global, peer *config.Neigh // MED Handling idx, _ = pd.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) if idx >= 0 { - newPathAttrs = append(newPathAttrs[:idx], newPathAttrs[idx+1:]...) + pd.pathAttrs = append(pd.pathAttrs[:idx], pd.pathAttrs[idx+1:]...) } } else if peer.PeerType == config.PEER_TYPE_INTERNAL { // For iBGP peers we are required to send local-pref attribute @@ -163,9 +177,9 @@ func (pd *PathDefault) updatePathAttrs(global *config.Global, peer *config.Neigh p := bgp.NewPathAttributeLocalPref(100) idx, _ := pd.getPathAttr(bgp.BGP_ATTR_TYPE_LOCAL_PREF) if idx < 0 { - newPathAttrs = append(newPathAttrs, p) + pd.pathAttrs = append(pd.pathAttrs, p) } else { - newPathAttrs[idx] = p + pd.pathAttrs[idx] = p } } else { log.WithFields(log.Fields{ |