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)
|
SDLLogger.shared.log("[SDLContext] get invalid arp packet", level: .debug)
|
||||||
}
|
}
|
||||||
case .ipv4:
|
case .ipv4:
|
||||||
guard let ipPacket = IPPacket(layerPacket.data), ipPacket.header.destination == networkAddr.ip else {
|
// 有数据是通过出口网关转发的,所有只判断是合法的ip包
|
||||||
|
guard let ipPacket = IPPacket(layerPacket.data) else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -676,19 +677,37 @@ actor SDLContextActor {
|
|||||||
SDLLogger.shared.log("[SDLContext] flow_session: \(flowSession)", level: .debug)
|
SDLLogger.shared.log("[SDLContext] flow_session: \(flowSession)", level: .debug)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找arp缓存中是否有目标mac地址
|
// 判断目标地址是否和当前的网络地址是否在同一个网段
|
||||||
if let dstMac = await self.arpServer.query(ip: dstIp) {
|
// 只有在同一个网段的ip数据才直接发送
|
||||||
SDLLogger.shared.log("[SDLContext] dstIp: \(dstIp.asIpAddress()), dst_mac is: \(SDLUtil.formatMacAddress(mac: dstMac))", level: .debug)
|
if SDLUtil.inSameNetwork(ip: dstIp, compareIp: networkAddr.ip, maskLen: networkAddr.maskLen) {
|
||||||
await self.routeLayerPacket(dstMac: dstMac, type: .ipv4, data: packet.data)
|
// 查找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)
|
||||||
|
await self.routeLayerPacket(dstMac: dstMac, type: .ipv4, data: packet.data)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
SDLLogger.shared.log("[SDLContext] dstIp: \(dstIp.asIpAddress()) arp query not found, broadcast", level: .debug)
|
||||||
|
// // 构造arp广播
|
||||||
|
// let arpReqeust = ARPPacket.arpRequest(senderIP: networkAddr.ip, senderMAC: networkAddr.mac, targetIP: dstIp)
|
||||||
|
// await self.routeLayerPacket(dstMac: ARPPacket.broadcastMac , type: .arp, data: arpReqeust.marshal())
|
||||||
|
|
||||||
|
try? await self.arpServer.arpRequest(targetIp: dstIp, use: self.quicClient)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// 不在同一个网段的数据,看到是否配置了网络出口
|
||||||
|
// 如果配置了,转发数据个网络出口,否则丢弃
|
||||||
else {
|
else {
|
||||||
SDLLogger.shared.log("[SDLContext] dstIp: \(dstIp.asIpAddress()) arp query not found, broadcast", level: .debug)
|
let exitNodeIp: UInt32 = 1234
|
||||||
// // 构造arp广播
|
SDLLogger.shared.log("[SDLContext] global dstIp: \(packet.header.destination.asIpAddress())", level: .debug)
|
||||||
// let arpReqeust = ARPPacket.arpRequest(senderIP: networkAddr.ip, senderMAC: networkAddr.mac, targetIP: dstIp)
|
// 查找arp缓存中是否有目标mac地址
|
||||||
// await self.routeLayerPacket(dstMac: ARPPacket.broadcastMac , type: .arp, data: arpReqeust.marshal())
|
if let dstMac = await self.arpServer.query(ip: exitNodeIp) {
|
||||||
|
await self.routeLayerPacket(dstMac: dstMac, type: .ipv4, data: packet.data)
|
||||||
try? await self.arpServer.arpRequest(targetIp: dstIp, use: self.quicClient)
|
}
|
||||||
|
else {
|
||||||
|
try? await self.arpServer.arpRequest(targetIp: exitNodeIp, use: self.quicClient)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func routeLayerPacket(dstMac: Data, type: LayerPacket.PacketType, data: Data) async {
|
private func routeLayerPacket(dstMac: Data, type: LayerPacket.PacketType, data: Data) async {
|
||||||
@ -739,6 +758,9 @@ actor SDLContextActor {
|
|||||||
let routes: [NEIPv4Route] = [
|
let routes: [NEIPv4Route] = [
|
||||||
NEIPv4Route(destinationAddress: networkAddress.netAddress, subnetMask: networkAddress.maskAddress),
|
NEIPv4Route(destinationAddress: networkAddress.netAddress, subnetMask: networkAddress.maskAddress),
|
||||||
NEIPv4Route(destinationAddress: dnsServer, subnetMask: "255.255.255.255"),
|
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.
|
// Add code here to start the process of connecting the tunnel.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user