mirror of
https://github.com/tailscale/tailscale.git
synced 2025-10-27 20:19:31 +00:00
feature/linkspeed: move cosmetic tstun netlink code out to modular feature
Part of making all netlink monitoring code optional. Updates #17311 (how I got started down this path) Updates #12614 Change-Id: Ic80d8a7a44dc261c4b8678b3c2241c3b3778370d Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
committed by
Brad Fitzpatrick
parent
63f7a400a8
commit
232b928974
@@ -74,7 +74,6 @@ tailscale.com/cmd/k8s-operator dependencies: (generated by github.com/tailscale/
|
||||
github.com/mailru/easyjson/buffer from github.com/mailru/easyjson/jwriter
|
||||
💣 github.com/mailru/easyjson/jlexer from github.com/go-openapi/swag
|
||||
github.com/mailru/easyjson/jwriter from github.com/go-openapi/swag
|
||||
L github.com/mdlayher/genetlink from tailscale.com/net/tstun
|
||||
L 💣 github.com/mdlayher/netlink from github.com/jsimonetti/rtnetlink+
|
||||
L 💣 github.com/mdlayher/netlink/nlenc from github.com/jsimonetti/rtnetlink+
|
||||
L 💣 github.com/mdlayher/socket from github.com/mdlayher/netlink+
|
||||
@@ -907,7 +906,7 @@ tailscale.com/cmd/k8s-operator dependencies: (generated by github.com/tailscale/
|
||||
golang.org/x/exp/constraints from tailscale.com/tsweb/varz+
|
||||
golang.org/x/exp/maps from sigs.k8s.io/controller-runtime/pkg/cache+
|
||||
golang.org/x/exp/slices from tailscale.com/cmd/k8s-operator+
|
||||
golang.org/x/net/bpf from github.com/mdlayher/genetlink+
|
||||
golang.org/x/net/bpf from github.com/mdlayher/netlink+
|
||||
golang.org/x/net/dns/dnsmessage from tailscale.com/appc+
|
||||
golang.org/x/net/http/httpguts from golang.org/x/net/http2+
|
||||
golang.org/x/net/http/httpproxy from tailscale.com/net/tshttpproxy
|
||||
|
||||
@@ -19,7 +19,6 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de
|
||||
github.com/klauspost/compress/internal/snapref from github.com/klauspost/compress/zstd
|
||||
github.com/klauspost/compress/zstd from tailscale.com/util/zstdframe
|
||||
github.com/klauspost/compress/zstd/internal/xxhash from github.com/klauspost/compress/zstd
|
||||
github.com/mdlayher/genetlink from tailscale.com/net/tstun
|
||||
💣 github.com/mdlayher/netlink from github.com/jsimonetti/rtnetlink+
|
||||
💣 github.com/mdlayher/netlink/nlenc from github.com/jsimonetti/rtnetlink+
|
||||
💣 github.com/mdlayher/socket from github.com/mdlayher/netlink
|
||||
@@ -204,7 +203,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de
|
||||
golang.org/x/crypto/salsa20/salsa from golang.org/x/crypto/nacl/box+
|
||||
golang.org/x/exp/constraints from tailscale.com/util/set
|
||||
golang.org/x/exp/maps from tailscale.com/ipn/store/mem
|
||||
golang.org/x/net/bpf from github.com/mdlayher/genetlink+
|
||||
golang.org/x/net/bpf from github.com/mdlayher/netlink+
|
||||
golang.org/x/net/dns/dnsmessage from tailscale.com/ipn/ipnlocal+
|
||||
golang.org/x/net/http/httpguts from tailscale.com/ipn/ipnlocal
|
||||
golang.org/x/net/icmp from tailscale.com/net/ping
|
||||
|
||||
@@ -25,7 +25,6 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de
|
||||
github.com/klauspost/compress/zstd/internal/xxhash from github.com/klauspost/compress/zstd
|
||||
github.com/mattn/go-colorable from tailscale.com/cmd/tailscale/cli
|
||||
github.com/mattn/go-isatty from github.com/mattn/go-colorable+
|
||||
github.com/mdlayher/genetlink from tailscale.com/net/tstun
|
||||
💣 github.com/mdlayher/netlink from github.com/jsimonetti/rtnetlink+
|
||||
💣 github.com/mdlayher/netlink/nlenc from github.com/jsimonetti/rtnetlink+
|
||||
💣 github.com/mdlayher/socket from github.com/mdlayher/netlink
|
||||
@@ -232,7 +231,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de
|
||||
golang.org/x/crypto/salsa20/salsa from golang.org/x/crypto/nacl/box+
|
||||
golang.org/x/exp/constraints from tailscale.com/util/set
|
||||
golang.org/x/exp/maps from tailscale.com/ipn/store/mem
|
||||
golang.org/x/net/bpf from github.com/mdlayher/genetlink+
|
||||
golang.org/x/net/bpf from github.com/mdlayher/netlink+
|
||||
golang.org/x/net/dns/dnsmessage from tailscale.com/cmd/tailscale/cli+
|
||||
golang.org/x/net/http/httpguts from tailscale.com/ipn/ipnlocal
|
||||
golang.org/x/net/icmp from tailscale.com/net/ping
|
||||
|
||||
@@ -143,7 +143,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de
|
||||
github.com/klauspost/compress/zstd/internal/xxhash from github.com/klauspost/compress/zstd
|
||||
github.com/kortschak/wol from tailscale.com/feature/wakeonlan
|
||||
LD github.com/kr/fs from github.com/pkg/sftp
|
||||
L github.com/mdlayher/genetlink from tailscale.com/net/tstun
|
||||
L github.com/mdlayher/genetlink from tailscale.com/feature/linkspeed
|
||||
L 💣 github.com/mdlayher/netlink from github.com/google/nftables+
|
||||
L 💣 github.com/mdlayher/netlink/nlenc from github.com/jsimonetti/rtnetlink+
|
||||
L github.com/mdlayher/netlink/nltest from github.com/google/nftables
|
||||
@@ -285,6 +285,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de
|
||||
tailscale.com/feature/debugportmapper from tailscale.com/feature/condregister
|
||||
tailscale.com/feature/doctor from tailscale.com/feature/condregister
|
||||
tailscale.com/feature/drive from tailscale.com/feature/condregister
|
||||
L tailscale.com/feature/linkspeed from tailscale.com/feature/condregister
|
||||
L tailscale.com/feature/linuxdnsfight from tailscale.com/feature/condregister
|
||||
tailscale.com/feature/portlist from tailscale.com/feature/condregister
|
||||
tailscale.com/feature/portmapper from tailscale.com/feature/condregister/portmapper
|
||||
|
||||
@@ -287,6 +287,7 @@ func TestMinTailscaledWithCLI(t *testing.T) {
|
||||
BadDeps: map[string]string{
|
||||
"golang.org/x/net/http2": "unexpected x/net/http2 dep; tailscale/tailscale#17305",
|
||||
"expvar": "unexpected expvar dep",
|
||||
"github.com/mdlayher/genetlink": "unexpected genetlink dep",
|
||||
},
|
||||
}.Check(t)
|
||||
}
|
||||
|
||||
@@ -38,7 +38,6 @@ tailscale.com/cmd/tsidp dependencies: (generated by github.com/tailscale/depawar
|
||||
github.com/klauspost/compress/internal/snapref from github.com/klauspost/compress/zstd
|
||||
github.com/klauspost/compress/zstd from tailscale.com/util/zstdframe
|
||||
github.com/klauspost/compress/zstd/internal/xxhash from github.com/klauspost/compress/zstd
|
||||
L github.com/mdlayher/genetlink from tailscale.com/net/tstun
|
||||
L 💣 github.com/mdlayher/netlink from github.com/jsimonetti/rtnetlink+
|
||||
L 💣 github.com/mdlayher/netlink/nlenc from github.com/jsimonetti/rtnetlink+
|
||||
L 💣 github.com/mdlayher/socket from github.com/mdlayher/netlink+
|
||||
@@ -335,7 +334,7 @@ tailscale.com/cmd/tsidp dependencies: (generated by github.com/tailscale/depawar
|
||||
LD golang.org/x/crypto/ssh/internal/bcrypt_pbkdf from golang.org/x/crypto/ssh
|
||||
golang.org/x/exp/constraints from tailscale.com/tsweb/varz+
|
||||
golang.org/x/exp/maps from tailscale.com/ipn/store/mem+
|
||||
golang.org/x/net/bpf from github.com/mdlayher/genetlink+
|
||||
golang.org/x/net/bpf from github.com/mdlayher/netlink+
|
||||
golang.org/x/net/dns/dnsmessage from tailscale.com/appc+
|
||||
golang.org/x/net/http/httpguts from tailscale.com/ipn/ipnlocal
|
||||
golang.org/x/net/http/httpproxy from tailscale.com/net/tshttpproxy
|
||||
|
||||
13
feature/buildfeatures/feature_linkspeed_disabled.go
Normal file
13
feature/buildfeatures/feature_linkspeed_disabled.go
Normal file
@@ -0,0 +1,13 @@
|
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
// Code generated by gen.go; DO NOT EDIT.
|
||||
|
||||
//go:build ts_omit_linkspeed
|
||||
|
||||
package buildfeatures
|
||||
|
||||
// HasLinkSpeed is whether the binary was built with support for modular feature "Set link speed on TUN device for better OS integration (Linux only)".
|
||||
// Specifically, it's whether the binary was NOT built with the "ts_omit_linkspeed" build tag.
|
||||
// It's a const so it can be used for dead code elimination.
|
||||
const HasLinkSpeed = false
|
||||
13
feature/buildfeatures/feature_linkspeed_enabled.go
Normal file
13
feature/buildfeatures/feature_linkspeed_enabled.go
Normal file
@@ -0,0 +1,13 @@
|
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
// Code generated by gen.go; DO NOT EDIT.
|
||||
|
||||
//go:build !ts_omit_linkspeed
|
||||
|
||||
package buildfeatures
|
||||
|
||||
// HasLinkSpeed is whether the binary was built with support for modular feature "Set link speed on TUN device for better OS integration (Linux only)".
|
||||
// Specifically, it's whether the binary was NOT built with the "ts_omit_linkspeed" build tag.
|
||||
// It's a const so it can be used for dead code elimination.
|
||||
const HasLinkSpeed = true
|
||||
8
feature/condregister/maybe_linkspeed.go
Normal file
8
feature/condregister/maybe_linkspeed.go
Normal file
@@ -0,0 +1,8 @@
|
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
//go:build linux && !android && !ts_omit_linkspeed
|
||||
|
||||
package condregister
|
||||
|
||||
import _ "tailscale.com/feature/linkspeed"
|
||||
@@ -161,6 +161,10 @@ var Features = map[FeatureTag]FeatureMeta{
|
||||
"kube": {Sym: "Kube", Desc: "Kubernetes integration"},
|
||||
"lazywg": {Sym: "LazyWG", Desc: "Lazy WireGuard configuration for memory-constrained devices with large netmaps"},
|
||||
"linuxdnsfight": {Sym: "LinuxDNSFight", Desc: "Linux support for detecting DNS fights (inotify watching of /etc/resolv.conf)"},
|
||||
"linkspeed": {
|
||||
Sym: "LinkSpeed",
|
||||
Desc: "Set link speed on TUN device for better OS integration (Linux only)",
|
||||
},
|
||||
"listenrawdisco": {
|
||||
Sym: "ListenRawDisco",
|
||||
Desc: "Use raw sockets for more robust disco (NAT traversal) message receiving (Linux only)",
|
||||
|
||||
6
feature/linkspeed/doc.go
Normal file
6
feature/linkspeed/doc.go
Normal file
@@ -0,0 +1,6 @@
|
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
// Package linkspeed registers support for setting the TUN link speed on Linux,
|
||||
// to better integrate with system monitoring tools.
|
||||
package linkspeed
|
||||
@@ -1,17 +1,22 @@
|
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
//go:build !android
|
||||
//go:build linux && !android
|
||||
|
||||
package tstun
|
||||
package linkspeed
|
||||
|
||||
import (
|
||||
"github.com/mdlayher/genetlink"
|
||||
"github.com/mdlayher/netlink"
|
||||
"github.com/tailscale/wireguard-go/tun"
|
||||
"golang.org/x/sys/unix"
|
||||
"tailscale.com/net/tstun"
|
||||
)
|
||||
|
||||
func init() {
|
||||
tstun.HookSetLinkAttrs.Set(setLinkAttrs)
|
||||
}
|
||||
|
||||
// setLinkSpeed sets the advertised link speed of the TUN interface.
|
||||
func setLinkSpeed(iface tun.Device, mbps int) error {
|
||||
name, err := iface.Name()
|
||||
@@ -1,12 +0,0 @@
|
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
//go:build !linux || android
|
||||
|
||||
package tstun
|
||||
|
||||
import "github.com/tailscale/wireguard-go/tun"
|
||||
|
||||
func setLinkAttrs(iface tun.Device) error {
|
||||
return nil
|
||||
}
|
||||
@@ -18,12 +18,16 @@ import (
|
||||
|
||||
"github.com/tailscale/wireguard-go/tun"
|
||||
"tailscale.com/feature"
|
||||
"tailscale.com/feature/buildfeatures"
|
||||
"tailscale.com/types/logger"
|
||||
)
|
||||
|
||||
// CreateTAP is the hook set by feature/tap.
|
||||
// CreateTAP is the hook maybe set by feature/tap.
|
||||
var CreateTAP feature.Hook[func(logf logger.Logf, tapName, bridgeName string) (tun.Device, error)]
|
||||
|
||||
// HookSetLinkAttrs is the hook maybe set by feature/linkspeed.
|
||||
var HookSetLinkAttrs feature.Hook[func(tun.Device) error]
|
||||
|
||||
// modprobeTunHook is a Linux-specific hook to run "/sbin/modprobe tun".
|
||||
var modprobeTunHook feature.Hook[func() error]
|
||||
|
||||
@@ -78,9 +82,13 @@ func New(logf logger.Logf, tunName string) (tun.Device, string, error) {
|
||||
dev.Close()
|
||||
return nil, "", err
|
||||
}
|
||||
if err := setLinkAttrs(dev); err != nil {
|
||||
if buildfeatures.HasLinkSpeed {
|
||||
if f, ok := HookSetLinkAttrs.GetOk(); ok {
|
||||
if err := f(dev); err != nil {
|
||||
logf("setting link attributes: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
name, err := interfaceName(dev)
|
||||
if err != nil {
|
||||
dev.Close()
|
||||
|
||||
@@ -38,7 +38,6 @@ tailscale.com/tsnet dependencies: (generated by github.com/tailscale/depaware)
|
||||
github.com/klauspost/compress/internal/snapref from github.com/klauspost/compress/zstd
|
||||
github.com/klauspost/compress/zstd from tailscale.com/util/zstdframe
|
||||
github.com/klauspost/compress/zstd/internal/xxhash from github.com/klauspost/compress/zstd
|
||||
L github.com/mdlayher/genetlink from tailscale.com/net/tstun
|
||||
L 💣 github.com/mdlayher/netlink from github.com/jsimonetti/rtnetlink+
|
||||
L 💣 github.com/mdlayher/netlink/nlenc from github.com/jsimonetti/rtnetlink+
|
||||
LA 💣 github.com/mdlayher/socket from github.com/mdlayher/netlink+
|
||||
@@ -328,7 +327,7 @@ tailscale.com/tsnet dependencies: (generated by github.com/tailscale/depaware)
|
||||
LD golang.org/x/crypto/ssh/internal/bcrypt_pbkdf from golang.org/x/crypto/ssh
|
||||
golang.org/x/exp/constraints from tailscale.com/tsweb/varz+
|
||||
golang.org/x/exp/maps from tailscale.com/ipn/store/mem+
|
||||
golang.org/x/net/bpf from github.com/mdlayher/genetlink+
|
||||
golang.org/x/net/bpf from github.com/mdlayher/netlink+
|
||||
golang.org/x/net/dns/dnsmessage from tailscale.com/appc+
|
||||
golang.org/x/net/http/httpguts from tailscale.com/ipn/ipnlocal
|
||||
golang.org/x/net/http/httpproxy from tailscale.com/net/tshttpproxy
|
||||
|
||||
Reference in New Issue
Block a user