aboutgitcodebugslistschat
path: root/passt.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2023-08-11 15:12:21 +1000
committerStefano Brivio <sbrivio@redhat.com>2023-08-13 17:29:51 +0200
commit34016444534120f2fa5a049675815843d041bc16 (patch)
tree2b61ca5998e756c0b8b8b316171941619bc01dcb /passt.c
parente26282b67d013f775eacd8603fa5ec1397dec714 (diff)
downloadpasst-34016444534120f2fa5a049675815843d041bc16.tar
passt-34016444534120f2fa5a049675815843d041bc16.tar.gz
passt-34016444534120f2fa5a049675815843d041bc16.tar.bz2
passt-34016444534120f2fa5a049675815843d041bc16.tar.lz
passt-34016444534120f2fa5a049675815843d041bc16.tar.xz
passt-34016444534120f2fa5a049675815843d041bc16.tar.zst
passt-34016444534120f2fa5a049675815843d041bc16.zip
epoll: Generalize epoll_ref to cover things other than sockets
The epoll_ref type includes fields for the IP protocol of a socket, and the socket fd. However, we already have a few things in the epoll which aren't protocol sockets, and we may have more in future. Rename these fields to an abstract "fd type" and file descriptor for more generality. Similarly, rather than using existing IP protocol numbers for the type, introduce our own number space. For now these just correspond to the supported protocols, but we'll expand on that in future. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'passt.c')
-rw-r--r--passt.c25
1 files changed, 12 insertions, 13 deletions
diff --git a/passt.c b/passt.c
index 9123868..ae69478 100644
--- a/passt.c
+++ b/passt.c
@@ -55,12 +55,11 @@
char pkt_buf[PKT_BUF_BYTES] __attribute__ ((aligned(PAGE_SIZE)));
-char *ip_proto_str[IPPROTO_SCTP + 1] = {
- [IPPROTO_ICMP] = "ICMP",
- [IPPROTO_TCP] = "TCP",
- [IPPROTO_UDP] = "UDP",
- [IPPROTO_ICMPV6] = "ICMPV6",
- [IPPROTO_SCTP] = "SCTP",
+char *epoll_type_str[EPOLL_TYPE_MAX + 1] = {
+ [EPOLL_TYPE_TCP] = "TCP socket",
+ [EPOLL_TYPE_UDP] = "UDP socket",
+ [EPOLL_TYPE_ICMP] = "ICMP socket",
+ [EPOLL_TYPE_ICMPV6] = "ICMPv6 socket",
};
/**
@@ -73,16 +72,16 @@ char *ip_proto_str[IPPROTO_SCTP + 1] = {
static void sock_handler(struct ctx *c, union epoll_ref ref,
uint32_t events, const struct timespec *now)
{
- trace("%s: %s packet from socket %i (events: 0x%08x)",
+ trace("%s: packet from %s %i (events: 0x%08x)",
c->mode == MODE_PASST ? "passt" : "pasta",
- IP_PROTO_STR(ref.proto), ref.s, events);
+ EPOLL_TYPE_STR(ref.type), ref.fd, events);
- if (!c->no_tcp && ref.proto == IPPROTO_TCP)
- tcp_sock_handler( c, ref, events, now);
- else if (!c->no_udp && ref.proto == IPPROTO_UDP)
- udp_sock_handler( c, ref, events, now);
+ if (!c->no_tcp && ref.type == EPOLL_TYPE_TCP)
+ tcp_sock_handler(c, ref, events, now);
+ else if (!c->no_udp && ref.type == EPOLL_TYPE_UDP)
+ udp_sock_handler(c, ref, events, now);
else if (!c->no_icmp &&
- (ref.proto == IPPROTO_ICMP || ref.proto == IPPROTO_ICMPV6))
+ (ref.type == EPOLL_TYPE_ICMP || ref.type == EPOLL_TYPE_ICMPV6))
icmp_sock_handler(c, ref, events, now);
}