public final class TunnelSetup
- Object
- 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. 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").
Fields
public static final int DEFAULT_MTU = 1400 | The MTU a link gets when the application does not choose one. |
Constructors
public TunnelSetup() |
Methods
public TunnelSetup address(String cidr) | The address this device takes on the tunnel, in CIDR form. |
public TunnelSetup server(String host) | 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. |
public TunnelSetup route(String cidr) | A route directed into the tunnel, in CIDR form. |
public TunnelSetup dnsServer(String address) | A DNS server the tunnel provides. |
public TunnelSetup searchDomain(String domain) | A DNS search domain. |
public TunnelSetup mtu(int bytes) | The link MTU. |
public TunnelSetup sessionName(String name) | The name the system shows for this VPN session. |
public TunnelSetup data(String value) | Application data handed to VpnTunnel.onStart as TunnelConfiguration.getData. |
public String getAddress() | |
public String getServer() | |
public String[] getRoutes() | |
public String[] getDnsServers() | |
public String[] getSearchDomains() | |
public int getMtu() | |
public String getSessionName() | |
public String getData() |
Inherited methods
Field details
DEFAULT_MTU
public static final int DEFAULT_MTU = 1400The 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.
Constructor details
TunnelSetup
public TunnelSetup()Method details
address
public TunnelSetup address(String cidr)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’s VpnService.Builder documents
that at least one address must be set before establish().
The prefix may be left off – /32 for IPv4, /128 for IPv6 – but
one that is written and unreadable FAILS the start the same way; see
route.
server
public TunnelSetup server(String host)route
public TunnelSetup route(String cidr)A route directed into the tunnel, in CIDR form. Repeatable.
0.0.0.0/0 and ::/0 are the full tunnel. An unreadable prefix
fails the start with INVALID_CONFIGURATION rather 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
public TunnelSetup dnsServer(String address)searchDomain
public TunnelSetup searchDomain(String domain)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
public TunnelSetup mtu(int bytes)DEFAULT_MTU.sessionName
public TunnelSetup sessionName(String name)data
public TunnelSetup data(String value)Application data handed to VpnTunnel.onStart as
TunnelConfiguration.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
public String getAddress()Returns
getServer
public String getServer()Returns
getRoutes
public String[] getRoutes()Returns
getDnsServers
public String[] getDnsServers()Returns
getSearchDomains
public String[] getSearchDomains()Returns
getMtu
public int getMtu()Returns
getSessionName
public String getSessionName()Returns
getData
public String getData()