bgpd: READ and WRITE flags are a part of the connection

Move PEER_THREAD_WRITES_ON and PEER_THREAD_READS_ON to
be a part of the `struct peer_connection` since this is
a connection oriented bit of data.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
This commit is contained in:
Donald Sharp 2021-06-03 15:20:11 -04:00
parent c528b3b153
commit 71d72c4998
6 changed files with 31 additions and 18 deletions

View File

@ -1657,8 +1657,10 @@ static void bgp_connect_check(struct event *thread)
struct peer *peer;
peer = EVENT_ARG(thread);
assert(!CHECK_FLAG(peer->thread_flags, PEER_THREAD_READS_ON));
assert(!CHECK_FLAG(peer->thread_flags, PEER_THREAD_WRITES_ON));
assert(!CHECK_FLAG(peer->connection.thread_flags,
PEER_THREAD_READS_ON));
assert(!CHECK_FLAG(peer->connection.thread_flags,
PEER_THREAD_WRITES_ON));
assert(!peer->connection.t_read);
assert(!peer->connection.t_write);
@ -1896,8 +1898,10 @@ enum bgp_fsm_state_progress bgp_start(struct peer *peer)
assert(!peer->connection.t_write);
assert(!peer->connection.t_read);
assert(!CHECK_FLAG(peer->thread_flags, PEER_THREAD_WRITES_ON));
assert(!CHECK_FLAG(peer->thread_flags, PEER_THREAD_READS_ON));
assert(!CHECK_FLAG(peer->connection.thread_flags,
PEER_THREAD_WRITES_ON));
assert(!CHECK_FLAG(peer->connection.thread_flags,
PEER_THREAD_READS_ON));
status = bgp_connect(peer);
switch (status) {

View File

@ -59,7 +59,7 @@ void bgp_writes_on(struct peer_connection *connection)
event_add_write(fpt->master, bgp_process_writes, connection,
connection->fd, &connection->t_write);
SET_FLAG(peer->thread_flags, PEER_THREAD_WRITES_ON);
SET_FLAG(connection->thread_flags, PEER_THREAD_WRITES_ON);
}
void bgp_writes_off(struct peer_connection *connection)
@ -71,7 +71,7 @@ void bgp_writes_off(struct peer_connection *connection)
event_cancel_async(fpt->master, &connection->t_write, NULL);
EVENT_OFF(peer->t_generate_updgrp_packets);
UNSET_FLAG(peer->thread_flags, PEER_THREAD_WRITES_ON);
UNSET_FLAG(peer->connection.thread_flags, PEER_THREAD_WRITES_ON);
}
void bgp_reads_on(struct peer_connection *connection)
@ -92,7 +92,7 @@ void bgp_reads_on(struct peer_connection *connection)
event_add_read(fpt->master, bgp_process_reads, connection,
connection->fd, &connection->t_read);
SET_FLAG(peer->thread_flags, PEER_THREAD_READS_ON);
SET_FLAG(connection->thread_flags, PEER_THREAD_READS_ON);
}
void bgp_reads_off(struct peer_connection *connection)
@ -105,7 +105,7 @@ void bgp_reads_off(struct peer_connection *connection)
EVENT_OFF(peer->t_process_packet);
EVENT_OFF(peer->t_process_packet_error);
UNSET_FLAG(peer->thread_flags, PEER_THREAD_READS_ON);
UNSET_FLAG(connection->thread_flags, PEER_THREAD_READS_ON);
}
/* Thread internal functions ----------------------------------------------- */

View File

@ -697,8 +697,10 @@ static int bgp_update_source(struct peer *peer)
/* BGP try to connect to the peer. */
int bgp_connect(struct peer *peer)
{
assert(!CHECK_FLAG(peer->thread_flags, PEER_THREAD_WRITES_ON));
assert(!CHECK_FLAG(peer->thread_flags, PEER_THREAD_READS_ON));
assert(!CHECK_FLAG(peer->connection.thread_flags,
PEER_THREAD_WRITES_ON));
assert(!CHECK_FLAG(peer->connection.thread_flags,
PEER_THREAD_READS_ON));
ifindex_t ifindex = 0;
if (peer->conf_if && BGP_PEER_SU_UNSPEC(peer)) {

View File

@ -15125,7 +15125,8 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
else
json_object_string_add(json_neigh, "readThread", "off");
if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
if (CHECK_FLAG(p->connection.thread_flags,
PEER_THREAD_WRITES_ON))
json_object_string_add(json_neigh, "writeThread", "on");
else
json_object_string_add(json_neigh, "writeThread",
@ -15157,7 +15158,8 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
p->connection.t_read ? "on" : "off",
CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
CHECK_FLAG(p->connection.thread_flags,
PEER_THREAD_WRITES_ON)
? "on"
: "off",
p->connection.fd);

View File

@ -2567,8 +2567,10 @@ int peer_delete(struct peer *peer)
event_cancel_event_ready(bm->master, peer);
FOREACH_AFI_SAFI (afi, safi)
EVENT_OFF(peer->t_revalidate_all[afi][safi]);
assert(!CHECK_FLAG(peer->thread_flags, PEER_THREAD_WRITES_ON));
assert(!CHECK_FLAG(peer->thread_flags, PEER_THREAD_READS_ON));
assert(!CHECK_FLAG(peer->connection.thread_flags,
PEER_THREAD_WRITES_ON));
assert(!CHECK_FLAG(peer->connection.thread_flags,
PEER_THREAD_READS_ON));
assert(!CHECK_FLAG(peer->thread_flags, PEER_THREAD_KEEPALIVES_ON));
if (CHECK_FLAG(peer->sflags, PEER_STATUS_NSF_WAIT))

View File

@ -1134,6 +1134,11 @@ struct peer_connection {
struct event *t_read;
struct event *t_write;
/* Thread flags */
_Atomic uint32_t thread_flags;
#define PEER_THREAD_WRITES_ON (1U << 0)
#define PEER_THREAD_READS_ON (1U << 1)
};
extern void bgp_peer_connection_buffers_free(struct peer_connection *connection);
@ -1558,10 +1563,8 @@ struct peer {
/* Thread flags. */
_Atomic uint32_t thread_flags;
#define PEER_THREAD_WRITES_ON (1U << 0)
#define PEER_THREAD_READS_ON (1U << 1)
#define PEER_THREAD_KEEPALIVES_ON (1U << 2)
#define PEER_THREAD_SUBGRP_ADV_DELAY (1U << 3)
#define PEER_THREAD_KEEPALIVES_ON (1U << 0)
#define PEER_THREAD_SUBGRP_ADV_DELAY (1U << 1)
/* workqueues */
struct work_queue *clear_node_queue;