return peer->sort;
}
+/*
+ * Mutex will be freed in peer_connection_free
+ * this is a convenience function to reduce cut-n-paste
+ */
+void bgp_peer_connection_buffers_free(struct peer_connection *connection)
+{
+ frr_with_mutex (&connection->io_mtx) {
+ if (connection->ibuf) {
+ stream_fifo_free(connection->ibuf);
+ connection->ibuf = NULL;
+ }
+
+ if (connection->obuf) {
+ stream_fifo_free(connection->obuf);
+ connection->obuf = NULL;
+ }
+
+ if (connection->ibuf_work) {
+ ringbuf_del(connection->ibuf_work);
+ connection->ibuf_work = NULL;
+ }
+ }
+}
+
+static void bgp_peer_connection_free(struct peer_connection *connection)
+{
+ bgp_peer_connection_buffers_free(connection);
+ pthread_mutex_destroy(&connection->io_mtx);
+}
+
static void peer_free(struct peer *peer)
{
afi_t afi;
assert(!peer->t_read);
BGP_EVENT_FLUSH(peer);
- pthread_mutex_destroy(&peer->connection.io_mtx);
+ bgp_peer_connection_free(&peer->connection);
/* Free connected nexthop, if present */
if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE)
peer_unlock(peer); /* bgp peer list reference */
}
- /* Buffers. */
- if (peer->connection.ibuf) {
- stream_fifo_free(peer->connection.ibuf);
- peer->connection.ibuf = NULL;
- }
-
- if (peer->connection.obuf) {
- stream_fifo_free(peer->connection.obuf);
- peer->connection.obuf = NULL;
- }
-
- if (peer->connection.ibuf_work) {
- ringbuf_del(peer->connection.ibuf_work);
- peer->connection.ibuf_work = NULL;
- }
-
/* Local and remote addresses. */
if (peer->su_local) {
sockunion_free(peer->su_local);
struct ringbuf *ibuf_work; // WiP buffer used by bgp_read() only
};
+extern void bgp_peer_connection_buffers_free(struct peer_connection *connection);
/* BGP neighbor structure. */
struct peer {
rfd->peer = peer_new(bgp);
rfd->peer->status = Established; /* keep bgp core happy */
- /*
- * since this peer is not on the I/O thread, this lock is not strictly
- * necessary, but serves as a reminder to those who may meddle...
- */
- frr_with_mutex (&rfd->peer->connection.io_mtx) {
- // we don't need any I/O related facilities
- if (rfd->peer->connection.ibuf)
- stream_fifo_free(rfd->peer->connection.ibuf);
- if (rfd->peer->connection.obuf)
- stream_fifo_free(rfd->peer->connection.obuf);
-
- if (rfd->peer->connection.ibuf_work)
- ringbuf_del(rfd->peer->connection.ibuf_work);
-
- rfd->peer->connection.ibuf = NULL;
- rfd->peer->connection.obuf = NULL;
- rfd->peer->connection.ibuf_work = NULL;
- }
+ bgp_peer_connection_buffers_free(&rfd->peer->connection);
{ /* base code assumes have valid host pointer */
char buf[INET6_ADDRSTRLEN];
vncHD1VR.peer->status =
Established; /* keep bgp core happy */
- /*
- * since this peer is not on the I/O thread, this lock
- * is not strictly necessary, but serves as a reminder
- * to those who may meddle...
- */
- frr_with_mutex (&vncHD1VR.peer->connection.io_mtx) {
- // we don't need any I/O related facilities
- if (vncHD1VR.peer->connection.ibuf)
- stream_fifo_free(
- vncHD1VR.peer->connection.ibuf);
- if (vncHD1VR.peer->connection.obuf)
- stream_fifo_free(
- vncHD1VR.peer->connection.obuf);
-
- if (vncHD1VR.peer->connection.ibuf_work)
- ringbuf_del(vncHD1VR.peer->connection
- .ibuf_work);
-
- vncHD1VR.peer->connection.ibuf = NULL;
- vncHD1VR.peer->connection.obuf = NULL;
- vncHD1VR.peer->connection.ibuf_work = NULL;
- }
+ bgp_peer_connection_buffers_free(
+ &vncHD1VR.peer->connection);
/* base code assumes have valid host pointer */
vncHD1VR.peer->host =