跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

gate_ipv6.go

37 行 · 1.3 KB历史下载
1package cage
2
3import (
4 "bytes"
5 "encoding/binary"
6 "net/netip"
7)
8
9const MacIPv6ProbePort = 49417
10const MacIPv6ProbePrefix = "Cage IPv6 link probe v1 "
11
12// ObserveDroppedIPv6 is called at the actual VM switch, before forwarding,
13// only when its instantiated network stack has no IPv6 protocol. Validate the
14// complete datagram; ambient NDP, stale checks or another VM cannot attest it.
15func (g *EgressGate) ObserveDroppedIPv6(packet []byte) {
16 if len(packet) < 48 || packet[0]>>4 != 6 || packet[6] != 17 || packet[7] != 1 {
17 return
18 }
19 n := int(binary.BigEndian.Uint16(packet[4:6]))
20 if n+40 != len(packet) || n != int(binary.BigEndian.Uint16(packet[44:46])) || binary.BigEndian.Uint16(packet[42:44]) != MacIPv6ProbePort || binary.BigEndian.Uint16(packet[46:48]) == 0 {
21 return
22 }
23 src := netip.AddrFrom16([16]byte(packet[8:24]))
24 dst := netip.AddrFrom16([16]byte(packet[24:40]))
25 if !src.IsLinkLocalUnicast() || dst != netip.MustParseAddr("ff02::2") || !bytes.HasPrefix(packet[48:], []byte(MacIPv6ProbePrefix)) {
26 return
27 }
28 g.mu.Lock()
29 defer g.mu.Unlock()
30 if g.state.Mode != GateChecking || !g.validLocked(g.epoch) || g.state.CheckID == "" {
31 return
32 }
33 want := MacIPv6ProbePrefix + g.state.RunID + " " + g.state.CheckID
34 if string(packet[48:]) == want {
35 g.state.IPv6LinkProbeCheck = g.state.CheckID
36 }
37}