#include <zebra.h>
#include <pthread.h> // for pthread_mutex_unlock, pthread_mutex_lock
-#include "frr_pthread.h" // for frr_pthread_get, frr_pthread
+#include "frr_pthread.h"
#include "linklist.h" // for list_delete, list_delete_all_node, lis...
#include "log.h" // for zlog_debug, safe_strerror, zlog_err
#include "memory.h" // for MTYPE_TMP, XCALLOC, XFREE
#include "bgpd/bgp_io.h"
#include "bgpd/bgp_debug.h" // for bgp_debug_neighbor_events, bgp_type_str
+#include "bgpd/bgp_errors.h" // for expanded error reference information
#include "bgpd/bgp_fsm.h" // for BGP_EVENT_ADD, bgp_event
#include "bgpd/bgp_packet.h" // for bgp_notify_send_with_data, bgp_notify...
#include "bgpd/bgpd.h" // for peer, BGP_MARKER_SIZE, bgp_master, bm
void bgp_writes_on(struct peer *peer)
{
- struct frr_pthread *fpt = frr_pthread_get(PTHREAD_IO);
+ struct frr_pthread *fpt = bgp_pth_io;
assert(fpt->running);
assert(peer->status != Deleted);
void bgp_writes_off(struct peer *peer)
{
- struct frr_pthread *fpt = frr_pthread_get(PTHREAD_IO);
+ struct frr_pthread *fpt = bgp_pth_io;
assert(fpt->running);
thread_cancel_async(fpt->master, &peer->t_write, NULL);
void bgp_reads_on(struct peer *peer)
{
- struct frr_pthread *fpt = frr_pthread_get(PTHREAD_IO);
+ struct frr_pthread *fpt = bgp_pth_io;
assert(fpt->running);
assert(peer->status != Deleted);
void bgp_reads_off(struct peer *peer)
{
- struct frr_pthread *fpt = frr_pthread_get(PTHREAD_IO);
+ struct frr_pthread *fpt = bgp_pth_io;
assert(fpt->running);
thread_cancel_async(fpt->master, &peer->t_read, NULL);
if (peer->fd < 0)
return -1;
- struct frr_pthread *fpt = frr_pthread_get(PTHREAD_IO);
+ struct frr_pthread *fpt = bgp_pth_io;
pthread_mutex_lock(&peer->io_mtx);
{
bool more = true; // whether we got more data
bool fatal = false; // whether fatal error occurred
bool added_pkt = false; // whether we pushed onto ->ibuf
- bool header_valid = true; // whether header is valid
/* clang-format on */
peer = THREAD_ARG(thread);
- if (peer->fd < 0)
+ if (peer->fd < 0 || bm->terminating)
return -1;
- struct frr_pthread *fpt = frr_pthread_get(PTHREAD_IO);
+ struct frr_pthread *fpt = bgp_pth_io;
pthread_mutex_lock(&peer->io_mtx);
{
if (ringbuf_remain(ibw) < BGP_HEADER_SIZE)
break;
- /* validate header */
- header_valid = validate_header(peer);
-
- if (!header_valid) {
+ /* check that header is valid */
+ if (!validate_header(peer)) {
fatal = true;
break;
}
*/
static uint16_t bgp_write(struct peer *peer)
{
- u_char type;
+ uint8_t type;
struct stream *s;
int num;
int update_last_write = 0;
uint16_t status = 0;
uint32_t wpkt_quanta_old;
- wpkt_quanta_old =
- atomic_load_explicit(&peer->bgp->wpkt_quanta, memory_order_relaxed);
+ wpkt_quanta_old = atomic_load_explicit(&peer->bgp->wpkt_quanta,
+ memory_order_relaxed);
while (count < wpkt_quanta_old && (s = stream_fifo_head(peer->obuf))) {
int writenum;
do {
writenum = stream_get_endp(s) - stream_get_getp(s);
- num = write(peer->fd, STREAM_PNT(s), writenum);
+ num = write(peer->fd, stream_pnt(s), writenum);
if (num < 0) {
if (!ERRNO_IO_RETRY(errno)) {
/* EAGAIN or EWOULDBLOCK; come back later */
if (nbytes < 0 && ERRNO_IO_RETRY(errno)) {
SET_FLAG(status, BGP_IO_TRANS_ERR);
- /* Fatal error; tear down session */
+ /* Fatal error; tear down session */
} else if (nbytes < 0) {
- zlog_err("%s [Error] bgp_read_packet error: %s", peer->host,
+ flog_err(EC_BGP_UPDATE_RCV,
+ "%s [Error] bgp_read_packet error: %s", peer->host,
safe_strerror(errno));
if (peer->status == Established) {
BGP_EVENT_ADD(peer, TCP_fatal_error);
SET_FLAG(status, BGP_IO_FATAL_ERR);
- /* Received EOF / TCP session closed */
+ /* Received EOF / TCP session closed */
} else if (nbytes == 0) {
if (bgp_debug_neighbor_events(peer))
zlog_debug("%s [Event] BGP connection closed fd %d",
type);
bgp_notify_send_with_data(peer, BGP_NOTIFY_HEADER_ERR,
- BGP_NOTIFY_HEADER_BAD_MESTYPE,
- &type, 1);
+ BGP_NOTIFY_HEADER_BAD_MESTYPE, &type,
+ 1);
return false;
}
zlog_debug("%s bad message length - %d for %s",
peer->host, size,
type == 128 ? "ROUTE-REFRESH"
- : bgp_type_str[(int) type]);
+ : bgp_type_str[(int)type]);
}
uint16_t nsize = htons(size);
bgp_notify_send_with_data(peer, BGP_NOTIFY_HEADER_ERR,
BGP_NOTIFY_HEADER_BAD_MESLEN,
- (unsigned char *) &nsize, 2);
+ (unsigned char *)&nsize, 2);
return false;
}