tc.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <ynl.h>
  5. #include <net/if.h>
  6. #include "tc-user.h"
  7. static void tc_qdisc_print(struct tc_getqdisc_rsp *q)
  8. {
  9. char ifname[IF_NAMESIZE];
  10. const char *name;
  11. name = if_indextoname(q->_hdr.tcm_ifindex, ifname);
  12. if (name)
  13. printf("%16s: ", name);
  14. if (q->_len.kind) {
  15. printf("%s ", q->kind);
  16. if (q->options._present.fq_codel) {
  17. struct tc_fq_codel_attrs *fq_codel;
  18. struct tc_fq_codel_xstats *stats;
  19. fq_codel = &q->options.fq_codel;
  20. stats = q->stats2.app.fq_codel;
  21. if (fq_codel->_present.limit)
  22. printf("limit: %dp ", fq_codel->limit);
  23. if (fq_codel->_present.target)
  24. printf("target: %dms ",
  25. (fq_codel->target + 500) / 1000);
  26. if (q->stats2.app._len.fq_codel)
  27. printf("new_flow_cnt: %d ",
  28. stats->qdisc_stats.new_flow_count);
  29. }
  30. }
  31. printf("\n");
  32. }
  33. int main(int argc, char **argv)
  34. {
  35. struct tc_getqdisc_req_dump *req;
  36. struct tc_getqdisc_list *rsp;
  37. struct ynl_error yerr;
  38. struct ynl_sock *ys;
  39. ys = ynl_sock_create(&ynl_tc_family, &yerr);
  40. if (!ys) {
  41. fprintf(stderr, "YNL: %s\n", yerr.msg);
  42. return 1;
  43. }
  44. req = tc_getqdisc_req_dump_alloc();
  45. if (!req)
  46. goto err_destroy;
  47. rsp = tc_getqdisc_dump(ys, req);
  48. tc_getqdisc_req_dump_free(req);
  49. if (!rsp)
  50. goto err_close;
  51. if (ynl_dump_empty(rsp))
  52. fprintf(stderr, "Error: no addresses reported\n");
  53. ynl_dump_foreach(rsp, qdisc)
  54. tc_qdisc_print(qdisc);
  55. tc_getqdisc_list_free(rsp);
  56. ynl_sock_destroy(ys);
  57. return 0;
  58. err_close:
  59. fprintf(stderr, "YNL: %s\n", ys->err.msg);
  60. err_destroy:
  61. ynl_sock_destroy(ys);
  62. return 2;
  63. }