Class TunnelSetup
What an application asks the platform to set up before its tunnel runs.
The mirror of TunnelConfiguration: this is what goes DOWN to the
platform, that is what comes back up to VpnTunnel.onStart(TunnelConfiguration). They are
separate types because they are not the same thing -- a setup is a
request, a configuration is what the platform actually established, and
a host that runs the tunnel in its own process decides the two apart.
Every field has a usable default, so the smallest tunnel is
new TunnelSetup().address("10.0.0.2/32").route("0.0.0.0/0").
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe MTU a link gets when the application does not choose one. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionThe address this device takes on the tunnel, in CIDR form.Application data handed toVpnTunnel.onStart(TunnelConfiguration)asTunnelConfiguration.getData().A DNS server the tunnel provides.getData()String[]intgetMtu()String[]String[]mtu(int bytes) The link MTU.A route directed into the tunnel, in CIDR form.searchDomain(String domain) A DNS search domain.The far end, which the platform excludes from the tunnel's own routes so the tunnel's own traffic does not loop back into it.sessionName(String name) The name the system shows for this VPN session.
-
Field Details
-
DEFAULT_MTU
public static final int DEFAULT_MTUThe MTU a link gets when the application does not choose one.
1400 rather than 1500: a tunnel adds its own encapsulation, and a link sized for the physical MTU fragments every full-size packet.
- See Also:
-
-
Constructor Details
-
TunnelSetup
public TunnelSetup()
-
-
Method Details
-
address
The address this device takes on the tunnel, in CIDR form.
REQUIRED. A setup without one fails the start with
INVALID_CONFIGURATION, because a link with no address is not one a platform can establish -- Android'sVpnService.Builderdocuments that at least one address must be set beforeestablish().The prefix may be left off --
/32for IPv4,/128for IPv6 -- but one that is written and unreadable FAILS the start the same way; seeroute(String). -
server
The far end, which the platform excludes from the tunnel's own routes so the tunnel's own traffic does not loop back into it. -
route
A route directed into the tunnel, in CIDR form. Repeatable.
0.0.0.0/0and::/0are the full tunnel. An unreadable prefix fails the start withINVALID_CONFIGURATIONrather than being narrowed to a host route:"0.0.0.0/o"is a typo for the default route, and a tunnel that started and carried one address would let every packet the app believed it was protecting out in the clear. Checked in the simulation as well, so the refusal is not something found first on a device. -
dnsServer
A DNS server the tunnel provides. Repeatable. -
searchDomain
A DNS search domain. Repeatable.
Android applies these. A platform that cannot express one ignores it rather than refusing the tunnel, because a search domain is a convenience and losing the tunnel over one is not a trade an app would choose.
-
mtu
The link MTU. SeeDEFAULT_MTU. -
sessionName
The name the system shows for this VPN session. -
data
Application data handed to
VpnTunnel.onStart(TunnelConfiguration)asTunnelConfiguration.getData().The one thing that reaches the tunnel from the app WITHOUT relying on the two sharing a process. Android's does, so a static works there; a host that constructed the tunnel elsewhere shares no statics, no singletons and no open connections with the app. A tunnel that takes its token, server list or key from here is the one that does not have to be rewritten.
-
getAddress
- Returns:
- the device's tunnel address in CIDR form
-
getServer
- Returns:
- the far end
-
getRoutes
- Returns:
- the routes directed into the tunnel
-
getDnsServers
- Returns:
- the DNS servers the tunnel provides
-
getSearchDomains
- Returns:
- the DNS search domains
-
getMtu
public int getMtu()- Returns:
- the link MTU
-
getSessionName
- Returns:
- the session name the system shows
-
getData
- Returns:
- the application data, never null
-