2025-04-15 08:28:48 -07:00
|
|
|
// Copyright (c) Tailscale Inc & AUTHORS
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
|
|
|
|
package taildrop
|
|
|
|
|
|
|
|
import (
|
|
|
|
"tailscale.com/ipn/ipnext"
|
|
|
|
"tailscale.com/ipn/ipnlocal"
|
|
|
|
"tailscale.com/taildrop"
|
|
|
|
"tailscale.com/types/logger"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
ipnext.RegisterExtension("taildrop", newExtension)
|
|
|
|
}
|
|
|
|
|
2025-04-24 13:55:39 -07:00
|
|
|
func newExtension(logf logger.Logf, b ipnext.SafeBackend) (ipnext.Extension, error) {
|
2025-04-15 08:28:48 -07:00
|
|
|
return &extension{
|
|
|
|
logf: logger.WithPrefix(logf, "taildrop: "),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type extension struct {
|
|
|
|
logf logger.Logf
|
2025-04-24 13:55:39 -07:00
|
|
|
sb ipnext.SafeBackend
|
2025-04-15 08:28:48 -07:00
|
|
|
mgr *taildrop.Manager
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *extension) Name() string {
|
|
|
|
return "taildrop"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *extension) Init(h ipnext.Host) error {
|
|
|
|
// TODO(bradfitz): move init of taildrop.Manager from ipnlocal/peerapi.go to
|
|
|
|
// here
|
|
|
|
e.mgr = nil
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *extension) Shutdown() error {
|
2025-04-24 13:55:39 -07:00
|
|
|
lb, ok := e.sb.(*ipnlocal.LocalBackend)
|
|
|
|
if !ok {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if mgr, err := lb.TaildropManager(); err == nil {
|
2025-04-15 08:28:48 -07:00
|
|
|
mgr.Shutdown()
|
|
|
|
} else {
|
|
|
|
e.logf("taildrop: failed to shutdown taildrop manager: %v", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|