Table of Contents

Interface IVpnKillSwitch

Namespace
VpnHood.Core.Client.VpnServices.Abstractions
Assembly
VpnHood.Core.Client.VpnServices.Abstractions.dll

Defines the kill switch's block: the OS's own firewall rules, which let nothing out but the tunnel, the VPN service itself and what VpnKillSwitchRules lets pass.

public interface IVpnKillSwitch

Remarks

It is the OS's, not the process's, so it stays through a crash of the service and, where the platform keeps it, a reboot, until the app lifts it: at a person's disconnect, unless the app keeps it then (its lockdown), or when they turn the switch off. Its presence is its whole state. Its rules' names are the SDK's, so every app built on VpnHood shares one block, as it shares the tunnel (IVpnTunnelLock): the tunnel's holder puts its own up, or removes whatever one a crashed or revoked holder left. Only the desktops have one, and each platform's has limits its class names, as the traffic Windows' WinNAT carries, which no filter sees.

Methods

Block(VpnKillSwitchRules, CancellationToken)

Puts this app's block up, or re-points it, in one change with no gap, in place of any app's.

Task Block(VpnKillSwitchRules rules, CancellationToken cancellationToken)

Parameters

rules VpnKillSwitchRules

What the block lets pass.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task

A task that completes once the block is up.

Remarks

It fails where it cannot, and then nothing may connect: a connect never goes on unprotected.

Exceptions

NotSupportedException

Linux has no nftables, or the service is in no cgroup v2 group of its own.

ExternalException

The OS refused the block: Linux's nft, or Windows' filtering engine, as without an administrator.

OperationCanceledException

cancellationToken was canceled.

IsBlocking(CancellationToken)

Determines whether this app's block is up.

Task<bool> IsBlocking(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task<bool>

A task whose result is true if this app's block is up; otherwise, false.

Exceptions

ExternalException

The OS's rules could not be read: Linux's nft, or Windows' filtering engine.

OperationCanceledException

cancellationToken was canceled.

Unblock(bool, CancellationToken)

Removes this app's block, or, with anyApp, any app's: the tunnel's holder's call.

Task Unblock(bool anyApp, CancellationToken cancellationToken)

Parameters

anyApp bool

true to remove any app's block; false to remove this app's only.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task

A task that completes once the block is gone.

Exceptions

ExternalException

The OS refused the change: Linux's nft, or Windows' filtering engine.

OperationCanceledException

cancellationToken was canceled.