summaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2017-01-18 13:28:46 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2017-02-03 22:47:34 -0800
commit1063bcab1ee22cac4c7e375aaf37589747bad133 (patch)
tree1045a331ace96926da8728915318e0084eb8c5c5 /server
parent356c01a9d061b2b6bb4c3068a9888b56dc435600 (diff)
cli: Communication on Administrative Shutdown NOTIFICATION
This patch enable to send an arbitrary message on the Cease NOTIFICATION message with "Administrative Shutdown" and "Administrative Reset" subcodes with "--reason" option. Usage: $ gobgp neighbor <neighbor address> shutdown --reason "some messages" $ gobgp neighbor <neighbor address> reset --reason "some messages" Reference: https://tools.ietf.org/html/draft-ietf-idr-shutdown-04 Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Diffstat (limited to 'server')
-rw-r--r--server/server.go12
-rw-r--r--server/util.go22
2 files changed, 27 insertions, 7 deletions
diff --git a/server/server.go b/server/server.go
index 902b6c8a..38b65422 100644
--- a/server/server.go
+++ b/server/server.go
@@ -1765,7 +1765,7 @@ func (s *BgpServer) addrToPeers(addr string) (l []*Peer, err error) {
return []*Peer{peer}, nil
}
-func (s *BgpServer) resetNeighbor(op, addr string, subcode uint8) error {
+func (s *BgpServer) resetNeighbor(op, addr string, subcode uint8, data []byte) error {
log.WithFields(log.Fields{
"Topic": "Operation",
"Key": addr,
@@ -1773,7 +1773,7 @@ func (s *BgpServer) resetNeighbor(op, addr string, subcode uint8) error {
peers, err := s.addrToPeers(addr)
if err == nil {
- m := bgp.NewBGPNotificationMessage(bgp.BGP_ERROR_CEASE, subcode, nil)
+ m := bgp.NewBGPNotificationMessage(bgp.BGP_ERROR_CEASE, subcode, data)
for _, peer := range peers {
sendFsmOutgoingMsg(peer, nil, m, false)
}
@@ -1781,15 +1781,15 @@ func (s *BgpServer) resetNeighbor(op, addr string, subcode uint8) error {
return err
}
-func (s *BgpServer) ShutdownNeighbor(addr string) error {
+func (s *BgpServer) ShutdownNeighbor(addr, communication string) error {
return s.mgmtOperation(func() error {
- return s.resetNeighbor("Neighbor shutdown", addr, bgp.BGP_ERROR_SUB_ADMINISTRATIVE_SHUTDOWN)
+ return s.resetNeighbor("Neighbor shutdown", addr, bgp.BGP_ERROR_SUB_ADMINISTRATIVE_SHUTDOWN, newAdministrativeCommunication(communication))
}, true)
}
-func (s *BgpServer) ResetNeighbor(addr string) error {
+func (s *BgpServer) ResetNeighbor(addr, communication string) error {
return s.mgmtOperation(func() error {
- err := s.resetNeighbor("Neighbor reset", addr, bgp.BGP_ERROR_SUB_ADMINISTRATIVE_RESET)
+ err := s.resetNeighbor("Neighbor reset", addr, bgp.BGP_ERROR_SUB_ADMINISTRATIVE_RESET, newAdministrativeCommunication(communication))
if err != nil {
return err
}
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
+}