vintage_net v0.6.0 VintageNet.Interface.Classification 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
Functions
Compute the routing metric for an interface with a status
Return a reasonable default for prioritizing interfaces
Classify a network type based on its name
Link to this section Types
connection_status()
View Sourceconnection_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
interface_type()
View Sourceinterface_type() :: :ethernet | :wifi | :mobile | :local | :unknown
Categorize interfaces based on their technology
prioritization()
View Sourceprioritization() :: {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
Link to this section Functions
compute_metric(type, status, prioritization)
View Sourcecompute_metric(interface_type(), connection_status(), [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.
default_prioritization()
View Sourcedefault_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.
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