xfrm_policy.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. Spi int
  42. Reqid int
  43. }
  44. func (t XfrmPolicyTmpl) String() string {
  45. return fmt.Sprintf("{Dst: %v, Src: %v, Proto: %s, Mode: %s, Spi: 0x%x, Reqid: 0x%x}",
  46. t.Dst, t.Src, t.Proto, t.Mode, t.Spi, t.Reqid)
  47. }
  48. // XfrmPolicy represents an ipsec policy. It represents the overlay network
  49. // and has a list of XfrmPolicyTmpls representing the base addresses of
  50. // the policy.
  51. type XfrmPolicy struct {
  52. Dst *net.IPNet
  53. Src *net.IPNet
  54. Proto Proto
  55. DstPort int
  56. SrcPort int
  57. Dir Dir
  58. Priority int
  59. Index int
  60. Mark *XfrmMark
  61. Tmpls []XfrmPolicyTmpl
  62. }
  63. func (p XfrmPolicy) String() string {
  64. return fmt.Sprintf("{Dst: %v, Src: %v, Proto: %s, DstPort: %d, SrcPort: %d, Dir: %s, Priority: %d, Index: %d, Mark: %s, Tmpls: %s}",
  65. p.Dst, p.Src, p.Proto, p.DstPort, p.SrcPort, p.Dir, p.Priority, p.Index, p.Mark, p.Tmpls)
  66. }