From 3b9098aa49bd083a7900dc6e0219bf76e389afd4 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Wed, 28 Feb 2024 22:25:20 +1100 Subject: fwd: Rename port_fwd.[ch] and their contents 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 Signed-off-by: Stefano Brivio --- fwd.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 fwd.h (limited to 'fwd.h') diff --git a/fwd.h b/fwd.h new file mode 100644 index 0000000..23281d9 --- /dev/null +++ b/fwd.h @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later + * Copyright Red Hat + * Author: Stefano Brivio + * Author: David Gibson + */ + +#ifndef FWD_H +#define FWD_H + +/* Number of ports for both TCP and UDP */ +#define NUM_PORTS (1U << 16) + +enum fwd_ports_mode { + FWD_SPEC = 1, + FWD_NONE, + FWD_AUTO, + FWD_ALL, +}; + +#define PORT_BITMAP_SIZE DIV_ROUND_UP(NUM_PORTS, 8) + +/** + * 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 fwd_ports { + enum fwd_ports_mode mode; + int scan4; + int scan6; + uint8_t map[PORT_BITMAP_SIZE]; + in_port_t delta[NUM_PORTS]; +}; + +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 /* FWD_H */ -- cgit v1.2.3