close raw sockets too
This commit is contained in:
parent
1f16800b73
commit
99658cb49c
|
@ -95,6 +95,7 @@ proc injectTcpPacket(rawFd: AsyncFD, ipPacket: IpPacket) {.async.} =
|
|||
proc captureSeqNumbers(attempt: ConnectAttempt, rawFd: AsyncFD,
|
||||
cb: PunchProgressCb) {.async.} =
|
||||
# FIXME: timeout?
|
||||
# FIXME: create raw socket here
|
||||
var seqNums = newSeq[uint32]()
|
||||
while seqNums.len < attempt.dstPorts.len:
|
||||
let packet = await rawFd.recv(4000)
|
||||
|
@ -110,10 +111,13 @@ proc captureSeqNumbers(attempt: ConnectAttempt, rawFd: AsyncFD,
|
|||
if parsed.tcpPortDst.int == port.int:
|
||||
seqNums.add(parsed.tcpSeqNumber)
|
||||
break
|
||||
closeSocket(rawFd)
|
||||
await cb(seqNums)
|
||||
|
||||
proc captureAndResendAck(attempt: ConnectAttempt, captureFd: AsyncFD,
|
||||
injectFd: AsyncFD) {.async.} =
|
||||
# FIXME: create raw socket here
|
||||
block loops:
|
||||
while true:
|
||||
let packet = await captureFd.recv(4000)
|
||||
if packet == "":
|
||||
|
@ -129,7 +133,9 @@ proc captureAndResendAck(attempt: ConnectAttempt, captureFd: AsyncFD,
|
|||
parsed.ipTTL = 64
|
||||
echo &"[{parsed.ipAddrSrc}:{parsed.tcpPortSrc.int} -> {parsed.ipAddrDst}:{parsed.tcpPortDst}, SEQ {parsed.tcpSeqNumber}] resending ACK with TTL {parsed.ipTTL}"
|
||||
await injectFd.injectTcpPacket(parsed)
|
||||
return
|
||||
break loops
|
||||
closeSocket(captureFd)
|
||||
closeSocket(injectFd)
|
||||
|
||||
proc initPuncher*(): TcpSyniPuncher = TcpSyniPuncher()
|
||||
|
||||
|
@ -291,6 +297,7 @@ proc accept*(puncher: TcpSyniPuncher, srcPort: Port, dstIp: IpAddress,
|
|||
tcpFlags: {SYN}, tcpWindowSize: 1452 * 10)
|
||||
echo &"[{ipPacket.ipAddrSrc}:{ipPacket.tcpPortSrc} -> {ipPacket.ipAddrDst}:{ipPacket.tcpPortDst}, SEQ {ipPacket.tcpSeqNumber}] injecting SYN"
|
||||
asyncCheck rawFd.injectTcpPacket(ipPacket)
|
||||
closeSocket(rawFd)
|
||||
await attempt.future or sleepAsync(Timeout)
|
||||
await attempt.deleteFirewallRules()
|
||||
puncher.acceptAttempts.del(puncher.acceptAttempts.find(attempt))
|
||||
|
|
Loading…
Reference in New Issue