public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
e664d1d062aa45137a4974288b52687e950e7d29 blob 3625 bytes (raw)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
 
/* SPDX-License-Identifier: GPL-2.0-or-later
 * Copyright Red Hat
 * Author: Stefano Brivio <sbrivio@redhat.com>
 * Author: David Gibson <david@gibson.dropbear.id.au>
 */

#ifndef FWD_H
#define FWD_H

#include <assert.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

#include <netinet/in.h>

#include "bitmap.h"
#include "inany.h"
#include "fwd_rule.h"

struct flowside;

#define FWD_RULE_BITS	8
#define MAX_FWD_RULES	MAX_FROM_BITS(FWD_RULE_BITS)
#define FWD_NO_HINT	(-1)

/**
 * struct fwd_listen_ref - information about a single listening socket
 * @port:	Bound port number of the socket
 * @pif:	pif in which the socket is listening
 * @rule:	Index of forwarding rule
 */
struct fwd_listen_ref {
	in_port_t	port;
	uint8_t		pif;
	unsigned	rule :FWD_RULE_BITS;
};

/* Maximum number of listening sockets (per pif)
 *
 * Rationale: This lets us listen on every port for two addresses and two
 * protocols (which we need for -T auto -U auto without SO_BINDTODEVICE), plus a
 * comfortable number of extras.
 */
#define MAX_LISTEN_SOCKS	(NUM_PORTS * 5)

/**
 * struct fwd_table - Forwarding state (per initiating pif)
 * @caps:	Forwarding capabilities for this initiating pif
 * @count:	Number of forwarding rules
 * @rules:	Array of forwarding rules
 * @rulesocks:	Parallel array of @rules (@count valid entries) of pointers to
 *		@socks entries giving the start of the corresponding rule's
 *		sockets within the larger array
 * @sock_count:	Number of entries used in @socks (for all rules combined)
 * @socks:	Listening sockets for forwarding
 */
struct fwd_table {
	uint32_t caps;
	unsigned count;
	struct fwd_rule rules[MAX_FWD_RULES];
	int *rulesocks[MAX_FWD_RULES];
	unsigned sock_count;
	int socks[MAX_LISTEN_SOCKS];
};

#define PORT_BITMAP_SIZE	DIV_ROUND_UP(NUM_PORTS, 8)

/**
 * struct fwd_scan - Port scanning state for a protocol+direction
 * @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
 */
struct fwd_scan {
	int scan4;
	int scan6;
	uint8_t map[PORT_BITMAP_SIZE];
};

#define FWD_PORT_SCAN_INTERVAL		1000	/* ms */

void fwd_rule_init(struct ctx *c);
int fwd_rule_add(struct fwd_table *fwd, const struct fwd_rule *new);
const struct fwd_rule *fwd_rule_search(const struct fwd_table *fwd,
				       const struct flowside *ini,
				       uint8_t proto, int hint);

void fwd_scan_ports_init(struct ctx *c);
void fwd_scan_ports_timer(struct ctx * c, const struct timespec *now);

int fwd_listen_sync(const struct ctx *c, uint8_t pif,
		    const struct fwd_scan *tcp, const struct fwd_scan *udp);
void fwd_listen_close(const struct fwd_table *fwd);
int fwd_listen_init(const struct ctx *c);

bool nat_inbound(const struct ctx *c, const union inany_addr *addr,
		 union inany_addr *translated);
uint8_t fwd_nat_from_tap(const struct ctx *c, uint8_t proto,
			 const struct flowside *ini, struct flowside *tgt);
uint8_t fwd_nat_from_splice(const struct fwd_rule *rule, uint8_t proto,
			    const struct flowside *ini, struct flowside *tgt);
uint8_t fwd_nat_from_host(const struct ctx *c,
			  const struct fwd_rule *rule, uint8_t proto,
			  const struct flowside *ini, struct flowside *tgt);
void fwd_neigh_table_update(const struct ctx *c, const union inany_addr *addr,
			    const uint8_t *mac, bool permanent);
void fwd_neigh_table_free(const struct ctx *c,
			  const union inany_addr *addr);
void fwd_neigh_mac_get(const struct ctx *c, const union inany_addr *addr,
		       uint8_t *mac);
void fwd_neigh_table_init(const struct ctx *c);

#endif /* FWD_H */
debug log:

solving e664d1d0 ...
found e664d1d0 in https://archives.passt.top/passt-dev/20260410010309.736855-23-david@gibson.dropbear.id.au/
found 3e365d35 in https://archives.passt.top/passt-dev/20260410010309.736855-21-david@gibson.dropbear.id.au/
found 43bfeadb in https://archives.passt.top/passt-dev/20260410010309.736855-12-david@gibson.dropbear.id.au/
found 96b8c608 in https://archives.passt.top/passt-dev/20260410010309.736855-10-david@gibson.dropbear.id.au/
found 805fabd0 in https://archives.passt.top/passt-dev/20260410010309.736855-8-david@gibson.dropbear.id.au/
found 7e9ec49e in https://archives.passt.top/passt-dev/20260410010309.736855-7-david@gibson.dropbear.id.au/
found 33600cbf in https://passt.top/passt
preparing index
index prepared:
100644 33600cbfa6aa7ac9204c4bdd394ee471645f0d5a	fwd.h

applying [1/6] https://archives.passt.top/passt-dev/20260410010309.736855-7-david@gibson.dropbear.id.au/
diff --git a/fwd.h b/fwd.h
index 33600cbf..7e9ec49e 100644


applying [2/6] https://archives.passt.top/passt-dev/20260410010309.736855-8-david@gibson.dropbear.id.au/
diff --git a/fwd.h b/fwd.h
index 7e9ec49e..805fabd0 100644


applying [3/6] https://archives.passt.top/passt-dev/20260410010309.736855-10-david@gibson.dropbear.id.au/
diff --git a/fwd.h b/fwd.h
index 805fabd0..96b8c608 100644


applying [4/6] https://archives.passt.top/passt-dev/20260410010309.736855-12-david@gibson.dropbear.id.au/
diff --git a/fwd.h b/fwd.h
index 96b8c608..43bfeadb 100644


applying [5/6] https://archives.passt.top/passt-dev/20260410010309.736855-21-david@gibson.dropbear.id.au/
diff --git a/fwd.h b/fwd.h
index 43bfeadb..3e365d35 100644


applying [6/6] https://archives.passt.top/passt-dev/20260410010309.736855-23-david@gibson.dropbear.id.au/
diff --git a/fwd.h b/fwd.h
index 3e365d35..e664d1d0 100644

Checking patch fwd.h...
Applied patch fwd.h cleanly.
Checking patch fwd.h...
Applied patch fwd.h cleanly.
Checking patch fwd.h...
Applied patch fwd.h cleanly.
Checking patch fwd.h...
Applied patch fwd.h cleanly.
Checking patch fwd.h...
Applied patch fwd.h cleanly.
Checking patch fwd.h...
Applied patch fwd.h cleanly.

index at:
100644 e664d1d062aa45137a4974288b52687e950e7d29	fwd.h

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).