aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2023-11-15 16:25:33 +1100
committerStefano Brivio <sbrivio@redhat.com>2023-11-19 09:08:37 +0100
commit4ccdeecb744d48e0c70386d561d34ced860bfacd (patch)
tree181393a05a4106cc39a5fae5c20e61581d21efd7
parent1776e7af9b25cfbb1e28eca94d9052563dad3724 (diff)
downloadpasst-4ccdeecb744d48e0c70386d561d34ced860bfacd.tar
passt-4ccdeecb744d48e0c70386d561d34ced860bfacd.tar.gz
passt-4ccdeecb744d48e0c70386d561d34ced860bfacd.tar.bz2
passt-4ccdeecb744d48e0c70386d561d34ced860bfacd.tar.lz
passt-4ccdeecb744d48e0c70386d561d34ced860bfacd.tar.xz
passt-4ccdeecb744d48e0c70386d561d34ced860bfacd.tar.zst
passt-4ccdeecb744d48e0c70386d561d34ced860bfacd.zip
tcp: Simplify away tcp_port_rebind()
tcp_port_rebind() is desgined to be called from NS_CALL() and has two disjoint cases: one where it enters the namespace (outbound forwards) and one where it doesn't (inbound forwards). We only actually need the NS_CALL() framing for the outbound case, for inbound we can just call tcp_port_do_rebind() directly. So simplify tcp_port_rebind() to tcp_port_rebind_outbound(), allowing us to eliminate an awkward parameters structure. With that done we can safely rename tcp_port_do_rebind() to tcp_port_rebind() for brevity. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r--tcp.c41
1 files changed, 12 insertions, 29 deletions
diff --git a/tcp.c b/tcp.c
index cb23204..a0e577d 100644
--- a/tcp.c
+++ b/tcp.c
@@ -3151,13 +3151,13 @@ int tcp_init(struct ctx *c)
}
/**
- * tcp_port_do_rebind() - Rebind ports to match forward maps
+ * tcp_port_rebind() - Rebind ports to match forward maps
* @c: Execution context
* @outbound: True to remap outbound forwards, otherwise inbound
*
* Must be called in namespace context if @outbound is true.
*/
-static void tcp_port_do_rebind(struct ctx *c, bool outbound)
+static void tcp_port_rebind(struct ctx *c, bool outbound)
{
const uint8_t *fmap = outbound ? c->tcp.fwd_out.map : c->tcp.fwd_in.map;
const uint8_t *rmap = outbound ? c->tcp.fwd_in.map : c->tcp.fwd_out.map;
@@ -3194,32 +3194,19 @@ static void tcp_port_do_rebind(struct ctx *c, bool outbound)
}
/**
- * struct tcp_port_rebind_arg - Arguments for tcp_port_rebind()
- * @c: Execution context
- * @bind_in_ns: Rebind ports in namespace, not in init
- */
-struct tcp_port_rebind_arg {
- struct ctx *c;
- int bind_in_ns;
-};
-
-/**
- * tcp_port_rebind() - Rebind ports in namespace or init
- * @arg: See struct tcp_port_rebind_arg
+ * tcp_port_rebind_outbound() - Rebind ports in namespace
+ * @arg: Execution context
+ *
+ * Called with NS_CALL()
*
* Return: 0
*/
-static int tcp_port_rebind(void *arg)
+static int tcp_port_rebind_outbound(void *arg)
{
- struct tcp_port_rebind_arg *a = (struct tcp_port_rebind_arg *)arg;
-
- if (a->bind_in_ns) {
- ns_enter(a->c);
+ struct ctx *c = (struct ctx *)arg;
- tcp_port_do_rebind(a->c, true);
- } else {
- tcp_port_do_rebind(a->c, false);
- }
+ ns_enter(c);
+ tcp_port_rebind(c, true);
return 0;
}
@@ -3236,18 +3223,14 @@ void tcp_timer(struct ctx *c, const struct timespec *ts)
(void)ts;
if (c->mode == MODE_PASTA) {
- struct tcp_port_rebind_arg rebind_arg = { c, 0 };
-
if (c->tcp.fwd_out.mode == FWD_AUTO) {
port_fwd_scan_tcp(&c->tcp.fwd_out, &c->tcp.fwd_in);
- rebind_arg.bind_in_ns = 1;
- NS_CALL(tcp_port_rebind, &rebind_arg);
+ NS_CALL(tcp_port_rebind_outbound, c);
}
if (c->tcp.fwd_in.mode == FWD_AUTO) {
port_fwd_scan_tcp(&c->tcp.fwd_in, &c->tcp.fwd_out);
- rebind_arg.bind_in_ns = 0;
- tcp_port_rebind(&rebind_arg);
+ tcp_port_rebind(c, false);
}
}