fix
This commit is contained in:
parent
19414b4543
commit
92f224e721
@ -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) {
|
||||
// 查找arp缓存中是否有目标mac地址
|
||||
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)
|
||||
// 查找arp缓存中是否有目标mac地址
|
||||
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.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user