libbpf: add support for passing classid for tc attached programs
Signed-off-by: Felix Fietkau <nbd@nbd.name>
This commit is contained in:
		
							
								
								
									
										54
									
								
								package/libs/libbpf/patches/100-bpf_tc_classid.patch
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								package/libs/libbpf/patches/100-bpf_tc_classid.patch
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,54 @@ | |||||||
|  | --- a/src/libbpf.h | ||||||
|  | +++ b/src/libbpf.h | ||||||
|  | @@ -1291,9 +1291,10 @@ struct bpf_tc_opts { | ||||||
|  |  	__u32 prog_id; | ||||||
|  |  	__u32 handle; | ||||||
|  |  	__u32 priority; | ||||||
|  | +	__u32 classid; | ||||||
|  |  	size_t :0; | ||||||
|  |  }; | ||||||
|  | -#define bpf_tc_opts__last_field priority | ||||||
|  | +#define bpf_tc_opts__last_field classid | ||||||
|  |   | ||||||
|  |  LIBBPF_API int bpf_tc_hook_create(struct bpf_tc_hook *hook); | ||||||
|  |  LIBBPF_API int bpf_tc_hook_destroy(struct bpf_tc_hook *hook); | ||||||
|  | --- a/src/netlink.c | ||||||
|  | +++ b/src/netlink.c | ||||||
|  | @@ -673,6 +673,8 @@ static int __get_tc_info(void *cookie, s | ||||||
|  |  	OPTS_SET(info->opts, prog_id, libbpf_nla_getattr_u32(tbb[TCA_BPF_ID])); | ||||||
|  |  	OPTS_SET(info->opts, handle, tc->tcm_handle); | ||||||
|  |  	OPTS_SET(info->opts, priority, TC_H_MAJ(tc->tcm_info) >> 16); | ||||||
|  | +	if (tbb[TCA_BPF_CLASSID]) | ||||||
|  | +		OPTS_SET(info->opts, classid, libbpf_nla_getattr_u32(tbb[TCA_BPF_CLASSID])); | ||||||
|  |   | ||||||
|  |  	info->processed = true; | ||||||
|  |  	return unicast ? NL_NEXT : NL_DONE; | ||||||
|  | @@ -717,7 +719,7 @@ static int tc_add_fd_and_name(struct lib | ||||||
|  |   | ||||||
|  |  int bpf_tc_attach(const struct bpf_tc_hook *hook, struct bpf_tc_opts *opts) | ||||||
|  |  { | ||||||
|  | -	__u32 protocol, bpf_flags, handle, priority, parent, prog_id, flags; | ||||||
|  | +	__u32 protocol, bpf_flags, handle, priority, parent, prog_id, flags, classid; | ||||||
|  |  	int ret, ifindex, attach_point, prog_fd; | ||||||
|  |  	struct bpf_cb_ctx info = {}; | ||||||
|  |  	struct libbpf_nla_req req; | ||||||
|  | @@ -737,6 +739,7 @@ int bpf_tc_attach(const struct bpf_tc_ho | ||||||
|  |  	prog_fd      = OPTS_GET(opts, prog_fd, 0); | ||||||
|  |  	prog_id      = OPTS_GET(opts, prog_id, 0); | ||||||
|  |  	flags        = OPTS_GET(opts, flags, 0); | ||||||
|  | +	classid      = OPTS_GET(opts, classid, 0); | ||||||
|  |   | ||||||
|  |  	if (ifindex <= 0 || !prog_fd || prog_id) | ||||||
|  |  		return libbpf_err(-EINVAL); | ||||||
|  | @@ -776,6 +779,11 @@ int bpf_tc_attach(const struct bpf_tc_ho | ||||||
|  |  	ret = nlattr_add(&req, TCA_BPF_FLAGS, &bpf_flags, sizeof(bpf_flags)); | ||||||
|  |  	if (ret < 0) | ||||||
|  |  		return libbpf_err(ret); | ||||||
|  | +	if (classid) { | ||||||
|  | +		ret = nlattr_add(&req, TCA_BPF_CLASSID, &classid, sizeof(classid)); | ||||||
|  | +		if (ret < 0) | ||||||
|  | +			return libbpf_err(ret); | ||||||
|  | +	} | ||||||
|  |  	nlattr_end_nested(&req, nla); | ||||||
|  |   | ||||||
|  |  	info.opts = opts; | ||||||
		Reference in New Issue
	
	Block a user
	 Felix Fietkau
					Felix Fietkau