aboutgitcodebugslistschat
path: root/icmp.c
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2021-04-22 13:39:36 +0200
committerStefano Brivio <sbrivio@redhat.com>2021-04-22 13:39:36 +0200
commit1f7cf04d343f185f9e044fdca70a1d0252492aed (patch)
tree77b28cc46e824f9247151ca21849e74da1cc0d57 /icmp.c
parent5b0c88d4ef48c2c3c434929faf418f46db06d555 (diff)
downloadpasst-1f7cf04d343f185f9e044fdca70a1d0252492aed.tar
passt-1f7cf04d343f185f9e044fdca70a1d0252492aed.tar.gz
passt-1f7cf04d343f185f9e044fdca70a1d0252492aed.tar.bz2
passt-1f7cf04d343f185f9e044fdca70a1d0252492aed.tar.lz
passt-1f7cf04d343f185f9e044fdca70a1d0252492aed.tar.xz
passt-1f7cf04d343f185f9e044fdca70a1d0252492aed.tar.zst
passt-1f7cf04d343f185f9e044fdca70a1d0252492aed.zip
passt: Introduce packet batching mechanism
Receive packets in batches from AF_UNIX, check if they can be sent with a single syscall, and batch them up with sendmmsg() in case. A bit rudimentary, currently only implemented for UDP, but it seems to work. Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'icmp.c')
-rw-r--r--icmp.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/icmp.c b/icmp.c
index b66c329..9a3c740 100644
--- a/icmp.c
+++ b/icmp.c
@@ -77,45 +77,54 @@ void icmp_sock_handler(struct ctx *c, int s, uint32_t events)
* icmp_tap_handler() - Handle packets from tap
* @c: Execution context
* @af: Address family, AF_INET or AF_INET6
- * @in: Input buffer
- * @len: Length, including UDP header
+ * @msg: Input message
+ * @count: Message count (always 1 for ICMP)
+ *
+ * Return: count of consumed packets (always 1, even if malformed)
*/
-void icmp_tap_handler(struct ctx *c, int af, void *addr, char *in, size_t len)
+int icmp_tap_handler(struct ctx *c, int af, void *addr,
+ struct tap_msg *msg, int count)
{
+ (void)count;
+
if (af == AF_INET) {
- struct icmphdr *ih = (struct icmphdr *)in;
+ struct icmphdr *ih = (struct icmphdr *)msg[0].l4h;
struct sockaddr_in sa = {
.sin_family = AF_INET,
.sin_addr.s_addr = htonl(INADDR_ANY),
};
- if (len < sizeof(*ih) || ih->type != ICMP_ECHO)
- return;
+ if (msg[0].l4_len < sizeof(*ih) || ih->type != ICMP_ECHO)
+ return 1;
sa.sin_port = ih->un.echo.id;
bind(c->icmp.s4, (struct sockaddr *)&sa, sizeof(sa));
sa.sin_addr = *(struct in_addr *)addr;
- sendto(c->icmp.s4, in, len, MSG_DONTWAIT,
+ sendto(c->icmp.s4, msg[0].l4h, msg[0].l4_len,
+ MSG_DONTWAIT | MSG_NOSIGNAL,
(struct sockaddr *)&sa, sizeof(sa));
} else if (af == AF_INET6) {
struct sockaddr_in6 sa = {
.sin6_family = AF_INET6,
.sin6_addr = IN6ADDR_ANY_INIT,
};
- struct icmp6hdr *ih = (struct icmp6hdr *)in;
+ struct icmp6hdr *ih = (struct icmp6hdr *)msg[0].l4h;
- if (len < sizeof(*ih) ||
+ if (msg[0].l4_len < sizeof(*ih) ||
(ih->icmp6_type != 128 && ih->icmp6_type != 129))
- return;
+ return 1;
sa.sin6_port = ih->icmp6_identifier;
bind(c->icmp.s6, (struct sockaddr *)&sa, sizeof(sa));
sa.sin6_addr = *(struct in6_addr *)addr;
- sendto(c->icmp.s6, in, len, MSG_DONTWAIT | MSG_NOSIGNAL,
+ sendto(c->icmp.s6, msg[0].l4h, msg[0].l4_len,
+ MSG_DONTWAIT | MSG_NOSIGNAL,
(struct sockaddr *)&sa, sizeof(sa));
}
+
+ return 1;
}
/**