aboutgitcodebugslistschat
path: root/udp.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2024-07-18 15:26:52 +1000
committerStefano Brivio <sbrivio@redhat.com>2024-07-19 18:33:57 +0200
commitd29fa0856e75816431e78552821ec77c59e25b3e (patch)
tree9117d52ad3ed4159cdf821d95509979d005dd688 /udp.c
parentd89b3aa097a6777e981a4eb537a0b37f08a5b3a7 (diff)
downloadpasst-d29fa0856e75816431e78552821ec77c59e25b3e.tar
passt-d29fa0856e75816431e78552821ec77c59e25b3e.tar.gz
passt-d29fa0856e75816431e78552821ec77c59e25b3e.tar.bz2
passt-d29fa0856e75816431e78552821ec77c59e25b3e.tar.lz
passt-d29fa0856e75816431e78552821ec77c59e25b3e.tar.xz
passt-d29fa0856e75816431e78552821ec77c59e25b3e.tar.zst
passt-d29fa0856e75816431e78552821ec77c59e25b3e.zip
udp: Remove rdelta port forwarding maps
In addition to the struct fwd_ports used by both UDP and TCP to track port forwarding, UDP also included an 'rdelta' field, which contained the reverse mapping of the main port map. This was used so that we could properly direct reply packets to a forwarded packet where we change the destination port. This has now been taken over by the flow table: reply packets will match the flow of the originating packet, and that gives the correct ports on the originating side. So, eliminate the rdelta field, and with it struct udp_fwd_ports, which now has no additional information over struct fwd_ports. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'udp.c')
-rw-r--r--udp.c42
1 files changed, 6 insertions, 36 deletions
diff --git a/udp.c b/udp.c
index 0a17d1b..4d612c3 100644
--- a/udp.c
+++ b/udp.c
@@ -206,33 +206,6 @@ void udp_portmap_clear(void)
}
/**
- * udp_invert_portmap() - Compute reverse port translations for return packets
- * @fwd: Port forwarding configuration to compute reverse map for
- */
-static void udp_invert_portmap(struct udp_fwd_ports *fwd)
-{
- unsigned int i;
-
- static_assert(ARRAY_SIZE(fwd->f.delta) == ARRAY_SIZE(fwd->rdelta),
- "Forward and reverse delta arrays must have same size");
- for (i = 0; i < ARRAY_SIZE(fwd->f.delta); i++) {
- in_port_t delta = fwd->f.delta[i];
-
- if (delta) {
- /* Keep rport calculation separate from its usage: we
- * need to perform the sum in in_port_t width (that is,
- * modulo 65536), but C promotion rules would sum the
- * two terms as 'int', if we just open-coded the array
- * index as 'i + delta'.
- */
- in_port_t rport = i + delta;
-
- fwd->rdelta[rport] = NUM_PORTS - delta;
- }
- }
-}
-
-/**
* udp_update_l2_buf() - Update L2 buffers with Ethernet and IPv4 addresses
* @eth_d: Ethernet destination address, NULL if unchanged
* @eth_s: Ethernet source address, NULL if unchanged
@@ -1080,9 +1053,9 @@ static void udp_port_rebind(struct ctx *c, bool outbound)
{
int (*socks)[NUM_PORTS] = outbound ? udp_splice_ns : udp_splice_init;
const uint8_t *fmap
- = outbound ? c->udp.fwd_out.f.map : c->udp.fwd_in.f.map;
+ = outbound ? c->udp.fwd_out.map : c->udp.fwd_in.map;
const uint8_t *rmap
- = outbound ? c->udp.fwd_in.f.map : c->udp.fwd_out.f.map;
+ = outbound ? c->udp.fwd_in.map : c->udp.fwd_out.map;
unsigned port;
for (port = 0; port < NUM_PORTS; port++) {
@@ -1158,14 +1131,14 @@ void udp_timer(struct ctx *c, const struct timespec *now)
ASSERT(!c->no_udp);
if (c->mode == MODE_PASTA) {
- if (c->udp.fwd_out.f.mode == FWD_AUTO) {
- fwd_scan_ports_udp(&c->udp.fwd_out.f, &c->udp.fwd_in.f,
+ if (c->udp.fwd_out.mode == FWD_AUTO) {
+ fwd_scan_ports_udp(&c->udp.fwd_out, &c->udp.fwd_in,
&c->tcp.fwd_out, &c->tcp.fwd_in);
NS_CALL(udp_port_rebind_outbound, c);
}
- if (c->udp.fwd_in.f.mode == FWD_AUTO) {
- fwd_scan_ports_udp(&c->udp.fwd_in.f, &c->udp.fwd_out.f,
+ if (c->udp.fwd_in.mode == FWD_AUTO) {
+ fwd_scan_ports_udp(&c->udp.fwd_in, &c->udp.fwd_out,
&c->tcp.fwd_in, &c->tcp.fwd_out);
udp_port_rebind(c, false);
}
@@ -1184,9 +1157,6 @@ int udp_init(struct ctx *c)
udp_iov_init(c);
- udp_invert_portmap(&c->udp.fwd_in);
- udp_invert_portmap(&c->udp.fwd_out);
-
if (c->mode == MODE_PASTA) {
udp_splice_iov_init();
NS_CALL(udp_port_rebind_outbound, c);