diff options
author | Satoshi Fujimoto <satoshi.fujimoto7@gmail.com> | 2017-06-13 14:04:50 +0900 |
---|---|---|
committer | Satoshi Fujimoto <satoshi.fujimoto7@gmail.com> | 2017-06-16 09:09:47 +0900 |
commit | be2524ee3e158a0d248d730f727da80bab09aed8 (patch) | |
tree | e27c107dc19f448bcfdd325f88cb27d82c406da4 /server/fsm.go | |
parent | 83684d5e62fb14596aabf03747a8b395543f91bb (diff) |
config: Use State to get NeighborAddress instead of Config
By introducing dynamic neighbor feature,
GoBGP can have dynamic neighbors,
and corresponding Config.NeighboAddress can be empty.
This patch sets State.NeighborAddress for all neighbors,
and gets the neighbor's address from them.
Signed-off-by: Satoshi Fujimoto <satoshi.fujimoto7@gmail.com>
Diffstat (limited to 'server/fsm.go')
-rw-r--r-- | server/fsm.go | 100 |
1 files changed, 50 insertions, 50 deletions
diff --git a/server/fsm.go b/server/fsm.go index 3817bd23..2c01c14d 100644 --- a/server/fsm.go +++ b/server/fsm.go @@ -227,7 +227,7 @@ func NewFSM(gConf *config.Global, pConf *config.Neighbor, policy *table.RoutingP func (fsm *FSM) StateChange(nextState bgp.FSMState) { log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, "old": fsm.state.String(), "new": nextState.String(), "reason": fsm.reason, @@ -298,12 +298,12 @@ func (fsm *FSM) sendNotificationFromErrorMsg(e *bgp.MessageError) error { fsm.h.conn.Close() log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, "Data": e, }).Warn("sent notification") return nil } - return fmt.Errorf("can't send notification to %s since TCP connection is not established", fsm.pConf.Config.NeighborAddress) + return fmt.Errorf("can't send notification to %s since TCP connection is not established", fsm.pConf.State.NeighborAddress) } func (fsm *FSM) sendNotification(code, subType uint8, data []byte, msg string) error { @@ -323,7 +323,7 @@ func (fsm *FSM) connectLoop() error { timer.Stop() connect := func() { - addr := fsm.pConf.Config.NeighborAddress + addr := fsm.pConf.State.NeighborAddress port := int(bgp.BGP_PORT) if fsm.pConf.Transport.Config.RemotePort != 0 { port = int(fsm.pConf.Transport.Config.RemotePort) @@ -342,7 +342,7 @@ func (fsm *FSM) connectLoop() error { if e != nil { log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, }).Warnf("failed to resolve ltcpaddr: %s", e) return } @@ -358,13 +358,13 @@ func (fsm *FSM) connectLoop() error { conn.Close() log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, }).Warn("active conn is closed to avoid being blocked") } } else { log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, }).Debugf("failed to connect: %s", err) } @@ -378,7 +378,7 @@ func (fsm *FSM) connectLoop() error { case <-fsm.t.Dying(): log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, }).Debug("stop connect loop") return nil case <-timer.C: @@ -429,7 +429,7 @@ func (h *FSMHandler) idle() (bgp.FSMState, FsmStateReason) { if fsm.pConf.GracefulRestart.State.PeerRestarting { log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, "State": fsm.state.String(), }).Warn("graceful restart timer expired") return bgp.BGP_FSM_IDLE, FSM_RESTART_TIMER_EXPIRED @@ -441,7 +441,7 @@ func (h *FSMHandler) idle() (bgp.FSMState, FsmStateReason) { conn.Close() log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, "State": fsm.state.String(), }).Warn("Closed an accepted connection") case <-idleHoldTimer.C: @@ -449,7 +449,7 @@ func (h *FSMHandler) idle() (bgp.FSMState, FsmStateReason) { if fsm.adminState == ADMIN_STATE_UP { log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, "Duration": fsm.idleHoldTime, }).Debug("IdleHoldTimer expired") fsm.idleHoldTime = HOLDTIME_IDLE @@ -503,7 +503,7 @@ func (h *FSMHandler) active() (bgp.FSMState, FsmStateReason) { if fsm.pConf.GracefulRestart.State.PeerRestarting { log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, "State": fsm.state.String(), }).Warn("graceful restart timer expired") return bgp.BGP_FSM_IDLE, FSM_RESTART_TIMER_EXPIRED @@ -519,7 +519,7 @@ func (h *FSMHandler) active() (bgp.FSMState, FsmStateReason) { case ADMIN_STATE_UP: log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, "State": fsm.state.String(), "AdminState": stateOp.State.String(), }).Panic("code logic bug") @@ -658,13 +658,13 @@ func (h *FSMHandler) recvMessageWithError() (*FsmMsg, error) { h.fsm.bgpMessageStateUpdate(0, true) log.WithFields(log.Fields{ "Topic": "Peer", - "Key": h.fsm.pConf.Config.NeighborAddress, + "Key": h.fsm.pConf.State.NeighborAddress, "State": h.fsm.state.String(), "error": err, }).Warn("malformed BGP Header") fmsg := &FsmMsg{ MsgType: FSM_MSG_BGP_MESSAGE, - MsgSrc: h.fsm.pConf.Config.NeighborAddress, + MsgSrc: h.fsm.pConf.State.NeighborAddress, MsgData: err, Version: h.fsm.version, } @@ -687,14 +687,14 @@ func (h *FSMHandler) recvMessageWithError() (*FsmMsg, error) { } fmsg := &FsmMsg{ MsgType: FSM_MSG_BGP_MESSAGE, - MsgSrc: h.fsm.pConf.Config.NeighborAddress, + MsgSrc: h.fsm.pConf.State.NeighborAddress, timestamp: now, Version: h.fsm.version, } if err != nil { log.WithFields(log.Fields{ "Topic": "Peer", - "Key": h.fsm.pConf.Config.NeighborAddress, + "Key": h.fsm.pConf.State.NeighborAddress, "State": h.fsm.state.String(), "error": err, }).Warn("malformed BGP message") @@ -717,7 +717,7 @@ func (h *FSMHandler) recvMessageWithError() (*FsmMsg, error) { if err != nil { log.WithFields(log.Fields{ "Topic": "Peer", - "Key": h.fsm.pConf.Config.NeighborAddress, + "Key": h.fsm.pConf.State.NeighborAddress, "State": h.fsm.state.String(), "error": err, }).Warn("malformed BGP update message") @@ -752,7 +752,7 @@ func (h *FSMHandler) recvMessageWithError() (*FsmMsg, error) { } fmsg.PathList = table.ProcessMessage(m, h.fsm.peerInfo, fmsg.timestamp) - id := h.fsm.pConf.Config.NeighborAddress + id := h.fsm.pConf.State.NeighborAddress for _, path := range fmsg.PathList { if path.IsEOR() { continue @@ -779,7 +779,7 @@ func (h *FSMHandler) recvMessageWithError() (*FsmMsg, error) { communication, rest := decodeAdministrativeCommunication(body.Data) log.WithFields(log.Fields{ "Topic": "Peer", - "Key": h.fsm.pConf.Config.NeighborAddress, + "Key": h.fsm.pConf.State.NeighborAddress, "Code": body.ErrorCode, "Subcode": body.ErrorSubcode, "Communicated-Reason": communication, @@ -788,7 +788,7 @@ func (h *FSMHandler) recvMessageWithError() (*FsmMsg, error) { } else { log.WithFields(log.Fields{ "Topic": "Peer", - "Key": h.fsm.pConf.Config.NeighborAddress, + "Key": h.fsm.pConf.State.NeighborAddress, "Code": body.ErrorCode, "Subcode": body.ErrorSubcode, "Data": body.Data, @@ -880,14 +880,14 @@ func (h *FSMHandler) opensent() (bgp.FSMState, FsmStateReason) { conn.Close() log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, "State": fsm.state.String(), }).Warn("Closed an accepted connection") case <-fsm.gracefulRestartTimer.C: if fsm.pConf.GracefulRestart.State.PeerRestarting { log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, "State": fsm.state.String(), }).Warn("graceful restart timer expired") h.conn.Close() @@ -919,7 +919,7 @@ func (h *FSMHandler) opensent() (bgp.FSMState, FsmStateReason) { fsm.pConf.State.PeerType = typ log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, "State": fsm.state.String(), }).Infof("skiped asn negotiation: peer-as: %d, peer-type: %s", peerAs, typ) } else { @@ -974,7 +974,7 @@ func (h *FSMHandler) opensent() (bgp.FSMState, FsmStateReason) { if fsm.pConf.GracefulRestart.State.PeerRestarting && cap.Flags&0x08 == 0 { log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, "State": fsm.state.String(), }).Warn("restart flag is not set") // send notification? @@ -1018,7 +1018,7 @@ func (h *FSMHandler) opensent() (bgp.FSMState, FsmStateReason) { default: log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, "State": fsm.state.String(), "Data": e.MsgData, }).Panic("unknown msg type") @@ -1040,7 +1040,7 @@ func (h *FSMHandler) opensent() (bgp.FSMState, FsmStateReason) { case ADMIN_STATE_UP: log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, "State": fsm.state.String(), "AdminState": stateOp.State.String(), }).Panic("code logic bug") @@ -1091,14 +1091,14 @@ func (h *FSMHandler) openconfirm() (bgp.FSMState, FsmStateReason) { conn.Close() log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, "State": fsm.state.String(), }).Warn("Closed an accepted connection") case <-fsm.gracefulRestartTimer.C: if fsm.pConf.GracefulRestart.State.PeerRestarting { log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, "State": fsm.state.String(), }).Warn("graceful restart timer expired") h.conn.Close() @@ -1130,7 +1130,7 @@ func (h *FSMHandler) openconfirm() (bgp.FSMState, FsmStateReason) { default: log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, "State": fsm.state.String(), "Data": e.MsgData, }).Panic("unknown msg type") @@ -1152,7 +1152,7 @@ func (h *FSMHandler) openconfirm() (bgp.FSMState, FsmStateReason) { case ADMIN_STATE_UP: log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, "State": fsm.state.String(), "AdminState": stateOp.State.String(), }).Panic("code logic bug") @@ -1170,7 +1170,7 @@ func (h *FSMHandler) sendMessageloop() error { if fsm.twoByteAsTrans && m.Header.Type == bgp.BGP_MSG_UPDATE { log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, "State": fsm.state.String(), "Data": m, }).Debug("update for 2byte AS peer") @@ -1181,7 +1181,7 @@ func (h *FSMHandler) sendMessageloop() error { if err != nil { log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, "State": fsm.state.String(), "Data": err, }).Warn("failed to serialize") @@ -1197,7 +1197,7 @@ func (h *FSMHandler) sendMessageloop() error { if err != nil { log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, "State": fsm.state.String(), "Data": err, }).Warn("failed to send") @@ -1214,7 +1214,7 @@ func (h *FSMHandler) sendMessageloop() error { communication, rest := decodeAdministrativeCommunication(body.Data) log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, "State": fsm.state.String(), "Code": body.ErrorCode, "Subcode": body.ErrorSubcode, @@ -1224,7 +1224,7 @@ func (h *FSMHandler) sendMessageloop() error { } else { log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, "State": fsm.state.String(), "Code": body.ErrorCode, "Subcode": body.ErrorSubcode, @@ -1238,7 +1238,7 @@ func (h *FSMHandler) sendMessageloop() error { update := m.Body.(*bgp.BGPUpdate) log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, "State": fsm.state.String(), "nlri": update.NLRI, "withdrawals": update.WithdrawnRoutes, @@ -1247,7 +1247,7 @@ func (h *FSMHandler) sendMessageloop() error { default: log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, "State": fsm.state.String(), "data": m, }).Debug("sent") @@ -1323,7 +1323,7 @@ func (h *FSMHandler) established() (bgp.FSMState, FsmStateReason) { conn.Close() log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, "State": fsm.state.String(), }).Warn("Closed an accepted connection") case err := <-h.errorCh: @@ -1333,7 +1333,7 @@ func (h *FSMHandler) established() (bgp.FSMState, FsmStateReason) { err = FSM_GRACEFUL_RESTART log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, "State": fsm.state.String(), }).Info("peer graceful restart") fsm.gracefulRestartTimer.Reset(time.Duration(fsm.pConf.GracefulRestart.State.PeerRestartTime) * time.Second) @@ -1342,7 +1342,7 @@ func (h *FSMHandler) established() (bgp.FSMState, FsmStateReason) { case <-holdTimer.C: log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, "State": fsm.state.String(), }).Warn("hold timer expired") m := bgp.NewBGPNotificationMessage(bgp.BGP_ERROR_HOLD_TIMER_EXPIRED, 0, nil) @@ -1399,7 +1399,7 @@ func (h *FSMHandler) loop() error { if nextState == bgp.BGP_FSM_ESTABLISHED && oldState == bgp.BGP_FSM_OPENCONFIRM { log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, "State": fsm.state.String(), }).Info("Peer Up") } @@ -1413,14 +1413,14 @@ func (h *FSMHandler) loop() error { } log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, "State": fsm.state.String(), "Reason": reason, }).Info("Peer Down") } e := time.AfterFunc(time.Second*120, func() { - log.WithFields(log.Fields{"Topic": "Peer"}).Fatalf("failed to free the fsm.h.t for %s %s %s", fsm.pConf.Config.NeighborAddress, oldState, nextState) + log.WithFields(log.Fields{"Topic": "Peer"}).Fatalf("failed to free the fsm.h.t for %s %s %s", fsm.pConf.State.NeighborAddress, oldState, nextState) }) h.t.Wait() e.Stop() @@ -1429,7 +1429,7 @@ func (h *FSMHandler) loop() error { if nextState >= bgp.BGP_FSM_IDLE { e := &FsmMsg{ MsgType: FSM_MSG_STATE_CHANGE, - MsgSrc: fsm.pConf.Config.NeighborAddress, + MsgSrc: fsm.pConf.State.NeighborAddress, MsgData: nextState, Version: h.fsm.version, } @@ -1443,7 +1443,7 @@ func (h *FSMHandler) changeAdminState(s AdminState) error { if fsm.adminState != s { log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, "State": fsm.state.String(), "AdminState": s.String(), }).Debug("admin state changed") @@ -1455,19 +1455,19 @@ func (h *FSMHandler) changeAdminState(s AdminState) error { case ADMIN_STATE_UP: log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, "State": fsm.state.String(), }).Info("Administrative start") case ADMIN_STATE_DOWN: log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, "State": fsm.state.String(), }).Info("Administrative shutdown") case ADMIN_STATE_PFX_CT: log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, "State": fsm.state.String(), }).Info("Administrative shutdown(Prefix limit reached)") } @@ -1475,7 +1475,7 @@ func (h *FSMHandler) changeAdminState(s AdminState) error { } else { log.WithFields(log.Fields{ "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, + "Key": fsm.pConf.State.NeighborAddress, "State": fsm.state.String(), }).Warn("cannot change to the same state") |