This commit is contained in:
anlicheng 2026-03-30 12:31:19 +08:00
parent 19414b4543
commit 92f224e721

View File

@ -564,7 +564,8 @@ actor SDLContextActor {
SDLLogger.shared.log("[SDLContext] get invalid arp packet", level: .debug)
}
case .ipv4:
guard let ipPacket = IPPacket(layerPacket.data), ipPacket.header.destination == networkAddr.ip else {
// ip
guard let ipPacket = IPPacket(layerPacket.data) else {
return
}
@ -676,6 +677,9 @@ actor SDLContextActor {
SDLLogger.shared.log("[SDLContext] flow_session: \(flowSession)", level: .debug)
}
//
// ip
if SDLUtil.inSameNetwork(ip: dstIp, compareIp: networkAddr.ip, maskLen: networkAddr.maskLen) {
// arpmac
if let dstMac = await self.arpServer.query(ip: dstIp) {
SDLLogger.shared.log("[SDLContext] dstIp: \(dstIp.asIpAddress()), dst_mac is: \(SDLUtil.formatMacAddress(mac: dstMac))", level: .debug)
@ -690,6 +694,21 @@ actor SDLContextActor {
try? await self.arpServer.arpRequest(targetIp: dstIp, use: self.quicClient)
}
}
//
//
else {
let exitNodeIp: UInt32 = 1234
SDLLogger.shared.log("[SDLContext] global dstIp: \(packet.header.destination.asIpAddress())", level: .debug)
// arpmac
if let dstMac = await self.arpServer.query(ip: exitNodeIp) {
await self.routeLayerPacket(dstMac: dstMac, type: .ipv4, data: packet.data)
}
else {
try? await self.arpServer.arpRequest(targetIp: exitNodeIp, use: self.quicClient)
}
}
}
private func routeLayerPacket(dstMac: Data, type: LayerPacket.PacketType, data: Data) async {
let networkAddr = self.config.networkAddress
@ -739,6 +758,9 @@ actor SDLContextActor {
let routes: [NEIPv4Route] = [
NEIPv4Route(destinationAddress: networkAddress.netAddress, subnetMask: networkAddress.maskAddress),
NEIPv4Route(destinationAddress: dnsServer, subnetMask: "255.255.255.255"),
// TODO
NEIPv4Route(destinationAddress: "172.16.1.0", subnetMask: "255.255.255.0"),
]
// Add code here to start the process of connecting the tunnel.