aboutgitcodebugslistschat
path: root/util.c
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2021-03-17 10:57:44 +0100
committerStefano Brivio <sbrivio@redhat.com>2021-03-18 12:58:03 +0100
commit1d807fc720bda7ec446c683bbc1a5e32897ca04e (patch)
tree7dc59149a94817fa5eddc6aa6e132fa1a7335f19 /util.c
parentd32edee60a938c3ffdb227a94e1f3afac0e40177 (diff)
downloadpasst-1d807fc720bda7ec446c683bbc1a5e32897ca04e.tar
passt-1d807fc720bda7ec446c683bbc1a5e32897ca04e.tar.gz
passt-1d807fc720bda7ec446c683bbc1a5e32897ca04e.tar.bz2
passt-1d807fc720bda7ec446c683bbc1a5e32897ca04e.tar.lz
passt-1d807fc720bda7ec446c683bbc1a5e32897ca04e.tar.xz
passt-1d807fc720bda7ec446c683bbc1a5e32897ca04e.tar.zst
passt-1d807fc720bda7ec446c683bbc1a5e32897ca04e.zip
passt: Introduce ICMP echo proxy
It's nice to be able to confirm connectivity using ICMP or ICMPv6 echo requests, and "ping" sockets on Linux (IPPROTO_ICMP datagram) allow us to do that without any special capability. Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'util.c')
-rw-r--r--util.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/util.c b/util.c
index e8ee57f..44357b7 100644
--- a/util.c
+++ b/util.c
@@ -160,7 +160,8 @@ int sock_l4_add(struct ctx *c, int v, uint16_t proto, uint16_t port)
const struct sockaddr *sa;
int fd, sl, one = 1;
- if (proto != IPPROTO_TCP && proto != IPPROTO_UDP)
+ if (proto != IPPROTO_TCP && proto != IPPROTO_UDP &&
+ proto != IPPROTO_ICMP && proto != IPPROTO_ICMPV6)
return -1; /* Not implemented. */
fd = socket(v == 4 ? AF_INET : AF_INET6,
@@ -170,6 +171,9 @@ int sock_l4_add(struct ctx *c, int v, uint16_t proto, uint16_t port)
return -1;
}
+ if (proto == IPPROTO_ICMP || proto == IPPROTO_ICMPV6)
+ goto epoll_add;
+
if (v == 4) {
sa = (const struct sockaddr *)&addr4;
sl = sizeof(addr4);
@@ -195,6 +199,7 @@ int sock_l4_add(struct ctx *c, int v, uint16_t proto, uint16_t port)
return -1;
}
+epoll_add:
ev.events = EPOLLIN;
ev.data.fd = fd;
if (epoll_ctl(c->epollfd, EPOLL_CTL_ADD, fd, &ev) == -1) {