vintage_net v0.2.1 VintageNet.Route.Calculator
This module computes the desired routing table contents
It's used by the RouteManager to update the Linux routing tables when interfaces come online or change state. See the RouteManager docs for a discussion of how routes are configured.
The functions in this module have no side effects so that it's easier to test that routing scenarios result in correct Linux routing table configurations.
Link to this section Summary
Functions
Compute a Linux routing table configuration
Initialize state carried between calculations
Utility function to trim IP address to its subnet
Link to this section Types
default_route()
default_route() ::
{:default_route, VintageNet.ifname(), :inet.ip_address(), metric(),
table_index()}
default_route() :: {:default_route, VintageNet.ifname(), :inet.ip_address(), metric(), table_index()}
entries()
entries() :: [entry()]
entries() :: [entry()]
entry()
entry() :: rule() | default_route() | local_route()
entry() :: rule() | default_route() | local_route()
interface_infos()
interface_infos() :: %{
optional(VintageNet.ifname()) => VintageNet.Route.InterfaceInfo.t()
}
interface_infos() :: %{ optional(VintageNet.ifname()) => VintageNet.Route.InterfaceInfo.t() }
local_route()
local_route() ::
{:local_route, VintageNet.ifname(), :inet.ip_address(), metric(),
table_index()}
local_route() :: {:local_route, VintageNet.ifname(), :inet.ip_address(), metric(), table_index()}
metric()
metric() :: 0..32767
metric() :: 0..32767
rule()
rule() :: {:rule, table_index(), :inet.ip_address()}
rule() :: {:rule, table_index(), :inet.ip_address()}
subnet_bits()
subnet_bits() :: 8..30
subnet_bits() :: 8..30
table_index()
table_index() :: 0..255 | :main | :local | :default
table_index() :: 0..255 | :main | :local | :default
table_indices()
table_indices() :: %{optional(VintageNet.ifname()) => table_index()}
table_indices() :: %{optional(VintageNet.ifname()) => table_index()}
Link to this section Functions
compute(table_indices, infos, prioritization)
compute(
table_indices(),
interface_infos(),
VintageNet.Interface.Classification.prioritization()
) :: {table_indices(), entries()}
compute( table_indices(), interface_infos(), VintageNet.Interface.Classification.prioritization() ) :: {table_indices(), entries()}
Compute a Linux routing table configuration
The entries are ordered so that List.myers_difference/2 can be used to minimize the routing table changes.
init()
init() :: table_indices()
init() :: table_indices()
Initialize state carried between calculations
to_subnet(arg, subnet_bits)
to_subnet(:inet.ip_address(), subnet_bits()) :: :inet.ip_address()
to_subnet(:inet.ip_address(), subnet_bits()) :: :inet.ip_address()
Utility function to trim IP address to its subnet
Examples:
iex> Calculator.to_subnet({192, 168, 1, 50}, 24)
{192, 168, 1, 0}
iex> Calculator.to_subnet({192, 168, 255, 50}, 22)
{192, 168, 252, 0}