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