ssh-net 0.1.0 → 0.1.1

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/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  本项目版本号与发布节奏仿 mihomo-cli:npm 公共分发,版本即升级动作。
4
4
 
5
+ ## [0.1.1] - 2026-09-29
6
+
7
+ ### 新增
8
+
9
+ - `v6-address` 新增 `SSH_NET_V6_ALLOW_ULA=1`:额外接受 fc00::/7 ULA,用于
10
+ 办公室内网彩排 peer 路径与纯内网部署;默认仍只选 2000::/3 公网单播。
11
+ - checkin 的 v6 校验放宽为「可拨号段」(2000::/3 公网单播或 fc00::/7 ULA):
12
+ 选取的严格性在 edge 侧 v6-address,core 只校验可拨性;link-local、组播、
13
+ 内嵌 v4、带 scope id 照拒。
14
+
5
15
  ## [0.1.0] - 2026-09-29
6
16
 
7
17
  首个可发布版本(迁移 Phase 1 软件交付,未做各机部署)。
package/README.md CHANGED
@@ -77,5 +77,7 @@ npm link # 开发机:全局 ssh-net 指向本仓,改脚本即时
77
77
 
78
78
  ## 状态
79
79
 
80
- 0.1.0 软件就绪、测试全绿(2026-09-29);尚未 publish,各机部署按
81
- docs/migration.md 的 Phase 2 起执行(Phase 0 现场项仍待真机闸门)。
80
+ 0.1.0 已发布 npm(2026-09-29,GitHub Actions 自动发布)。部署:m4(core)与
81
+ n007/n061(node)已切换至 ssh-net(2026-09-29,服务端三台齐、旧 ssh-reverse
82
+ 三台清零,s100 上 12022/12031/12032 均为新链);edge 侧按 docs/migration.md
83
+ Phase 4/5 待 mb5/mb1 到场(known-hosts 待填 edge 公钥)。
@@ -1,24 +1,47 @@
1
- // checkin v6 入参的严格校验。唯一外部输入面(design §6.3):
2
- // 合法 IPv6 字面值 + 落在 2000::/3 全局单播段;拒绝 scope id、内嵌 v4
3
- // (含 ::ffff: v4-mapped)、ULA、link-local、unspecified、保留段等一切非 2000::/3。
4
- // 依赖 net.isIP 做字面值合法性,首 hextet 判段——2000::/3 即首组 0x2000–0x3fff,
5
- // 其余该拒的段(fc/fd、fe80、ff、::1、::)本就不在此区间,无需逐段分类。
1
+ // checkin v6 入参校验(design §6.3)。唯一外部输入面:合法 IPv6 字面值 +
2
+ // 可拨号段——2000::/3 公网单播,或 fc00::/7 ULA(2026-09-29 起收 ULA:
3
+ // 办公室内网彩排 peer 路径 / 纯内网部署场景。「报不报 ULA」的严格性在
4
+ // edge 侧 v6-address 的选取,checkin 只管「这个地址能不能拨」)。
5
+ // 仍拒绝 scope id、内嵌 v4(含 ::ffff: v4-mapped)、link-local、unspecified、
6
+ // 组播等。依赖 net.isIP 做字面值合法性,首 hextet 判段。
6
7
  import net from 'node:net';
7
8
 
8
9
  /**
10
+ * 取首 hextet 数值;不是「无 scope、非内嵌 v4 的合法 IPv6 字面值」返回 null。
9
11
  * @param {unknown} value
10
- * @returns {boolean}
12
+ * @returns {number | null}
11
13
  */
12
- export function isGlobalUnicastV6(value) {
13
- if (typeof value !== 'string') return false;
14
- if (value.length === 0 || value.includes('%')) return false; // 无 scope id
15
- if (net.isIP(value) !== 6) return false;
14
+ function firstHextetOf(value) {
15
+ if (typeof value !== 'string') return null;
16
+ if (value.length === 0 || value.includes('%')) return null; // 无 scope id
17
+ if (net.isIP(value) !== 6) return null;
16
18
  // 任何内嵌 v4 形态(末段含点,如 ::ffff:192.0.2.1)一律拒
17
19
  const tail = value.slice(value.lastIndexOf(':') + 1);
18
- if (tail.includes('.')) return false;
20
+ if (tail.includes('.')) return null;
19
21
  const firstGroup = value.split(':')[0];
20
22
  const g0 = firstGroup === '' ? 0 : Number.parseInt(firstGroup, 16);
21
- return Number.isInteger(g0) && g0 >= 0x2000 && g0 <= 0x3fff;
23
+ return Number.isInteger(g0) ? g0 : null;
24
+ }
25
+
26
+ /**
27
+ * 2000::/3 全局单播(首组 0x2000–0x3fff)。
28
+ * @param {unknown} value
29
+ * @returns {boolean}
30
+ */
31
+ export function isGlobalUnicastV6(value) {
32
+ const g0 = firstHextetOf(value);
33
+ return g0 !== null && g0 >= 0x2000 && g0 <= 0x3fff;
34
+ }
35
+
36
+ /**
37
+ * 可拨号段:2000::/3 公网单播或 fc00::/7 ULA(首组 0xfc00–0xfdff)。
38
+ * @param {unknown} value
39
+ * @returns {boolean}
40
+ */
41
+ export function isDialableV6(value) {
42
+ const g0 = firstHextetOf(value);
43
+ return g0 !== null
44
+ && ((g0 >= 0x2000 && g0 <= 0x3fff) || (g0 >= 0xfc00 && g0 <= 0xfdff));
22
45
  }
23
46
 
24
47
  /**
@@ -32,8 +55,8 @@ export function explainV6Error(value) {
32
55
  if (net.isIP(value) !== 6) return '不是合法 IPv6 字面值';
33
56
  if (value.slice(value.lastIndexOf(':') + 1).includes('.'))
34
57
  return '拒绝内嵌 v4(含 ::ffff: v4-mapped)';
35
- // 2000::/3 判定单一来源是 isGlobalUnicastV6,别在这抄第二份
36
- if (!isGlobalUnicastV6(value))
37
- return '不是 2000::/3 全局单播地址(拒绝 ULA/link-local/保留段)';
58
+ // 可拨号判定单一来源是 isDialableV6,别在这抄第二份
59
+ if (!isDialableV6(value))
60
+ return '不是可拨号 v6(收 2000::/3 公网单播与 fc00::/7 ULA,拒 link-local/组播/保留段)';
38
61
  return null;
39
62
  }
@@ -2,6 +2,8 @@
2
2
  # v6-address:选取本机可注册的公网 v6——默认路由网卡上 2000::/3 全局单播、
3
3
  # autoconf secured、非 deprecated/temporary 的第一个地址(design §6.4)。
4
4
  # 无输出 = 没有可注册 v6(v4-only/咖啡厅场景),退出码恒 0。
5
+ # SSH_NET_V6_ALLOW_ULA=1 额外收 fc00::/7 ULA(办公室内网彩排 peer 路径 /
6
+ # 纯内网部署;默认公网行为不变)。
5
7
  # 除 route/ifconfig 不引外部命令;ROUTE/IFCONFIG/SSH_NET_DEFAULT_IF 仅测试注入。
6
8
  set -u
7
9
  LC_ALL=C
@@ -9,16 +11,21 @@ export LC_ALL
9
11
  ROUTE=${ROUTE:-/sbin/route}
10
12
  IFCONFIG=${IFCONFIG:-/sbin/ifconfig}
11
13
 
12
- # 首 hextet ∈ [0x2000,0x3fff] 即 2000::/3。合法地址首段直接取首个冒号前,
14
+ # 首 hextet 判段:默认 [0x2000,0x3fff](2000::/3);SSH_NET_V6_ALLOW_ULA=1
15
+ # 时额外收 [0xfc00,0xfdff](fc00::/7 ULA)。合法地址首段直接取首个冒号前,
13
16
  # 不需展开 ::;拒内嵌点(v4/v4-mapped)与非十六进制。
14
- in_global_unicast() {
17
+ in_allowed_range() {
15
18
  local a=$1 g v
16
19
  case "$a" in *.*) return 1 ;; esac
17
20
  g=${a%%:*}
18
21
  [ -n "$g" ] || return 1
19
22
  case "$g" in *[!0-9a-fA-F]*) return 1 ;; esac
20
23
  v=$((16#$g))
21
- [ "$v" -ge $((16#2000)) ] && [ "$v" -le $((16#3fff)) ]
24
+ if [ "$v" -ge $((16#2000)) ] && [ "$v" -le $((16#3fff)) ]; then return 0; fi
25
+ if [ "${SSH_NET_V6_ALLOW_ULA:-}" = 1 ]; then
26
+ [ "$v" -ge $((16#fc00)) ] && [ "$v" -le $((16#fdff)) ] && return 0
27
+ fi
28
+ return 1
22
29
  }
23
30
 
24
31
  # 默认路由网卡(route 输出 "interface: en0"),纯内建解析
@@ -50,7 +57,7 @@ while IFS= read -r line; do
50
57
  case "$line" in *autoconf*secured*) ;; *) continue ;; esac
51
58
  case "$line" in *deprecated*|*temporary*) continue ;; esac
52
59
  addr=${2%%%*} # 去可能的 scope
53
- if in_global_unicast "$addr"; then
60
+ if in_allowed_range "$addr"; then
54
61
  printf '%s\n' "$addr"
55
62
  exit 0
56
63
  fi
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ssh-net",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "description": "个人 SSH 组网:v6 直连优先、relay 兜底、关机有界重试后静默",
6
6
  "bin": {