summaryrefslogtreecommitdiffhomepage
path: root/server/util.go
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2017-01-19 10:04:01 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2017-02-03 22:47:34 -0800
commitada5cb1db61b481378ad78ba2d78bf36eff67e2e (patch)
treed9d8ff43802828190da1b8277a68a2be500d6883 /server/util.go
parent1063bcab1ee22cac4c7e375aaf37589747bad133 (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/util.go')
-rw-r--r--server/util.go16
1 files changed, 16 insertions, 0 deletions
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:]
+}