encapsulation.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2019 the Kilo 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 encapsulation
  15. import (
  16. "net"
  17. "github.com/squat/kilo/pkg/iptables"
  18. )
  19. // Strategy identifies which packets within a location should
  20. // be encapsulated.
  21. type Strategy string
  22. const (
  23. // Never indicates that no packets within a location
  24. // should be encapsulated.
  25. Never Strategy = "never"
  26. // CrossSubnet indicates that only packets that
  27. // traverse subnets within a location should be encapsulated.
  28. CrossSubnet Strategy = "crosssubnet"
  29. // Always indicates that all packets within a location
  30. // should be encapsulated.
  31. Always Strategy = "always"
  32. )
  33. // Encapsulator can:
  34. // * configure the encapsulation interface;
  35. // * determine the gateway IP corresponding to a node;
  36. // * get the encapsulation interface index;
  37. // * set the interface IP address;
  38. // * return the required IPTables rules;
  39. // * return the encapsulation strategy; and
  40. // * clean up any changes applied to the backend.
  41. type Encapsulator interface {
  42. CleanUp() error
  43. Gw(net.IP, net.IP, net.IP, *net.IPNet) net.IP
  44. Index() int
  45. Init(int) error
  46. // CNICompatibilityIP returns the local overlay IP that should be
  47. // advertised to other nodes for CNI-compatible routing.
  48. CNICompatibilityIP() *net.IPNet
  49. Rules([]*net.IPNet) iptables.RuleSet
  50. Set(*net.IPNet) error
  51. Strategy() Strategy
  52. }