common.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. "golang.org/x/net/context"
  19. "github.com/coreos/flannel/subnet"
  20. )
  21. type ExternalInterface struct {
  22. Iface *net.Interface
  23. IfaceAddr net.IP
  24. ExtAddr net.IP
  25. }
  26. // Besides the entry points in the Backend interface, the backend's New()
  27. // function receives static network interface information (like internal and
  28. // external IP addresses, MTU, etc) which it should cache for later use if
  29. // needed.
  30. type Backend interface {
  31. // Called when the backend should create or begin managing a new network
  32. RegisterNetwork(ctx context.Context, wg *sync.WaitGroup, config *subnet.Config) (Network, error)
  33. }
  34. type Network interface {
  35. Lease() *subnet.Lease
  36. MTU() int
  37. Run(ctx context.Context)
  38. }
  39. type BackendCtor func(sm subnet.Manager, ei *ExternalInterface) (Backend, error)