Feature: resolve ip with proxy adapter
This commit is contained in:
@ -28,10 +28,6 @@ func hijackUDPDns(conn golwip.UDPConn, pkt []byte, addr *net.UDPAddr) {
|
||||
_ = conn.Close()
|
||||
}(conn)
|
||||
|
||||
if err := conn.SetDeadline(time.Now().Add(defaultDnsReadTimeout)); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
answer, err := D.RelayDnsPacket(pkt)
|
||||
if err != nil {
|
||||
return
|
||||
@ -81,7 +77,7 @@ func hijackTCPDns(conn net.Conn) {
|
||||
|
||||
type dnsHandler struct{}
|
||||
|
||||
func NewDnsHandler() golwip.DnsHandler {
|
||||
func newDnsHandler() golwip.DnsHandler {
|
||||
return &dnsHandler{}
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ type tcpHandler struct {
|
||||
tcpIn chan<- C.ConnContext
|
||||
}
|
||||
|
||||
func NewTCPHandler(dnsIP net.IP, tcpIn chan<- C.ConnContext) golwip.TCPConnHandler {
|
||||
func newTCPHandler(dnsIP net.IP, tcpIn chan<- C.ConnContext) golwip.TCPConnHandler {
|
||||
return &tcpHandler{dnsIP, tcpIn}
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ func NewAdapter(device dev.TunDevice, conf config.Tun, mtu int, tcpIn chan<- C.C
|
||||
})
|
||||
|
||||
// Set custom buffer pool
|
||||
golwip.SetPoolAllocator(&lwipPool{})
|
||||
golwip.SetPoolAllocator(newLWIPPool())
|
||||
|
||||
// Setup TCP/IP stack.
|
||||
lwipStack, err := golwip.NewLWIPStack(mtu)
|
||||
@ -59,9 +59,9 @@ func NewAdapter(device dev.TunDevice, conf config.Tun, mtu int, tcpIn chan<- C.C
|
||||
}
|
||||
adapter.lwipStack = lwipStack
|
||||
|
||||
golwip.RegisterDnsHandler(NewDnsHandler())
|
||||
golwip.RegisterTCPConnHandler(NewTCPHandler(dnsIP, tcpIn))
|
||||
golwip.RegisterUDPConnHandler(NewUDPHandler(dnsIP, udpIn))
|
||||
golwip.RegisterDnsHandler(newDnsHandler())
|
||||
golwip.RegisterTCPConnHandler(newTCPHandler(dnsIP, tcpIn))
|
||||
golwip.RegisterUDPConnHandler(newUDPHandler(dnsIP, udpIn))
|
||||
|
||||
// Copy packets from tun device to lwip stack, it's the loop.
|
||||
go func(lwipStack golwip.LWIPStack, device dev.TunDevice, mtu int) {
|
||||
@ -95,7 +95,7 @@ func (l *lwipAdapter) Close() {
|
||||
|
||||
func (l *lwipAdapter) stopLocked() {
|
||||
if l.lwipStack != nil {
|
||||
l.lwipStack.Close()
|
||||
_ = l.lwipStack.Close()
|
||||
}
|
||||
|
||||
if l.device != nil {
|
||||
@ -115,3 +115,7 @@ func (p lwipPool) Get(size int) []byte {
|
||||
func (p lwipPool) Put(buf []byte) error {
|
||||
return pool.Put(buf)
|
||||
}
|
||||
|
||||
func newLWIPPool() golwip.LWIPPool {
|
||||
return &lwipPool{}
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ type udpHandler struct {
|
||||
udpIn chan<- *inbound.PacketAdapter
|
||||
}
|
||||
|
||||
func NewUDPHandler(dnsIP net.IP, udpIn chan<- *inbound.PacketAdapter) golwip.UDPConnHandler {
|
||||
func newUDPHandler(dnsIP net.IP, udpIn chan<- *inbound.PacketAdapter) golwip.UDPConnHandler {
|
||||
return &udpHandler{dnsIP, udpIn}
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
"github.com/kr328/tun2socket/redirect"
|
||||
)
|
||||
|
||||
const defaultDnsReadTimeout = time.Second * 10
|
||||
const defaultDnsReadTimeout = time.Second * 30
|
||||
|
||||
func shouldHijackDns(dnsAddr binding.Address, targetAddr binding.Address) bool {
|
||||
if targetAddr.Port != 53 {
|
||||
|
Reference in New Issue
Block a user