tc.c 15 KB

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