summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaria Matejka <mq@ucw.cz>2023-04-20 21:06:42 +0200
committerMaria Matejka <mq@ucw.cz>2023-04-22 20:48:42 +0200
commitb3f805ce29487f790090fcf31096f5a7cf1d585d (patch)
tree5391762ee46af090a2ca5bb0d5674c66a8aab04e
parent074739e0e9baaba53f2a99edd348b76c3613b455 (diff)
Socket closing has its dedicated function
-rw-r--r--lib/socket.h1
-rw-r--r--nest/cli.c2
-rw-r--r--proto/babel/packets.c2
-rw-r--r--proto/bfd/bfd.c4
-rw-r--r--proto/bfd/packets.c6
-rw-r--r--proto/bgp/bgp.c12
-rw-r--r--proto/ospf/iface.c4
-rw-r--r--proto/radv/packets.c2
-rw-r--r--proto/rip/packets.c2
-rw-r--r--proto/rip/rip.c2
-rw-r--r--proto/rpki/transport.c2
-rw-r--r--sysdep/bsd/krt-sock.c4
-rw-r--r--sysdep/unix/io.c2
13 files changed, 23 insertions, 22 deletions
diff --git a/lib/socket.h b/lib/socket.h
index 4b169581..6225977b 100644
--- a/lib/socket.h
+++ b/lib/socket.h
@@ -88,6 +88,7 @@ sock *sock_new(pool *); /* Allocate new socket */
int sk_open(sock *, struct birdloop *); /* Open socket */
void sk_reloop(sock *, struct birdloop *); /* Move socket to another loop. Both loops must be locked. */
+static inline void sk_close(sock *s) { rfree(&s->r); } /* Explicitly close socket */
int sk_rx_ready(sock *s);
_Bool sk_tx_pending(sock *s);
diff --git a/nest/cli.c b/nest/cli.c
index 1debfccf..39a3eef7 100644
--- a/nest/cli.c
+++ b/nest/cli.c
@@ -417,7 +417,7 @@ cli_free(cli *c)
if (defer)
{
- rfree(c->sock);
+ sk_close(c->sock);
c->sock = NULL;
}
else
diff --git a/proto/babel/packets.c b/proto/babel/packets.c
index d26ee5c6..47d065cd 100644
--- a/proto/babel/packets.c
+++ b/proto/babel/packets.c
@@ -1680,7 +1680,7 @@ babel_open_socket(struct babel_iface *ifa)
err:
sk_log_error(sk, p->p.name);
- rfree(sk);
+ sk_close(sk);
return 0;
}
diff --git a/proto/bfd/bfd.c b/proto/bfd/bfd.c
index c88c1cb2..ddbc4948 100644
--- a/proto/bfd/bfd.c
+++ b/proto/bfd/bfd.c
@@ -604,10 +604,10 @@ bfd_free_iface(struct bfd_iface *ifa)
return;
if (ifa->sk)
- rfree(ifa->sk);
+ sk_close(ifa->sk);
if (ifa->rx)
- rfree(ifa->rx);
+ sk_close(ifa->rx);
rem_node(&ifa->n);
mb_free(ifa);
diff --git a/proto/bfd/packets.c b/proto/bfd/packets.c
index a22f223b..fa8c328f 100644
--- a/proto/bfd/packets.c
+++ b/proto/bfd/packets.c
@@ -439,7 +439,7 @@ bfd_open_rx_sk(struct bfd_proto *p, int multihop, int af)
err:
sk_log_error(sk, p->p.name);
- rfree(sk);
+ sk_close(sk);
return NULL;
}
@@ -470,7 +470,7 @@ bfd_open_rx_sk_bound(struct bfd_proto *p, ip_addr local, struct iface *ifa)
err:
sk_log_error(sk, p->p.name);
- rfree(sk);
+ sk_close(sk);
return NULL;
}
@@ -501,6 +501,6 @@ bfd_open_tx_sk(struct bfd_proto *p, ip_addr local, struct iface *ifa)
err:
sk_log_error(sk, p->p.name);
- rfree(sk);
+ sk_close(sk);
return NULL;
}
diff --git a/proto/bgp/bgp.c b/proto/bgp/bgp.c
index cda0eb8d..0525d502 100644
--- a/proto/bgp/bgp.c
+++ b/proto/bgp/bgp.c
@@ -294,7 +294,7 @@ bgp_listen_create(void *_ UNUSED)
{
sk_log_error(sk, p->p.name);
log(L_ERR "%s: Cannot open listening socket", p->p.name);
- rfree(sk);
+ sk_close(sk);
UNLOCK_DOMAIN(rtable, bgp_listen_domain);
bgp_initiate_disable(p, BEM_NO_SOCKET);
@@ -335,7 +335,7 @@ bgp_listen_create(void *_ UNUSED)
WALK_LIST_DELSAFE(bs, nxt, bgp_sockets)
if (EMPTY_LIST(bs->requests))
{
- rfree(bs->sk);
+ sk_close(bs->sk);
rem_node(&bs->n);
mb_free(bs);
}
@@ -465,7 +465,7 @@ bgp_close_conn(struct bgp_conn *conn)
rfree(conn->tx_ev);
conn->tx_ev = NULL;
- rfree(conn->sk);
+ sk_close(conn->sk);
conn->sk = NULL;
mb_free(conn->local_caps);
@@ -1336,7 +1336,7 @@ bgp_incoming_connection(sock *sk, uint dummy UNUSED)
{
log(L_WARN "BGP: Unexpected connect from unknown address %I%J (port %d)",
sk->daddr, ipa_is_link_local(sk->daddr) ? sk->iface : NULL, sk->dport);
- rfree(sk);
+ sk_close(sk);
return 0;
}
@@ -1370,7 +1370,7 @@ bgp_incoming_connection(sock *sk, uint dummy UNUSED)
if (!acc)
{
- rfree(sk);
+ sk_close(sk);
goto leave;
}
@@ -1410,7 +1410,7 @@ bgp_incoming_connection(sock *sk, uint dummy UNUSED)
err:
sk_log_error(sk, p->p.name);
log(L_ERR "%s: Incoming connection aborted", p->p.name);
- rfree(sk);
+ sk_close(sk);
leave:
birdloop_leave(p->p.loop);
diff --git a/proto/ospf/iface.c b/proto/ospf/iface.c
index 0aa7fa00..37f642d1 100644
--- a/proto/ospf/iface.c
+++ b/proto/ospf/iface.c
@@ -173,7 +173,7 @@ ospf_sk_open(struct ospf_iface *ifa)
err:
sk_log_error(sk, p->p.name);
- rfree(sk);
+ sk_close(sk);
return 0;
}
@@ -234,7 +234,7 @@ ospf_open_vlink_sk(struct ospf_proto *p)
err:
sk_log_error(sk, p->p.name);
log(L_ERR "%s: Cannot open virtual link socket", p->p.name);
- rfree(sk);
+ sk_close(sk);
}
static void
diff --git a/proto/radv/packets.c b/proto/radv/packets.c
index c6b565d2..d1d8663f 100644
--- a/proto/radv/packets.c
+++ b/proto/radv/packets.c
@@ -511,7 +511,7 @@ radv_sk_open(struct radv_iface *ifa)
err:
sk_log_error(sk, ifa->ra->p.name);
- rfree(sk);
+ sk_close(sk);
return 0;
}
diff --git a/proto/rip/packets.c b/proto/rip/packets.c
index fecdf896..70108ac3 100644
--- a/proto/rip/packets.c
+++ b/proto/rip/packets.c
@@ -1040,6 +1040,6 @@ rip_open_socket(struct rip_iface *ifa)
err:
sk_log_error(sk, p->p.name);
- rfree(sk);
+ sk_close(sk);
return 0;
}
diff --git a/proto/rip/rip.c b/proto/rip/rip.c
index d15177da..dded05c7 100644
--- a/proto/rip/rip.c
+++ b/proto/rip/rip.c
@@ -750,7 +750,7 @@ rip_remove_iface(struct rip_proto *p, struct rip_iface *ifa)
rem_node(NODE ifa);
- rfree(ifa->sk);
+ sk_close(ifa->sk);
rfree(ifa->lock);
rfree(ifa->timer);
diff --git a/proto/rpki/transport.c b/proto/rpki/transport.c
index 81bd6dd8..8c6dcc11 100644
--- a/proto/rpki/transport.c
+++ b/proto/rpki/transport.c
@@ -120,7 +120,7 @@ rpki_tr_close(struct rpki_tr_sock *tr)
if (tr->sk)
{
- rfree(tr->sk);
+ sk_close(tr->sk);
tr->sk = NULL;
}
}
diff --git a/sysdep/bsd/krt-sock.c b/sysdep/bsd/krt-sock.c
index 094268b7..6bf756ff 100644
--- a/sysdep/bsd/krt-sock.c
+++ b/sysdep/bsd/krt-sock.c
@@ -1118,7 +1118,7 @@ krt_sock_close_shared(void)
if (!krt_sock_count)
{
- rfree(krt_sock);
+ sk_close(krt_sock);
krt_sock = NULL;
}
}
@@ -1181,7 +1181,7 @@ krt_sys_shutdown(struct krt_proto *p)
{
krt_table_cf[(KRT_CF->sys.table_id)/32][!!(p->af == AF_INET6)] &= ~(1 << ((KRT_CF->sys.table_id)%32));
- rfree(p->sys.sk);
+ sk_close(p->sys.sk);
p->sys.sk = NULL;
krt_buffer_release(&p->p);
diff --git a/sysdep/unix/io.c b/sysdep/unix/io.c
index 88d187a4..40a6f114 100644
--- a/sysdep/unix/io.c
+++ b/sysdep/unix/io.c
@@ -1081,7 +1081,7 @@ sk_passive_connected(sock *s, int type)
/* FIXME: handle it better in rfree() */
close(t->fd);
t->fd = -1;
- rfree(t);
+ sk_close(t);
return 1;
}