-
-
Notifications
You must be signed in to change notification settings - Fork 892
[client] Add WireGuard interface lifecycle monitoring #4370
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
Changes from 2 commits
64bb6db
6016dbd
88f98a0
bf5e12d
6cc8df9
f37cc27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -464,6 +464,9 @@ func (e *Engine) Start() error { | |||||||
|
||||||||
// starting network monitor at the very last to avoid disruptions | ||||||||
e.startNetworkMonitor() | ||||||||
|
||||||||
// monitor WireGuard interface lifecycle and restart engine on changes | ||||||||
e.startWGIfaceMonitor() | ||||||||
return nil | ||||||||
} | ||||||||
|
||||||||
|
@@ -1701,6 +1704,87 @@ func (e *Engine) startNetworkMonitor() { | |||||||
}() | ||||||||
} | ||||||||
|
||||||||
// startWGIfaceMonitor starts a background watcher that restarts the engine if | ||||||||
// the WireGuard interface is deleted externally while the engine is running. | ||||||||
// It relies on the engine context cancellation to stop. | ||||||||
func (e *Engine) startWGIfaceMonitor() { | ||||||||
hakansa marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||
// Skip on mobile platforms as they handle interface lifecycle differently | ||||||||
if runtime.GOOS == "android" || runtime.GOOS == "ios" { | ||||||||
log.Debugf("Interface monitor: skipped on %s platform", runtime.GOOS) | ||||||||
return | ||||||||
} | ||||||||
|
||||||||
// wgInterface should be initialized at this point | ||||||||
if e.wgInterface == nil { | ||||||||
return | ||||||||
} | ||||||||
|
||||||||
name := e.wgInterface.Name() | ||||||||
hakansa marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||
if name == "" { | ||||||||
return | ||||||||
} | ||||||||
|
||||||||
// Get initial interface index to track the specific interface instance | ||||||||
initialIndex, err := getInterfaceIndex(name) | ||||||||
if err != nil { | ||||||||
log.Debugf("Interface monitor: interface %s not found, skipping monitor", name) | ||||||||
return | ||||||||
} | ||||||||
|
||||||||
// Polling approach for cross-platform simplicity | ||||||||
go func(ctx context.Context, ifaceName string, expectedIndex int) { | ||||||||
hakansa marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||
log.Infof("Interface monitor: watching %s (index: %d)", ifaceName, expectedIndex) | ||||||||
|
||||||||
ticker := time.NewTicker(2 * time.Second) | ||||||||
|
ticker := time.NewTicker(2 * time.Second) | |
ticker := time.NewTicker(wgIfaceMonitorPollInterval) |
Copilot uses AI. Check for mistakes.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error check errors.Is(err, &net.OpError{})
is incorrect. errors.Is
compares error values, not types. Use var opErr *net.OpError; errors.As(err, &opErr)
to check if the error is of type *net.OpError
.
if errors.Is(err, &net.OpError{}) { | |
var opErr *net.OpError | |
if errors.As(err, &opErr) { |
Copilot uses AI. Check for mistakes.
Uh oh!
There was an error while loading. Please reload this page.