xfrm_policy.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package netlink
  2. import (
  3. "fmt"
  4. "net"
  5. )
  6. // Dir is an enum representing an ipsec template direction.
  7. type Dir uint8
  8. const (
  9. XFRM_DIR_IN Dir = iota
  10. XFRM_DIR_OUT
  11. XFRM_DIR_FWD
  12. XFRM_SOCKET_IN
  13. XFRM_SOCKET_OUT
  14. XFRM_SOCKET_FWD
  15. )
  16. func (d Dir) String() string {
  17. switch d {
  18. case XFRM_DIR_IN:
  19. return "dir in"
  20. case XFRM_DIR_OUT:
  21. return "dir out"
  22. case XFRM_DIR_FWD:
  23. return "dir fwd"
  24. case XFRM_SOCKET_IN:
  25. return "socket in"
  26. case XFRM_SOCKET_OUT:
  27. return "socket out"
  28. case XFRM_SOCKET_FWD:
  29. return "socket fwd"
  30. }
  31. return fmt.Sprintf("socket %d", d-XFRM_SOCKET_IN)
  32. }
  33. // XfrmPolicyTmpl encapsulates a rule for the base addresses of an ipsec
  34. // policy. These rules are matched with XfrmState to determine encryption
  35. // and authentication algorithms.
  36. type XfrmPolicyTmpl struct {
  37. Dst net.IP
  38. Src net.IP
  39. Proto Proto
  40. Mode Mode
  41. Reqid int
  42. }
  43. // XfrmPolicy represents an ipsec policy. It represents the overlay network
  44. // and has a list of XfrmPolicyTmpls representing the base addresses of
  45. // the policy.
  46. type XfrmPolicy struct {
  47. Dst *net.IPNet
  48. Src *net.IPNet
  49. Dir Dir
  50. Priority int
  51. Index int
  52. Tmpls []XfrmPolicyTmpl
  53. }