public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: passt-dev@passt.top, Stefano Brivio <sbrivio@redhat.com>
Cc: David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH v3 20/20] fwd: Rename port_fwd.[ch] and their contents
Date: Wed, 28 Feb 2024 22:25:20 +1100	[thread overview]
Message-ID: <20240228112520.2078220-21-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20240228112520.2078220-1-david@gibson.dropbear.id.au>

Currently port_fwd.[ch] contains helpers related to port forwarding,
particular automatic port forwarding.  We're planning to allow much more
flexible sorts of forwarding, including both port translation and NAT based
on the flow table.  This will subsume the existing port forwarding logic,
so rename port_fwd.[ch] to fwd.[ch] with matching updates to all the names
within.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 Makefile            | 12 ++++++------
 conf.c              |  8 ++++----
 port_fwd.c => fwd.c | 32 ++++++++++++++++----------------
 port_fwd.h => fwd.h | 24 ++++++++++++------------
 passt.h             |  2 +-
 tcp.c               |  4 ++--
 tcp.h               |  4 ++--
 udp.c               | 10 +++++-----
 udp.h               | 10 +++++-----
 9 files changed, 53 insertions(+), 53 deletions(-)
 rename port_fwd.c => fwd.c (83%)
 rename port_fwd.h => fwd.h (62%)

diff --git a/Makefile b/Makefile
index 026e341c..2d6a5155 100644
--- a/Makefile
+++ b/Makefile
@@ -44,19 +44,19 @@ FLAGS += -DARCH=\"$(TARGET_ARCH)\"
 FLAGS += -DVERSION=\"$(VERSION)\"
 FLAGS += -DDUAL_STACK_SOCKETS=$(DUAL_STACK_SOCKETS)
 
-PASST_SRCS = arch.c arp.c checksum.c conf.c dhcp.c dhcpv6.c flow.c icmp.c \
-	igmp.c inany.c iov.c isolation.c lineread.c log.c mld.c ndp.c \
-	netlink.c packet.c passt.c pasta.c pcap.c pif.c port_fwd.c tap.c tcp.c \
+PASST_SRCS = arch.c arp.c checksum.c conf.c dhcp.c dhcpv6.c flow.c fwd.c \
+	icmp.c igmp.c inany.c iov.c isolation.c lineread.c log.c mld.c ndp.c \
+	netlink.c packet.c passt.c pasta.c pcap.c pif.c tap.c tcp.c \
 	tcp_splice.c udp.c util.c
 QRAP_SRCS = qrap.c
 SRCS = $(PASST_SRCS) $(QRAP_SRCS)
 
 MANPAGES = passt.1 pasta.1 qrap.1
 
-PASST_HEADERS = arch.h arp.h checksum.h conf.h dhcp.h dhcpv6.h flow.h \
+PASST_HEADERS = arch.h arp.h checksum.h conf.h dhcp.h dhcpv6.h flow.h fwd.h \
 	flow_table.h icmp.h inany.h iov.h isolation.h lineread.h log.h ndp.h \
-	netlink.h packet.h passt.h pasta.h pcap.h pif.h port_fwd.h siphash.h \
-	tap.h tcp.h tcp_conn.h tcp_splice.h udp.h util.h
+	netlink.h packet.h passt.h pasta.h pcap.h pif.h siphash.h tap.h tcp.h \
+	tcp_conn.h tcp_splice.h udp.h util.h
 HEADERS = $(PASST_HEADERS) seccomp.h
 
 C := \#include <linux/tcp.h>\nstruct tcp_info x = { .tcpi_snd_wnd = 0 };
diff --git a/conf.c b/conf.c
index 17cf2793..23a3acf0 100644
--- a/conf.c
+++ b/conf.c
@@ -109,10 +109,10 @@ static int parse_port_range(const char *s, char **endptr,
  * @c:		Execution context
  * @optname:	Short option name, t, T, u, or U
  * @optarg:	Option argument (port specification)
- * @fwd:	Pointer to @port_fwd to be updated
+ * @fwd:	Pointer to @fwd_ports to be updated
  */
 static void conf_ports(const struct ctx *c, char optname, const char *optarg,
-		       struct port_fwd *fwd)
+		       struct fwd_ports *fwd)
 {
 	char addr_buf[sizeof(struct in6_addr)] = { 0 }, *addr = addr_buf;
 	char buf[BUFSIZ], *spec, *ifname = NULL, *p;
@@ -1158,7 +1158,7 @@ void conf(struct ctx *c, int argc, char **argv)
 	};
 	char userns[PATH_MAX] = { 0 }, netns[PATH_MAX] = { 0 };
 	bool copy_addrs_opt = false, copy_routes_opt = false;
-	enum port_fwd_mode fwd_default = FWD_NONE;
+	enum fwd_ports_mode fwd_default = FWD_NONE;
 	bool v4_only = false, v6_only = false;
 	struct in6_addr *dns6 = c->ip6.dns;
 	struct fqdn *dnss = c->dns_search;
@@ -1746,7 +1746,7 @@ void conf(struct ctx *c, int argc, char **argv)
 	if (!c->udp.fwd_out.f.mode)
 		c->udp.fwd_out.f.mode = fwd_default;
 
-	port_fwd_init(c);
+	fwd_scan_ports_init(c);
 
 	if (!c->quiet)
 		conf_print(c);
diff --git a/port_fwd.c b/fwd.c
similarity index 83%
rename from port_fwd.c
rename to fwd.c
index a7121fe2..09650b26 100644
--- a/port_fwd.c
+++ b/fwd.c
@@ -6,7 +6,7 @@
  * PASTA - Pack A Subtle Tap Abstraction
  *  for network namespace/tap device mode
  *
- * port_fwd.c - Port forwarding helpers
+ * fwd.c - Port forwarding helpers
  *
  * Copyright Red Hat
  * Author: Stefano Brivio <sbrivio@redhat.com>
@@ -21,7 +21,7 @@
 #include <stdio.h>
 
 #include "util.h"
-#include "port_fwd.h"
+#include "fwd.h"
 #include "passt.h"
 #include "lineread.h"
 
@@ -73,11 +73,11 @@ static void procfs_scan_listen(int fd, unsigned int lstate,
 }
 
 /**
- * port_fwd_scan_tcp() - Scan /proc to update TCP forwarding map
+ * fwd_scan_ports_tcp() - Scan /proc to update TCP forwarding map
  * @fwd:	Forwarding information to update
  * @rev:	Forwarding information for the reverse direction
  */
-void port_fwd_scan_tcp(struct port_fwd *fwd, const struct port_fwd *rev)
+void fwd_scan_ports_tcp(struct fwd_ports *fwd, const struct fwd_ports *rev)
 {
 	memset(fwd->map, 0, PORT_BITMAP_SIZE);
 	procfs_scan_listen(fwd->scan4, TCP_LISTEN, fwd->map, rev->map);
@@ -85,15 +85,15 @@ void port_fwd_scan_tcp(struct port_fwd *fwd, const struct port_fwd *rev)
 }
 
 /**
- * port_fwd_scan_udp() - Scan /proc to update UDP forwarding map
+ * fwd_scan_ports_udp() - Scan /proc to update UDP forwarding map
  * @fwd:	Forwarding information to update
  * @rev:	Forwarding information for the reverse direction
  * @tcp_fwd:	Corresponding TCP forwarding information
  * @tcp_rev:	TCP forwarding information for the reverse direction
  */
-void port_fwd_scan_udp(struct port_fwd *fwd, const struct port_fwd *rev,
-		       const struct port_fwd *tcp_fwd,
-		       const struct port_fwd *tcp_rev)
+void fwd_scan_ports_udp(struct fwd_ports *fwd, const struct fwd_ports *rev,
+			const struct fwd_ports *tcp_fwd,
+			const struct fwd_ports *tcp_rev)
 {
 	uint8_t exclude[PORT_BITMAP_SIZE];
 
@@ -118,10 +118,10 @@ void port_fwd_scan_udp(struct port_fwd *fwd, const struct port_fwd *rev,
 }
 
 /**
- * port_fwd_init() - Initial setup for port forwarding
+ * fwd_scan_ports_init() - Initial setup for automatic port forwarding
  * @c:		Execution context
  */
-void port_fwd_init(struct ctx *c)
+void fwd_scan_ports_init(struct ctx *c)
 {
 	const int flags = O_RDONLY | O_CLOEXEC;
 
@@ -133,23 +133,23 @@ void port_fwd_init(struct ctx *c)
 	if (c->tcp.fwd_in.mode == FWD_AUTO) {
 		c->tcp.fwd_in.scan4 = open_in_ns(c, "/proc/net/tcp", flags);
 		c->tcp.fwd_in.scan6 = open_in_ns(c, "/proc/net/tcp6", flags);
-		port_fwd_scan_tcp(&c->tcp.fwd_in, &c->tcp.fwd_out);
+		fwd_scan_ports_tcp(&c->tcp.fwd_in, &c->tcp.fwd_out);
 	}
 	if (c->udp.fwd_in.f.mode == FWD_AUTO) {
 		c->udp.fwd_in.f.scan4 = open_in_ns(c, "/proc/net/udp", flags);
 		c->udp.fwd_in.f.scan6 = open_in_ns(c, "/proc/net/udp6", flags);
-		port_fwd_scan_udp(&c->udp.fwd_in.f, &c->udp.fwd_out.f,
-				  &c->tcp.fwd_in, &c->tcp.fwd_out);
+		fwd_scan_ports_udp(&c->udp.fwd_in.f, &c->udp.fwd_out.f,
+				   &c->tcp.fwd_in, &c->tcp.fwd_out);
 	}
 	if (c->tcp.fwd_out.mode == FWD_AUTO) {
 		c->tcp.fwd_out.scan4 = open("/proc/net/tcp", flags);
 		c->tcp.fwd_out.scan6 = open("/proc/net/tcp6", flags);
-		port_fwd_scan_tcp(&c->tcp.fwd_out, &c->tcp.fwd_in);
+		fwd_scan_ports_tcp(&c->tcp.fwd_out, &c->tcp.fwd_in);
 	}
 	if (c->udp.fwd_out.f.mode == FWD_AUTO) {
 		c->udp.fwd_out.f.scan4 = open("/proc/net/udp", flags);
 		c->udp.fwd_out.f.scan6 = open("/proc/net/udp6", flags);
-		port_fwd_scan_udp(&c->udp.fwd_out.f, &c->udp.fwd_in.f,
-				  &c->tcp.fwd_out, &c->tcp.fwd_in);
+		fwd_scan_ports_udp(&c->udp.fwd_out.f, &c->udp.fwd_in.f,
+				   &c->tcp.fwd_out, &c->tcp.fwd_in);
 	}
 }
diff --git a/port_fwd.h b/fwd.h
similarity index 62%
rename from port_fwd.h
rename to fwd.h
index f6bf1b53..23281d90 100644
--- a/port_fwd.h
+++ b/fwd.h
@@ -4,13 +4,13 @@
  * Author: David Gibson <david@gibson.dropbear.id.au>
  */
 
-#ifndef PORT_FWD_H
-#define PORT_FWD_H
+#ifndef FWD_H
+#define FWD_H
 
 /* Number of ports for both TCP and UDP */
 #define	NUM_PORTS	(1U << 16)
 
-enum port_fwd_mode {
+enum fwd_ports_mode {
 	FWD_SPEC = 1,
 	FWD_NONE,
 	FWD_AUTO,
@@ -20,25 +20,25 @@ enum port_fwd_mode {
 #define PORT_BITMAP_SIZE	DIV_ROUND_UP(NUM_PORTS, 8)
 
 /**
- * port_fwd - Describes port forwarding for one protocol and direction
+ * fwd_ports - Describes port forwarding for one protocol and direction
  * @mode:	Overall forwarding mode (all, none, auto, specific ports)
  * @scan4:	/proc/net fd to scan for IPv4 ports when in AUTO mode
  * @scan6:	/proc/net fd to scan for IPv6 ports when in AUTO mode
  * @map:	Bitmap describing which ports are forwarded
  * @delta:	Offset between the original destination and mapped port number
  */
-struct port_fwd {
-	enum port_fwd_mode mode;
+struct fwd_ports {
+	enum fwd_ports_mode mode;
 	int scan4;
 	int scan6;
 	uint8_t map[PORT_BITMAP_SIZE];
 	in_port_t delta[NUM_PORTS];
 };
 
-void port_fwd_scan_tcp(struct port_fwd *fwd, const struct port_fwd *rev);
-void port_fwd_scan_udp(struct port_fwd *fwd, const struct port_fwd *rev,
-		       const struct port_fwd *tcp_fwd,
-		       const struct port_fwd *tcp_rev);
-void port_fwd_init(struct ctx *c);
+void fwd_scan_ports_tcp(struct fwd_ports *fwd, const struct fwd_ports *rev);
+void fwd_scan_ports_udp(struct fwd_ports *fwd, const struct fwd_ports *rev,
+			const struct fwd_ports *tcp_fwd,
+			const struct fwd_ports *tcp_rev);
+void fwd_scan_ports_init(struct ctx *c);
 
-#endif /* PORT_FWD_H */
+#endif /* FWD_H */
diff --git a/passt.h b/passt.h
index fb729b69..e6d43585 100644
--- a/passt.h
+++ b/passt.h
@@ -39,7 +39,7 @@ union epoll_ref;
 #include "packet.h"
 #include "flow.h"
 #include "icmp.h"
-#include "port_fwd.h"
+#include "fwd.h"
 #include "tcp.h"
 #include "udp.h"
 
diff --git a/tcp.c b/tcp.c
index 2ea985e6..560d1d49 100644
--- a/tcp.c
+++ b/tcp.c
@@ -3237,12 +3237,12 @@ void tcp_timer(struct ctx *c, const struct timespec *now)
 
 	if (c->mode == MODE_PASTA) {
 		if (c->tcp.fwd_out.mode == FWD_AUTO) {
-			port_fwd_scan_tcp(&c->tcp.fwd_out, &c->tcp.fwd_in);
+			fwd_scan_ports_tcp(&c->tcp.fwd_out, &c->tcp.fwd_in);
 			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);
+			fwd_scan_ports_tcp(&c->tcp.fwd_in, &c->tcp.fwd_out);
 			tcp_port_rebind(c, false);
 		}
 	}
diff --git a/tcp.h b/tcp.h
index 5e6756d4..a9b8bf87 100644
--- a/tcp.h
+++ b/tcp.h
@@ -59,8 +59,8 @@ union tcp_listen_epoll_ref {
  * @pipe_size:		Size of pipes for spliced connections
  */
 struct tcp_ctx {
-	struct port_fwd fwd_in;
-	struct port_fwd fwd_out;
+	struct fwd_ports fwd_in;
+	struct fwd_ports fwd_out;
 	struct timespec timer_run;
 #ifdef HAS_SND_WND
 	int kernel_snd_wnd;
diff --git a/udp.c b/udp.c
index 1520ca8d..dd46e67f 100644
--- a/udp.c
+++ b/udp.c
@@ -259,7 +259,7 @@ 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_port_fwd *fwd)
+static void udp_invert_portmap(struct udp_fwd_ports *fwd)
 {
 	unsigned int i;
 
@@ -1198,14 +1198,14 @@ void udp_timer(struct ctx *c, const struct timespec *now)
 
 	if (c->mode == MODE_PASTA) {
 		if (c->udp.fwd_out.f.mode == FWD_AUTO) {
-			port_fwd_scan_udp(&c->udp.fwd_out.f, &c->udp.fwd_in.f,
-					  &c->tcp.fwd_out, &c->tcp.fwd_in);
+			fwd_scan_ports_udp(&c->udp.fwd_out.f, &c->udp.fwd_in.f,
+					   &c->tcp.fwd_out, &c->tcp.fwd_in);
 			NS_CALL(udp_port_rebind_outbound, c);
 		}
 
 		if (c->udp.fwd_in.f.mode == FWD_AUTO) {
-			port_fwd_scan_udp(&c->udp.fwd_in.f, &c->udp.fwd_out.f,
-					  &c->tcp.fwd_in, &c->tcp.fwd_out);
+			fwd_scan_ports_udp(&c->udp.fwd_in.f, &c->udp.fwd_out.f,
+					   &c->tcp.fwd_in, &c->tcp.fwd_out);
 			udp_port_rebind(c, false);
 		}
 	}
diff --git a/udp.h b/udp.h
index f3d5d6d2..9976b623 100644
--- a/udp.h
+++ b/udp.h
@@ -43,12 +43,12 @@ union udp_epoll_ref {
 
 
 /**
- * udp_port_fwd - UDP specific port forwarding configuration
+ * udp_fwd_ports - 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;
+struct udp_fwd_ports {
+	struct fwd_ports f;
 	in_port_t rdelta[NUM_PORTS];
 };
 
@@ -59,8 +59,8 @@ struct udp_port_fwd {
  * @timer_run:		Timestamp of most recent timer run
  */
 struct udp_ctx {
-	struct udp_port_fwd fwd_in;
-	struct udp_port_fwd fwd_out;
+	struct udp_fwd_ports fwd_in;
+	struct udp_fwd_ports fwd_out;
 	struct timespec timer_run;
 };
 
-- 
@@ -43,12 +43,12 @@ union udp_epoll_ref {
 
 
 /**
- * udp_port_fwd - UDP specific port forwarding configuration
+ * udp_fwd_ports - 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;
+struct udp_fwd_ports {
+	struct fwd_ports f;
 	in_port_t rdelta[NUM_PORTS];
 };
 
@@ -59,8 +59,8 @@ struct udp_port_fwd {
  * @timer_run:		Timestamp of most recent timer run
  */
 struct udp_ctx {
-	struct udp_port_fwd fwd_in;
-	struct udp_port_fwd fwd_out;
+	struct udp_fwd_ports fwd_in;
+	struct udp_fwd_ports fwd_out;
 	struct timespec timer_run;
 };
 
-- 
2.43.2


  parent reply	other threads:[~2024-02-28 11:25 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-28 11:25 [PATCH v3 00/20] More flow table preliminaries: address handling improvements David Gibson
2024-02-28 11:25 ` [PATCH v3 01/20] inany: Helper to test for various address types David Gibson
2024-02-28 11:25 ` [PATCH v3 02/20] inany: Add inany_ntop() helper David Gibson
2024-02-28 11:25 ` [PATCH v3 03/20] inany: Provide more conveniently typed constants for special addresses David Gibson
2024-02-28 11:25 ` [PATCH v3 04/20] inany: Introduce union sockaddr_inany David Gibson
2024-02-28 11:25 ` [PATCH v3 05/20] util: Allow IN4_IS_* macros to operate on untyped addresses David Gibson
2024-02-28 11:25 ` [PATCH v3 06/20] tcp, udp: Don't precompute port remappings in epoll references David Gibson
2024-02-28 11:25 ` [PATCH v3 07/20] flow: Add helper to determine a flow's protocol David Gibson
2024-02-28 11:25 ` [PATCH v3 08/20] tcp_splice: Simplify clean up logic David Gibson
2024-02-28 11:25 ` [PATCH v3 09/20] tcp_splice: Don't use flow_trace() before setting flow type David Gibson
2024-02-28 11:25 ` [PATCH v3 10/20] flow: Clarify flow entry life cycle, introduce uniform logging David Gibson
2024-02-28 11:25 ` [PATCH v3 11/20] tcp_splice: More specific variable names in new splice path David Gibson
2024-02-28 11:25 ` [PATCH v3 12/20] tcp_splice: Merge tcp_splice_new() into its caller David Gibson
2024-02-28 11:25 ` [PATCH v3 13/20] tcp_splice: Make tcp_splice_connect() create its own sockets David Gibson
2024-02-28 11:25 ` [PATCH v3 14/20] tcp_splice: Improve error reporting on connect path David Gibson
2024-02-28 11:25 ` [PATCH v3 15/20] tcp_splice: Improve logic deciding when to splice David Gibson
2024-02-28 11:25 ` [PATCH v3 16/20] tcp, tcp_splice: Parse listening socket epoll ref in tcp_listen_handler() David Gibson
2024-02-28 11:25 ` [PATCH v3 17/20] tcp: Validate TCP endpoint addresses David Gibson
2024-02-28 11:25 ` [PATCH v3 18/20] tap: Disallow loopback addresses on tap interface David Gibson
2024-02-28 11:25 ` [PATCH v3 19/20] port_fwd: Fix copypasta error in port_fwd_scan_udp() comments David Gibson
2024-02-28 11:25 ` David Gibson [this message]
2024-02-29 10:53 ` [PATCH v3 00/20] More flow table preliminaries: address handling improvements Stefano Brivio

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240228112520.2078220-21-david@gibson.dropbear.id.au \
    --to=david@gibson.dropbear.id.au \
    --cc=passt-dev@passt.top \
    --cc=sbrivio@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).