# `VintageNet.RouteManager`
[🔗](https://github.com/nerves-networking/vintage_net/blob/v0.13.9/lib/vintage_net/route_manager.ex#L8)

This module manages the default route.

Devices with more than one network interface may have more than one
way of reaching the Internet. The routing table decides which interface
an IP packet should use by looking at the "default route" entries.
One interface is chosen.

Since not all interfaces are equal, we'd like Linux to pick the
fastest and lowest latency one. for example, one could
prefer wired Ethernet over WiFi and prefer WiFi over a cellular
connection. This module lets you specify an ordering for interfaces
and sets up the routes based on this ordering.

This module also handles networking failures. One failure that
Linux can't figure out on its own is whether an interface can
reach the Internet. Internet reachability is handled elsewhere
like in the `ConnectivityChecker` module. This module should be
told reachability status so that it can properly order default
routes so that the best reachable interface is used.

IMPORTANT: This module uses priority-based routing. Make sure the
following kernel options are enabled:

```text
CONFIG_IP_ADVANCED_ROUTER=y
CONFIG_IP_MULTIPLE_TABLES=y
```

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `clear_route`

```elixir
@spec clear_route(VintageNet.ifname()) :: :ok
```

Clear out the default gateway for an interface.

# `refresh_route_metrics`

```elixir
@spec refresh_route_metrics() :: :ok
```

Refresh route metrics for all interfaces.

# `set_connection_status`

```elixir
@spec set_connection_status(
  VintageNet.ifname(),
  VintageNet.connection_status(),
  String.t() | nil
) :: :ok
```

Set the connection status on an interface.

Changing the connection status can re-prioritize routing. The
specified interface doesn't need to have a default route.

# `set_route`

```elixir
@spec set_route(
  VintageNet.ifname(),
  [{:inet.ip_address(), VintageNet.prefix_length()}],
  :inet.ip_address()
) :: :ok
```

Set the default route for an interface.

This replaces any existing routes on that interface

# `start_link`

```elixir
@spec start_link(keyword()) :: GenServer.on_start()
```

Start the route manager

Options:

* `:route_metric_fun` - a 2-arity function that takes a ifname and `VintageNet.Route.InterfaceInfo`
  and returns `VintageNet.Route.metric()`. Both MFA and function forms are supported

# `stop`

```elixir
@spec stop() :: :ok
```

Stop the route manager.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
