vintage_net v0.5.1 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

Link to this type

connection_status()

View Source
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
Link to this type

interface_type()

View Source
interface_type() :: :ethernet | :wifi | :mobile | :local | :unknown

Categorize interfaces based on their technology

Link to this type

prioritization()

View Source
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

Link to this section Functions

Link to this function

compute_metric(type, status, prioritization)

View Source
compute_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.

Link to this function

default_prioritization()

View Source
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.

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