(h *localapi.Handler, w http.ResponseWriter, r *http.Request)
| 28 | } |
| 29 | |
| 30 | func serveDebugPortmap(h *localapi.Handler, w http.ResponseWriter, r *http.Request) { |
| 31 | if !h.PermitWrite { |
| 32 | http.Error(w, "debug access denied", http.StatusForbidden) |
| 33 | return |
| 34 | } |
| 35 | w.Header().Set("Content-Type", "text/plain") |
| 36 | |
| 37 | dur, err := time.ParseDuration(r.FormValue("duration")) |
| 38 | if err != nil { |
| 39 | http.Error(w, err.Error(), http.StatusBadRequest) |
| 40 | return |
| 41 | } |
| 42 | |
| 43 | gwSelf := r.FormValue("gateway_and_self") |
| 44 | |
| 45 | trueFunc := func() bool { return true } |
| 46 | // Update portmapper debug flags |
| 47 | debugKnobs := &portmapper.DebugKnobs{VerboseLogs: true} |
| 48 | switch r.FormValue("type") { |
| 49 | case "": |
| 50 | case "pmp": |
| 51 | debugKnobs.DisablePCPFunc = trueFunc |
| 52 | debugKnobs.DisableUPnPFunc = trueFunc |
| 53 | case "pcp": |
| 54 | debugKnobs.DisablePMPFunc = trueFunc |
| 55 | debugKnobs.DisableUPnPFunc = trueFunc |
| 56 | case "upnp": |
| 57 | debugKnobs.DisablePCPFunc = trueFunc |
| 58 | debugKnobs.DisablePMPFunc = trueFunc |
| 59 | default: |
| 60 | http.Error(w, "unknown portmap debug type", http.StatusBadRequest) |
| 61 | return |
| 62 | } |
| 63 | if k := h.LocalBackend().ControlKnobs(); k != nil { |
| 64 | if k.DisableUPnP.Load() { |
| 65 | debugKnobs.DisableUPnPFunc = trueFunc |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | if defBool(r.FormValue("log_http"), false) { |
| 70 | debugKnobs.LogHTTP = true |
| 71 | } |
| 72 | |
| 73 | var ( |
| 74 | logLock sync.Mutex |
| 75 | handlerDone bool |
| 76 | ) |
| 77 | logf := func(format string, args ...any) { |
| 78 | if !strings.HasSuffix(format, "\n") { |
| 79 | format = format + "\n" |
| 80 | } |
| 81 | |
| 82 | logLock.Lock() |
| 83 | defer logLock.Unlock() |
| 84 | |
| 85 | // The portmapper can call this log function after the HTTP |
| 86 | // handler returns, which is not allowed and can cause a panic. |
| 87 | // If this happens, ignore the log lines since this typically |
nothing calls this directly
no test coverage detected
searching dependent graphs…