summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/grpc_server.go6
-rw-r--r--server/server.go65
2 files changed, 38 insertions, 33 deletions
diff --git a/server/grpc_server.go b/server/grpc_server.go
index 73068b55..8c938fd3 100644
--- a/server/grpc_server.go
+++ b/server/grpc_server.go
@@ -448,11 +448,7 @@ func (s *Server) neighbor(reqType int, address string, d interface{}) (interface
}
func (s *Server) ResetNeighbor(ctx context.Context, arg *api.ResetNeighborRequest) (*api.ResetNeighborResponse, error) {
- d, err := s.neighbor(REQ_NEIGHBOR_RESET, arg.Address, arg)
- if err != nil {
- return nil, err
- }
- return d.(*api.ResetNeighborResponse), err
+ return &api.ResetNeighborResponse{}, s.bgpServer.ResetNeighbor(arg.Address)
}
func (s *Server) SoftResetNeighbor(ctx context.Context, arg *api.SoftResetNeighborRequest) (*api.SoftResetNeighborResponse, error) {
diff --git a/server/server.go b/server/server.go
index aa781dbe..f2fcddd2 100644
--- a/server/server.go
+++ b/server/server.go
@@ -1511,20 +1511,6 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) {
Data: paths,
}
close(grpcReq.ResponseCh)
- case REQ_NEIGHBOR_RESET:
- peers, err := reqToPeers(grpcReq)
- if err != nil {
- break
- }
- logOp(grpcReq.Name, "Neighbor reset")
- m := bgp.NewBGPNotificationMessage(bgp.BGP_ERROR_CEASE, bgp.BGP_ERROR_SUB_ADMINISTRATIVE_RESET, nil)
- for _, peer := range peers {
- peer.fsm.idleHoldTime = peer.fsm.pConf.Timers.Config.IdleHoldTimeAfterReset
- sendFsmOutgoingMsg(peer, nil, m, false)
- }
- grpcReq.ResponseCh <- &GrpcResponse{Data: &api.ResetNeighborResponse{}}
- close(grpcReq.ResponseCh)
-
case REQ_NEIGHBOR_SOFT_RESET, REQ_NEIGHBOR_SOFT_RESET_IN:
peers, err := reqToPeers(grpcReq)
if err != nil {
@@ -1904,39 +1890,62 @@ func (s *BgpServer) UpdateNeighbor(c *config.Neighbor) (policyUpdated bool, err
return policyUpdated, err
}
-func (s *BgpServer) addrToPeers(address string) (l []*Peer, err error) {
- if address == "all" {
+func (s *BgpServer) addrToPeers(addr string) (l []*Peer, err error) {
+ if len(addr) == 0 {
for _, p := range s.neighborMap {
l = append(l, p)
}
return l, nil
}
- peer, found := s.neighborMap[address]
+ peer, found := s.neighborMap[addr]
if !found {
- return l, fmt.Errorf("Neighbor that has %v doesn't exist.", address)
+ return l, fmt.Errorf("Neighbor that has %v doesn't exist.", addr)
}
return []*Peer{peer}, nil
}
-func (s *BgpServer) ShutdownNeighbor(address string) (err error) {
+func (s *BgpServer) resetNeighbor(op, addr string, subcode uint8) error {
+ log.WithFields(log.Fields{
+ "Topic": "Operation",
+ "Key": addr,
+ }).Info(op)
+
+ peers, err := s.addrToPeers(addr)
+ if err == nil {
+ m := bgp.NewBGPNotificationMessage(bgp.BGP_ERROR_CEASE, subcode, nil)
+ for _, peer := range peers {
+ sendFsmOutgoingMsg(peer, nil, m, false)
+ }
+ }
+ return err
+}
+
+func (s *BgpServer) ShutdownNeighbor(addr string) (err error) {
ch := make(chan struct{})
defer func() { <-ch }()
s.mgmtCh <- func() {
defer close(ch)
- log.WithFields(log.Fields{
- "Topic": "Operation",
- "Key": address,
- }).Info("Neighbor shutdown")
+ err = s.resetNeighbor("Neighbor shutdown", addr, bgp.BGP_ERROR_SUB_ADMINISTRATIVE_SHUTDOWN)
+ }
+ return err
+}
- l := []*Peer{}
- l, err = s.addrToPeers(address)
+func (s *BgpServer) ResetNeighbor(addr string) (err error) {
+ ch := make(chan struct{})
+ defer func() { <-ch }()
+
+ s.mgmtCh <- func() {
+ defer close(ch)
+
+ err = s.resetNeighbor("Neighbor reset", addr, bgp.BGP_ERROR_SUB_ADMINISTRATIVE_RESET)
if err == nil {
- m := bgp.NewBGPNotificationMessage(bgp.BGP_ERROR_CEASE, bgp.BGP_ERROR_SUB_ADMINISTRATIVE_SHUTDOWN, nil)
- for _, peer := range l {
- sendFsmOutgoingMsg(peer, nil, m, false)
+ peers, _ := s.addrToPeers(addr)
+ for _, peer := range peers {
+ peer.fsm.idleHoldTime = peer.fsm.pConf.Timers.Config.IdleHoldTimeAfterReset
}
+
}
}
return err