xfrm.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 = syscall.IPPROTO_COMP
  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. }