aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2026-04-10 11:02:48 +1000
committerStefano Brivio <sbrivio@redhat.com>2026-04-15 23:31:34 +0200
commitde8ebc5dd9ce53d632390edf44cabeb04c7e2f98 (patch)
tree9be32a710f4ba0423785ad66a1c465cef8a46796
parent4d8aa0a29a6bd463987b28ae9885f70d780fabea (diff)
downloadpasst-de8ebc5dd9ce53d632390edf44cabeb04c7e2f98.tar
passt-de8ebc5dd9ce53d632390edf44cabeb04c7e2f98.tar.gz
passt-de8ebc5dd9ce53d632390edf44cabeb04c7e2f98.tar.bz2
passt-de8ebc5dd9ce53d632390edf44cabeb04c7e2f98.tar.lz
passt-de8ebc5dd9ce53d632390edf44cabeb04c7e2f98.tar.xz
passt-de8ebc5dd9ce53d632390edf44cabeb04c7e2f98.tar.zst
passt-de8ebc5dd9ce53d632390edf44cabeb04c7e2f98.zip
conf: Simplify handling of default forwarding mode
For passt, the default forwarding mode is "none", which falls out naturally from the other handling: if we don't get any options, we get empty forwarding tables, which corresponds to "none" behaviour. However, for pasta the default is "auto". This is handled a bit oddly: in conf_ports() we set the mode variable, but don't set up the rules we need for "auto" mode. Instead we want until nearly the end of conf() and if the mode is FWD_MODE_AUTO or unset, we make conf_ports_range_except() calls to set up the "auto" rules. Simplify this a bit, by creating the rules within conf_ports() itself when we parse -[tuTU] auto. For the case of no forwarding options we call into conf_ports() itself with synthetic arguments. As well as making the code a little shorter, this makes it more obvious that giving no arguments really is equivalent to -[tuTU] auto. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r--conf.c54
1 files changed, 22 insertions, 32 deletions
diff --git a/conf.c b/conf.c
index e385afc..58edebc 100644
--- a/conf.c
+++ b/conf.c
@@ -345,6 +345,10 @@ static void conf_ports(const struct ctx *c, char optname, const char *optarg,
die("'auto' port forwarding is only allowed for pasta");
*mode = FWD_MODE_AUTO;
+
+ conf_ports_range_except(c, optname, optarg, fwd, NULL, NULL,
+ 1, NUM_PORTS - 1, NULL, 1, FWD_SCAN);
+
return;
}
@@ -1576,7 +1580,6 @@ void conf(struct ctx *c, int argc, char **argv)
enum fwd_mode udp_out_mode = FWD_MODE_UNSET;
enum fwd_mode tcp_in_mode = FWD_MODE_UNSET;
enum fwd_mode udp_in_mode = FWD_MODE_UNSET;
- enum fwd_mode fwd_default = FWD_MODE_NONE;
bool v4_only = false, v6_only = false;
unsigned dns4_idx = 0, dns6_idx = 0;
unsigned long max_mtu = IP_MAX_MTU;
@@ -1593,10 +1596,8 @@ void conf(struct ctx *c, int argc, char **argv)
gid_t gid;
- if (c->mode == MODE_PASTA) {
+ if (c->mode == MODE_PASTA)
c->no_dhcp_dns = c->no_dhcp_dns_search = 1;
- fwd_default = FWD_MODE_AUTO;
- }
if (tap_l2_max_len(c) - ETH_HLEN < max_mtu)
max_mtu = tap_l2_max_len(c) - ETH_HLEN;
@@ -2244,34 +2245,23 @@ void conf(struct ctx *c, int argc, char **argv)
if_indextoname(c->ifi6, c->pasta_ifn);
}
- if (!tcp_in_mode)
- tcp_in_mode = fwd_default;
- if (!tcp_out_mode)
- tcp_out_mode = fwd_default;
- if (!udp_in_mode)
- udp_in_mode = fwd_default;
- if (!udp_out_mode)
- udp_out_mode = fwd_default;
-
- if (tcp_in_mode == FWD_MODE_AUTO) {
- conf_ports_range_except(c, 't', "auto", c->fwd[PIF_HOST],
- NULL, NULL, 1, NUM_PORTS - 1, NULL, 1,
- FWD_SCAN);
- }
- if (tcp_out_mode == FWD_MODE_AUTO) {
- conf_ports_range_except(c, 'T', "auto", c->fwd[PIF_SPLICE],
- NULL, "lo", 1, NUM_PORTS - 1, NULL, 1,
- FWD_SCAN);
- }
- if (udp_in_mode == FWD_MODE_AUTO) {
- conf_ports_range_except(c, 'u', "auto", c->fwd[PIF_HOST],
- NULL, NULL, 1, NUM_PORTS - 1, NULL, 1,
- FWD_SCAN);
- }
- if (udp_out_mode == FWD_MODE_AUTO) {
- conf_ports_range_except(c, 'U', "auto", c->fwd[PIF_SPLICE],
- NULL, "lo", 1, NUM_PORTS - 1, NULL, 1,
- FWD_SCAN);
+ if (c->mode == MODE_PASTA) {
+ if (!tcp_in_mode) {
+ conf_ports(c, 't', "auto",
+ c->fwd[PIF_HOST], &tcp_in_mode);
+ }
+ if (!tcp_out_mode) {
+ conf_ports(c, 'T', "auto",
+ c->fwd[PIF_SPLICE], &tcp_out_mode);
+ }
+ if (!udp_in_mode) {
+ conf_ports(c, 'u', "auto",
+ c->fwd[PIF_HOST], &udp_in_mode);
+ }
+ if (!udp_out_mode) {
+ conf_ports(c, 'U', "auto",
+ c->fwd[PIF_SPLICE], &udp_out_mode);
+ }
}
if (!c->quiet)