subnet_router_wrapper.go 820 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright (c) 2021 Tailscale Inc & AUTHORS All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package netstack
  5. import (
  6. "reflect"
  7. "tailscale.com/wgengine"
  8. "tailscale.com/wgengine/router"
  9. )
  10. func init() {
  11. wgengine.NetstackRouterType = reflect.TypeOf(&subnetRouter{})
  12. }
  13. type subnetRouter struct {
  14. router.Router
  15. }
  16. // NewSubnetRouterWrapper returns a Router wrapper that prevents the
  17. // underlying Router r from seeing any advertised subnet routes, as
  18. // netstack will handle them instead.
  19. func NewSubnetRouterWrapper(r router.Router) router.Router {
  20. return &subnetRouter{
  21. Router: r,
  22. }
  23. }
  24. func (r *subnetRouter) Set(c *router.Config) error {
  25. if c != nil {
  26. c.SubnetRoutes = nil // netstack will handle
  27. }
  28. return r.Router.Set(c)
  29. }