tc.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  4. *
  5. * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
  6. *
  7. * Bernhard Reutner-Fischer adjusted for busybox
  8. */
  9. //usage:#define tc_trivial_usage
  10. /* //usage: "[OPTIONS] OBJECT CMD [dev STRING]" */
  11. //usage: "OBJECT CMD [dev STRING]"
  12. //usage:#define tc_full_usage "\n\n"
  13. //usage: "OBJECT: {qdisc|class|filter}\n"
  14. //usage: "CMD: {add|del|change|replace|show}\n"
  15. //usage: "\n"
  16. //usage: "qdisc [ handle QHANDLE ] [ root |"IF_FEATURE_TC_INGRESS(" ingress |")" parent CLASSID ]\n"
  17. /* //usage: "[ estimator INTERVAL TIME_CONSTANT ]\n" */
  18. //usage: " [ [ QDISC_KIND ] [ help | OPTIONS ] ]\n"
  19. //usage: " QDISC_KIND := { [p|b]fifo | tbf | prio | cbq | red | etc. }\n"
  20. //usage: "qdisc show [ dev STRING ]"IF_FEATURE_TC_INGRESS(" [ingress]")"\n"
  21. //usage: "class [ classid CLASSID ] [ root | parent CLASSID ]\n"
  22. //usage: " [ [ QDISC_KIND ] [ help | OPTIONS ] ]\n"
  23. //usage: "class show [ dev STRING ] [ root | parent CLASSID ]\n"
  24. //usage: "filter [ pref PRIO ] [ protocol PROTO ]\n"
  25. /* //usage: "\t[ estimator INTERVAL TIME_CONSTANT ]\n" */
  26. //usage: " [ root | classid CLASSID ] [ handle FILTERID ]\n"
  27. //usage: " [ [ FILTER_TYPE ] [ help | OPTIONS ] ]\n"
  28. //usage: "filter show [ dev STRING ] [ root | parent CLASSID ]"
  29. #include "libbb.h"
  30. #include "libiproute/utils.h"
  31. #include "libiproute/ip_common.h"
  32. #include "libiproute/rt_names.h"
  33. #include <linux/pkt_sched.h> /* for the TC_H_* macros */
  34. #define parse_rtattr_nested(tb, max, rta) \
  35. (parse_rtattr((tb), (max), RTA_DATA(rta), RTA_PAYLOAD(rta)))
  36. /* nullifies tb on error */
  37. #define __parse_rtattr_nested_compat(tb, max, rta, len) \
  38. ({if ((RTA_PAYLOAD(rta) >= len) && \
  39. (RTA_PAYLOAD(rta) >= RTA_ALIGN(len) + sizeof(struct rtattr))) { \
  40. rta = RTA_DATA(rta) + RTA_ALIGN(len); \
  41. parse_rtattr_nested(tb, max, rta); \
  42. } else \
  43. memset(tb, 0, sizeof(struct rtattr *) * (max + 1)); \
  44. })
  45. #define parse_rtattr_nested_compat(tb, max, rta, data, len) \
  46. ({data = RTA_PAYLOAD(rta) >= len ? RTA_DATA(rta) : NULL; \
  47. __parse_rtattr_nested_compat(tb, max, rta, len); })
  48. #define show_details (0) /* not implemented. Does anyone need it? */
  49. #define use_iec (0) /* not currently documented in the upstream manpage */
  50. struct globals {
  51. int filter_ifindex;
  52. uint32_t filter_qdisc;
  53. uint32_t filter_parent;
  54. uint32_t filter_prio;
  55. uint32_t filter_proto;
  56. } FIX_ALIASING;
  57. #define G (*(struct globals*)&bb_common_bufsiz1)
  58. #define filter_ifindex (G.filter_ifindex)
  59. #define filter_qdisc (G.filter_qdisc)
  60. #define filter_parent (G.filter_parent)
  61. #define filter_prio (G.filter_prio)
  62. #define filter_proto (G.filter_proto)
  63. #define INIT_G() do { \
  64. BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
  65. } while (0)
  66. /* Allocates a buffer containing the name of a class id.
  67. * The caller must free the returned memory. */
  68. static char* print_tc_classid(uint32_t cid)
  69. {
  70. #if 0 /* IMPOSSIBLE */
  71. if (cid == TC_H_ROOT)
  72. return xasprintf("root");
  73. else
  74. #endif
  75. if (cid == TC_H_UNSPEC)
  76. return xasprintf("none");
  77. else if (TC_H_MAJ(cid) == 0)
  78. return xasprintf(":%x", TC_H_MIN(cid));
  79. else if (TC_H_MIN(cid) == 0)
  80. return xasprintf("%x:", TC_H_MAJ(cid)>>16);
  81. else
  82. return xasprintf("%x:%x", TC_H_MAJ(cid)>>16, TC_H_MIN(cid));
  83. }
  84. /* Get a qdisc handle. Return 0 on success, !0 otherwise. */
  85. static int get_qdisc_handle(uint32_t *h, const char *str) {
  86. uint32_t maj;
  87. char *p;
  88. maj = TC_H_UNSPEC;
  89. if (!strcmp(str, "none"))
  90. goto ok;
  91. maj = strtoul(str, &p, 16);
  92. if (p == str)
  93. return 1;
  94. maj <<= 16;
  95. if (*p != ':' && *p != '\0')
  96. return 1;
  97. ok:
  98. *h = maj;
  99. return 0;
  100. }
  101. /* Get class ID. Return 0 on success, !0 otherwise. */
  102. static int get_tc_classid(uint32_t *h, const char *str) {
  103. uint32_t maj, min;
  104. char *p;
  105. maj = TC_H_ROOT;
  106. if (!strcmp(str, "root"))
  107. goto ok;
  108. maj = TC_H_UNSPEC;
  109. if (!strcmp(str, "none"))
  110. goto ok;
  111. maj = strtoul(str, &p, 16);
  112. if (p == str) {
  113. if (*p != ':')
  114. return 1;
  115. maj = 0;
  116. }
  117. if (*p == ':') {
  118. if (maj >= (1<<16))
  119. return 1;
  120. maj <<= 16;
  121. str = p + 1;
  122. min = strtoul(str, &p, 16);
  123. //FIXME: check for "" too?
  124. if (*p != '\0' || min >= (1<<16))
  125. return 1;
  126. maj |= min;
  127. } else if (*p != 0)
  128. return 1;
  129. ok:
  130. *h = maj;
  131. return 0;
  132. }
  133. static void print_rate(char *buf, int len, uint32_t rate)
  134. {
  135. double tmp = (double)rate*8;
  136. if (use_iec) {
  137. if (tmp >= 1000*1024*1024)
  138. snprintf(buf, len, "%.0fMibit", tmp/(1024*1024));
  139. else if (tmp >= 1000*1024)
  140. snprintf(buf, len, "%.0fKibit", tmp/1024);
  141. else
  142. snprintf(buf, len, "%.0fbit", tmp);
  143. } else {
  144. if (tmp >= 1000*1000000)
  145. snprintf(buf, len, "%.0fMbit", tmp/1000000);
  146. else if (tmp >= 1000*1000)
  147. snprintf(buf, len, "%.0fKbit", tmp/1000);
  148. else
  149. snprintf(buf, len, "%.0fbit", tmp);
  150. }
  151. }
  152. /* This is "pfifo_fast". */
  153. static int prio_parse_opt(int argc, char **argv, struct nlmsghdr *n)
  154. {
  155. return 0;
  156. }
  157. static int prio_print_opt(struct rtattr *opt)
  158. {
  159. int i;
  160. struct tc_prio_qopt *qopt;
  161. struct rtattr *tb[TCA_PRIO_MAX+1];
  162. if (opt == NULL)
  163. return 0;
  164. parse_rtattr_nested_compat(tb, TCA_PRIO_MAX, opt, qopt, sizeof(*qopt));
  165. if (tb == NULL)
  166. return 0;
  167. printf("bands %u priomap ", qopt->bands);
  168. for (i=0; i<=TC_PRIO_MAX; i++)
  169. printf(" %d", qopt->priomap[i]);
  170. if (tb[TCA_PRIO_MQ])
  171. printf(" multiqueue: o%s ",
  172. *(unsigned char *)RTA_DATA(tb[TCA_PRIO_MQ]) ? "n" : "ff");
  173. return 0;
  174. }
  175. /* Class Based Queue */
  176. static int cbq_parse_opt(int argc, char **argv, struct nlmsghdr *n)
  177. {
  178. return 0;
  179. }
  180. static int cbq_print_opt(struct rtattr *opt)
  181. {
  182. struct rtattr *tb[TCA_CBQ_MAX+1];
  183. struct tc_ratespec *r = NULL;
  184. struct tc_cbq_lssopt *lss = NULL;
  185. struct tc_cbq_wrropt *wrr = NULL;
  186. struct tc_cbq_fopt *fopt = NULL;
  187. struct tc_cbq_ovl *ovl = NULL;
  188. const char *const error = "CBQ: too short %s opt";
  189. char buf[64];
  190. if (opt == NULL)
  191. goto done;
  192. parse_rtattr_nested(tb, TCA_CBQ_MAX, opt);
  193. if (tb[TCA_CBQ_RATE]) {
  194. if (RTA_PAYLOAD(tb[TCA_CBQ_RATE]) < sizeof(*r))
  195. bb_error_msg(error, "rate");
  196. else
  197. r = RTA_DATA(tb[TCA_CBQ_RATE]);
  198. }
  199. if (tb[TCA_CBQ_LSSOPT]) {
  200. if (RTA_PAYLOAD(tb[TCA_CBQ_LSSOPT]) < sizeof(*lss))
  201. bb_error_msg(error, "lss");
  202. else
  203. lss = RTA_DATA(tb[TCA_CBQ_LSSOPT]);
  204. }
  205. if (tb[TCA_CBQ_WRROPT]) {
  206. if (RTA_PAYLOAD(tb[TCA_CBQ_WRROPT]) < sizeof(*wrr))
  207. bb_error_msg(error, "wrr");
  208. else
  209. wrr = RTA_DATA(tb[TCA_CBQ_WRROPT]);
  210. }
  211. if (tb[TCA_CBQ_FOPT]) {
  212. if (RTA_PAYLOAD(tb[TCA_CBQ_FOPT]) < sizeof(*fopt))
  213. bb_error_msg(error, "fopt");
  214. else
  215. fopt = RTA_DATA(tb[TCA_CBQ_FOPT]);
  216. }
  217. if (tb[TCA_CBQ_OVL_STRATEGY]) {
  218. if (RTA_PAYLOAD(tb[TCA_CBQ_OVL_STRATEGY]) < sizeof(*ovl))
  219. bb_error_msg("CBQ: too short overlimit strategy %u/%u",
  220. (unsigned) RTA_PAYLOAD(tb[TCA_CBQ_OVL_STRATEGY]),
  221. (unsigned) sizeof(*ovl));
  222. else
  223. ovl = RTA_DATA(tb[TCA_CBQ_OVL_STRATEGY]);
  224. }
  225. if (r) {
  226. print_rate(buf, sizeof(buf), r->rate);
  227. printf("rate %s ", buf);
  228. if (show_details) {
  229. printf("cell %ub ", 1<<r->cell_log);
  230. if (r->mpu)
  231. printf("mpu %ub ", r->mpu);
  232. if (r->overhead)
  233. printf("overhead %ub ", r->overhead);
  234. }
  235. }
  236. if (lss && lss->flags) {
  237. bool comma = false;
  238. bb_putchar('(');
  239. if (lss->flags&TCF_CBQ_LSS_BOUNDED) {
  240. printf("bounded");
  241. comma = true;
  242. }
  243. if (lss->flags&TCF_CBQ_LSS_ISOLATED) {
  244. if (comma)
  245. bb_putchar(',');
  246. printf("isolated");
  247. }
  248. printf(") ");
  249. }
  250. if (wrr) {
  251. if (wrr->priority != TC_CBQ_MAXPRIO)
  252. printf("prio %u", wrr->priority);
  253. else
  254. printf("prio no-transmit");
  255. if (show_details) {
  256. printf("/%u ", wrr->cpriority);
  257. if (wrr->weight != 1) {
  258. print_rate(buf, sizeof(buf), wrr->weight);
  259. printf("weight %s ", buf);
  260. }
  261. if (wrr->allot)
  262. printf("allot %ub ", wrr->allot);
  263. }
  264. }
  265. done:
  266. return 0;
  267. }
  268. static int print_qdisc(const struct sockaddr_nl *who UNUSED_PARAM,
  269. struct nlmsghdr *hdr, void *arg UNUSED_PARAM)
  270. {
  271. struct tcmsg *msg = NLMSG_DATA(hdr);
  272. int len = hdr->nlmsg_len;
  273. struct rtattr * tb[TCA_MAX+1];
  274. char *name;
  275. if (hdr->nlmsg_type != RTM_NEWQDISC && hdr->nlmsg_type != RTM_DELQDISC) {
  276. /* bb_error_msg("not a qdisc"); */
  277. return 0; /* ??? mimic upstream; should perhaps return -1 */
  278. }
  279. len -= NLMSG_LENGTH(sizeof(*msg));
  280. if (len < 0) {
  281. /* bb_error_msg("wrong len %d", len); */
  282. return -1;
  283. }
  284. /* not the desired interface? */
  285. if (filter_ifindex && filter_ifindex != msg->tcm_ifindex)
  286. return 0;
  287. memset (tb, 0, sizeof(tb));
  288. parse_rtattr(tb, TCA_MAX, TCA_RTA(msg), len);
  289. if (tb[TCA_KIND] == NULL) {
  290. /* bb_error_msg("%s: NULL kind", "qdisc"); */
  291. return -1;
  292. }
  293. if (hdr->nlmsg_type == RTM_DELQDISC)
  294. printf("deleted ");
  295. name = (char*)RTA_DATA(tb[TCA_KIND]);
  296. printf("qdisc %s %x: ", name, msg->tcm_handle>>16);
  297. if (filter_ifindex == 0)
  298. printf("dev %s ", ll_index_to_name(msg->tcm_ifindex));
  299. if (msg->tcm_parent == TC_H_ROOT)
  300. printf("root ");
  301. else if (msg->tcm_parent) {
  302. char *classid = print_tc_classid(msg->tcm_parent);
  303. printf("parent %s ", classid);
  304. if (ENABLE_FEATURE_CLEAN_UP)
  305. free(classid);
  306. }
  307. if (msg->tcm_info != 1)
  308. printf("refcnt %d ", msg->tcm_info);
  309. if (tb[TCA_OPTIONS]) {
  310. static const char _q_[] ALIGN1 = "pfifo_fast\0""cbq\0";
  311. int qqq = index_in_strings(_q_, name);
  312. if (qqq == 0) { /* pfifo_fast aka prio */
  313. prio_print_opt(tb[TCA_OPTIONS]);
  314. } else if (qqq == 1) { /* class based queuing */
  315. cbq_print_opt(tb[TCA_OPTIONS]);
  316. } else
  317. bb_error_msg("unknown %s", name);
  318. }
  319. bb_putchar('\n');
  320. return 0;
  321. }
  322. static int print_class(const struct sockaddr_nl *who UNUSED_PARAM,
  323. struct nlmsghdr *hdr, void *arg UNUSED_PARAM)
  324. {
  325. struct tcmsg *msg = NLMSG_DATA(hdr);
  326. int len = hdr->nlmsg_len;
  327. struct rtattr * tb[TCA_MAX+1];
  328. char *name, *classid;
  329. /*XXX Eventually factor out common code */
  330. if (hdr->nlmsg_type != RTM_NEWTCLASS && hdr->nlmsg_type != RTM_DELTCLASS) {
  331. /* bb_error_msg("not a class"); */
  332. return 0; /* ??? mimic upstream; should perhaps return -1 */
  333. }
  334. len -= NLMSG_LENGTH(sizeof(*msg));
  335. if (len < 0) {
  336. /* bb_error_msg("wrong len %d", len); */
  337. return -1;
  338. }
  339. /* not the desired interface? */
  340. if (filter_qdisc && TC_H_MAJ(msg->tcm_handle^filter_qdisc))
  341. return 0;
  342. memset (tb, 0, sizeof(tb));
  343. parse_rtattr(tb, TCA_MAX, TCA_RTA(msg), len);
  344. if (tb[TCA_KIND] == NULL) {
  345. /* bb_error_msg("%s: NULL kind", "class"); */
  346. return -1;
  347. }
  348. if (hdr->nlmsg_type == RTM_DELTCLASS)
  349. printf("deleted ");
  350. name = (char*)RTA_DATA(tb[TCA_KIND]);
  351. classid = !msg->tcm_handle ? NULL : print_tc_classid(
  352. filter_qdisc ? TC_H_MIN(msg->tcm_parent) : msg->tcm_parent);
  353. printf ("class %s %s", name, classid);
  354. if (ENABLE_FEATURE_CLEAN_UP)
  355. free(classid);
  356. if (filter_ifindex == 0)
  357. printf("dev %s ", ll_index_to_name(msg->tcm_ifindex));
  358. if (msg->tcm_parent == TC_H_ROOT)
  359. printf("root ");
  360. else if (msg->tcm_parent) {
  361. classid = print_tc_classid(filter_qdisc ?
  362. TC_H_MIN(msg->tcm_parent) : msg->tcm_parent);
  363. printf("parent %s ", classid);
  364. if (ENABLE_FEATURE_CLEAN_UP)
  365. free(classid);
  366. }
  367. if (msg->tcm_info)
  368. printf("leaf %x ", msg->tcm_info >> 16);
  369. /* Do that get_qdisc_kind(RTA_DATA(tb[TCA_KIND])). */
  370. if (tb[TCA_OPTIONS]) {
  371. static const char _q_[] ALIGN1 = "pfifo_fast\0""cbq\0";
  372. int qqq = index_in_strings(_q_, name);
  373. if (qqq == 0) { /* pfifo_fast aka prio */
  374. /* nothing. */ /*prio_print_opt(tb[TCA_OPTIONS]);*/
  375. } else if (qqq == 1) { /* class based queuing */
  376. /* cbq_print_copt() is identical to cbq_print_opt(). */
  377. cbq_print_opt(tb[TCA_OPTIONS]);
  378. } else
  379. bb_error_msg("unknown %s", name);
  380. }
  381. bb_putchar('\n');
  382. return 0;
  383. }
  384. static int print_filter(const struct sockaddr_nl *who UNUSED_PARAM,
  385. struct nlmsghdr *hdr, void *arg UNUSED_PARAM)
  386. {
  387. return 0;
  388. }
  389. int tc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  390. int tc_main(int argc UNUSED_PARAM, char **argv)
  391. {
  392. static const char objects[] ALIGN1 =
  393. "qdisc\0""class\0""filter\0"
  394. ;
  395. enum { OBJ_qdisc = 0, OBJ_class, OBJ_filter };
  396. static const char commands[] ALIGN1 =
  397. "add\0""delete\0""change\0"
  398. "link\0" /* only qdisc */
  399. "replace\0"
  400. "show\0""list\0"
  401. ;
  402. static const char args[] ALIGN1 =
  403. "dev\0" /* qdisc, class, filter */
  404. "root\0" /* class, filter */
  405. "parent\0" /* class, filter */
  406. "qdisc\0" /* class */
  407. "handle\0" /* change: qdisc, class(classid) list: filter */
  408. "classid\0" /* change: for class use "handle" */
  409. "preference\0""priority\0""protocol\0" /* filter */
  410. ;
  411. enum { CMD_add = 0, CMD_del, CMD_change, CMD_link, CMD_replace, CMD_show };
  412. enum { ARG_dev = 0, ARG_root, ARG_parent, ARG_qdisc,
  413. ARG_handle, ARG_classid, ARG_pref, ARG_prio, ARG_proto};
  414. struct rtnl_handle rth;
  415. struct tcmsg msg;
  416. int ret, obj, cmd, arg;
  417. char *dev = NULL;
  418. INIT_G();
  419. if (!*++argv)
  420. bb_show_usage();
  421. xrtnl_open(&rth);
  422. ret = EXIT_SUCCESS;
  423. obj = index_in_substrings(objects, *argv++);
  424. if (obj < 0)
  425. bb_show_usage();
  426. if (!*argv)
  427. cmd = CMD_show; /* list is the default */
  428. else {
  429. cmd = index_in_substrings(commands, *argv);
  430. if (cmd < 0)
  431. invarg_1_to_2(*argv, argv[-1]);
  432. argv++;
  433. }
  434. memset(&msg, 0, sizeof(msg));
  435. msg.tcm_family = AF_UNSPEC;
  436. ll_init_map(&rth);
  437. while (*argv) {
  438. arg = index_in_substrings(args, *argv);
  439. if (arg == ARG_dev) {
  440. NEXT_ARG();
  441. if (dev)
  442. duparg2("dev", *argv);
  443. dev = *argv++;
  444. msg.tcm_ifindex = xll_name_to_index(dev);
  445. if (cmd >= CMD_show)
  446. filter_ifindex = msg.tcm_ifindex;
  447. } else
  448. if ((arg == ARG_qdisc && obj == OBJ_class && cmd >= CMD_show)
  449. || (arg == ARG_handle && obj == OBJ_qdisc && cmd == CMD_change)
  450. ) {
  451. NEXT_ARG();
  452. /* We don't care about duparg2("qdisc handle",*argv) for now */
  453. if (get_qdisc_handle(&filter_qdisc, *argv))
  454. invarg_1_to_2(*argv, "qdisc");
  455. } else
  456. if (obj != OBJ_qdisc
  457. && (arg == ARG_root
  458. || arg == ARG_parent
  459. || (obj == OBJ_filter && arg >= ARG_pref)
  460. )
  461. ) {
  462. /* nothing */
  463. } else {
  464. invarg_1_to_2(*argv, "command");
  465. }
  466. NEXT_ARG();
  467. if (arg == ARG_root) {
  468. if (msg.tcm_parent)
  469. duparg("parent", *argv);
  470. msg.tcm_parent = TC_H_ROOT;
  471. if (obj == OBJ_filter)
  472. filter_parent = TC_H_ROOT;
  473. } else if (arg == ARG_parent) {
  474. uint32_t handle;
  475. if (msg.tcm_parent)
  476. duparg(*argv, "parent");
  477. if (get_tc_classid(&handle, *argv))
  478. invarg_1_to_2(*argv, "parent");
  479. msg.tcm_parent = handle;
  480. if (obj == OBJ_filter)
  481. filter_parent = handle;
  482. } else if (arg == ARG_handle) { /* filter::list */
  483. if (msg.tcm_handle)
  484. duparg(*argv, "handle");
  485. /* reject LONG_MIN || LONG_MAX */
  486. /* TODO: for fw
  487. slash = strchr(handle, '/');
  488. if (slash != NULL)
  489. *slash = '\0';
  490. */
  491. msg.tcm_handle = get_u32(*argv, "handle");
  492. /* if (slash) {if (get_u32(uint32_t &mask, slash+1, NULL)) inv mask; addattr32(n, MAX_MSG, TCA_FW_MASK, mask); */
  493. } else if (arg == ARG_classid && obj == OBJ_class && cmd == CMD_change){
  494. } else if (arg == ARG_pref || arg == ARG_prio) { /* filter::list */
  495. if (filter_prio)
  496. duparg(*argv, "priority");
  497. filter_prio = get_u32(*argv, "priority");
  498. } else if (arg == ARG_proto) { /* filter::list */
  499. uint16_t tmp;
  500. if (filter_proto)
  501. duparg(*argv, "protocol");
  502. if (ll_proto_a2n(&tmp, *argv))
  503. invarg_1_to_2(*argv, "protocol");
  504. filter_proto = tmp;
  505. }
  506. }
  507. if (cmd >= CMD_show) { /* show or list */
  508. if (obj == OBJ_filter)
  509. msg.tcm_info = TC_H_MAKE(filter_prio<<16, filter_proto);
  510. if (rtnl_dump_request(&rth, obj == OBJ_qdisc ? RTM_GETQDISC :
  511. obj == OBJ_class ? RTM_GETTCLASS : RTM_GETTFILTER,
  512. &msg, sizeof(msg)) < 0)
  513. bb_simple_perror_msg_and_die("can't send dump request");
  514. xrtnl_dump_filter(&rth, obj == OBJ_qdisc ? print_qdisc :
  515. obj == OBJ_class ? print_class : print_filter,
  516. NULL);
  517. }
  518. if (ENABLE_FEATURE_CLEAN_UP) {
  519. rtnl_close(&rth);
  520. }
  521. return ret;
  522. }