Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monitor network changes #1904

Merged
merged 13 commits into from
May 7, 2024
Merged

Monitor network changes #1904

merged 13 commits into from
May 7, 2024

Conversation

lixmal
Copy link
Contributor

@lixmal lixmal commented Apr 29, 2024

Describe your changes

This introduces a network monitor feature that automatically restarts our engine in response to significant changes in network configurations.

The network monitor is disabled by default and can be enabled by passing the flag --network-monitor to the netbird up command
Upon engine startup, the network monitor collects the current default IPv4 and/or IPv6 route's next hop and associated interfaces. It then actively monitors network changes that require an engine restart. The triggers for these restarts vary by operating system:

Linux:

  • Monitored interface deletion: Engine restarts on the deletion of any interfaces associated with the default route.
  • Interface going down: Engine restarts when any monitored interfaces go down.
  • Default route deletion: Engine restarts if the default route with our next hop is deleted.
  • Addition of any default route: Engine restarts when a new default route is added, which might provide a better path due to different network interface priorities (e.g., switching from WiFi to Ethernet with both being available).

BSD (including macOS):

  • Default route changes: Engine restarts when the default route with our next hop disappears or any new default route is added.
  • Interface status: Engine restarts if any network interfaces associated with our monitored default route go down.

Windows:

  • Default route monitoring: Engine restarts if the default route with any of our next hops disappears.
  • Neighbor state monitoring: Restarts if the state of any neighbor with our next hops changes to anything other than permanent or reachable.

Testing

To ensure the Network Watcher functions correctly across different platforms, follow these OS-specific testing steps:

Linux:

  1. Change interface state: ip link set <interface> down, restore with ip link set <interface> up
  2. Change default route: ip route replace default via <new-ip> and restore with ip route replace default via <old-ip>
  3. Add another default route: ip route add default via <some-other-ip> metric 100, restore with ip route delete default via <some-other-ip> metric 100
  4. Delete default route: ip route delete default, restore with ip route add default via <old-params>

BSD (including macOS):

  1. Change interface state: ifconfig <interface> down, restore with ifonfig <interface> up
  2. Change default route: route change default <new-ip>, restore with route change default <old-ip>
  3. Add default route: route add default <new-ip>, restore with route delete default <new-ip>
  4. Delete default route: route delete default, restore with route add default <old-params>

Windows:

  1. Modify routing table: route change 0.0.0.0/0 <new-gateway> and restore with route change 0.0.0.0/0 <old-gateway>
  2. Add a new route: route add 0.0.0.0/0 <new-gateway> metric 1 and restore with route delete 0.0.0.0/0 <new-gateway>
  3. Clear entry in arp cache: arp -d <gateway IP>

In all cases, you can simulate a network switch (e.g., from local WiFi to Ethernet or a mobile hotspot) to trigger the network watcher and observe the engine's response.

Issue ticket number and link

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)
  • Extended the README / documentation, if necessary

@lixmal lixmal force-pushed the feature/monitor-network-changes branch 2 times, most recently from f02b8e9 to c88084e Compare May 2, 2024 11:11
@lixmal lixmal marked this pull request as ready for review May 2, 2024 11:53
@lixmal lixmal force-pushed the feature/monitor-network-changes branch from ff52eb5 to b51cb98 Compare May 7, 2024 16:22
@lixmal lixmal merged commit 9208779 into main May 7, 2024
15 checks passed
@lixmal lixmal deleted the feature/monitor-network-changes branch May 7, 2024 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants