common.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2015 flannel authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package backend
  15. import (
  16. "net"
  17. "sync"
  18. "github.com/flannel-io/flannel/subnet"
  19. "golang.org/x/net/context"
  20. )
  21. type ExternalInterface struct {
  22. Iface *net.Interface
  23. IfaceAddr net.IP
  24. IfaceV6Addr net.IP
  25. ExtAddr net.IP
  26. ExtV6Addr net.IP
  27. }
  28. // Besides the entry points in the Backend interface, the backend's New()
  29. // function receives static network interface information (like internal and
  30. // external IP addresses, MTU, etc) which it should cache for later use if
  31. // needed.
  32. type Backend interface {
  33. // Called when the backend should create or begin managing a new network
  34. RegisterNetwork(ctx context.Context, wg *sync.WaitGroup, config *subnet.Config) (Network, error)
  35. }
  36. type Network interface {
  37. Lease() *subnet.Lease
  38. MTU() int
  39. Run(ctx context.Context)
  40. }
  41. type BackendCtor func(sm subnet.Manager, ei *ExternalInterface) (Backend, error)