@@ -117,21 +117,25 @@ struct ctl_table_header;
117
117
118
118
/* ALU ops on immediates, bpf_add|sub|...: dst_reg += imm32 */
119
119
120
- #define BPF_ALU64_IMM (OP , DST , IMM ) \
120
+ #define BPF_ALU64_IMM_OFF (OP , DST , IMM , OFF ) \
121
121
((struct bpf_insn) { \
122
122
.code = BPF_ALU64 | BPF_OP(OP) | BPF_K, \
123
123
.dst_reg = DST, \
124
124
.src_reg = 0, \
125
- .off = 0 , \
125
+ .off = OFF , \
126
126
.imm = IMM })
127
+ #define BPF_ALU64_IMM (OP , DST , IMM ) \
128
+ BPF_ALU64_IMM_OFF(OP, DST, IMM, 0)
127
129
128
- #define BPF_ALU32_IMM (OP , DST , IMM ) \
130
+ #define BPF_ALU32_IMM_OFF (OP , DST , IMM , OFF ) \
129
131
((struct bpf_insn) { \
130
132
.code = BPF_ALU | BPF_OP(OP) | BPF_K, \
131
133
.dst_reg = DST, \
132
134
.src_reg = 0, \
133
- .off = 0 , \
135
+ .off = OFF , \
134
136
.imm = IMM })
137
+ #define BPF_ALU32_IMM (OP , DST , IMM ) \
138
+ BPF_ALU32_IMM_OFF(OP, DST, IMM, 0)
135
139
136
140
/* Endianess conversion, cpu_to_{l,b}e(), {l,b}e_to_cpu() */
137
141
@@ -143,6 +147,16 @@ struct ctl_table_header;
143
147
.off = 0, \
144
148
.imm = LEN })
145
149
150
+ /* Byte Swap, bswap16/32/64 */
151
+
152
+ #define BPF_BSWAP (DST , LEN ) \
153
+ ((struct bpf_insn) { \
154
+ .code = BPF_ALU64 | BPF_END | BPF_SRC(BPF_TO_LE), \
155
+ .dst_reg = DST, \
156
+ .src_reg = 0, \
157
+ .off = 0, \
158
+ .imm = LEN })
159
+
146
160
/* Short form of mov, dst_reg = src_reg */
147
161
148
162
#define BPF_MOV64_REG (DST , SRC ) \
@@ -179,6 +193,24 @@ struct ctl_table_header;
179
193
.off = 0, \
180
194
.imm = IMM })
181
195
196
+ /* Short form of movsx, dst_reg = (s8,s16,s32)src_reg */
197
+
198
+ #define BPF_MOVSX64_REG (DST , SRC , OFF ) \
199
+ ((struct bpf_insn) { \
200
+ .code = BPF_ALU64 | BPF_MOV | BPF_X, \
201
+ .dst_reg = DST, \
202
+ .src_reg = SRC, \
203
+ .off = OFF, \
204
+ .imm = 0 })
205
+
206
+ #define BPF_MOVSX32_REG (DST , SRC , OFF ) \
207
+ ((struct bpf_insn) { \
208
+ .code = BPF_ALU | BPF_MOV | BPF_X, \
209
+ .dst_reg = DST, \
210
+ .src_reg = SRC, \
211
+ .off = OFF, \
212
+ .imm = 0 })
213
+
182
214
/* Special form of mov32, used for doing explicit zero extension on dst. */
183
215
#define BPF_ZEXT_REG (DST ) \
184
216
((struct bpf_insn) { \
@@ -263,6 +295,16 @@ static inline bool insn_is_zext(const struct bpf_insn *insn)
263
295
.off = OFF, \
264
296
.imm = 0 })
265
297
298
+ /* Memory load, dst_reg = *(signed size *) (src_reg + off16) */
299
+
300
+ #define BPF_LDX_MEMSX (SIZE , DST , SRC , OFF ) \
301
+ ((struct bpf_insn) { \
302
+ .code = BPF_LDX | BPF_SIZE(SIZE) | BPF_MEMSX, \
303
+ .dst_reg = DST, \
304
+ .src_reg = SRC, \
305
+ .off = OFF, \
306
+ .imm = 0 })
307
+
266
308
/* Memory store, *(uint *) (dst_reg + off16) = src_reg */
267
309
268
310
#define BPF_STX_MEM (SIZE , DST , SRC , OFF ) \
0 commit comments