3
0

tc.c 15 KB

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