Browse Source

Fix: session is nil for packet tunnel clients

Rod Hynes 8 years ago
parent
commit
4cafd54007
1 changed files with 18 additions and 10 deletions
  1. 18 10
      psiphon/common/tun/tun.go

+ 18 - 10
psiphon/common/tun/tun.go

@@ -2361,26 +2361,34 @@ func processPacket(
 
 		if protocol == internetProtocolTCP {
 
-			checkAllowedTCPPortFunc := session.getCheckAllowedTCPPortFunc()
+			invalidPort := (checkPort == 0)
 
-			if checkPort == 0 ||
-				(isServer &&
-					(checkAllowedTCPPortFunc == nil ||
-						!checkAllowedTCPPortFunc(net.IP(ID.upstreamIPAddress[:]), checkPort))) {
+			if !invalidPort && isServer {
+				checkAllowedTCPPortFunc := session.getCheckAllowedTCPPortFunc()
+				if checkAllowedTCPPortFunc == nil ||
+					!checkAllowedTCPPortFunc(net.IP(ID.upstreamIPAddress[:]), checkPort) {
+					invalidPort = true
+				}
+			}
 
+			if invalidPort {
 				metrics.rejectedPacket(direction, packetRejectTCPPort)
 				return false
 			}
 
 		} else if protocol == internetProtocolUDP {
 
-			checkAllowedUDPPortFunc := session.getCheckAllowedUDPPortFunc()
+			invalidPort := (checkPort == 0)
 
-			if checkPort == 0 ||
-				(isServer &&
-					(checkAllowedUDPPortFunc == nil ||
-						!checkAllowedUDPPortFunc(net.IP(ID.upstreamIPAddress[:]), checkPort))) {
+			if !invalidPort && isServer {
+				checkAllowedUDPPortFunc := session.getCheckAllowedUDPPortFunc()
+				if checkAllowedUDPPortFunc == nil ||
+					!checkAllowedUDPPortFunc(net.IP(ID.upstreamIPAddress[:]), checkPort) {
+					invalidPort = true
+				}
+			}
 
+			if invalidPort {
 				metrics.rejectedPacket(direction, packetRejectUDPPort)
 				return false
 			}