Files
gluetun/internal/vpn/cleanup.go
Quentin McGaw (desktop) 40342619e7 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
2021-09-13 00:50:20 +00:00

28 lines
630 B
Go

package vpn
import (
"context"
"time"
"github.com/qdm12/gluetun/internal/publicip/models"
)
func (l *Loop) cleanup(ctx context.Context, pfEnabled bool) {
for _, vpnPort := range l.vpnInputPorts {
err := l.fw.RemoveAllowedPort(ctx, vpnPort)
if err != nil {
l.logger.Error("cannot remove allowed input port from firewall: " + err.Error())
}
}
l.publicip.SetData(models.IPInfoData{}) // clear public IP address data
if pfEnabled {
const pfTimeout = 100 * time.Millisecond
err := l.stopPortForwarding(ctx, pfTimeout)
if err != nil {
l.logger.Error("cannot stop port forwarding: " + err.Error())
}
}
}