aboutgitcodebugslistschat
path: root/port_fwd.h
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2022-09-24 19:08:16 +1000
committerStefano Brivio <sbrivio@redhat.com>2022-09-24 14:48:35 +0200
commit1128fa03fe73092dc68f30d0550283f0897d1f89 (patch)
treed5888f195c6be778f64f0e5e45d58a84c8a69361 /port_fwd.h
parent11e285df8f6f5943e87c78d025da2c95ca158e0b (diff)
downloadpasst-1128fa03fe73092dc68f30d0550283f0897d1f89.tar
passt-1128fa03fe73092dc68f30d0550283f0897d1f89.tar.gz
passt-1128fa03fe73092dc68f30d0550283f0897d1f89.tar.bz2
passt-1128fa03fe73092dc68f30d0550283f0897d1f89.tar.lz
passt-1128fa03fe73092dc68f30d0550283f0897d1f89.tar.xz
passt-1128fa03fe73092dc68f30d0550283f0897d1f89.tar.zst
passt-1128fa03fe73092dc68f30d0550283f0897d1f89.zip
Improve types and names for port forwarding configuration
enum conf_port_type is local to conf.c and is used to track the port forwarding mode during configuration. We don't keep it around in the context structure, however the 'init_detect_ports' and 'ns_detect_ports' fields in the context are based solely on this. Rather than changing encoding, just include the forwarding mode into the context structure. Move the type definition to a new port_fwd.h, which is kind of trivial at the moment but will have more stuff later. While we're there, "conf_port_type" doesn't really convey that this enum is describing how port forwarding is configured. Rename it to port_fwd_mode. The variables (now fields) of this type also have mildly confusing names since it's not immediately obvious whether 'ns' and 'init' refer to the source or destination of the packets. Use "in" (host to guest / init to ns) and "out" (guest to host / ns to init) instead. This has the added bonus that we no longer have locals 'udp_init' and 'tcp_init' which shadow global functions. In addition, add a typedef 'port_fwd_map' for a bitmap of each port number, which is used in several places. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'port_fwd.h')
-rw-r--r--port_fwd.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/port_fwd.h b/port_fwd.h
new file mode 100644
index 0000000..b938022
--- /dev/null
+++ b/port_fwd.h
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: AGPL-3.0-or-later
+ * Copyright Red Hat
+ * Author: Stefano Brivio <sbrivio@redhat.com>
+ * Author: David Gibson <david@gibson.dropbear.id.au>
+ */
+
+#ifndef PORT_FWD_H
+#define PORT_FWD_H
+
+enum port_fwd_mode {
+ FWD_SPEC = 1,
+ FWD_NONE,
+ FWD_AUTO,
+ FWD_ALL,
+};
+
+#define PORT_BITMAP_SIZE DIV_ROUND_UP(USHRT_MAX, 8)
+
+#endif /* PORT_FWD_H */