Browse Source

don't use new address if not in redirect mode

Darien Raymond 6 years ago
parent
commit
35432832c4
1 changed files with 5 additions and 1 deletions
  1. 5 1
      proxy/dokodemo/dokodemo.go

+ 5 - 1
proxy/dokodemo/dokodemo.go

@@ -78,13 +78,17 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn in
 		Address: d.address,
 		Address: d.address,
 		Port:    d.port,
 		Port:    d.port,
 	}
 	}
+
+	destinationOverridden := false
 	if d.config.FollowRedirect {
 	if d.config.FollowRedirect {
 		if outbound := session.OutboundFromContext(ctx); outbound != nil && outbound.Target.IsValid() {
 		if outbound := session.OutboundFromContext(ctx); outbound != nil && outbound.Target.IsValid() {
 			dest = outbound.Target
 			dest = outbound.Target
+			destinationOverridden = true
 		} else if handshake, ok := conn.(hasHandshakeAddress); ok {
 		} else if handshake, ok := conn.(hasHandshakeAddress); ok {
 			addr := handshake.HandshakeAddress()
 			addr := handshake.HandshakeAddress()
 			if addr != nil {
 			if addr != nil {
 				dest.Address = addr
 				dest.Address = addr
+				destinationOverridden = true
 			}
 			}
 		}
 		}
 	}
 	}
@@ -121,7 +125,7 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn in
 			writer = buf.NewWriter(conn)
 			writer = buf.NewWriter(conn)
 		} else {
 		} else {
 			//if we are in TPROXY mode, use linux's udp forging functionality
 			//if we are in TPROXY mode, use linux's udp forging functionality
-			if !d.config.FollowRedirect {
+			if !destinationOverridden {
 				writer = &buf.SequentialWriter{Writer: conn}
 				writer = &buf.SequentialWriter{Writer: conn}
 			} else {
 			} else {
 				sockopt := &internet.SocketConfig{
 				sockopt := &internet.SocketConfig{