MCPcopy
hub / github.com/passteque/gluetun / onTunnelUp

Method onTunnelUp

internal/vpn/tunnelup.go:24–87  ·  view source on GitHub ↗
(ctx, loopCtx context.Context, data tunnelUpData)

Source from the content-addressed store, hash-verified

22}
23
24func (l *Loop) onTunnelUp(ctx, loopCtx context.Context, data tunnelUpData) {
25 l.client.CloseIdleConnections()
26
27 for _, vpnPort := range l.vpnInputPorts {
28 err := l.fw.SetAllowedPort(ctx, vpnPort, data.vpnIntf)
29 if err != nil {
30 l.logger.Error("cannot allow input port through firewall: " + err.Error())
31 }
32 }
33
34 icmpTargetIPs := l.healthSettings.ICMPTargetIPs
35 if len(icmpTargetIPs) == 1 && icmpTargetIPs[0].IsUnspecified() {
36 icmpTargetIPs = []netip.Addr{data.serverIP}
37 }
38 l.healthChecker.SetConfig(l.healthSettings.TargetAddresses, icmpTargetIPs,
39 l.healthSettings.SmallCheckType)
40
41 healthErrCh, err := l.healthChecker.Start(ctx)
42 l.healthServer.SetError(err)
43 if err != nil {
44 if *l.healthSettings.RestartVPN {
45 // Note this restart call must be done in a separate goroutine
46 // from the VPN loop goroutine.
47 l.restartVPN(loopCtx, err)
48 return
49 }
50 l.logger.Warnf("(ignored) healthchecker start failed: %s", err)
51 l.logger.Info("👉 See https://github.com/qdm12/gluetun-wiki/blob/main/faq/healthcheck.md")
52 }
53
54 // Start collecting health errors asynchronously, since
55 // we should not wait for the code below to complete
56 // to start monitoring health and auto-healing.
57 go l.collectHealthErrors(ctx, loopCtx, healthErrCh)
58
59 if *l.dnsLooper.GetSettings().ServerEnabled {
60 _, _ = l.dnsLooper.ApplyStatus(ctx, constants.Running)
61 } else {
62 err := check.WaitForDNS(ctx, check.Settings{})
63 if err != nil {
64 l.logger.Error("waiting for DNS to be ready: " + err.Error())
65 }
66 }
67
68 err = l.publicip.RunOnce(ctx)
69 if err != nil {
70 l.logger.Error("getting public IP address information: " + err.Error())
71 }
72
73 if l.versionInfo {
74 l.versionInfo = false // only get the version information once
75 message, err := version.GetMessage(ctx, l.buildInfo, l.client)
76 if err != nil {
77 l.logger.Error("cannot get version information: " + err.Error())
78 } else {
79 l.logger.Info(message)
80 }
81 }

Callers 1

RunMethod · 0.95

Calls 14

restartVPNMethod · 0.95
collectHealthErrorsMethod · 0.95
startPortForwardingMethod · 0.95
GetMessageFunction · 0.92
SetAllowedPortMethod · 0.65
ErrorMethod · 0.65
SetConfigMethod · 0.65
StartMethod · 0.65
SetErrorMethod · 0.65
WarnfMethod · 0.65
InfoMethod · 0.65
GetSettingsMethod · 0.65

Tested by

no test coverage detected