summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bgpd/bgpd.c48
-rw-r--r--bgpd/bgpd.h1
-rw-r--r--bgpd/rfapi/rfapi.c19
-rw-r--r--bgpd/rfapi/vnc_zebra.c24
4 files changed, 35 insertions, 57 deletions
diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c
index c9cd55ee23..76c7859bab 100644
--- a/bgpd/bgpd.c
+++ b/bgpd/bgpd.c
@@ -1110,6 +1110,36 @@ enum bgp_peer_sort peer_sort_lookup(struct peer *peer)
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;
@@ -1132,7 +1162,7 @@ static void peer_free(struct peer *peer)
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)
@@ -2590,22 +2620,6 @@ int peer_delete(struct peer *peer)
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);
diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h
index 78876f65e1..7855d1d765 100644
--- a/bgpd/bgpd.h
+++ b/bgpd/bgpd.h
@@ -1130,6 +1130,7 @@ struct peer_connection {
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 {
diff --git a/bgpd/rfapi/rfapi.c b/bgpd/rfapi/rfapi.c
index 2de9508e9d..d24a07cd8a 100644
--- a/bgpd/rfapi/rfapi.c
+++ b/bgpd/rfapi/rfapi.c
@@ -1238,24 +1238,7 @@ static int rfapi_open_inner(struct rfapi_descriptor *rfd, struct bgp *bgp,
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];
diff --git a/bgpd/rfapi/vnc_zebra.c b/bgpd/rfapi/vnc_zebra.c
index edbe2e9f31..8a30edce91 100644
--- a/bgpd/rfapi/vnc_zebra.c
+++ b/bgpd/rfapi/vnc_zebra.c
@@ -174,28 +174,8 @@ static void vnc_redistribute_add(struct prefix *p, uint32_t metric,
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 =