From 85145b6264482697a8a9cc7e261b65d99b06444a Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Fri, 4 Aug 2017 14:27:42 -0400 Subject: [PATCH] bgpd: fix some formatting in bgp_io.c Signed-off-by: Quentin Young --- bgpd/bgp_io.c | 89 ++++++++++++++++++++++----------------------------- 1 file changed, 39 insertions(+), 50 deletions(-) diff --git a/bgpd/bgp_io.c b/bgpd/bgp_io.c index f80757f85f..0529cd5c19 100644 --- a/bgpd/bgp_io.c +++ b/bgpd/bgp_io.c @@ -478,59 +478,48 @@ static uint16_t bgp_read(struct peer *peer) nbytes = stream_read_try(peer->ibuf_work, peer->fd, readsize); - if (nbytes <= 0) // handle errors - { - switch (nbytes) { - case -1: // fatal error; tear down the session - zlog_err("%s [Error] bgp_read_packet error: %s", - peer->host, safe_strerror(errno)); - - if (peer->status == Established) { - if (CHECK_FLAG(peer->sflags, - PEER_STATUS_NSF_MODE)) { - peer->last_reset = - PEER_DOWN_NSF_CLOSE_SESSION; - SET_FLAG(peer->sflags, - PEER_STATUS_NSF_WAIT); - } else - peer->last_reset = - PEER_DOWN_CLOSE_SESSION; - } - - BGP_EVENT_ADD(peer, TCP_fatal_error); - SET_FLAG(status, BGP_IO_FATAL_ERR); - break; - - case 0: // TCP session closed - if (bgp_debug_neighbor_events(peer)) - zlog_debug( - "%s [Event] BGP connection closed fd %d", - peer->host, peer->fd); - - if (peer->status == Established) { - if (CHECK_FLAG(peer->sflags, - PEER_STATUS_NSF_MODE)) { - peer->last_reset = - PEER_DOWN_NSF_CLOSE_SESSION; - SET_FLAG(peer->sflags, - PEER_STATUS_NSF_WAIT); - } else - peer->last_reset = - PEER_DOWN_CLOSE_SESSION; - } - - BGP_EVENT_ADD(peer, TCP_connection_closed); - SET_FLAG(status, BGP_IO_FATAL_ERR); - break; + switch (nbytes) { + /* Fatal error; tear down session */ + case -1: + zlog_err("%s [Error] bgp_read_packet error: %s", peer->host, + safe_strerror(errno)); + + if (peer->status == Established) { + if (CHECK_FLAG(peer->sflags, PEER_STATUS_NSF_MODE)) { + peer->last_reset = PEER_DOWN_NSF_CLOSE_SESSION; + SET_FLAG(peer->sflags, PEER_STATUS_NSF_WAIT); + } else + peer->last_reset = PEER_DOWN_CLOSE_SESSION; + } - case -2: // temporary error; come back later - SET_FLAG(status, BGP_IO_TRANS_ERR); - break; - default: - break; + BGP_EVENT_ADD(peer, TCP_fatal_error); + SET_FLAG(status, BGP_IO_FATAL_ERR); + break; + + /* Received EOF / TCP session closed */ + case 0: + if (bgp_debug_neighbor_events(peer)) + zlog_debug("%s [Event] BGP connection closed fd %d", + peer->host, peer->fd); + + if (peer->status == Established) { + if (CHECK_FLAG(peer->sflags, PEER_STATUS_NSF_MODE)) { + peer->last_reset = PEER_DOWN_NSF_CLOSE_SESSION; + SET_FLAG(peer->sflags, PEER_STATUS_NSF_WAIT); + } else + peer->last_reset = PEER_DOWN_CLOSE_SESSION; } - return status; + BGP_EVENT_ADD(peer, TCP_connection_closed); + SET_FLAG(status, BGP_IO_FATAL_ERR); + break; + + /* EAGAIN or EWOULDBLOCK; come back later */ + case -2: + SET_FLAG(status, BGP_IO_TRANS_ERR); + break; + default: + break; } return status; -- 2.39.5