@kvbox/server 0.5.27 → 0.5.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/kvbox-server.js +1005 -428
- package/dist/kvbox-server.js.map +1 -1
- package/package.json +1 -1
- package/scripts/net-setup.sh +106 -19
package/package.json
CHANGED
package/scripts/net-setup.sh
CHANGED
|
@@ -2,22 +2,30 @@
|
|
|
2
2
|
# Host networking for kvbox: bridge kvbox0 (172.30.0.1/24), IP forwarding, NAT to the
|
|
3
3
|
# default route, and FORWARD accept rules for the bridge (Docker sets FORWARD's policy
|
|
4
4
|
# to DROP, so NAT alone is not enough), and the guard around boxes: no box to box, box to
|
|
5
|
-
# host, box to private networks or outbound mail
|
|
5
|
+
# host (except asking it for a <box>.kvbox name), box to private networks or outbound mail, except the
|
|
6
|
+
# links the owner made (one box to one port of another). Needs root; re-execs itself with sudo.
|
|
6
7
|
# Idempotent. The bridge and the rules vanish on host reboot, so this runs from
|
|
7
8
|
# install-server.sh once and from kvbox-server at start whenever the bridge is missing.
|
|
8
9
|
#
|
|
9
10
|
# net-setup.sh [up] create/repair everything
|
|
10
11
|
# net-setup.sh down remove the rules and the bridge (detaches any taps still on it)
|
|
11
12
|
# net-setup.sh status show what is in place; exit 1 if anything is missing
|
|
12
|
-
# net-setup.sh tap add <name> create tap <name> owned by the calling user, plugged into
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
13
|
+
# net-setup.sh tap add <name> <ip> <mac> create tap <name> owned by the calling user, plugged into
|
|
14
|
+
# the bridge; the box behind it may send as <ip>/<mac> only
|
|
15
|
+
# net-setup.sh tap add <name> <ip> <mac> detached the same, but up and not plugged in yet (a restored box
|
|
16
|
+
# keeps its old addresses until kvbox-agent changes them)
|
|
17
|
+
# net-setup.sh tap attach <name> <ip> <mac> plug a detached tap into the bridge
|
|
18
|
+
# net-setup.sh tap pin <name> <ip> <mac> pin a tap that is already plugged in (a box running
|
|
19
|
+
# from before the pin; kvbox-server does it at start)
|
|
16
20
|
# net-setup.sh tap del <name> delete it
|
|
17
21
|
# net-setup.sh proxy add <box-id> <box-ip> <host-port> <guest-port> [tcp|udp]
|
|
18
22
|
# port <host-port> on this host's public side reaches <box-ip>:<guest-port>
|
|
19
23
|
# (DNAT + forward accept, rules tagged kvbox:<box-id>; tcp by default)
|
|
20
24
|
# net-setup.sh proxy rm <box-id> <box-ip> <host-port> <guest-port> [tcp|udp] remove exactly that
|
|
25
|
+
# net-setup.sh link add <box-id> <from-ip> <to-ip> <port>
|
|
26
|
+
# box <from-ip> may open TCP connections to <to-ip>:<port> (#98), through
|
|
27
|
+
# this host; rule tagged kvbox:<box-id> (the target's) in chain KVBOX-LINKS
|
|
28
|
+
# net-setup.sh link rm <box-id> <from-ip> <to-ip> <port> remove exactly that
|
|
21
29
|
# net-setup.sh relay up <conf> [port] install <conf> (written by kvbox-server relay) as /etc/wireguard/kvbox.conf,
|
|
22
30
|
# keep the tunnel to the relay up, now and after reboots (wg-quick@kvbox), and
|
|
23
31
|
# let the control plane's HTTPS port (default 7777) in on the tunnel interface
|
|
@@ -35,9 +43,12 @@ SUBNET="${KVBOX_SUBNET:-172.30.0.0/24}"
|
|
|
35
43
|
GATEWAY="${KVBOX_GATEWAY:-172.30.0.1}"
|
|
36
44
|
PREFIX="${SUBNET#*/}"
|
|
37
45
|
TAG="kvbox:$BRIDGE" # iptables comment; `down` finds our rules by it
|
|
46
|
+
DNS_PORT=10053 # where kvbox-server answers <name>.kvbox (DNS_PORT in core/dns.ts)
|
|
47
|
+
LINKS=KVBOX-LINKS # chain of the links between boxes (#98), entered from FORWARD above the drops
|
|
38
48
|
action="${1:-up}"
|
|
39
|
-
tap_op="${2:-}"; tap_name="${3:-}";
|
|
49
|
+
tap_op="${2:-}"; tap_name="${3:-}"; tap_ip="${4:-}"; tap_mac="${5:-}"; tap_mode="${6:-}"
|
|
40
50
|
px_op="${2:-}"; px_box="${3:-}"; px_ip="${4:-}"; px_hport="${5:-}"; px_gport="${6:-}"; px_proto="${7:-tcp}"
|
|
51
|
+
lk_op="${2:-}"; lk_box="${3:-}"; lk_from="${4:-}"; lk_to="${5:-}"; lk_port="${6:-}"
|
|
41
52
|
relay_op="${2:-}"; relay_conf="${3:-}"; relay_port="${4:-7777}"
|
|
42
53
|
RELAY_IF=kvbox # wg-quick@kvbox reads /etc/wireguard/kvbox.conf
|
|
43
54
|
|
|
@@ -48,17 +59,22 @@ fail() { printf '%s✗%s %s\n' "$RED" "$NC" "$*" >&2; exit 1; }
|
|
|
48
59
|
|
|
49
60
|
case "$action" in
|
|
50
61
|
up|down|status) ;;
|
|
51
|
-
tap) [[ "$tap_op" =~ ^(add|attach|del)$ && "$tap_name" =~ ^[a-z0-9][a-z0-9._-]{0,14}$ && "$tap_mode" =~ ^(|detached)$
|
|
52
|
-
|
|
62
|
+
tap) [[ "$tap_op" =~ ^(add|attach|pin|del)$ && "$tap_name" =~ ^[a-z0-9][a-z0-9._-]{0,14}$ && "$tap_mode" =~ ^(|detached)$
|
|
63
|
+
&& ( "$tap_op" == del || ( "$tap_ip" =~ ^[0-9]{1,3}(\.[0-9]{1,3}){3}$ && "$tap_mac" =~ ^[0-9A-Fa-f]{2}(:[0-9A-Fa-f]{2}){5}$ ) ) ]] \
|
|
64
|
+
|| fail "usage: $0 tap add <name> <ip> <mac> [detached] | tap attach|pin <name> <ip> <mac> | tap del <name> (name: up to 15 chars, [a-z0-9._-])" ;;
|
|
53
65
|
proxy) [[ "$px_op" =~ ^(add|rm)$ && "$px_box" =~ ^[a-z0-9][a-z0-9._-]{0,14}$ && "$px_ip" =~ ^[0-9]{1,3}(\.[0-9]{1,3}){3}$ \
|
|
54
66
|
&& "$px_hport" =~ ^[0-9]{1,5}$ && "$px_gport" =~ ^[0-9]{1,5}$ && "$px_hport" -ne 22 && "$px_proto" =~ ^(tcp|udp)$ ]] \
|
|
55
67
|
|| fail "usage: $0 proxy add|rm <box-id> <box-ip> <host-port> <guest-port> [tcp|udp] (host port is never 22)" ;;
|
|
68
|
+
link) [[ "$lk_op" =~ ^(add|rm)$ && "$lk_box" =~ ^[a-z0-9][a-z0-9._-]{0,14}$ && "$lk_from" =~ ^[0-9]{1,3}(\.[0-9]{1,3}){3}$ \
|
|
69
|
+
&& "$lk_to" =~ ^[0-9]{1,3}(\.[0-9]{1,3}){3}$ && "$lk_port" =~ ^[0-9]{1,5}$ ]] \
|
|
70
|
+
|| fail "usage: $0 link add|rm <box-id> <from-ip> <to-ip> <port>" ;;
|
|
56
71
|
relay) if [[ ! "$relay_op" =~ ^(up|restart|down|status)$ ]] || { [[ "$relay_op" == up ]] && [[ -z "$relay_conf" ]]; } || [[ ! "$relay_port" =~ ^[0-9]{1,5}$ ]]; then
|
|
57
72
|
fail "usage: $0 relay up <conf> [port] | relay restart | relay down | relay status"
|
|
58
73
|
fi ;;
|
|
59
|
-
*) fail "usage: $0 [up|down|status|tap add|attach|del <name
|
|
74
|
+
*) fail "usage: $0 [up|down|status|tap add|attach|del <name> ...|proxy add|rm ...|link add|rm ...|relay up|restart|down|status]" ;;
|
|
60
75
|
esac
|
|
61
76
|
for bin in ip iptables sysctl; do command -v "$bin" >/dev/null 2>&1 || fail "$bin not found"; done
|
|
77
|
+
if [[ "$action" == tap ]]; then command -v tc >/dev/null 2>&1 || fail "tc not found (iproute2)"; fi
|
|
62
78
|
if [[ "$action" == relay ]]; then
|
|
63
79
|
# The conf is read before sudo drops the caller's view of its home: resolve it while we are still that user.
|
|
64
80
|
[[ "$relay_op" != up ]] || [[ -r "$relay_conf" ]] || fail "cannot read $relay_conf"
|
|
@@ -101,21 +117,34 @@ for net in "${PRIVATE_NETS[@]}"; do
|
|
|
101
117
|
done
|
|
102
118
|
RULE_DESC+=(
|
|
103
119
|
"firewall: boxes cannot send mail directly (port 25), so spam never gets this host's address blocked"
|
|
104
|
-
"firewall: boxes
|
|
120
|
+
"firewall: boxes cannot reach each other, whatever the subnet (unless linked)"
|
|
121
|
+
"firewall: boxes may answer connections made to them (published ports, the relay, links)"
|
|
105
122
|
"firewall: boxes cannot reach this host itself"
|
|
106
123
|
"firewall: this host may still talk to its boxes"
|
|
124
|
+
"DNS: boxes asking this host for a name reach kvbox-server, which answers <box>.kvbox"
|
|
125
|
+
"firewall: boxes may ask this host for names (only that)"
|
|
126
|
+
"firewall: a box may reach another box's port when they are linked (kvbox vm link)"
|
|
107
127
|
)
|
|
108
128
|
RULE_SPEC+=(
|
|
109
129
|
"filter FORWARD -i $BRIDGE -p tcp --dport 25 -m comment --comment $TAG -j DROP"
|
|
130
|
+
"filter FORWARD -i $BRIDGE -o $BRIDGE -m comment --comment $TAG -j DROP"
|
|
110
131
|
"filter FORWARD -i $BRIDGE -m conntrack --ctstate RELATED,ESTABLISHED -m comment --comment $TAG -j ACCEPT"
|
|
111
132
|
"filter INPUT -i $BRIDGE -m comment --comment $TAG -j DROP"
|
|
112
133
|
"filter INPUT -i $BRIDGE -m conntrack --ctstate RELATED,ESTABLISHED -m comment --comment $TAG -j ACCEPT"
|
|
134
|
+
"nat PREROUTING -i $BRIDGE -d $GATEWAY -p udp --dport 53 -m comment --comment $TAG -j REDIRECT --to-ports $DNS_PORT"
|
|
135
|
+
"filter INPUT -i $BRIDGE -d $GATEWAY -p udp --dport $DNS_PORT -m comment --comment $TAG -j ACCEPT"
|
|
136
|
+
"filter FORWARD -i $BRIDGE -o $BRIDGE -m comment --comment $TAG -j $LINKS"
|
|
113
137
|
)
|
|
114
138
|
has_rule() { local t=$1 c=$2; shift 2; iptables -t "$t" -C "$c" "$@" 2>/dev/null; }
|
|
115
139
|
add_rule() { local t=$1 c=$2; shift 2; iptables -t "$t" -I "$c" 1 "$@"; }
|
|
116
140
|
del_rule() { local t=$1 c=$2; shift 2; while iptables -t "$t" -C "$c" "$@" 2>/dev/null; do iptables -t "$t" -D "$c" "$@"; done; }
|
|
117
141
|
|
|
118
142
|
bridge_exists() { [[ -d "/sys/class/net/$BRIDGE" ]]; }
|
|
143
|
+
# Boxes' ports are isolated, so a box cannot reach another on the bridge; with this the host answers ARP
|
|
144
|
+
# for the other boxes, and box to box goes through the host's FORWARD chain: dropped there (bridge to
|
|
145
|
+
# bridge, whatever the subnet) unless a link accepts it (#98). Lives on the bridge, so it goes when the bridge does.
|
|
146
|
+
pvlan_key="net.ipv4.conf.$BRIDGE.proxy_arp_pvlan"
|
|
147
|
+
pvlan_on() { [[ "$(sysctl -n "$pvlan_key" 2>/dev/null)" == 1 ]]; }
|
|
119
148
|
taps_on_bridge() { local t out=""; for t in "/sys/class/net/$BRIDGE/brif"/*; do [[ -e "$t" ]] && out+="${t##*/} "; done; printf '%s' "$out"; }
|
|
120
149
|
bridge_has_ip() { ip -4 -o addr show dev "$BRIDGE" 2>/dev/null | grep -q " inet $GATEWAY/$PREFIX "; }
|
|
121
150
|
# Administrative UP flag only: an empty bridge reports operstate "down" (NO-CARRIER) until a tap joins.
|
|
@@ -127,6 +156,9 @@ do_up() {
|
|
|
127
156
|
if bridge_has_ip; then skip "$BRIDGE already has address $GATEWAY"; else ip addr add "$GATEWAY/$PREFIX" dev "$BRIDGE"; ok "gave this host address $GATEWAY on $BRIDGE (boxes use it as their gateway)"; fi
|
|
128
157
|
if bridge_is_up; then skip "$BRIDGE is already up"; else ip link set "$BRIDGE" up; ok "brought $BRIDGE up"; fi
|
|
129
158
|
if [[ "$(sysctl -n net.ipv4.ip_forward)" == 1 ]]; then skip "IP forwarding already enabled"; else sysctl -q -w net.ipv4.ip_forward=1; ok "enabled IP forwarding (this host routes for the boxes)"; fi
|
|
159
|
+
if pvlan_on; then skip "box to box already goes through this host's firewall"; else sysctl -q -w "$pvlan_key=1"; ok "box to box now goes through this host's firewall (closed unless linked)"; fi
|
|
160
|
+
# The base rules jump to it, so it must exist before they are checked.
|
|
161
|
+
iptables -t filter -N "$LINKS" 2>/dev/null || true
|
|
130
162
|
local i missing=0 present=()
|
|
131
163
|
for i in "${!RULE_SPEC[@]}"; do
|
|
132
164
|
# shellcheck disable=SC2086 # the rule is a word list by design
|
|
@@ -170,7 +202,8 @@ do_down() {
|
|
|
170
202
|
# shellcheck disable=SC2086 # iptables-save wrote the rule as a word list
|
|
171
203
|
eval "iptables -t $t -D $rule" && n=$((n + 1))
|
|
172
204
|
done < <(proxy_rules)
|
|
173
|
-
if [[ $n -gt 0 ]]; then ok "removed $n box port forward rule(s)"; else skip "no box port forwards"; fi
|
|
205
|
+
if [[ $n -gt 0 ]]; then ok "removed $n box port forward and link rule(s)"; else skip "no box port forwards or links"; fi
|
|
206
|
+
if iptables -t filter -X "$LINKS" 2>/dev/null; then ok "removed the links chain"; fi
|
|
174
207
|
}
|
|
175
208
|
|
|
176
209
|
# ── status ───────────────────────────────────────────────────────────────────
|
|
@@ -182,6 +215,7 @@ do_status() {
|
|
|
182
215
|
elif ! bridge_has_ip; then bad "bridge $BRIDGE has no address $GATEWAY"
|
|
183
216
|
else bad "bridge $BRIDGE is down"; fi
|
|
184
217
|
if [[ "$(sysctl -n net.ipv4.ip_forward)" == 1 ]]; then ok "IP forwarding enabled"; else bad "IP forwarding disabled"; fi
|
|
218
|
+
if pvlan_on; then ok "box to box goes through this host's firewall"; elif bridge_exists; then bad "box to box does not go through this host's firewall (links cannot work)"; fi
|
|
185
219
|
for i in "${!RULE_SPEC[@]}"; do
|
|
186
220
|
# shellcheck disable=SC2086
|
|
187
221
|
if has_rule ${RULE_SPEC[$i]}; then ok "${RULE_DESC[$i]}"; else bad "missing: ${RULE_DESC[$i]}"; fi
|
|
@@ -189,9 +223,14 @@ do_status() {
|
|
|
189
223
|
local taps; taps="$(taps_on_bridge)"
|
|
190
224
|
if [[ -z "$taps" ]]; then skip "no boxes attached to $BRIDGE yet"; else ok "boxes attached to $BRIDGE: $taps"; fi
|
|
191
225
|
local tap
|
|
192
|
-
for tap in $taps; do
|
|
226
|
+
for tap in $taps; do
|
|
227
|
+
tap_isolated "$tap" || bad "box on $tap can reach other boxes (tap not isolated)"
|
|
228
|
+
tap_pinned "$tap" || bad "box on $tap may send as another box (tap not pinned to its address; restart kvbox-server)"
|
|
229
|
+
done
|
|
193
230
|
local fwds; fwds="$(proxy_summary)"
|
|
194
231
|
if [[ -z "$fwds" ]]; then skip "no box ports published on this host"; else ok "box ports published on this host:"; printf '%s\n' "$fwds"; fi
|
|
232
|
+
local links; links="$(link_summary)"
|
|
233
|
+
if [[ -z "$links" ]]; then skip "no links between boxes"; else ok "links between boxes:"; printf '%s\n' "$links"; fi
|
|
195
234
|
if [[ $missing -eq 0 ]]; then echo; ok "host network is ready"; else echo; printf '%s✗%s host network incomplete; run: kvbox-server net up\n' "$RED" "$NC"; fi
|
|
196
235
|
return $missing
|
|
197
236
|
}
|
|
@@ -199,7 +238,7 @@ do_status() {
|
|
|
199
238
|
# ── tap add|del ──────────────────────────────────────────────────────────────
|
|
200
239
|
# One tap per box: a virtual cable with one end in the VM and the other plugged into the bridge.
|
|
201
240
|
do_tap_add() {
|
|
202
|
-
local tap=$1 mode=${
|
|
241
|
+
local tap=$1 ip=$2 mac=$3 mode=${4:-} owner="${KVBOX_TAP_USER:-${SUDO_USER:-root}}"
|
|
203
242
|
bridge_exists || fail "bridge $BRIDGE does not exist; run: kvbox-server net up"
|
|
204
243
|
if [[ -d "/sys/class/net/$tap" ]]; then
|
|
205
244
|
skip "tap $tap already exists"
|
|
@@ -211,20 +250,33 @@ do_tap_add() {
|
|
|
211
250
|
ip link set "$tap" up
|
|
212
251
|
ok "tap $tap is up, not plugged into $BRIDGE yet"
|
|
213
252
|
else
|
|
214
|
-
do_tap_attach "$tap"
|
|
253
|
+
do_tap_attach "$tap" "$ip" "$mac"
|
|
215
254
|
fi
|
|
216
255
|
}
|
|
217
256
|
do_tap_attach() {
|
|
218
|
-
local tap=$1
|
|
257
|
+
local tap=$1 ip=$2 mac=$3
|
|
219
258
|
[[ -d "/sys/class/net/$tap" ]] || fail "tap $tap does not exist"
|
|
259
|
+
pin_tap "$tap" "$ip" "$mac"
|
|
220
260
|
ip link set "$tap" master "$BRIDGE" up
|
|
221
261
|
isolate_tap "$tap"
|
|
222
|
-
ok "tap $tap plugged into $BRIDGE"
|
|
262
|
+
ok "tap $tap plugged into $BRIDGE, sending as $ip only"
|
|
223
263
|
}
|
|
224
264
|
# An isolated bridge port talks to the host (the gateway) but never to another isolated port:
|
|
225
265
|
# one box cannot see another box's ports, whoever owns them.
|
|
226
266
|
isolate_tap() { ip link set dev "$1" type bridge_slave isolated on; }
|
|
227
267
|
tap_isolated() { ip -d link show dev "$1" 2>/dev/null | grep -q "isolated on"; }
|
|
268
|
+
# A link is granted to a source IP (#98), and the guest has root: without this a box could take another
|
|
269
|
+
# box's IP (or MAC) and answer the host's ARP for it. What the box sends (the tap's ingress) passes only
|
|
270
|
+
# with its own MAC and IP, ARP only for its own IP; everything else, IPv6 included, is dropped.
|
|
271
|
+
pin_tap() {
|
|
272
|
+
local tap=$1 ip=$2 mac=$3
|
|
273
|
+
tc qdisc replace dev "$tap" clsact
|
|
274
|
+
tc filter del dev "$tap" ingress 2>/dev/null || true
|
|
275
|
+
tc filter add dev "$tap" ingress pref 10 protocol ip flower src_mac "$mac" src_ip "$ip" action pass
|
|
276
|
+
tc filter add dev "$tap" ingress pref 20 protocol arp flower src_mac "$mac" arp_sip "$ip" action pass
|
|
277
|
+
tc filter add dev "$tap" ingress pref 30 protocol all matchall action drop
|
|
278
|
+
}
|
|
279
|
+
tap_pinned() { tc filter show dev "$1" ingress 2>/dev/null | grep -q "matchall"; }
|
|
228
280
|
do_tap_del() {
|
|
229
281
|
local tap=$1
|
|
230
282
|
if [[ -d "/sys/class/net/$tap" ]]; then ip link del "$tap"; ok "deleted tap $tap"; else skip "tap $tap does not exist"; fi
|
|
@@ -272,7 +324,36 @@ proxy_rules() {
|
|
|
272
324
|
}
|
|
273
325
|
# One line per published port: "port 31207 -> box a3f9c1 (172.30.0.2:22)".
|
|
274
326
|
proxy_summary() {
|
|
275
|
-
proxy_rules | grep -F "PREROUTING" | sed -E 's/.*-p ([a-z]+) .*--dport ([0-9]+) .*--comment kvbox:([^ ]+) .*--to-destination ([0-9.:]+).*/ \1 port \2 -> box \3 (\4)/'
|
|
327
|
+
proxy_rules | grep -F "PREROUTING" | sed -E 's/.*-p ([a-z]+) .*--dport ([0-9]+) .*--comment kvbox:([^ ]+) .*--to-destination ([0-9.:]+).*/ \1 port \2 -> box \3 (\4)/' || true
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
# ── link add|rm ──────────────────────────────────────────────────────────────
|
|
331
|
+
# A link (#98): one box may open TCP connections to one port of another, through this host. One rule in
|
|
332
|
+
# KVBOX-LINKS, which FORWARD enters for bridge-to-bridge traffic above the drops (a base rule, so `up`
|
|
333
|
+
# keeps the order); replies come back on the RELATED,ESTABLISHED accept. Tagged with the target's box id.
|
|
334
|
+
link_spec() { printf '%s' "filter $LINKS -s $2 -d $3 -p tcp --dport $4 -m comment --comment kvbox:$1 -j ACCEPT"; }
|
|
335
|
+
link_jump="filter FORWARD -i $BRIDGE -o $BRIDGE -m comment --comment $TAG -j $LINKS"
|
|
336
|
+
do_link_add() {
|
|
337
|
+
# shellcheck disable=SC2086
|
|
338
|
+
if ! pvlan_on || ! has_rule $link_jump; then fail "this host's network predates links between boxes; run: kvbox-server net up"; fi
|
|
339
|
+
# A link trusts the source IP: refuse while any box could still send as another (a tap from before the pin).
|
|
340
|
+
local tap
|
|
341
|
+
for tap in $(taps_on_bridge); do tap_pinned "$tap" || fail "a box on this host ($tap) runs from before boxes were pinned to their address; restart kvbox-server, which pins it"; done
|
|
342
|
+
local spec; spec="$(link_spec "$@")"
|
|
343
|
+
# shellcheck disable=SC2086 # the rule is a word list by design
|
|
344
|
+
if has_rule $spec; then skip "box $2 already reaches $3 port $4"; else add_rule $spec; ok "box $2 may now reach $3 port $4"; fi
|
|
345
|
+
}
|
|
346
|
+
do_link_rm() {
|
|
347
|
+
local spec; spec="$(link_spec "$@")"
|
|
348
|
+
# shellcheck disable=SC2086
|
|
349
|
+
if has_rule $spec; then del_rule $spec; ok "box $2 no longer reaches $3 port $4"; else skip "box $2 was not linked to $3 port $4"; fi
|
|
350
|
+
# Open connections outlive the rule otherwise.
|
|
351
|
+
if command -v conntrack >/dev/null 2>&1; then conntrack -D -p tcp -s "$2" -d "$3" --dport "$4" >/dev/null 2>&1 || true; fi
|
|
352
|
+
}
|
|
353
|
+
# One line per link: "172.30.0.5 -> 172.30.0.9 port 5432".
|
|
354
|
+
link_summary() {
|
|
355
|
+
iptables-save -t filter 2>/dev/null | sed -n "s/^-A $LINKS //p" \
|
|
356
|
+
| sed -E 's/.*-s ([0-9.]+)(\/32)? -d ([0-9.]+)(\/32)? .*--dport ([0-9]+).*/ \1 -> \3 port \5/' || true
|
|
276
357
|
}
|
|
277
358
|
|
|
278
359
|
# ── relay up|down|status ─────────────────────────────────────────────────────
|
|
@@ -355,14 +436,20 @@ case "$action" in
|
|
|
355
436
|
down) do_down ;;
|
|
356
437
|
status) do_status ;;
|
|
357
438
|
tap) case "$tap_op" in
|
|
358
|
-
add) do_tap_add "$tap_name" "$tap_mode" ;;
|
|
359
|
-
attach) do_tap_attach "$tap_name" ;;
|
|
439
|
+
add) do_tap_add "$tap_name" "$tap_ip" "$tap_mac" "$tap_mode" ;;
|
|
440
|
+
attach) do_tap_attach "$tap_name" "$tap_ip" "$tap_mac" ;;
|
|
441
|
+
pin) [[ -d "/sys/class/net/$tap_name" ]] || fail "tap $tap_name does not exist"
|
|
442
|
+
pin_tap "$tap_name" "$tap_ip" "$tap_mac"; ok "tap $tap_name sends as $tap_ip only" ;;
|
|
360
443
|
del) do_tap_del "$tap_name" ;;
|
|
361
444
|
esac ;;
|
|
362
445
|
proxy) case "$px_op" in
|
|
363
446
|
add) do_proxy_add "$px_box" "$px_ip" "$px_hport" "$px_gport" "$px_proto" ;;
|
|
364
447
|
rm) do_proxy_rm "$px_box" "$px_ip" "$px_hport" "$px_gport" "$px_proto" ;;
|
|
365
448
|
esac ;;
|
|
449
|
+
link) case "$lk_op" in
|
|
450
|
+
add) do_link_add "$lk_box" "$lk_from" "$lk_to" "$lk_port" ;;
|
|
451
|
+
rm) do_link_rm "$lk_box" "$lk_from" "$lk_to" "$lk_port" ;;
|
|
452
|
+
esac ;;
|
|
366
453
|
relay) case "$relay_op" in
|
|
367
454
|
up) do_relay_up "$relay_conf" "$relay_port" ;;
|
|
368
455
|
restart) do_relay_restart ;;
|