bgpd: Convert bgp_io.c to take struct peer_connection

bgp_io.c is clearly connection oriented so let's convert
it over to using `struct peer_connection`

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
This commit is contained in:
Donald Sharp 2021-04-30 16:39:40 -04:00
parent 84d1abd3d9
commit ccb51e8266
6 changed files with 129 additions and 113 deletions

View file

@ -149,10 +149,10 @@ static struct peer *peer_xfer_conn(struct peer *from_peer)
from_peer->host, from_peer, from_peer->connection.fd, from_peer->host, from_peer, from_peer->connection.fd,
peer, peer->connection.fd); peer, peer->connection.fd);
bgp_writes_off(peer); bgp_writes_off(&peer->connection);
bgp_reads_off(peer); bgp_reads_off(&peer->connection);
bgp_writes_off(from_peer); bgp_writes_off(&from_peer->connection);
bgp_reads_off(from_peer); bgp_reads_off(&from_peer->connection);
/* /*
* Before exchanging FD remove doppelganger from * Before exchanging FD remove doppelganger from
@ -338,9 +338,9 @@ static struct peer *peer_xfer_conn(struct peer *from_peer)
if (from_peer) if (from_peer)
bgp_replace_nexthop_by_peer(from_peer, peer); bgp_replace_nexthop_by_peer(from_peer, peer);
bgp_reads_on(peer); bgp_reads_on(&peer->connection);
bgp_writes_on(peer); bgp_writes_on(&peer->connection);
event_add_event(bm->master, bgp_process_packet, peer, 0, event_add_event(bm->master, bgp_process_packet, &peer->connection, 0,
&peer->t_process_packet); &peer->t_process_packet);
return (peer); return (peer);
@ -1500,8 +1500,8 @@ enum bgp_fsm_state_progress bgp_stop(struct peer *peer)
bgp_keepalives_off(peer); bgp_keepalives_off(peer);
/* Stop read and write threads. */ /* Stop read and write threads. */
bgp_writes_off(peer); bgp_writes_off(&peer->connection);
bgp_reads_off(peer); bgp_reads_off(&peer->connection);
EVENT_OFF(peer->t_connect_check_r); EVENT_OFF(peer->t_connect_check_r);
EVENT_OFF(peer->t_connect_check_w); EVENT_OFF(peer->t_connect_check_w);
@ -1710,7 +1710,7 @@ static enum bgp_fsm_state_progress bgp_connect_success(struct peer *peer)
__func__, peer->host, peer->connection.fd); __func__, peer->host, peer->connection.fd);
bgp_notify_send(peer, BGP_NOTIFY_FSM_ERR, bgp_notify_send(peer, BGP_NOTIFY_FSM_ERR,
bgp_fsm_error_subcode(peer->status)); bgp_fsm_error_subcode(peer->status));
bgp_writes_on(peer); bgp_writes_on(&peer->connection);
return BGP_FSM_FAILURE; return BGP_FSM_FAILURE;
} }
@ -1720,7 +1720,7 @@ static enum bgp_fsm_state_progress bgp_connect_success(struct peer *peer)
*/ */
bgp_nht_interface_events(peer); bgp_nht_interface_events(peer);
bgp_reads_on(peer); bgp_reads_on(&peer->connection);
if (bgp_debug_neighbor_events(peer)) { if (bgp_debug_neighbor_events(peer)) {
if (!CHECK_FLAG(peer->sflags, PEER_STATUS_ACCEPT_PEER)) if (!CHECK_FLAG(peer->sflags, PEER_STATUS_ACCEPT_PEER))
@ -1754,7 +1754,7 @@ bgp_connect_success_w_delayopen(struct peer *peer)
__func__, peer->host, peer->connection.fd); __func__, peer->host, peer->connection.fd);
bgp_notify_send(peer, BGP_NOTIFY_FSM_ERR, bgp_notify_send(peer, BGP_NOTIFY_FSM_ERR,
bgp_fsm_error_subcode(peer->status)); bgp_fsm_error_subcode(peer->status));
bgp_writes_on(peer); bgp_writes_on(&peer->connection);
return BGP_FSM_FAILURE; return BGP_FSM_FAILURE;
} }
@ -1764,7 +1764,7 @@ bgp_connect_success_w_delayopen(struct peer *peer)
*/ */
bgp_nht_interface_events(peer); bgp_nht_interface_events(peer);
bgp_reads_on(peer); bgp_reads_on(&peer->connection);
if (bgp_debug_neighbor_events(peer)) { if (bgp_debug_neighbor_events(peer)) {
if (!CHECK_FLAG(peer->sflags, PEER_STATUS_ACCEPT_PEER)) if (!CHECK_FLAG(peer->sflags, PEER_STATUS_ACCEPT_PEER))

View file

@ -29,11 +29,11 @@
/* clang-format on */ /* clang-format on */
/* forward declarations */ /* forward declarations */
static uint16_t bgp_write(struct peer *); static uint16_t bgp_write(struct peer_connection *connection);
static uint16_t bgp_read(struct peer *peer, int *code_p); static uint16_t bgp_read(struct peer_connection *connection, int *code_p);
static void bgp_process_writes(struct event *event); static void bgp_process_writes(struct event *event);
static void bgp_process_reads(struct event *event); static void bgp_process_reads(struct event *event);
static bool validate_header(struct peer *); static bool validate_header(struct peer_connection *connection);
/* generic i/o status codes */ /* generic i/o status codes */
#define BGP_IO_TRANS_ERR (1 << 0) /* EAGAIN or similar occurred */ #define BGP_IO_TRANS_ERR (1 << 0) /* EAGAIN or similar occurred */
@ -42,26 +42,29 @@ static bool validate_header(struct peer *);
/* Thread external API ----------------------------------------------------- */ /* Thread external API ----------------------------------------------------- */
void bgp_writes_on(struct peer *peer) void bgp_writes_on(struct peer_connection *connection)
{ {
struct frr_pthread *fpt = bgp_pth_io; struct frr_pthread *fpt = bgp_pth_io;
struct peer *peer = connection->peer;
assert(fpt->running); assert(fpt->running);
assert(peer->status != Deleted); assert(peer->status != Deleted);
assert(peer->connection.obuf); assert(connection->obuf);
assert(peer->connection.ibuf); assert(connection->ibuf);
assert(peer->connection.ibuf_work); assert(connection->ibuf_work);
assert(!peer->t_connect_check_r); assert(!peer->t_connect_check_r);
assert(!peer->t_connect_check_w); assert(!peer->t_connect_check_w);
assert(peer->connection.fd); assert(connection->fd);
event_add_write(fpt->master, bgp_process_writes, peer, event_add_write(fpt->master, bgp_process_writes, connection,
peer->connection.fd, &peer->t_write); connection->fd, &peer->t_write);
SET_FLAG(peer->thread_flags, PEER_THREAD_WRITES_ON); SET_FLAG(peer->thread_flags, PEER_THREAD_WRITES_ON);
} }
void bgp_writes_off(struct peer *peer) void bgp_writes_off(struct peer_connection *connection)
{ {
struct peer *peer = connection->peer;
struct frr_pthread *fpt = bgp_pth_io; struct frr_pthread *fpt = bgp_pth_io;
assert(fpt->running); assert(fpt->running);
@ -71,28 +74,30 @@ void bgp_writes_off(struct peer *peer)
UNSET_FLAG(peer->thread_flags, PEER_THREAD_WRITES_ON); UNSET_FLAG(peer->thread_flags, PEER_THREAD_WRITES_ON);
} }
void bgp_reads_on(struct peer *peer) void bgp_reads_on(struct peer_connection *connection)
{ {
struct peer *peer = connection->peer;
struct frr_pthread *fpt = bgp_pth_io; struct frr_pthread *fpt = bgp_pth_io;
assert(fpt->running); assert(fpt->running);
assert(peer->status != Deleted); assert(peer->status != Deleted);
assert(peer->connection.ibuf); assert(connection->ibuf);
assert(peer->connection.fd); assert(connection->fd);
assert(peer->connection.ibuf_work); assert(connection->ibuf_work);
assert(peer->connection.obuf); assert(connection->obuf);
assert(!peer->t_connect_check_r); assert(!peer->t_connect_check_r);
assert(!peer->t_connect_check_w); assert(!peer->t_connect_check_w);
assert(peer->connection.fd); assert(connection->fd);
event_add_read(fpt->master, bgp_process_reads, peer, event_add_read(fpt->master, bgp_process_reads, connection,
peer->connection.fd, &peer->t_read); connection->fd, &peer->t_read);
SET_FLAG(peer->thread_flags, PEER_THREAD_READS_ON); SET_FLAG(peer->thread_flags, PEER_THREAD_READS_ON);
} }
void bgp_reads_off(struct peer *peer) void bgp_reads_off(struct peer_connection *connection)
{ {
struct peer *peer = connection->peer;
struct frr_pthread *fpt = bgp_pth_io; struct frr_pthread *fpt = bgp_pth_io;
assert(fpt->running); assert(fpt->running);
@ -111,19 +116,21 @@ void bgp_reads_off(struct peer *peer)
static void bgp_process_writes(struct event *thread) static void bgp_process_writes(struct event *thread)
{ {
static struct peer *peer; static struct peer *peer;
peer = EVENT_ARG(thread); struct peer_connection *connection = EVENT_ARG(thread);
uint16_t status; uint16_t status;
bool reschedule; bool reschedule;
bool fatal = false; bool fatal = false;
if (peer->connection.fd < 0) peer = connection->peer;
if (connection->fd < 0)
return; return;
struct frr_pthread *fpt = bgp_pth_io; struct frr_pthread *fpt = bgp_pth_io;
frr_with_mutex (&peer->connection.io_mtx) { frr_with_mutex (&connection->io_mtx) {
status = bgp_write(peer); status = bgp_write(connection);
reschedule = (stream_fifo_head(peer->connection.obuf) != NULL); reschedule = (stream_fifo_head(connection->obuf) != NULL);
} }
/* no problem */ /* no problem */
@ -142,26 +149,26 @@ static void bgp_process_writes(struct event *thread)
* sent in the update message * sent in the update message
*/ */
if (reschedule) { if (reschedule) {
event_add_write(fpt->master, bgp_process_writes, peer, event_add_write(fpt->master, bgp_process_writes, connection,
peer->connection.fd, &peer->t_write); connection->fd, &peer->t_write);
} else if (!fatal) { } else if (!fatal) {
BGP_UPDATE_GROUP_TIMER_ON(&peer->t_generate_updgrp_packets, BGP_UPDATE_GROUP_TIMER_ON(&peer->t_generate_updgrp_packets,
bgp_generate_updgrp_packets); bgp_generate_updgrp_packets);
} }
} }
static int read_ibuf_work(struct peer *peer) static int read_ibuf_work(struct peer_connection *connection)
{ {
/* static buffer for transferring packets */ /* static buffer for transferring packets */
/* shorter alias to peer's input buffer */ /* shorter alias to peer's input buffer */
struct ringbuf *ibw = peer->connection.ibuf_work; struct ringbuf *ibw = connection->ibuf_work;
/* packet size as given by header */ /* packet size as given by header */
uint16_t pktsize = 0; uint16_t pktsize = 0;
struct stream *pkt; struct stream *pkt;
/* ============================================== */ /* ============================================== */
frr_with_mutex (&peer->connection.io_mtx) { frr_with_mutex (&connection->io_mtx) {
if (peer->connection.ibuf->count >= bm->inq_limit) if (connection->ibuf->count >= bm->inq_limit)
return -ENOMEM; return -ENOMEM;
} }
@ -170,7 +177,7 @@ static int read_ibuf_work(struct peer *peer)
return 0; return 0;
/* check that header is valid */ /* check that header is valid */
if (!validate_header(peer)) if (!validate_header(connection))
return -EBADMSG; return -EBADMSG;
/* header is valid; retrieve packet size */ /* header is valid; retrieve packet size */
@ -179,7 +186,7 @@ static int read_ibuf_work(struct peer *peer)
pktsize = ntohs(pktsize); pktsize = ntohs(pktsize);
/* if this fails we are seriously screwed */ /* if this fails we are seriously screwed */
assert(pktsize <= peer->max_packet_size); assert(pktsize <= connection->peer->max_packet_size);
/* /*
* If we have that much data, chuck it into its own * If we have that much data, chuck it into its own
@ -195,9 +202,9 @@ static int read_ibuf_work(struct peer *peer)
assert(ringbuf_get(ibw, pkt->data, pktsize) == pktsize); assert(ringbuf_get(ibw, pkt->data, pktsize) == pktsize);
stream_set_endp(pkt, pktsize); stream_set_endp(pkt, pktsize);
frrtrace(2, frr_bgp, packet_read, peer, pkt); frrtrace(2, frr_bgp, packet_read, connection->peer, pkt);
frr_with_mutex (&peer->connection.io_mtx) { frr_with_mutex (&connection->io_mtx) {
stream_fifo_push(peer->connection.ibuf, pkt); stream_fifo_push(connection->ibuf, pkt);
} }
return pktsize; return pktsize;
@ -214,6 +221,7 @@ static int read_ibuf_work(struct peer *peer)
static void bgp_process_reads(struct event *thread) static void bgp_process_reads(struct event *thread)
{ {
/* clang-format off */ /* clang-format off */
struct peer_connection *connection = EVENT_ARG(thread);
static struct peer *peer; /* peer to read from */ static struct peer *peer; /* peer to read from */
uint16_t status; /* bgp_read status code */ uint16_t status; /* bgp_read status code */
bool fatal = false; /* whether fatal error occurred */ bool fatal = false; /* whether fatal error occurred */
@ -223,15 +231,15 @@ static void bgp_process_reads(struct event *thread)
int ret = 1; int ret = 1;
/* clang-format on */ /* clang-format on */
peer = EVENT_ARG(thread); peer = connection->peer;
if (bm->terminating || peer->connection.fd < 0) if (bm->terminating || connection->fd < 0)
return; return;
struct frr_pthread *fpt = bgp_pth_io; struct frr_pthread *fpt = bgp_pth_io;
frr_with_mutex (&peer->connection.io_mtx) { frr_with_mutex (&connection->io_mtx) {
status = bgp_read(peer, &code); status = bgp_read(connection, &code);
} }
/* error checking phase */ /* error checking phase */
@ -247,13 +255,13 @@ static void bgp_process_reads(struct event *thread)
/* Handle the error in the main pthread, include the /* Handle the error in the main pthread, include the
* specific state change from 'bgp_read'. * specific state change from 'bgp_read'.
*/ */
event_add_event(bm->master, bgp_packet_process_error, peer, event_add_event(bm->master, bgp_packet_process_error,
code, &peer->t_process_packet_error); connection, code, &peer->t_process_packet_error);
goto done; goto done;
} }
while (true) { while (true) {
ret = read_ibuf_work(peer); ret = read_ibuf_work(connection);
if (ret <= 0) if (ret <= 0)
break; break;
@ -283,14 +291,14 @@ done:
/* handle invalid header */ /* handle invalid header */
if (fatal) { if (fatal) {
/* wipe buffer just in case someone screwed up */ /* wipe buffer just in case someone screwed up */
ringbuf_wipe(peer->connection.ibuf_work); ringbuf_wipe(connection->ibuf_work);
return; return;
} }
event_add_read(fpt->master, bgp_process_reads, peer, event_add_read(fpt->master, bgp_process_reads, peer, connection->fd,
peer->connection.fd, &peer->t_read); &peer->t_read);
if (added_pkt) if (added_pkt)
event_add_event(bm->master, bgp_process_packet, peer, 0, event_add_event(bm->master, bgp_process_packet, connection, 0,
&peer->t_process_packet); &peer->t_process_packet);
} }
@ -307,8 +315,9 @@ done:
* The return value is equal to the number of packets written * The return value is equal to the number of packets written
* (which may be zero). * (which may be zero).
*/ */
static uint16_t bgp_write(struct peer *peer) static uint16_t bgp_write(struct peer_connection *connection)
{ {
struct peer *peer = connection->peer;
uint8_t type; uint8_t type;
struct stream *s; struct stream *s;
int update_last_write = 0; int update_last_write = 0;
@ -330,7 +339,7 @@ static uint16_t bgp_write(struct peer *peer)
struct stream **streams = ostreams; struct stream **streams = ostreams;
struct iovec iov[wpkt_quanta_old]; struct iovec iov[wpkt_quanta_old];
s = stream_fifo_head(peer->connection.obuf); s = stream_fifo_head(connection->obuf);
if (!s) if (!s)
goto done; goto done;
@ -350,7 +359,7 @@ static uint16_t bgp_write(struct peer *peer)
total_written = 0; total_written = 0;
do { do {
num = writev(peer->connection.fd, iov, iovsz); num = writev(connection->fd, iov, iovsz);
if (num < 0) { if (num < 0) {
if (!ERRNO_IO_RETRY(errno)) { if (!ERRNO_IO_RETRY(errno)) {
@ -399,7 +408,7 @@ static uint16_t bgp_write(struct peer *peer)
/* Handle statistics */ /* Handle statistics */
for (unsigned int i = 0; i < total_written; i++) { for (unsigned int i = 0; i < total_written; i++) {
s = stream_fifo_pop(peer->connection.obuf); s = stream_fifo_pop(connection->obuf);
assert(s == ostreams[i]); assert(s == ostreams[i]);
@ -490,14 +499,14 @@ uint8_t ibuf_scratch[BGP_EXTENDED_MESSAGE_MAX_PACKET_SIZE * BGP_READ_PACKET_MAX]
* per peer then we need to rethink the global ibuf_scratch * per peer then we need to rethink the global ibuf_scratch
* data structure above. * data structure above.
*/ */
static uint16_t bgp_read(struct peer *peer, int *code_p) static uint16_t bgp_read(struct peer_connection *connection, int *code_p)
{ {
size_t readsize; /* how many bytes we want to read */ size_t readsize; /* how many bytes we want to read */
ssize_t nbytes; /* how many bytes we actually read */ ssize_t nbytes; /* how many bytes we actually read */
size_t ibuf_work_space; /* space we can read into the work buf */ size_t ibuf_work_space; /* space we can read into the work buf */
uint16_t status = 0; uint16_t status = 0;
ibuf_work_space = ringbuf_space(peer->connection.ibuf_work); ibuf_work_space = ringbuf_space(connection->ibuf_work);
if (ibuf_work_space == 0) { if (ibuf_work_space == 0) {
SET_FLAG(status, BGP_IO_WORK_FULL_ERR); SET_FLAG(status, BGP_IO_WORK_FULL_ERR);
@ -506,7 +515,7 @@ static uint16_t bgp_read(struct peer *peer, int *code_p)
readsize = MIN(ibuf_work_space, sizeof(ibuf_scratch)); readsize = MIN(ibuf_work_space, sizeof(ibuf_scratch));
nbytes = read(peer->connection.fd, ibuf_scratch, readsize); nbytes = read(connection->fd, ibuf_scratch, readsize);
/* EAGAIN or EWOULDBLOCK; come back later */ /* EAGAIN or EWOULDBLOCK; come back later */
if (nbytes < 0 && ERRNO_IO_RETRY(errno)) { if (nbytes < 0 && ERRNO_IO_RETRY(errno)) {
@ -514,8 +523,8 @@ static uint16_t bgp_read(struct peer *peer, int *code_p)
} else if (nbytes < 0) { } else if (nbytes < 0) {
/* Fatal error; tear down session */ /* Fatal error; tear down session */
flog_err(EC_BGP_UPDATE_RCV, flog_err(EC_BGP_UPDATE_RCV,
"%s [Error] bgp_read_packet error: %s", peer->host, "%s [Error] bgp_read_packet error: %s",
safe_strerror(errno)); connection->peer->host, safe_strerror(errno));
/* Handle the error in the main pthread. */ /* Handle the error in the main pthread. */
if (code_p) if (code_p)
@ -525,9 +534,9 @@ static uint16_t bgp_read(struct peer *peer, int *code_p)
} else if (nbytes == 0) { } else if (nbytes == 0) {
/* Received EOF / TCP session closed */ /* Received EOF / TCP session closed */
if (bgp_debug_neighbor_events(peer)) if (bgp_debug_neighbor_events(connection->peer))
zlog_debug("%s [Event] BGP connection closed fd %d", zlog_debug("%s [Event] BGP connection closed fd %d",
peer->host, peer->connection.fd); connection->peer->host, connection->fd);
/* Handle the error in the main pthread. */ /* Handle the error in the main pthread. */
if (code_p) if (code_p)
@ -535,7 +544,7 @@ static uint16_t bgp_read(struct peer *peer, int *code_p)
SET_FLAG(status, BGP_IO_FATAL_ERR); SET_FLAG(status, BGP_IO_FATAL_ERR);
} else { } else {
assert(ringbuf_put(peer->connection.ibuf_work, ibuf_scratch, assert(ringbuf_put(connection->ibuf_work, ibuf_scratch,
nbytes) == (size_t)nbytes); nbytes) == (size_t)nbytes);
} }
@ -549,11 +558,12 @@ static uint16_t bgp_read(struct peer *peer, int *code_p)
* Assumes that there are at least BGP_HEADER_SIZE readable bytes in the input * Assumes that there are at least BGP_HEADER_SIZE readable bytes in the input
* buffer. * buffer.
*/ */
static bool validate_header(struct peer *peer) static bool validate_header(struct peer_connection *connection)
{ {
struct peer *peer = connection->peer;
uint16_t size; uint16_t size;
uint8_t type; uint8_t type;
struct ringbuf *pkt = peer->connection.ibuf_work; struct ringbuf *pkt = connection->ibuf_work;
static const uint8_t m_correct[BGP_MARKER_SIZE] = { static const uint8_t m_correct[BGP_MARKER_SIZE] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,

View file

@ -14,6 +14,8 @@
#include "bgpd/bgpd.h" #include "bgpd/bgpd.h"
#include "frr_pthread.h" #include "frr_pthread.h"
struct peer_connection;
/** /**
* Start function for write thread. * Start function for write thread.
* *
@ -33,57 +35,57 @@ extern int bgp_io_stop(void **result, struct frr_pthread *fpt);
/** /**
* Turns on packet writing for a peer. * Turns on packet writing for a peer.
* *
* After this function is called, any packets placed on peer->obuf will be * After this function is called, any packets placed on connection->obuf will be
* written to peer->fd until no more packets remain. * written to connection->fd until no more packets remain.
* *
* Additionally, it becomes unsafe to perform socket actions on peer->fd. * Additionally, it becomes unsafe to perform socket actions on connection->fd.
* *
* @param peer - peer to register * @param peer - peer to register
*/ */
extern void bgp_writes_on(struct peer *peer); extern void bgp_writes_on(struct peer_connection *peer);
/** /**
* Turns off packet writing for a peer. * Turns off packet writing for a peer.
* *
* After this function returns, packets placed on peer->obuf will not be * After this function returns, packets placed on connection->obuf will not be
* written to peer->fd by the I/O thread. * written to connection->fd by the I/O thread.
* *
* After this function returns it becomes safe to perform socket actions on * After this function returns it becomes safe to perform socket actions on
* peer->fd. * connection->fd.
* *
* @param peer - peer to deregister * @param connection - connection to deregister
* @param flush - as described * @param flush - as described
*/ */
extern void bgp_writes_off(struct peer *peer); extern void bgp_writes_off(struct peer_connection *connection);
/** /**
* Turns on packet reading for a peer. * Turns on packet reading for a peer.
* *
* After this function is called, any packets received on peer->fd will be read * After this function is called, any packets received on connection->fd
* and copied into the FIFO queue peer->ibuf. * will be read and copied into the FIFO queue connection->ibuf.
* *
* Additionally, it becomes unsafe to perform socket actions on peer->fd. * Additionally, it becomes unsafe to perform socket actions on connection->fd.
* *
* Whenever one or more packets are placed onto peer->ibuf, a task of type * Whenever one or more packets are placed onto connection->ibuf, a task of type
* THREAD_EVENT will be placed on the main thread whose handler is * THREAD_EVENT will be placed on the main thread whose handler is
* *
* bgp_packet.c:bgp_process_packet() * bgp_packet.c:bgp_process_packet()
* *
* @param peer - peer to register * @param connection - The connection to register
*/ */
extern void bgp_reads_on(struct peer *peer); extern void bgp_reads_on(struct peer_connection *connection);
/** /**
* Turns off packet reading for a peer. * Turns off packet reading for a peer.
* *
* After this function is called, any packets received on peer->fd will not be * After this function is called, any packets received on connection->fd
* read by the I/O thread. * will not be read by the I/O thread.
* *
* After this function returns it becomes safe to perform socket actions on * After this function returns it becomes safe to perform socket actions on
* peer->fd. * connection->fd.
* *
* @param peer - peer to deregister * @param connection - The connection to register for
*/ */
extern void bgp_reads_off(struct peer *peer); extern void bgp_reads_off(struct peer_connection *connection);
#endif /* _FRR_BGP_IO_H */ #endif /* _FRR_BGP_IO_H */

View file

@ -608,7 +608,7 @@ void bgp_generate_updgrp_packets(struct event *thread)
(peer->connection.obuf->count <= bm->outq_limit)); (peer->connection.obuf->count <= bm->outq_limit));
if (generated) if (generated)
bgp_writes_on(peer); bgp_writes_on(&peer->connection);
bgp_write_proceed_actions(peer); bgp_write_proceed_actions(peer);
} }
@ -637,7 +637,7 @@ void bgp_keepalive_send(struct peer *peer)
/* Add packet to the peer. */ /* Add packet to the peer. */
bgp_packet_add(peer, s); bgp_packet_add(peer, s);
bgp_writes_on(peer); bgp_writes_on(&peer->connection);
} }
/* /*
@ -706,7 +706,7 @@ void bgp_open_send(struct peer *peer)
/* Add packet to the peer. */ /* Add packet to the peer. */
bgp_packet_add(peer, s); bgp_packet_add(peer, s);
bgp_writes_on(peer); bgp_writes_on(&peer->connection);
} }
/* /*
@ -1181,7 +1181,7 @@ void bgp_route_refresh_send(struct peer *peer, afi_t afi, safi_t safi,
/* Add packet to the peer. */ /* Add packet to the peer. */
bgp_packet_add(peer, s); bgp_packet_add(peer, s);
bgp_writes_on(peer); bgp_writes_on(&peer->connection);
} }
/* /*
@ -1299,7 +1299,7 @@ void bgp_capability_send(struct peer *peer, afi_t afi, safi_t safi,
/* Add packet to the peer. */ /* Add packet to the peer. */
bgp_packet_add(peer, s); bgp_packet_add(peer, s);
bgp_writes_on(peer); bgp_writes_on(&peer->connection);
} }
/* RFC1771 6.8 Connection collision detection. */ /* RFC1771 6.8 Connection collision detection. */
@ -2989,11 +2989,13 @@ void bgp_process_packet(struct event *thread)
{ {
/* Yes first of all get peer pointer. */ /* Yes first of all get peer pointer. */
struct peer *peer; // peer struct peer *peer; // peer
struct peer_connection *connection;
uint32_t rpkt_quanta_old; // how many packets to read uint32_t rpkt_quanta_old; // how many packets to read
int fsm_update_result; // return code of bgp_event_update() int fsm_update_result; // return code of bgp_event_update()
int mprc; // message processing return code int mprc; // message processing return code
peer = EVENT_ARG(thread); connection = EVENT_ARG(thread);
peer = connection->peer;
rpkt_quanta_old = atomic_load_explicit(&peer->bgp->rpkt_quanta, rpkt_quanta_old = atomic_load_explicit(&peer->bgp->rpkt_quanta,
memory_order_relaxed); memory_order_relaxed);
fsm_update_result = 0; fsm_update_result = 0;
@ -3009,8 +3011,8 @@ void bgp_process_packet(struct event *thread)
bgp_size_t size; bgp_size_t size;
char notify_data_length[2]; char notify_data_length[2];
frr_with_mutex (&peer->connection.io_mtx) { frr_with_mutex (&connection->io_mtx) {
peer->curr = stream_fifo_pop(peer->connection.ibuf); peer->curr = stream_fifo_pop(connection->ibuf);
} }
if (peer->curr == NULL) // no packets to process, hmm... if (peer->curr == NULL) // no packets to process, hmm...
@ -3136,11 +3138,11 @@ void bgp_process_packet(struct event *thread)
if (fsm_update_result != FSM_PEER_TRANSFERRED if (fsm_update_result != FSM_PEER_TRANSFERRED
&& fsm_update_result != FSM_PEER_STOPPED) { && fsm_update_result != FSM_PEER_STOPPED) {
frr_with_mutex (&peer->connection.io_mtx) { frr_with_mutex (&connection->io_mtx) {
// more work to do, come back later // more work to do, come back later
if (peer->connection.ibuf->count > 0) if (connection->ibuf->count > 0)
event_add_event(bm->master, bgp_process_packet, event_add_event(bm->master, bgp_process_packet,
peer, 0, connection, 0,
&peer->t_process_packet); &peer->t_process_packet);
} }
} }
@ -3164,15 +3166,17 @@ void bgp_send_delayed_eor(struct bgp *bgp)
*/ */
void bgp_packet_process_error(struct event *thread) void bgp_packet_process_error(struct event *thread)
{ {
struct peer_connection *connection;
struct peer *peer; struct peer *peer;
int code; int code;
peer = EVENT_ARG(thread); connection = EVENT_ARG(thread);
peer = connection->peer;
code = EVENT_VAL(thread); code = EVENT_VAL(thread);
if (bgp_debug_neighbor_events(peer)) if (bgp_debug_neighbor_events(peer))
zlog_debug("%s [Event] BGP error %d on fd %d", peer->host, code, zlog_debug("%s [Event] BGP error %d on fd %d", peer->host, code,
peer->connection.fd); connection->fd);
/* Closed connection or error on the socket */ /* Closed connection or error on the socket */
if (peer_established(peer)) { if (peer_established(peer)) {

View file

@ -54,9 +54,9 @@ PKT_PROCESS_TRACEPOINT_INSTANCE(refresh_process)
TRACEPOINT_EVENT( TRACEPOINT_EVENT(
frr_bgp, frr_bgp,
packet_read, packet_read,
TP_ARGS(struct peer *, peer, struct stream *, pkt), TP_ARGS(struct peer_connection *, connection, struct stream *, pkt),
TP_FIELDS( TP_FIELDS(
ctf_string(peer, PEER_HOSTNAME(peer)) ctf_string(peer, PEER_HOSTNAME(connection->peer))
ctf_sequence_hex(uint8_t, packet, pkt->data, size_t, ctf_sequence_hex(uint8_t, packet, pkt->data, size_t,
STREAM_READABLE(pkt)) STREAM_READABLE(pkt))
) )

View file

@ -1179,8 +1179,8 @@ static void peer_free(struct peer *peer)
* but just to be sure.. * but just to be sure..
*/ */
bgp_timer_set(peer); bgp_timer_set(peer);
bgp_reads_off(peer); bgp_reads_off(&peer->connection);
bgp_writes_off(peer); bgp_writes_off(&peer->connection);
event_cancel_event_ready(bm->master, peer); event_cancel_event_ready(bm->master, peer);
FOREACH_AFI_SAFI (afi, safi) FOREACH_AFI_SAFI (afi, safi)
EVENT_OFF(peer->t_revalidate_all[afi][safi]); EVENT_OFF(peer->t_revalidate_all[afi][safi]);
@ -2562,8 +2562,8 @@ int peer_delete(struct peer *peer)
bgp_soft_reconfig_table_task_cancel(bgp, NULL, peer); bgp_soft_reconfig_table_task_cancel(bgp, NULL, peer);
bgp_keepalives_off(peer); bgp_keepalives_off(peer);
bgp_reads_off(peer); bgp_reads_off(&peer->connection);
bgp_writes_off(peer); bgp_writes_off(&peer->connection);
event_cancel_event_ready(bm->master, peer); event_cancel_event_ready(bm->master, peer);
FOREACH_AFI_SAFI (afi, safi) FOREACH_AFI_SAFI (afi, safi)
EVENT_OFF(peer->t_revalidate_all[afi][safi]); EVENT_OFF(peer->t_revalidate_all[afi][safi]);