@kvbox/server 0.6.10 → 0.6.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kvbox/server",
3
- "version": "0.6.10",
3
+ "version": "0.6.11",
4
4
  "description": "kvbox host daemon: owns Firecracker microVMs on a Linux host and serves the kvbox API. Managed with the @kvbox/cli CLI.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -82,6 +82,24 @@ if [[ "$action" == relay ]]; then
82
82
  command -v wg-quick >/dev/null 2>&1 || fail "WireGuard is not installed on this host (apt install wireguard-tools), so it cannot use a relay"
83
83
  command -v systemctl >/dev/null 2>&1 || fail "systemd is needed to keep the relay tunnel up across reboots"
84
84
  fi
85
+ # The boxes' range must not be a network this machine is already on: its own address on the bridge would
86
+ # then answer for the real gateway and the machine loses its network (kvbox-server run inside a kvbox box,
87
+ # whose host gave it the same default range). Checked before sudo, so nothing is touched.
88
+ ip_int() { local a b c d; IFS=. read -r a b c d <<<"$1"; echo $(( (a << 24) | (b << 16) | (c << 8) | d )); }
89
+ clashing_net() { # "<interface> <address>" of the first other interface whose network overlaps SUBNET
90
+ local dev cidr p mask
91
+ while read -r _ dev _ cidr _; do
92
+ if [[ "$dev" == "$BRIDGE" || "$dev" == lo ]]; then continue; fi
93
+ [[ "$cidr" == */* ]] || cidr="$cidr/32"
94
+ p="${cidr#*/}"; if (( p > PREFIX )); then p="$PREFIX"; fi
95
+ mask=$(( p == 0 ? 0 : (0xFFFFFFFF << (32 - p)) & 0xFFFFFFFF ))
96
+ if (( ($(ip_int "${cidr%/*}") & mask) == ($(ip_int "${SUBNET%/*}") & mask) )); then echo "$dev $cidr"; return 0; fi
97
+ done < <(ip -4 -o addr show)
98
+ return 1
99
+ }
100
+ if [[ "$action" == up ]] && clash="$(clashing_net)"; then
101
+ fail "this machine is already on $SUBNET itself (${clash#* } on ${clash%% *}), the range kvbox gives its boxes: setting it up would cut this machine off the network. Nothing was changed. Give the boxes another range in kvbox's config.json, for example \"subnet\": \"172.31.0.0/24\" and \"gateway\": \"172.31.0.1\""
102
+ fi
85
103
  if [[ $EUID -ne 0 ]]; then
86
104
  # From a terminal sudo may prompt; from kvbox-server (no tty) it must not hang.
87
105
  # KVBOX_TAP_USER tells the root side who should own a new tap (Firecracker runs as that user).