aboutgitcodebugslistschat
path: root/tcp.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2022-11-17 16:59:02 +1100
committerStefano Brivio <sbrivio@redhat.com>2022-11-25 01:35:48 +0100
commit034fa8a58d87ad2ea5f8b56d267d17dbc75798de (patch)
treef635dc58f88475a526b2229e8ea68ebaa56616ec /tcp.c
parent7f1f2f3f518eace6ee08a00158189aaf571f3dcb (diff)
downloadpasst-034fa8a58d87ad2ea5f8b56d267d17dbc75798de.tar
passt-034fa8a58d87ad2ea5f8b56d267d17dbc75798de.tar.gz
passt-034fa8a58d87ad2ea5f8b56d267d17dbc75798de.tar.bz2
passt-034fa8a58d87ad2ea5f8b56d267d17dbc75798de.tar.lz
passt-034fa8a58d87ad2ea5f8b56d267d17dbc75798de.tar.xz
passt-034fa8a58d87ad2ea5f8b56d267d17dbc75798de.tar.zst
passt-034fa8a58d87ad2ea5f8b56d267d17dbc75798de.zip
tcp: Remove v6 flag from tcp_epoll_ref
This bit in the TCP specific epoll reference indicates whether the connection is IPv6 or IPv4. However the sites which refer to it are already calling accept() which (optionally) returns an address for the remote end of the connection. We can use the sa_family field in that address to determine the connection type independent of the epoll reference. This does have a cost: for the spliced case, it means we now need to get that address from accept() which introduces an extran copy_to_user(). However, in future we want to allow handling IPv4 connectons through IPv6 sockets, which means we won't be able to determine the IP version at the time we create the listening socket and epoll reference. So, at some point we'll have to pay this cost anyway. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'tcp.c')
-rw-r--r--tcp.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/tcp.c b/tcp.c
index 559e271..7d5ac6c 100644
--- a/tcp.c
+++ b/tcp.c
@@ -662,8 +662,7 @@ static int tcp_epoll_ctl(const struct ctx *c, struct tcp_tap_conn *conn)
{
int m = conn->c.in_epoll ? EPOLL_CTL_MOD : EPOLL_CTL_ADD;
union epoll_ref ref = { .r.proto = IPPROTO_TCP, .r.s = conn->sock,
- .r.p.tcp.tcp.index = CONN_IDX(conn),
- .r.p.tcp.tcp.v6 = CONN_V6(conn) };
+ .r.p.tcp.tcp.index = CONN_IDX(conn) };
struct epoll_event ev = { .data.u64 = ref.u64 };
if (conn->events == CLOSED) {
@@ -2745,7 +2744,7 @@ static void tcp_tap_conn_from_sock(struct ctx *c, union epoll_ref ref,
conn->ws_to_tap = conn->ws_from_tap = 0;
conn_event(c, conn, SOCK_ACCEPTED);
- if (ref.r.p.tcp.tcp.v6) {
+ if (sa->sa_family == AF_INET6) {
struct sockaddr_in6 sa6;
memcpy(&sa6, sa, sizeof(sa6));
@@ -3019,8 +3018,7 @@ static void tcp_sock_init6(const struct ctx *c,
in_port_t port)
{
in_port_t idx = port + c->tcp.fwd_in.delta[port];
- union tcp_epoll_ref tref = { .tcp.listen = 1, .tcp.v6 = 1,
- .tcp.index = idx };
+ union tcp_epoll_ref tref = { .tcp.listen = 1, .tcp.index = idx };
int s;
s = sock_l4(c, AF_INET6, IPPROTO_TCP, addr, ifname, port, tref.u32);
@@ -3084,7 +3082,7 @@ static void tcp_ns_sock_init6(const struct ctx *c, in_port_t port)
{
in_port_t idx = port + c->tcp.fwd_out.delta[port];
union tcp_epoll_ref tref = { .tcp.listen = 1, .tcp.outbound = 1,
- .tcp.v6 = 1, .tcp.index = idx };
+ .tcp.index = idx };
int s;
assert(c->mode == MODE_PASTA);