Maint: dynamically set allowed VPN input ports

- Feat: allow to change VPN type at runtime
- Feat: allow to change interface name at runtime
- Maint: Add cleanup method to cleanup VPN loop on a vpn shutdown
- Change: allow VPN inputs ports only when tunnel is up
This commit is contained in:
Quentin McGaw (desktop)
2021-09-13 00:50:20 +00:00
parent 19bf62c21f
commit 40342619e7
6 changed files with 49 additions and 30 deletions

View File

@@ -40,20 +40,14 @@ func (l *Loop) startPortForwarding(ctx context.Context, data tunnelUpData) (err
return nil
}
func (l *Loop) stopPortForwarding(ctx context.Context, enabled bool,
timeout time.Duration) {
if !enabled {
return // nothing to stop
}
func (l *Loop) stopPortForwarding(ctx context.Context,
timeout time.Duration) (err error) {
if timeout > 0 {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(ctx, timeout)
defer cancel()
}
_, err := l.portForward.Stop(ctx)
if err != nil {
l.logger.Error("cannot stop port forwarding: " + err.Error())
}
_, err = l.portForward.Stop(ctx)
return err
}