feature/featuretags, all: add build features, use existing ones in more places
Saves 270 KB. Updates #12614 Change-Id: I4c3fe06d32c49edb3a4bb0758a8617d83f291cf5 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
committed by
Brad Fitzpatrick
parent
aa5b2ce83b
commit
c45f8813b4
+30
-17
@@ -10,6 +10,7 @@ import (
|
||||
"net/http"
|
||||
"path"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -33,26 +34,34 @@ import (
|
||||
// exists for that, a map entry with an empty method is used as a fallback.
|
||||
var c2nHandlers = map[methodAndPath]c2nHandler{
|
||||
// Debug.
|
||||
req("/echo"): handleC2NEcho,
|
||||
req("/debug/goroutines"): handleC2NDebugGoroutines,
|
||||
req("/debug/prefs"): handleC2NDebugPrefs,
|
||||
req("/debug/metrics"): handleC2NDebugMetrics,
|
||||
req("/debug/component-logging"): handleC2NDebugComponentLogging,
|
||||
req("/debug/logheap"): handleC2NDebugLogHeap,
|
||||
req("/debug/netmap"): handleC2NDebugNetMap,
|
||||
req("/echo"): handleC2NEcho,
|
||||
}
|
||||
|
||||
// PPROF - We only expose a subset of typical pprof endpoints for security.
|
||||
req("/debug/pprof/heap"): handleC2NPprof,
|
||||
req("/debug/pprof/allocs"): handleC2NPprof,
|
||||
func init() {
|
||||
if buildfeatures.HasSSH {
|
||||
RegisterC2N("/ssh/usernames", handleC2NSSHUsernames)
|
||||
}
|
||||
if buildfeatures.HasLogTail {
|
||||
RegisterC2N("POST /logtail/flush", handleC2NLogtailFlush)
|
||||
}
|
||||
if buildfeatures.HasDebug {
|
||||
RegisterC2N("POST /sockstats", handleC2NSockStats)
|
||||
|
||||
req("POST /logtail/flush"): handleC2NLogtailFlush,
|
||||
req("POST /sockstats"): handleC2NSockStats,
|
||||
// pprof:
|
||||
// we only expose a subset of typical pprof endpoints for security.
|
||||
RegisterC2N("/debug/pprof/heap", handleC2NPprof)
|
||||
RegisterC2N("/debug/pprof/allocs", handleC2NPprof)
|
||||
|
||||
// SSH
|
||||
req("/ssh/usernames"): handleC2NSSHUsernames,
|
||||
|
||||
// Linux netfilter.
|
||||
req("POST /netfilter-kind"): handleC2NSetNetfilterKind,
|
||||
RegisterC2N("/debug/goroutines", handleC2NDebugGoroutines)
|
||||
RegisterC2N("/debug/prefs", handleC2NDebugPrefs)
|
||||
RegisterC2N("/debug/metrics", handleC2NDebugMetrics)
|
||||
RegisterC2N("/debug/component-logging", handleC2NDebugComponentLogging)
|
||||
RegisterC2N("/debug/logheap", handleC2NDebugLogHeap)
|
||||
RegisterC2N("/debug/netmap", handleC2NDebugNetMap)
|
||||
}
|
||||
if runtime.GOOS == "linux" && buildfeatures.HasOSRouter {
|
||||
RegisterC2N("POST /netfilter-kind", handleC2NSetNetfilterKind)
|
||||
}
|
||||
}
|
||||
|
||||
// RegisterC2N registers a new c2n handler for the given pattern.
|
||||
@@ -265,6 +274,10 @@ func handleC2NPprof(b *LocalBackend, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func handleC2NSSHUsernames(b *LocalBackend, w http.ResponseWriter, r *http.Request) {
|
||||
if !buildfeatures.HasSSH {
|
||||
http.Error(w, feature.ErrUnavailable.Error(), http.StatusNotImplemented)
|
||||
return
|
||||
}
|
||||
var req tailcfg.C2NSSHUsernamesRequest
|
||||
if r.Method == "POST" {
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user