@@ -93,6 +93,7 @@ enum bpf_cmd {
93
93
BPF_PROG_GET_FD_BY_ID ,
94
94
BPF_MAP_GET_FD_BY_ID ,
95
95
BPF_OBJ_GET_INFO_BY_FD ,
96
+ BPF_PROG_QUERY ,
96
97
};
97
98
98
99
enum bpf_map_type {
@@ -144,11 +145,47 @@ enum bpf_attach_type {
144
145
145
146
#define MAX_BPF_ATTACH_TYPE __MAX_BPF_ATTACH_TYPE
146
147
147
- /* If BPF_F_ALLOW_OVERRIDE flag is used in BPF_PROG_ATTACH command
148
- * to the given target_fd cgroup the descendent cgroup will be able to
149
- * override effective bpf program that was inherited from this cgroup
148
+ /* cgroup-bpf attach flags used in BPF_PROG_ATTACH command
149
+ *
150
+ * NONE(default): No further bpf programs allowed in the subtree.
151
+ *
152
+ * BPF_F_ALLOW_OVERRIDE: If a sub-cgroup installs some bpf program,
153
+ * the program in this cgroup yields to sub-cgroup program.
154
+ *
155
+ * BPF_F_ALLOW_MULTI: If a sub-cgroup installs some bpf program,
156
+ * that cgroup program gets run in addition to the program in this cgroup.
157
+ *
158
+ * Only one program is allowed to be attached to a cgroup with
159
+ * NONE or BPF_F_ALLOW_OVERRIDE flag.
160
+ * Attaching another program on top of NONE or BPF_F_ALLOW_OVERRIDE will
161
+ * release old program and attach the new one. Attach flags has to match.
162
+ *
163
+ * Multiple programs are allowed to be attached to a cgroup with
164
+ * BPF_F_ALLOW_MULTI flag. They are executed in FIFO order
165
+ * (those that were attached first, run first)
166
+ * The programs of sub-cgroup are executed first, then programs of
167
+ * this cgroup and then programs of parent cgroup.
168
+ * When children program makes decision (like picking TCP CA or sock bind)
169
+ * parent program has a chance to override it.
170
+ *
171
+ * A cgroup with MULTI or OVERRIDE flag allows any attach flags in sub-cgroups.
172
+ * A cgroup with NONE doesn't allow any programs in sub-cgroups.
173
+ * Ex1:
174
+ * cgrp1 (MULTI progs A, B) ->
175
+ * cgrp2 (OVERRIDE prog C) ->
176
+ * cgrp3 (MULTI prog D) ->
177
+ * cgrp4 (OVERRIDE prog E) ->
178
+ * cgrp5 (NONE prog F)
179
+ * the event in cgrp5 triggers execution of F,D,A,B in that order.
180
+ * if prog F is detached, the execution is E,D,A,B
181
+ * if prog F and D are detached, the execution is E,A,B
182
+ * if prog F, E and D are detached, the execution is C,A,B
183
+ *
184
+ * All eligible programs are executed regardless of return code from
185
+ * earlier programs.
150
186
*/
151
187
#define BPF_F_ALLOW_OVERRIDE (1U << 0)
188
+ #define BPF_F_ALLOW_MULTI (1U << 1)
152
189
153
190
/* If BPF_F_STRICT_ALIGNMENT is used in BPF_PROG_LOAD command, the
154
191
* verifier will perform strict alignment checking as if the kernel
@@ -176,6 +213,11 @@ enum bpf_attach_type {
176
213
/* Specify numa node during map creation */
177
214
#define BPF_F_NUMA_NODE (1U << 2)
178
215
216
+ /* flags for BPF_PROG_QUERY */
217
+ #define BPF_F_QUERY_EFFECTIVE (1U << 0)
218
+
219
+ #define BPF_OBJ_NAME_LEN 16U
220
+
179
221
union bpf_attr {
180
222
struct { /* anonymous struct used by BPF_MAP_CREATE command */
181
223
__u32 map_type ; /* one of enum bpf_map_type */
@@ -253,6 +295,17 @@ union bpf_attr {
253
295
__u32 info_len ;
254
296
__aligned_u64 info ;
255
297
} info ;
298
+
299
+ #ifndef __GENKSYMS__
300
+ struct { /* anonymous struct used by BPF_PROG_QUERY command */
301
+ __u32 target_fd ; /* container object to query */
302
+ __u32 attach_type ;
303
+ __u32 query_flags ;
304
+ __u32 attach_flags ;
305
+ __aligned_u64 prog_ids ;
306
+ __u32 prog_cnt ;
307
+ } query ;
308
+ #endif
256
309
} __attribute__((aligned (8 )));
257
310
258
311
/* BPF helper function descriptions:
0 commit comments