aboutgitcodebugslistschat
path: root/udp.c
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2021-07-21 17:44:39 +0200
committerStefano Brivio <sbrivio@redhat.com>2021-07-21 17:44:39 +0200
commit49631a38a6ec550fb9254f2f9e4a049eea02ed6d (patch)
tree1c1d294c156dd9bf2c0977bbbd6ba89a9c8ee95f /udp.c
parentb508079c4c6ef3b79b253736eaeb654486922324 (diff)
downloadpasst-49631a38a6ec550fb9254f2f9e4a049eea02ed6d.tar
passt-49631a38a6ec550fb9254f2f9e4a049eea02ed6d.tar.gz
passt-49631a38a6ec550fb9254f2f9e4a049eea02ed6d.tar.bz2
passt-49631a38a6ec550fb9254f2f9e4a049eea02ed6d.tar.lz
passt-49631a38a6ec550fb9254f2f9e4a049eea02ed6d.tar.xz
passt-49631a38a6ec550fb9254f2f9e4a049eea02ed6d.tar.zst
passt-49631a38a6ec550fb9254f2f9e4a049eea02ed6d.zip
tcp, udp: Split IPv4 and IPv6 bound port sets
Allow to bind IPv4 and IPv6 ports to tap, namespace or init separately. Port numbers of TCP ports that are bound in a namespace are also bound for UDP for convenience (e.g. iperf3), and IPv4 ports are always bound if the corresponding IPv6 port is bound (socket might not have the IPV6_V6ONLY option set). This will also be configurable later. Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'udp.c')
-rw-r--r--udp.c68
1 files changed, 39 insertions, 29 deletions
diff --git a/udp.c b/udp.c
index 3eb2ecf..30659e0 100644
--- a/udp.c
+++ b/udp.c
@@ -890,19 +890,24 @@ int udp_sock_init_ns(void *arg)
ns_enter(c->pasta_pid);
- for (port = 0; port < USHRT_MAX; port++) {
- if (!bitmap_isset(c->udp.port_to_init, port))
- continue;
-
- uref.port = port;
+ if (c->v4) {
+ uref.v6 = 0;
+ for (port = 0; port < USHRT_MAX; port++) {
+ if (!bitmap_isset(c->udp.port4_to_init, port))
+ continue;
- if (c->v4) {
- uref.v6 = 0;
+ uref.port = port;
sock_l4(c, AF_INET, IPPROTO_UDP, port, 1, uref.u32);
}
+ }
+
+ if (c->v6) {
+ uref.v6 = 1;
+ for (port = 0; port < USHRT_MAX; port++) {
+ if (!bitmap_isset(c->udp.port6_to_init, port))
+ continue;
- if (c->v6) {
- uref.v6 = 1;
+ uref.port = port;
sock_l4(c, AF_INET6, IPPROTO_UDP, port, 1, uref.u32);
}
}
@@ -976,40 +981,45 @@ int udp_sock_init(struct ctx *c)
in_port_t port;
int s;
- for (port = 0; port < USHRT_MAX; port++) {
- if (bitmap_isset(c->udp.port_to_ns, port))
- uref.splice = UDP_TO_NS;
- else if (bitmap_isset(c->udp.port_to_tap, port))
- uref.splice = 0;
- else
- continue;
-
- uref.port = port;
+ if (c->v4) {
+ uref.v6 = 0;
+ for (port = 0; port < USHRT_MAX; port++) {
+ if (bitmap_isset(c->udp.port4_to_ns, port))
+ uref.splice = UDP_TO_NS;
+ else if (bitmap_isset(c->udp.port4_to_tap, port))
+ uref.splice = 0;
+ else
+ continue;
- if (c->v4) {
- uref.v6 = 0;
+ uref.port = port;
s = sock_l4(c, AF_INET, IPPROTO_UDP, port,
uref.splice == UDP_TO_NS, uref.u32);
-
if (!uref.splice && s > 0)
udp_tap_map[V4][port].sock = s;
}
- if (c->v6) {
- uref.v6 = 1;
+ udp_sock4_iov_init();
+ }
+
+ if (c->v6) {
+ uref.v6 = 1;
+ for (port = 0; port < USHRT_MAX; port++) {
+ if (bitmap_isset(c->udp.port6_to_ns, port))
+ uref.splice = UDP_TO_NS;
+ else if (bitmap_isset(c->udp.port6_to_tap, port))
+ uref.splice = 0;
+ else
+ continue;
+
+ uref.port = port;
s = sock_l4(c, AF_INET6, IPPROTO_UDP, port,
uref.splice == UDP_TO_NS, uref.u32);
-
if (!uref.splice && s > 0)
udp_tap_map[V6][port].sock = s;
}
- }
-
- if (c->v4)
- udp_sock4_iov_init();
- if (c->v6)
udp_sock6_iov_init();
+ }
if (c->mode == MODE_PASTA) {
udp_splice_iov_init();