Skip to content

Commit

Permalink
Fix handling 4-in-6 IP for WriteBack
Browse files Browse the repository at this point in the history
  • Loading branch information
comzyh committed Jul 1, 2023
1 parent 06eaed0 commit 2e2f6f0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions listener/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ func ReCreateTun(conf config.Tun, tcpIn chan<- C.ConnContext, udpIn chan<- *inbo
}
tunAdapter.ReCreateDNSServer(conf.DNSListen)
}

func ResetDNSResolver(resolver *dns.Resolver, mapper *dns.ResolverEnhancer) {
if tunAdapter != nil {
tunAdapter.ResetDNSResolver(resolver, mapper)
Expand Down
4 changes: 4 additions & 0 deletions listener/tun/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func (c *fakeConn) WriteBack(b []byte, addr net.Addr) (n int, err error) {
} else {
udpaddr, _ := addr.(*net.UDPAddr)
localAddress = tcpip.AddrFromSlice(udpaddr.IP)
// We may get 4-in-6 IP here, but should not use 16 bytes IP in FindRoute
if c.pkt.NetworkProtocolNumber == header.IPv4ProtocolNumber {
localAddress = localAddress.To4()
}
localPort = uint16(udpaddr.Port)
}

Expand Down

0 comments on commit 2e2f6f0

Please sign in to comment.