add udp redirect listener

This commit is contained in:
ginuerzh
2021-12-17 15:00:13 +08:00
parent 8e31e532e4
commit 6c1522dace
10 changed files with 202 additions and 4 deletions

View File

@ -16,6 +16,7 @@ import (
func init() {
registry.RegisterHandler("red", NewHandler)
registry.RegisterHandler("redu", NewHandler)
registry.RegisterHandler("redir", NewHandler)
registry.RegisterHandler("redirect", NewHandler)
}
@ -49,6 +50,8 @@ func (h *redirectHandler) WithChain(chain *chain.Chain) {
}
func (h *redirectHandler) Handle(ctx context.Context, conn net.Conn) {
defer conn.Close()
start := time.Now()
h.logger = h.logger.WithFields(map[string]interface{}{
"remote": conn.RemoteAddr().String(),
@ -78,7 +81,6 @@ func (h *redirectHandler) Handle(ctx context.Context, conn net.Conn) {
return
}
}
defer conn.Close()
h.logger = h.logger.WithFields(map[string]interface{}{
"dst": fmt.Sprintf("%s/%s", dstAddr, network),

View File

@ -10,6 +10,6 @@ import (
func (h *redirectHandler) getOriginalDstAddr(conn net.Conn) (addr net.Addr, c net.Conn, err error) {
defer conn.Close()
err = errors.New("TCP redirect is not available on Windows platform")
err = errors.New("TCP redirect is not available on non-linux platform")
return
}