aboutgitcodebugslistschat
path: root/icmp.c
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2021-05-21 11:14:53 +0200
committerStefano Brivio <sbrivio@redhat.com>2021-05-21 11:14:53 +0200
commit9311ceb8b6fe7064cffca3efda051ef1e1801642 (patch)
tree6ffceb50e313b00305eedfb53341ed37a484b5fd /icmp.c
parent5fd6db7751c4fd20a4a2415fdda8b09b5ce524f9 (diff)
downloadpasst-9311ceb8b6fe7064cffca3efda051ef1e1801642.tar
passt-9311ceb8b6fe7064cffca3efda051ef1e1801642.tar.gz
passt-9311ceb8b6fe7064cffca3efda051ef1e1801642.tar.bz2
passt-9311ceb8b6fe7064cffca3efda051ef1e1801642.tar.lz
passt-9311ceb8b6fe7064cffca3efda051ef1e1801642.tar.xz
passt-9311ceb8b6fe7064cffca3efda051ef1e1801642.tar.zst
passt-9311ceb8b6fe7064cffca3efda051ef1e1801642.zip
icmp: Implement lazy bind for ping sockets
It turns out that binding ICMP/ICMPv6 echo sockets takes a long time. Instead of binding all of them (one for each possible echo identification number, that is, 2^17) at start-up, bind them as ICMP/ICMPv6 packets are sent by the guest. Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'icmp.c')
-rw-r--r--icmp.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/icmp.c b/icmp.c
index 08e7324..378e787 100644
--- a/icmp.c
+++ b/icmp.c
@@ -105,7 +105,8 @@ int icmp_tap_handler(struct ctx *c, int af, void *addr,
struct icmphdr *ih = (struct icmphdr *)msg[0].l4h;
struct sockaddr_in sa = {
.sin_family = AF_INET,
- .sin_addr = *(struct in_addr *)addr,
+ .sin_addr = { .s_addr = INADDR_ANY },
+ .sin_port = ih->un.echo.id,
};
if (msg[0].l4_len < sizeof(*ih) || ih->type != ICMP_ECHO)
@@ -114,6 +115,9 @@ int icmp_tap_handler(struct ctx *c, int af, void *addr,
if ((s = icmp_s_v4[ntohs(ih->un.echo.id)]) < 0)
return 1;
+ bind(s, (struct sockaddr *)&sa, sizeof(sa));
+
+ sa.sin_addr = *(struct in_addr *)addr;
sendto(s, msg[0].l4h, msg[0].l4_len,
MSG_DONTWAIT | MSG_NOSIGNAL,
(struct sockaddr *)&sa, sizeof(sa));
@@ -121,7 +125,8 @@ int icmp_tap_handler(struct ctx *c, int af, void *addr,
struct icmp6hdr *ih = (struct icmp6hdr *)msg[0].l4h;
struct sockaddr_in6 sa = {
.sin6_family = AF_INET6,
- .sin6_addr = *(struct in6_addr *)addr,
+ .sin6_addr = IN6ADDR_ANY_INIT,
+ .sin6_port = ih->icmp6_identifier,
};
if (msg[0].l4_len < sizeof(*ih) ||
@@ -131,6 +136,9 @@ int icmp_tap_handler(struct ctx *c, int af, void *addr,
if ((s = icmp_s_v6[ntohs(ih->icmp6_identifier)]) < 0)
return 1;
+ bind(s, (struct sockaddr *)&sa, sizeof(sa));
+
+ sa.sin6_addr = *(struct in6_addr *)addr;
sendto(s, msg[0].l4h, msg[0].l4_len,
MSG_DONTWAIT | MSG_NOSIGNAL,
(struct sockaddr *)&sa, sizeof(sa));