xfrm_policy_linux.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package nl
  2. import (
  3. "unsafe"
  4. )
  5. const (
  6. SizeofXfrmUserpolicyId = 0x40
  7. SizeofXfrmUserpolicyInfo = 0xa8
  8. SizeofXfrmUserTmpl = 0x40
  9. )
  10. // struct xfrm_userpolicy_id {
  11. // struct xfrm_selector sel;
  12. // __u32 index;
  13. // __u8 dir;
  14. // };
  15. //
  16. type XfrmUserpolicyId struct {
  17. Sel XfrmSelector
  18. Index uint32
  19. Dir uint8
  20. Pad [3]byte
  21. }
  22. func (msg *XfrmUserpolicyId) Len() int {
  23. return SizeofXfrmUserpolicyId
  24. }
  25. func DeserializeXfrmUserpolicyId(b []byte) *XfrmUserpolicyId {
  26. return (*XfrmUserpolicyId)(unsafe.Pointer(&b[0:SizeofXfrmUserpolicyId][0]))
  27. }
  28. func (msg *XfrmUserpolicyId) Serialize() []byte {
  29. return (*(*[SizeofXfrmUserpolicyId]byte)(unsafe.Pointer(msg)))[:]
  30. }
  31. // struct xfrm_userpolicy_info {
  32. // struct xfrm_selector sel;
  33. // struct xfrm_lifetime_cfg lft;
  34. // struct xfrm_lifetime_cur curlft;
  35. // __u32 priority;
  36. // __u32 index;
  37. // __u8 dir;
  38. // __u8 action;
  39. // #define XFRM_POLICY_ALLOW 0
  40. // #define XFRM_POLICY_BLOCK 1
  41. // __u8 flags;
  42. // #define XFRM_POLICY_LOCALOK 1 /* Allow user to override global policy */
  43. // /* Automatically expand selector to include matching ICMP payloads. */
  44. // #define XFRM_POLICY_ICMP 2
  45. // __u8 share;
  46. // };
  47. type XfrmUserpolicyInfo struct {
  48. Sel XfrmSelector
  49. Lft XfrmLifetimeCfg
  50. Curlft XfrmLifetimeCur
  51. Priority uint32
  52. Index uint32
  53. Dir uint8
  54. Action uint8
  55. Flags uint8
  56. Share uint8
  57. Pad [4]byte
  58. }
  59. func (msg *XfrmUserpolicyInfo) Len() int {
  60. return SizeofXfrmUserpolicyInfo
  61. }
  62. func DeserializeXfrmUserpolicyInfo(b []byte) *XfrmUserpolicyInfo {
  63. return (*XfrmUserpolicyInfo)(unsafe.Pointer(&b[0:SizeofXfrmUserpolicyInfo][0]))
  64. }
  65. func (msg *XfrmUserpolicyInfo) Serialize() []byte {
  66. return (*(*[SizeofXfrmUserpolicyInfo]byte)(unsafe.Pointer(msg)))[:]
  67. }
  68. // struct xfrm_user_tmpl {
  69. // struct xfrm_id id;
  70. // __u16 family;
  71. // xfrm_address_t saddr;
  72. // __u32 reqid;
  73. // __u8 mode;
  74. // __u8 share;
  75. // __u8 optional;
  76. // __u32 aalgos;
  77. // __u32 ealgos;
  78. // __u32 calgos;
  79. // }
  80. type XfrmUserTmpl struct {
  81. XfrmId XfrmId
  82. Family uint16
  83. Pad1 [2]byte
  84. Saddr XfrmAddress
  85. Reqid uint32
  86. Mode uint8
  87. Share uint8
  88. Optional uint8
  89. Pad2 byte
  90. Aalgos uint32
  91. Ealgos uint32
  92. Calgos uint32
  93. }
  94. func (msg *XfrmUserTmpl) Len() int {
  95. return SizeofXfrmUserTmpl
  96. }
  97. func DeserializeXfrmUserTmpl(b []byte) *XfrmUserTmpl {
  98. return (*XfrmUserTmpl)(unsafe.Pointer(&b[0:SizeofXfrmUserTmpl][0]))
  99. }
  100. func (msg *XfrmUserTmpl) Serialize() []byte {
  101. return (*(*[SizeofXfrmUserTmpl]byte)(unsafe.Pointer(msg)))[:]
  102. }