Merge "Skip adding ingress discard rule to legacy VPN" into main
This commit is contained in:
commit
c4b4feed19
1 changed files with 35 additions and 15 deletions
|
|
@ -27,6 +27,7 @@ import android.net.NetworkCapabilities.TRANSPORT_VPN
|
|||
import android.net.NetworkCapabilities.TRANSPORT_WIFI
|
||||
import android.net.NetworkRequest
|
||||
import android.net.VpnManager.TYPE_VPN_SERVICE
|
||||
import android.net.VpnManager.TYPE_VPN_LEGACY
|
||||
import android.net.VpnTransportInfo
|
||||
import android.os.Build
|
||||
import androidx.test.filters.SmallTest
|
||||
|
|
@ -49,19 +50,20 @@ private const val WIFI_IFNAME = "wlan0"
|
|||
private const val TIMEOUT_MS = 1_000L
|
||||
private const val LONG_TIMEOUT_MS = 5_000
|
||||
|
||||
private fun vpnNc() = NetworkCapabilities.Builder()
|
||||
.addTransportType(TRANSPORT_VPN)
|
||||
.removeCapability(NET_CAPABILITY_NOT_VPN)
|
||||
.addCapability(NET_CAPABILITY_NOT_VCN_MANAGED)
|
||||
.setTransportInfo(
|
||||
VpnTransportInfo(
|
||||
TYPE_VPN_SERVICE,
|
||||
"MySession12345",
|
||||
false /* bypassable */,
|
||||
false /* longLivedTcpConnectionsExpensive */
|
||||
)
|
||||
)
|
||||
.build()
|
||||
private fun vpnNc(legacyVpn: Boolean = false) = NetworkCapabilities.Builder().apply {
|
||||
addTransportType(TRANSPORT_VPN)
|
||||
removeCapability(NET_CAPABILITY_NOT_VPN)
|
||||
addCapability(NET_CAPABILITY_NOT_VCN_MANAGED)
|
||||
val vpnType = if (legacyVpn) { TYPE_VPN_LEGACY } else { TYPE_VPN_SERVICE }
|
||||
setTransportInfo(
|
||||
VpnTransportInfo(
|
||||
vpnType,
|
||||
"MySession12345",
|
||||
false /* bypassable */,
|
||||
false /* longLivedTcpConnectionsExpensive */
|
||||
)
|
||||
)
|
||||
}.build()
|
||||
|
||||
private fun wifiNc() = NetworkCapabilities.Builder()
|
||||
.addTransportType(TRANSPORT_WIFI)
|
||||
|
|
@ -310,4 +312,19 @@ class CSIngressDiscardRuleTests : CSTest() {
|
|||
// IngressDiscardRule should not be added since feature is disabled
|
||||
verify(bpfNetMaps, never()).setIngressDiscardRule(any(), any())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testVpnIngressDiscardRule_LegacyVpn() {
|
||||
val nr = nr(TRANSPORT_VPN)
|
||||
val cb = TestableNetworkCallback()
|
||||
cm.registerNetworkCallback(nr, cb)
|
||||
val nc = vpnNc(legacyVpn = true)
|
||||
val lp = lp(VPN_IFNAME, IPV6_LINK_ADDRESS, LOCAL_IPV6_LINK_ADDRRESS)
|
||||
val agent = Agent(nc = nc, lp = lp)
|
||||
agent.connect()
|
||||
cb.expectAvailableCallbacks(agent.network, validated = false)
|
||||
|
||||
// IngressDiscardRule should not be added to Legacy VPN
|
||||
verify(bpfNetMaps, never()).setIngressDiscardRule(any(), any())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue