2021-09-13 00:50:20 +00:00
|
|
|
package vpn
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"time"
|
|
|
|
|
|
2022-06-12 00:53:39 +00:00
|
|
|
"github.com/qdm12/gluetun/internal/publicip/ipinfo"
|
2021-09-13 00:50:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
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())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-12 00:53:39 +00:00
|
|
|
l.publicip.SetData(ipinfo.Response{}) // clear public IP address data
|
2021-09-13 00:50:20 +00:00
|
|
|
|
|
|
|
|
if pfEnabled {
|
|
|
|
|
const pfTimeout = 100 * time.Millisecond
|
|
|
|
|
err := l.stopPortForwarding(ctx, pfTimeout)
|
|
|
|
|
if err != nil {
|
|
|
|
|
l.logger.Error("cannot stop port forwarding: " + err.Error())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|