100-bpf_tc_classid.patch 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. --- a/src/libbpf.h
  2. +++ b/src/libbpf.h
  3. @@ -1291,9 +1291,10 @@ struct bpf_tc_opts {
  4. __u32 prog_id;
  5. __u32 handle;
  6. __u32 priority;
  7. + __u32 classid;
  8. size_t :0;
  9. };
  10. -#define bpf_tc_opts__last_field priority
  11. +#define bpf_tc_opts__last_field classid
  12. LIBBPF_API int bpf_tc_hook_create(struct bpf_tc_hook *hook);
  13. LIBBPF_API int bpf_tc_hook_destroy(struct bpf_tc_hook *hook);
  14. --- a/src/netlink.c
  15. +++ b/src/netlink.c
  16. @@ -673,6 +673,8 @@ static int __get_tc_info(void *cookie, s
  17. OPTS_SET(info->opts, prog_id, libbpf_nla_getattr_u32(tbb[TCA_BPF_ID]));
  18. OPTS_SET(info->opts, handle, tc->tcm_handle);
  19. OPTS_SET(info->opts, priority, TC_H_MAJ(tc->tcm_info) >> 16);
  20. + if (tbb[TCA_BPF_CLASSID])
  21. + OPTS_SET(info->opts, classid, libbpf_nla_getattr_u32(tbb[TCA_BPF_CLASSID]));
  22. info->processed = true;
  23. return unicast ? NL_NEXT : NL_DONE;
  24. @@ -717,7 +719,7 @@ static int tc_add_fd_and_name(struct lib
  25. int bpf_tc_attach(const struct bpf_tc_hook *hook, struct bpf_tc_opts *opts)
  26. {
  27. - __u32 protocol, bpf_flags, handle, priority, parent, prog_id, flags;
  28. + __u32 protocol, bpf_flags, handle, priority, parent, prog_id, flags, classid;
  29. int ret, ifindex, attach_point, prog_fd;
  30. struct bpf_cb_ctx info = {};
  31. struct libbpf_nla_req req;
  32. @@ -737,6 +739,7 @@ int bpf_tc_attach(const struct bpf_tc_ho
  33. prog_fd = OPTS_GET(opts, prog_fd, 0);
  34. prog_id = OPTS_GET(opts, prog_id, 0);
  35. flags = OPTS_GET(opts, flags, 0);
  36. + classid = OPTS_GET(opts, classid, 0);
  37. if (ifindex <= 0 || !prog_fd || prog_id)
  38. return libbpf_err(-EINVAL);
  39. @@ -776,6 +779,11 @@ int bpf_tc_attach(const struct bpf_tc_ho
  40. ret = nlattr_add(&req, TCA_BPF_FLAGS, &bpf_flags, sizeof(bpf_flags));
  41. if (ret < 0)
  42. return libbpf_err(ret);
  43. + if (classid) {
  44. + ret = nlattr_add(&req, TCA_BPF_CLASSID, &classid, sizeof(classid));
  45. + if (ret < 0)
  46. + return libbpf_err(ret);
  47. + }
  48. nlattr_end_nested(&req, nla);
  49. info.opts = opts;