From 055fb51ed9c1b44bcc790613b71720e85aeaf83d Mon Sep 17 00:00:00 2001 From: RPRX <63339210+rprx@users.noreply.github.com> Date: Fri, 5 Mar 2021 12:06:37 +0000 Subject: [PATCH] Apply UDPOverride to Freedom Outbound PacketReader --- proxy/freedom/freedom.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/proxy/freedom/freedom.go b/proxy/freedom/freedom.go index 7a8c336a..95ba4fdc 100644 --- a/proxy/freedom/freedom.go +++ b/proxy/freedom/freedom.go @@ -169,7 +169,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte if destination.Network == net.Network_TCP { reader = buf.NewReader(conn) } else { - reader = NewPacketReader(conn) + reader = NewPacketReader(conn, UDPOverride) } if err := buf.Copy(reader, output, buf.UpdateActivity(timer)); err != nil { return newError("failed to process response").Base(err) @@ -185,7 +185,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte return nil } -func NewPacketReader(conn net.Conn) buf.Reader { +func NewPacketReader(conn net.Conn, UDPOverride net.Destination) buf.Reader { iConn := conn statConn, ok := iConn.(*internet.StatCouterConnection) if ok { @@ -199,6 +199,7 @@ func NewPacketReader(conn net.Conn) buf.Reader { return &PacketReader{ PacketConnWrapper: c, Counter: counter, + UDPOverride: UDPOverride, } } return &buf.PacketReader{Reader: conn} @@ -207,6 +208,7 @@ func NewPacketReader(conn net.Conn) buf.Reader { type PacketReader struct { *internet.PacketConnWrapper stats.Counter + UDPOverride net.Destination } func (r *PacketReader) ReadMultiBuffer() (buf.MultiBuffer, error) { @@ -223,6 +225,12 @@ func (r *PacketReader) ReadMultiBuffer() (buf.MultiBuffer, error) { Port: net.Port(d.(*net.UDPAddr).Port), Network: net.Network_UDP, } + if r.UDPOverride.Address != nil { + b.UDP.Address = r.UDPOverride.Address + } + if r.UDPOverride.Port != 0 { + b.UDP.Port = r.UDPOverride.Port + } if r.Counter != nil { r.Counter.Add(int64(n)) }