aboutgitcodebugslistschat
path: root/icmp.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2024-01-16 16:16:12 +1100
committerStefano Brivio <sbrivio@redhat.com>2024-01-22 23:36:43 +0100
commit24badd0acf887fdd9009e4c249bf0e68344ea49d (patch)
treecebbf6e58890cfffa37fed36d86a69ce53991c65 /icmp.c
parent43713af50e8a343e0df1f219a29e3d2891a094d6 (diff)
downloadpasst-24badd0acf887fdd9009e4c249bf0e68344ea49d.tar
passt-24badd0acf887fdd9009e4c249bf0e68344ea49d.tar.gz
passt-24badd0acf887fdd9009e4c249bf0e68344ea49d.tar.bz2
passt-24badd0acf887fdd9009e4c249bf0e68344ea49d.tar.lz
passt-24badd0acf887fdd9009e4c249bf0e68344ea49d.tar.xz
passt-24badd0acf887fdd9009e4c249bf0e68344ea49d.tar.zst
passt-24badd0acf887fdd9009e4c249bf0e68344ea49d.zip
icmp: Use -1 to represent "missing" sockets
icmp_id_map[] contains, amongst other things, fds for "ping" sockets associated with various ICMP echo ids. However, we only lazily open() those sockets, so many will be missing. We currently represent that with a 0, which isn't great, since that's technically a valid fd. Use -1 instead. This does require initializing the fields in icmp_id_map[] but we already have an obvious place to do that. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'icmp.c')
-rw-r--r--icmp.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/icmp.c b/icmp.c
index 2407daf..01ef34a 100644
--- a/icmp.c
+++ b/icmp.c
@@ -179,7 +179,7 @@ int icmp_tap_handler(const struct ctx *c, uint8_t pif, int af,
iref.id = id = ntohs(ih->un.echo.id);
- if ((s = icmp_id_map[V4][id].sock) <= 0) {
+ if ((s = icmp_id_map[V4][id].sock) < 0) {
s = sock_l4(c, AF_INET, IPPROTO_ICMP, &c->ip4.addr_out,
c->ip4.ifname_out, 0, iref.u32);
if (s < 0)
@@ -221,7 +221,7 @@ int icmp_tap_handler(const struct ctx *c, uint8_t pif, int af,
return 1;
iref.id = id = ntohs(ih->icmp6_identifier);
- if ((s = icmp_id_map[V6][id].sock) <= 0) {
+ if ((s = icmp_id_map[V6][id].sock) < 0) {
s = sock_l4(c, AF_INET6, IPPROTO_ICMPV6,
&c->ip6.addr_out,
c->ip6.ifname_out, 0, iref.u32);
@@ -277,7 +277,7 @@ static void icmp_timer_one(const struct ctx *c, int v6, uint16_t id,
epoll_ctl(c->epollfd, EPOLL_CTL_DEL, id_map->sock, NULL);
close(id_map->sock);
- id_map->sock = 0;
+ id_map->sock = -1;
id_map->seq = -1;
}
@@ -315,6 +315,8 @@ void icmp_init(void)
{
unsigned i;
- for (i = 0; i < ICMP_NUM_IDS; i++)
+ for (i = 0; i < ICMP_NUM_IDS; i++) {
icmp_id_map[V4][i].seq = icmp_id_map[V6][i].seq = -1;
+ icmp_id_map[V4][i].sock = icmp_id_map[V6][i].sock = -1;
+ }
}