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