VintageNet.Interface.Classification (vintage_net v0.9.3) View Source
Module for classifying and prioritizing network interfaces
Link to this section Summary
Types
Interface connection status
Categorize interfaces based on their technology
Prioritization for using default gateways
A weight used to disambiguate interfaces that would otherwise have the same priority
Functions
Compute the routing metric for an interface with a status
Return a reasonable default for prioritizing interfaces
Extract a number out of an interface name
Classify a network type based on its name
Link to this section Types
Specs
connection_status() :: :lan | :internet | :disconnected
Interface connection status
:disconnected
- The interface doesn't exist or it's not connected:lan
- The interface is connected to the LAN, but may not be able reach the Internet:internet
- Packets going through the interface should be able to reach the Internet
Specs
interface_type() :: :ethernet | :wifi | :mobile | :local | :unknown
Categorize interfaces based on their technology
Specs
prioritization() :: {interface_type() | :_, connection_status() | :_}
Prioritization for using default gateways
Examples
{:ethernet, :internet}
- Wired ethernet that's Internet connected{:ethernet, :_}
- Wired ethernet with any status{:_, :internet}
- Any Internet-connected network interface
Specs
weight() :: 0..9
A weight used to disambiguate interfaces that would otherwise have the same priority
Low weights are higher priority.
Link to this section Functions
Specs
compute_metric(interface_type(), connection_status(), weight(), [ prioritization() ]) :: pos_integer() | :disabled
Compute the routing metric for an interface with a status
This uses the prioritization list to figure out what number should
be used for the Linux routing table metric. It could also be :disabled
to indicate that a route shouldn't be added to the Linux routing tables
at all.
Specs
default_prioritization() :: [prioritization()]
Return a reasonable default for prioritizing interfaces
The logic is that Internet-connected interfaces are prioritized first and after than Ethernet is preferred over WiFi and WiFi over LTE.
Specs
to_instance(VintageNet.ifname()) :: non_neg_integer()
Extract a number out of an interface name
The result is the interface index for most interfaces seen on Nerves (eth0, eth1, ...), and something quite imperfect when using predictable interface naming (enp6s0, enp6s1).
This is currently used to order priorities when there are two interfaces available of the same type that cannot be differentiated by other means. It has the one property of being easy to explain.
Specs
to_type(VintageNet.ifname()) :: interface_type()
Classify a network type based on its name
Examples
iex> Classification.to_type("eth0")
:ethernet
iex> Classification.to_type("wlp5s0")
:wifi
iex> Classification.to_type("ppp0")
:mobile