xfrm.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package netlink
  2. import (
  3. "fmt"
  4. "syscall"
  5. )
  6. // Proto is an enum representing an ipsec protocol.
  7. type Proto uint8
  8. const (
  9. XFRM_PROTO_ROUTE2 Proto = syscall.IPPROTO_ROUTING
  10. XFRM_PROTO_ESP Proto = syscall.IPPROTO_ESP
  11. XFRM_PROTO_AH Proto = syscall.IPPROTO_AH
  12. XFRM_PROTO_HAO Proto = syscall.IPPROTO_DSTOPTS
  13. XFRM_PROTO_COMP Proto = 0x6c // NOTE not defined on darwin
  14. XFRM_PROTO_IPSEC_ANY Proto = syscall.IPPROTO_RAW
  15. )
  16. func (p Proto) String() string {
  17. switch p {
  18. case XFRM_PROTO_ROUTE2:
  19. return "route2"
  20. case XFRM_PROTO_ESP:
  21. return "esp"
  22. case XFRM_PROTO_AH:
  23. return "ah"
  24. case XFRM_PROTO_HAO:
  25. return "hao"
  26. case XFRM_PROTO_COMP:
  27. return "comp"
  28. case XFRM_PROTO_IPSEC_ANY:
  29. return "ipsec-any"
  30. }
  31. return fmt.Sprintf("%d", p)
  32. }
  33. // Mode is an enum representing an ipsec transport.
  34. type Mode uint8
  35. const (
  36. XFRM_MODE_TRANSPORT Mode = iota
  37. XFRM_MODE_TUNNEL
  38. XFRM_MODE_ROUTEOPTIMIZATION
  39. XFRM_MODE_IN_TRIGGER
  40. XFRM_MODE_BEET
  41. XFRM_MODE_MAX
  42. )
  43. func (m Mode) String() string {
  44. switch m {
  45. case XFRM_MODE_TRANSPORT:
  46. return "transport"
  47. case XFRM_MODE_TUNNEL:
  48. return "tunnel"
  49. case XFRM_MODE_ROUTEOPTIMIZATION:
  50. return "ro"
  51. case XFRM_MODE_IN_TRIGGER:
  52. return "in_trigger"
  53. case XFRM_MODE_BEET:
  54. return "beet"
  55. }
  56. return fmt.Sprintf("%d", m)
  57. }
  58. // XfrmMark represents the mark associated to the state or policy
  59. type XfrmMark struct {
  60. Value uint32
  61. Mask uint32
  62. }
  63. func (m *XfrmMark) String() string {
  64. return fmt.Sprintf("(0x%x,0x%x)", m.Value, m.Mask)
  65. }