From ada5cb1db61b481378ad78ba2d78bf36eff67e2e Mon Sep 17 00:00:00 2001 From: IWASE Yusuke Date: Thu, 19 Jan 2017 10:04:01 +0900 Subject: 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 --- server/util.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'server/util.go') 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:] +} -- cgit v1.2.3