diff options
author | Wataru Ishida <ishida.wataru@lab.ntt.co.jp> | 2016-11-04 13:19:47 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-11-04 13:19:47 +0900 |
commit | a17832195c5fc42d6d0ec3dd7cc4868694bed88d (patch) | |
tree | 14381d27f1e58a6c399de90cc206d2433d8d366f /server/server.go | |
parent | 97bc9dd0da71ce743dbb7deb4a09f260ca518dcc (diff) |
support neighbor belongs to VRF
$ gobgp vrf add red rd 100:100 rt both 100:100
$ gobgp neighbor add 10.0.0.1 as 2 vrf red
$ gobgp vrf red neighbor
Peer AS Up/Down State |#Advertised Received Accepted
10.0.0.1 2 never Active | 0 0 0
Signed-off-by: Wataru Ishida <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'server/server.go')
-rw-r--r-- | server/server.go | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/server/server.go b/server/server.go index 8e26a45b..17710f11 100644 --- a/server/server.go +++ b/server/server.go @@ -816,8 +816,13 @@ func (server *BgpServer) handleFSMMessage(peer *Peer, e *FsmMsg) { } if len(pathList) > 0 { - var altered []*table.Path - altered = server.propagateUpdate(peer, pathList) + if v := peer.fsm.pConf.Config.Vrf; v != "" { + vrf := server.globalRib.Vrfs[v] + for idx, path := range pathList { + pathList[idx] = path.ToGlobal(vrf) + } + } + altered := server.propagateUpdate(peer, pathList) if server.isWatched(WATCH_EVENT_TYPE_POST_UPDATE) { _, y := peer.fsm.capMap[bgp.BGP_CAP_FOUR_OCTET_AS_NUMBER] l, _ := peer.fsm.LocalHostPort() @@ -1288,6 +1293,13 @@ func (s *BgpServer) DeleteVrf(name string) (err error) { s.mgmtCh <- func() { defer close(ch) + for _, n := range s.neighborMap { + if n.fsm.pConf.Config.Vrf == name { + err = fmt.Errorf("failed to delete VRF %s: neighbor %s is in use", name, n.ID()) + return + } + } + pathList, err := s.globalRib.DeleteVrf(name) if err == nil && len(pathList) > 0 { s.propagateUpdate(nil, pathList) @@ -1644,6 +1656,25 @@ func (server *BgpServer) addNeighbor(c *config.Neighbor) error { return fmt.Errorf("Can't overwrite the existing peer: %s", addr) } + if vrf := c.Config.Vrf; vrf != "" { + if c.RouteServer.Config.RouteServerClient { + return fmt.Errorf("route server client can't be enslaved to VRF") + } + if c.RouteReflector.Config.RouteReflectorClient { + return fmt.Errorf("route reflector client can't be enslaved to VRF") + } + families, _ := config.AfiSafis(c.AfiSafis).ToRfList() + for _, f := range families { + if f != bgp.RF_IPv4_UC && f != bgp.RF_IPv6_UC { + return fmt.Errorf("%s is not supported for VRF enslaved neighbor", f) + } + } + _, y := server.globalRib.Vrfs[vrf] + if !y { + return fmt.Errorf("VRF not found: %s", vrf) + } + } + if server.bgpConfig.Global.Config.Port > 0 { for _, l := range server.Listeners(addr) { if err := SetTcpMD5SigSockopts(l, addr, c.Config.AuthPassword); err != nil { |