summaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/fsm.go17
-rw-r--r--server/peer.go20
-rw-r--r--server/server.go4
3 files changed, 31 insertions, 10 deletions
diff --git a/server/fsm.go b/server/fsm.go
index d57a6f42..81050b31 100644
--- a/server/fsm.go
+++ b/server/fsm.go
@@ -122,7 +122,7 @@ type FSMHandler struct {
func NewFSMHandler(fsm *FSM) *FSMHandler {
f := &FSMHandler{
fsm: fsm,
- errorCh: make(chan bool),
+ errorCh: make(chan bool, 2),
}
f.t.Go(f.loop)
return f
@@ -281,7 +281,11 @@ func (h *FSMHandler) opensent() bgp.FSMState {
case *bgp.MessageError:
err := e.MsgData.(*bgp.MessageError)
m := bgp.NewBGPNotificationMessage(err.TypeCode, err.SubTypeCode, err.Data)
- h.fsm.outgoing <- m
+ b, _ := m.Serialize()
+ fsm.passiveConn.Write(b)
+ fsm.bgpMessageStateUpdate(m.Header.Type, false)
+ h.conn.Close()
+ nextState = bgp.BGP_FSM_IDLE
default:
log.WithFields(log.Fields{
"Topic": "Peer",
@@ -330,10 +334,11 @@ func (h *FSMHandler) openconfirm() bgp.FSMState {
case *bgp.MessageError:
err := e.MsgData.(*bgp.MessageError)
m := bgp.NewBGPNotificationMessage(err.TypeCode, err.SubTypeCode, err.Data)
- h.fsm.outgoing <- m
- // tx goroutine will close the tcp
- // connection and state will be
- // changed. so no need to change here.
+ b, _ := m.Serialize()
+ fsm.passiveConn.Write(b)
+ fsm.bgpMessageStateUpdate(m.Header.Type, false)
+ h.conn.Close()
+ return bgp.BGP_FSM_IDLE
default:
log.WithFields(log.Fields{
"Topic": "Peer",
diff --git a/server/peer.go b/server/peer.go
index 4e6f2ff3..6f0d2f6b 100644
--- a/server/peer.go
+++ b/server/peer.go
@@ -168,8 +168,24 @@ func (peer *Peer) sendMessages(msgs []*bgp.BGPMessage) {
func (peer *Peer) handleREST(restReq *api.RestRequest) {
result := &api.RestResponse{}
- j, _ := json.Marshal(peer.rib.Tables[peer.rf])
- result.Data = j
+ switch restReq.RequestType {
+ case api.REQ_LOCAL_RIB:
+ j, _ := json.Marshal(peer.rib.Tables[peer.rf])
+ result.Data = j
+ case api.REQ_NEIGHBOR_SHUTDOWN:
+ peer.fsm.outgoing <- bgp.NewBGPNotificationMessage(bgp.BGP_ERROR_CEASE, bgp.BGP_ERROR_SUB_ADMINISTRATIVE_SHUTDOWN, nil)
+ case api.REQ_NEIGHBOR_RESET:
+ peer.fsm.outgoing <- bgp.NewBGPNotificationMessage(bgp.BGP_ERROR_CEASE, bgp.BGP_ERROR_SUB_ADMINISTRATIVE_RESET, nil)
+ case api.REQ_NEIGHBOR_SOFT_RESET:
+ case api.REQ_NEIGHBOR_SOFT_RESET_IN:
+ // check capability
+ // drop allIn and other peers?
+ // peer.adjRib.DropAllIn(peer.rf)
+ peer.fsm.outgoing <- bgp.NewBGPRouteRefreshMessage(uint16(int(peer.rf)>>16), 0, uint8(int(peer.rf)&0xff))
+ case api.REQ_NEIGHBOR_SOFT_RESET_OUT:
+ pathList := peer.adjRib.GetOutPathList(peer.rf)
+ peer.sendMessages(table.CreateUpdateMsgFromPaths(pathList))
+ }
restReq.ResponseCh <- result
close(restReq.ResponseCh)
}
diff --git a/server/server.go b/server/server.go
index bc4274de..cbd67732 100644
--- a/server/server.go
+++ b/server/server.go
@@ -228,7 +228,7 @@ func (server *BgpServer) handleRest(restReq *api.RestRequest) {
restReq.ResponseCh <- result
close(restReq.ResponseCh)
- case api.REQ_NEIGHBOR: // get neighbor state
+ case api.REQ_NEIGHBOR:
remoteAddr := restReq.RemoteAddr
result := &api.RestResponse{}
@@ -241,7 +241,7 @@ func (server *BgpServer) handleRest(restReq *api.RestRequest) {
}
restReq.ResponseCh <- result
close(restReq.ResponseCh)
- case api.REQ_LOCAL_RIB:
+ case api.REQ_LOCAL_RIB, api.REQ_NEIGHBOR_SHUTDOWN, api.REQ_NEIGHBOR_RESET, api.REQ_NEIGHBOR_SOFT_RESET_IN, api.REQ_NEIGHBOR_SOFT_RESET_OUT:
remoteAddr := restReq.RemoteAddr
result := &api.RestResponse{}
info, found := server.peerMap[remoteAddr]