Table of Contents

Class StaticIpFilter

Namespace
VpnHood.Core.Filtering.Abstractions
Assembly
VpnHood.Core.Filtering.Abstractions.dll

Provides a stage of an IP filter pipe that decides by sets held in memory: blocked, excluded and included address ranges, and blocked TCP and UDP ports.

public class StaticIpFilter : IIpFilter, IDisposable
Inheritance
StaticIpFilter
Implements
Inherited Members

Remarks

The next stage decides first, and its verdict stands unless it is Default. Then a destination in the blocked ranges or on a blocked port is blocked; one in the excluded ranges is excluded; and, when the included ranges are not empty, one outside them is excluded too. The rest get Default: the stage's own sets never give Include. Setting a set raises Changed.

Constructors

StaticIpFilter(IIpFilter?, bool)

Initializes a new instance of the StaticIpFilter class, with empty sets.

public StaticIpFilter(IIpFilter? nextFilter, bool autoDisposeNextFilter = true)

Parameters

nextFilter IIpFilter

The stage that decides first, or null.

autoDisposeNextFilter bool

true to dispose nextFilter with this stage.

Properties

BlockedRanges

Gets or sets the address ranges whose flows are blocked. The default is empty.

public IpRangeOrderedList BlockedRanges { get; set; }

Property Value

IpRangeOrderedList

BlockedTcpPorts

Gets or sets the destination ports whose TCP flows are blocked. The default is empty.

public IReadOnlyList<PortRange> BlockedTcpPorts { get; set; }

Property Value

IReadOnlyList<PortRange>

Remarks

The setter copies the list.

BlockedUdpPorts

Gets or sets the destination ports whose UDP flows are blocked. The default is empty.

public IReadOnlyList<PortRange> BlockedUdpPorts { get; set; }

Property Value

IReadOnlyList<PortRange>

Remarks

The setter copies the list.

ExcludeRanges

Gets or sets the address ranges whose flows go around the tunnel. The default is empty.

public IpRangeOrderedList ExcludeRanges { get; set; }

Property Value

IpRangeOrderedList

IncludeRanges

Gets or sets the address ranges that alone may take the default way; when not empty, a flow to an address outside them goes around the tunnel. The default is empty.

public IpRangeOrderedList IncludeRanges { get; set; }

Property Value

IpRangeOrderedList

IsEmpty

Gets a value indicating whether the pipe holds no rule, so it can only answer Default. Read it again when Changed occurs.

public bool IsEmpty { get; }

Property Value

bool

true while the five sets are empty and the next stage, if any, is empty too.

Methods

Dispose()

Disposes the next stage when this stage was made to.

public void Dispose()

Process(IpProtocol, IpEndPointValue)

Decides what happens to a flow.

public FilterAction Process(IpProtocol protocol, IpEndPointValue endPoint)

Parameters

protocol IpProtocol

The flow's protocol.

endPoint IpEndPointValue

The flow's destination.

Returns

FilterAction

The verdict; Default when the pipe has no objection.

Remarks

The next stage decides first; see the class's remarks for the order of the sets.

Reconfigure(CancellationToken)

Tells the pipe that its configuration outside the program, such as a database's path, may have changed.

public Task Reconfigure(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task

A task that represents the asynchronous operation.

Remarks

Each stage passes it to its next one; a stage that owns such configuration reads it again and swaps its own parts, raising Changed if its verdicts may differ.

Events

Changed

Occurs when the pipe's verdicts may have changed, as when a stage swaps its rules. A stage raises its next stage's event as its own, so the event reaches the outermost stage; a stage whose verdicts never change never raises it.

public event EventHandler? Changed

Event Type

EventHandler