tc.c 16 KB

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