aboutgitcodebugslistschat
path: root/udp.h
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2022-09-24 19:08:17 +1000
committerStefano Brivio <sbrivio@redhat.com>2022-09-24 14:48:35 +0200
commit163dc5f18899808e97b92ddae0314928c903bb4b (patch)
treed2e8984fe9f1b77fbdf5e878173a666c7a66f801 /udp.h
parent1128fa03fe73092dc68f30d0550283f0897d1f89 (diff)
downloadpasst-163dc5f18899808e97b92ddae0314928c903bb4b.tar
passt-163dc5f18899808e97b92ddae0314928c903bb4b.tar.gz
passt-163dc5f18899808e97b92ddae0314928c903bb4b.tar.bz2
passt-163dc5f18899808e97b92ddae0314928c903bb4b.tar.lz
passt-163dc5f18899808e97b92ddae0314928c903bb4b.tar.xz
passt-163dc5f18899808e97b92ddae0314928c903bb4b.tar.zst
passt-163dc5f18899808e97b92ddae0314928c903bb4b.zip
Consolidate port forwarding configuration into a common structure
The configuration for how to forward ports in and out of the guest/ns is divided between several different variables. For each connect direction and protocol we have a mode in the udp/tcp context structure, a bitmap of which ports to forward also in the context structure and an array of deltas to apply if the outward facing and inward facing port numbers are different. This last is a separate global variable, rather than being in the context structure, for no particular reason. UDP also requires an additional array which has the reverse mapping used for return packets. Consolidate these into a re-used substructure in the context structure. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'udp.h')
-rw-r--r--udp.h27
1 files changed, 17 insertions, 10 deletions
diff --git a/udp.h b/udp.h
index 706306c..cfd1a97 100644
--- a/udp.h
+++ b/udp.h
@@ -18,8 +18,8 @@ int udp_init(const struct ctx *c);
void udp_timer(struct ctx *c, const struct timespec *ts);
void udp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s,
const uint32_t *ip_da);
-void udp_remap_to_tap(in_port_t port, in_port_t delta);
-void udp_remap_to_init(in_port_t port, in_port_t delta);
+void udp_remap_to_tap(struct ctx *c, in_port_t port, in_port_t delta);
+void udp_remap_to_init(struct ctx *c, in_port_t port, in_port_t delta);
/**
* union udp_epoll_ref - epoll reference portion for TCP connections
@@ -44,19 +44,26 @@ union udp_epoll_ref {
uint32_t u32;
};
+
+/**
+ * udp_port_fwd - UDP specific port forwarding configuration
+ * @f: Generic forwarding configuration
+ * @rdelta: Reversed delta map to translate source ports on return packets
+ */
+struct udp_port_fwd {
+ struct port_fwd f;
+ in_port_t rdelta[USHRT_MAX];
+};
+
/**
* struct udp_ctx - Execution context for UDP
- * @port_to_tap: Ports bound host-side, data to tap or ns L4 socket
- * @fwd_mode_in: Port forwarding mode for inbound packets
- * @port_to_init: Ports bound namespace-side, data to init L4 socket
- * @fwd_mode_out: Port forwarding mode for outbound packets
+ * @fwd_in: Port forwarding configuration for inbound packets
+ * @fwd_out: Port forwarding configuration for outbound packets
* @timer_run: Timestamp of most recent timer run
*/
struct udp_ctx {
- uint8_t port_to_tap [PORT_BITMAP_SIZE];
- enum port_fwd_mode fwd_mode_in;
- uint8_t port_to_init [PORT_BITMAP_SIZE];
- enum port_fwd_mode fwd_mode_out;
+ struct udp_port_fwd fwd_in;
+ struct udp_port_fwd fwd_out;
struct timespec timer_run;
};