diff options
author | IWASE Yusuke <iwase.yusuke0@gmail.com> | 2017-01-19 10:04:01 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2017-02-03 22:47:34 -0800 |
commit | ada5cb1db61b481378ad78ba2d78bf36eff67e2e (patch) | |
tree | d9d8ff43802828190da1b8277a68a2be500d6883 /server | |
parent | 1063bcab1ee22cac4c7e375aaf37589747bad133 (diff) |
server/fsm: Logging Administrative Shutdown Communication
This patch enable to log the body of the Cease NOTIFICATION message
with "Administrative Shutdown" and "Administrative Reset" subcodes.
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Diffstat (limited to 'server')
-rw-r--r-- | server/fsm.go | 54 | ||||
-rw-r--r-- | server/util.go | 16 |
2 files changed, 57 insertions, 13 deletions
diff --git a/server/fsm.go b/server/fsm.go index c72f7f24..a8ca047a 100644 --- a/server/fsm.go +++ b/server/fsm.go @@ -696,13 +696,26 @@ func (h *FSMHandler) recvMessageWithError() (*FsmMsg, error) { } case bgp.BGP_MSG_NOTIFICATION: body := m.Body.(*bgp.BGPNotification) - log.WithFields(log.Fields{ - "Topic": "Peer", - "Key": h.fsm.pConf.Config.NeighborAddress, - "Code": body.ErrorCode, - "Subcode": body.ErrorSubcode, - "Data": body.Data, - }).Warn("received notification") + if body.ErrorCode == bgp.BGP_ERROR_CEASE && (body.ErrorSubcode == bgp.BGP_ERROR_SUB_ADMINISTRATIVE_SHUTDOWN || body.ErrorSubcode == bgp.BGP_ERROR_SUB_ADMINISTRATIVE_RESET) { + communication, rest := decodeAdministrativeCommunication(body.Data) + log.WithFields(log.Fields{ + "Topic": "Peer", + "Key": h.fsm.pConf.Config.NeighborAddress, + "Code": body.ErrorCode, + "Subcode": body.ErrorSubcode, + "Communicated-Reason": communication, + "Data": rest, + }).Warn("received notification") + } else { + log.WithFields(log.Fields{ + "Topic": "Peer", + "Key": h.fsm.pConf.Config.NeighborAddress, + "Code": body.ErrorCode, + "Subcode": body.ErrorSubcode, + "Data": body.Data, + }).Warn("received notification") + } + if s := h.fsm.pConf.GracefulRestart.State; s.Enabled && s.NotificationEnabled && body.ErrorCode == bgp.BGP_ERROR_CEASE && body.ErrorSubcode == bgp.BGP_ERROR_SUB_HARD_RESET { sendToErrorCh(FSM_HARD_RESET) } else { @@ -1097,13 +1110,28 @@ func (h *FSMHandler) sendMessageloop() error { switch m.Header.Type { case bgp.BGP_MSG_NOTIFICATION: - log.WithFields(log.Fields{ - "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, - "State": fsm.state.String(), - "Data": m, - }).Warn("sent notification") body := m.Body.(*bgp.BGPNotification) + if body.ErrorCode == bgp.BGP_ERROR_CEASE && (body.ErrorSubcode == bgp.BGP_ERROR_SUB_ADMINISTRATIVE_SHUTDOWN || body.ErrorSubcode == bgp.BGP_ERROR_SUB_ADMINISTRATIVE_RESET) { + communication, rest := decodeAdministrativeCommunication(body.Data) + log.WithFields(log.Fields{ + "Topic": "Peer", + "Key": fsm.pConf.Config.NeighborAddress, + "State": fsm.state.String(), + "Code": body.ErrorCode, + "Subcode": body.ErrorSubcode, + "Communicated-Reason": communication, + "Data": rest, + }).Warn("sent notification") + } else { + log.WithFields(log.Fields{ + "Topic": "Peer", + "Key": fsm.pConf.Config.NeighborAddress, + "State": fsm.state.String(), + "Code": body.ErrorCode, + "Subcode": body.ErrorSubcode, + "Data": body.Data, + }).Warn("sent notification") + } h.errorCh <- FsmStateReason(fmt.Sprintf("%s %s", FSM_NOTIFICATION_SENT, bgp.NewNotificationErrorCode(body.ErrorCode, body.ErrorSubcode).String())) conn.Close() return fmt.Errorf("closed") diff --git a/server/util.go b/server/util.go index 9e11a0a1..951d712c 100644 --- a/server/util.go +++ b/server/util.go @@ -43,3 +43,19 @@ func newAdministrativeCommunication(communication string) (data []byte) { } return data } + +// Parses the given NOTIFICATION message data as a binary value and returns +// the Administrative Shutdown Communication in string and the rest binary. +func decodeAdministrativeCommunication(data []byte) (string, []byte) { + if len(data) == 0 { + return "", data + } + communicationLen := int(data[0]) + if communicationLen > bgp.BGP_ERROR_ADMINISTRATIVE_COMMUNICATION_MAX { + communicationLen = bgp.BGP_ERROR_ADMINISTRATIVE_COMMUNICATION_MAX + } + if communicationLen > len(data)+1 { + communicationLen = len(data) + 1 + } + return string(data[1 : communicationLen+1]), data[communicationLen+1:] +} |