diff options
Diffstat (limited to 'server/util.go')
-rw-r--r-- | server/util.go | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/server/util.go b/server/util.go index 43c85bc1..9e11a0a1 100644 --- a/server/util.go +++ b/server/util.go @@ -15,7 +15,10 @@ package server -import "github.com/eapache/channels" +import ( + "github.com/eapache/channels" + "github.com/osrg/gobgp/packet/bgp" +) func cleanInfiniteChannel(ch *channels.InfiniteChannel) { ch.Close() @@ -23,3 +26,20 @@ func cleanInfiniteChannel(ch *channels.InfiniteChannel) { for range ch.Out() { } } + +// Returns the binary formatted Administrative Shutdown Communication from the +// given string value. +func newAdministrativeCommunication(communication string) (data []byte) { + if communication == "" { + return nil + } + com := []byte(communication) + if len(com) > bgp.BGP_ERROR_ADMINISTRATIVE_COMMUNICATION_MAX { + data = []byte{bgp.BGP_ERROR_ADMINISTRATIVE_COMMUNICATION_MAX} + data = append(data, com[:bgp.BGP_ERROR_ADMINISTRATIVE_COMMUNICATION_MAX]...) + } else { + data = []byte{byte(len(com))} + data = append(data, com...) + } + return data +} |