tc.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  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. printf("bands %u priomap ", qopt->bands);
  198. for (i=0; i<=TC_PRIO_MAX; i++)
  199. printf(" %d", qopt->priomap[i]);
  200. if (tb[TCA_PRIO_MQ])
  201. printf(" multiqueue: o%s ",
  202. *(unsigned char *)RTA_DATA(tb[TCA_PRIO_MQ]) ? "n" : "ff");
  203. return 0;
  204. }
  205. #if 0
  206. /* Class Based Queue */
  207. static int cbq_parse_opt(int argc, char **argv, struct nlmsghdr *n)
  208. {
  209. return 0;
  210. }
  211. #endif
  212. static int cbq_print_opt(struct rtattr *opt)
  213. {
  214. struct rtattr *tb[TCA_CBQ_MAX+1];
  215. struct tc_ratespec *r = NULL;
  216. struct tc_cbq_lssopt *lss = NULL;
  217. struct tc_cbq_wrropt *wrr = NULL;
  218. struct tc_cbq_fopt *fopt = NULL;
  219. struct tc_cbq_ovl *ovl = NULL;
  220. const char *const error = "CBQ: too short %s opt";
  221. char buf[64];
  222. if (opt == NULL)
  223. goto done;
  224. parse_rtattr_nested(tb, TCA_CBQ_MAX, opt);
  225. if (tb[TCA_CBQ_RATE]) {
  226. if (RTA_PAYLOAD(tb[TCA_CBQ_RATE]) < sizeof(*r))
  227. bb_error_msg(error, "rate");
  228. else
  229. r = RTA_DATA(tb[TCA_CBQ_RATE]);
  230. }
  231. if (tb[TCA_CBQ_LSSOPT]) {
  232. if (RTA_PAYLOAD(tb[TCA_CBQ_LSSOPT]) < sizeof(*lss))
  233. bb_error_msg(error, "lss");
  234. else
  235. lss = RTA_DATA(tb[TCA_CBQ_LSSOPT]);
  236. }
  237. if (tb[TCA_CBQ_WRROPT]) {
  238. if (RTA_PAYLOAD(tb[TCA_CBQ_WRROPT]) < sizeof(*wrr))
  239. bb_error_msg(error, "wrr");
  240. else
  241. wrr = RTA_DATA(tb[TCA_CBQ_WRROPT]);
  242. }
  243. if (tb[TCA_CBQ_FOPT]) {
  244. if (RTA_PAYLOAD(tb[TCA_CBQ_FOPT]) < sizeof(*fopt))
  245. bb_error_msg(error, "fopt");
  246. else
  247. fopt = RTA_DATA(tb[TCA_CBQ_FOPT]);
  248. }
  249. if (tb[TCA_CBQ_OVL_STRATEGY]) {
  250. if (RTA_PAYLOAD(tb[TCA_CBQ_OVL_STRATEGY]) < sizeof(*ovl))
  251. bb_error_msg("CBQ: too short overlimit strategy %u/%u",
  252. (unsigned) RTA_PAYLOAD(tb[TCA_CBQ_OVL_STRATEGY]),
  253. (unsigned) sizeof(*ovl));
  254. else
  255. ovl = RTA_DATA(tb[TCA_CBQ_OVL_STRATEGY]);
  256. }
  257. if (r) {
  258. print_rate(buf, sizeof(buf), r->rate);
  259. printf("rate %s ", buf);
  260. if (show_details) {
  261. printf("cell %ub ", 1<<r->cell_log);
  262. if (r->mpu)
  263. printf("mpu %ub ", r->mpu);
  264. if (r->overhead)
  265. printf("overhead %ub ", r->overhead);
  266. }
  267. }
  268. if (lss && lss->flags) {
  269. bool comma = false;
  270. bb_putchar('(');
  271. if (lss->flags&TCF_CBQ_LSS_BOUNDED) {
  272. printf("bounded");
  273. comma = true;
  274. }
  275. if (lss->flags&TCF_CBQ_LSS_ISOLATED) {
  276. if (comma)
  277. bb_putchar(',');
  278. printf("isolated");
  279. }
  280. printf(") ");
  281. }
  282. if (wrr) {
  283. if (wrr->priority != TC_CBQ_MAXPRIO)
  284. printf("prio %u", wrr->priority);
  285. else
  286. printf("prio no-transmit");
  287. if (show_details) {
  288. printf("/%u ", wrr->cpriority);
  289. if (wrr->weight != 1) {
  290. print_rate(buf, sizeof(buf), wrr->weight);
  291. printf("weight %s ", buf);
  292. }
  293. if (wrr->allot)
  294. printf("allot %ub ", wrr->allot);
  295. }
  296. }
  297. done:
  298. return 0;
  299. }
  300. static FAST_FUNC int print_qdisc(
  301. const struct sockaddr_nl *who UNUSED_PARAM,
  302. struct nlmsghdr *hdr,
  303. void *arg UNUSED_PARAM)
  304. {
  305. struct tcmsg *msg = NLMSG_DATA(hdr);
  306. int len = hdr->nlmsg_len;
  307. struct rtattr * tb[TCA_MAX+1];
  308. char *name;
  309. if (hdr->nlmsg_type != RTM_NEWQDISC && hdr->nlmsg_type != RTM_DELQDISC) {
  310. /* bb_error_msg("not a qdisc"); */
  311. return 0; /* ??? mimic upstream; should perhaps return -1 */
  312. }
  313. len -= NLMSG_LENGTH(sizeof(*msg));
  314. if (len < 0) {
  315. /* bb_error_msg("wrong len %d", len); */
  316. return -1;
  317. }
  318. /* not the desired interface? */
  319. if (filter_ifindex && filter_ifindex != msg->tcm_ifindex)
  320. return 0;
  321. memset (tb, 0, sizeof(tb));
  322. parse_rtattr(tb, TCA_MAX, TCA_RTA(msg), len);
  323. if (tb[TCA_KIND] == NULL) {
  324. /* bb_error_msg("%s: NULL kind", "qdisc"); */
  325. return -1;
  326. }
  327. if (hdr->nlmsg_type == RTM_DELQDISC)
  328. printf("deleted ");
  329. name = (char*)RTA_DATA(tb[TCA_KIND]);
  330. printf("qdisc %s %x: ", name, msg->tcm_handle>>16);
  331. if (filter_ifindex == 0)
  332. printf("dev %s ", ll_index_to_name(msg->tcm_ifindex));
  333. if (msg->tcm_parent == TC_H_ROOT)
  334. printf("root ");
  335. else if (msg->tcm_parent) {
  336. char *classid = print_tc_classid(msg->tcm_parent);
  337. printf("parent %s ", classid);
  338. if (ENABLE_FEATURE_CLEAN_UP)
  339. free(classid);
  340. }
  341. if (msg->tcm_info != 1)
  342. printf("refcnt %d ", msg->tcm_info);
  343. if (tb[TCA_OPTIONS]) {
  344. static const char _q_[] ALIGN1 = "pfifo_fast\0""cbq\0";
  345. int qqq = index_in_strings(_q_, name);
  346. if (qqq == 0) { /* pfifo_fast aka prio */
  347. prio_print_opt(tb[TCA_OPTIONS]);
  348. } else if (qqq == 1) { /* class based queuing */
  349. cbq_print_opt(tb[TCA_OPTIONS]);
  350. } else
  351. bb_error_msg("unknown %s", name);
  352. }
  353. bb_putchar('\n');
  354. return 0;
  355. }
  356. static FAST_FUNC int print_class(
  357. const struct sockaddr_nl *who UNUSED_PARAM,
  358. struct nlmsghdr *hdr,
  359. void *arg UNUSED_PARAM)
  360. {
  361. struct tcmsg *msg = NLMSG_DATA(hdr);
  362. int len = hdr->nlmsg_len;
  363. struct rtattr * tb[TCA_MAX+1];
  364. char *name, *classid;
  365. /*XXX Eventually factor out common code */
  366. if (hdr->nlmsg_type != RTM_NEWTCLASS && hdr->nlmsg_type != RTM_DELTCLASS) {
  367. /* bb_error_msg("not a class"); */
  368. return 0; /* ??? mimic upstream; should perhaps return -1 */
  369. }
  370. len -= NLMSG_LENGTH(sizeof(*msg));
  371. if (len < 0) {
  372. /* bb_error_msg("wrong len %d", len); */
  373. return -1;
  374. }
  375. /* not the desired interface? */
  376. if (filter_qdisc && TC_H_MAJ(msg->tcm_handle^filter_qdisc))
  377. return 0;
  378. memset (tb, 0, sizeof(tb));
  379. parse_rtattr(tb, TCA_MAX, TCA_RTA(msg), len);
  380. if (tb[TCA_KIND] == NULL) {
  381. /* bb_error_msg("%s: NULL kind", "class"); */
  382. return -1;
  383. }
  384. if (hdr->nlmsg_type == RTM_DELTCLASS)
  385. printf("deleted ");
  386. name = (char*)RTA_DATA(tb[TCA_KIND]);
  387. classid = !msg->tcm_handle ? NULL : print_tc_classid(
  388. filter_qdisc ? TC_H_MIN(msg->tcm_parent) : msg->tcm_parent);
  389. printf ("class %s %s", name, classid);
  390. if (ENABLE_FEATURE_CLEAN_UP)
  391. free(classid);
  392. if (filter_ifindex == 0)
  393. printf("dev %s ", ll_index_to_name(msg->tcm_ifindex));
  394. if (msg->tcm_parent == TC_H_ROOT)
  395. printf("root ");
  396. else if (msg->tcm_parent) {
  397. classid = print_tc_classid(filter_qdisc ?
  398. TC_H_MIN(msg->tcm_parent) : msg->tcm_parent);
  399. printf("parent %s ", classid);
  400. if (ENABLE_FEATURE_CLEAN_UP)
  401. free(classid);
  402. }
  403. if (msg->tcm_info)
  404. printf("leaf %x ", msg->tcm_info >> 16);
  405. /* Do that get_qdisc_kind(RTA_DATA(tb[TCA_KIND])). */
  406. if (tb[TCA_OPTIONS]) {
  407. static const char _q_[] ALIGN1 = "pfifo_fast\0""cbq\0";
  408. int qqq = index_in_strings(_q_, name);
  409. if (qqq == 0) { /* pfifo_fast aka prio */
  410. /* nothing. */ /*prio_print_opt(tb[TCA_OPTIONS]);*/
  411. } else if (qqq == 1) { /* class based queuing */
  412. /* cbq_print_copt() is identical to cbq_print_opt(). */
  413. cbq_print_opt(tb[TCA_OPTIONS]);
  414. } else
  415. bb_error_msg("unknown %s", name);
  416. }
  417. bb_putchar('\n');
  418. return 0;
  419. }
  420. static FAST_FUNC int print_filter(
  421. const struct sockaddr_nl *who UNUSED_PARAM,
  422. struct nlmsghdr *hdr UNUSED_PARAM,
  423. void *arg UNUSED_PARAM)
  424. {
  425. return 0;
  426. }
  427. int tc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  428. int tc_main(int argc UNUSED_PARAM, char **argv)
  429. {
  430. static const char objects[] ALIGN1 =
  431. "qdisc\0""class\0""filter\0"
  432. ;
  433. enum { OBJ_qdisc = 0, OBJ_class, OBJ_filter };
  434. static const char commands[] ALIGN1 =
  435. "add\0""delete\0""change\0"
  436. "link\0" /* only qdisc */
  437. "replace\0"
  438. "show\0""list\0"
  439. ;
  440. enum {
  441. CMD_add = 0, CMD_del, CMD_change,
  442. CMD_link,
  443. CMD_replace,
  444. CMD_show
  445. };
  446. static const char args[] ALIGN1 =
  447. "dev\0" /* qdisc, class, filter */
  448. "root\0" /* class, filter */
  449. "parent\0" /* class, filter */
  450. "qdisc\0" /* class */
  451. "handle\0" /* change: qdisc, class(classid) list: filter */
  452. "classid\0" /* change: for class use "handle" */
  453. "preference\0""priority\0""protocol\0" /* filter */
  454. ;
  455. enum {
  456. ARG_dev = 0,
  457. ARG_root,
  458. ARG_parent,
  459. ARG_qdisc,
  460. ARG_handle,
  461. ARG_classid,
  462. ARG_pref, ARG_prio, ARG_proto
  463. };
  464. struct rtnl_handle rth;
  465. struct tcmsg msg;
  466. int ret, obj, cmd, arg;
  467. char *dev = NULL;
  468. INIT_G();
  469. if (!*++argv)
  470. bb_show_usage();
  471. xrtnl_open(&rth);
  472. ret = EXIT_SUCCESS;
  473. obj = index_in_substrings(objects, *argv++);
  474. if (obj < 0)
  475. bb_show_usage();
  476. if (!*argv)
  477. cmd = CMD_show; /* list is the default */
  478. else {
  479. cmd = index_in_substrings(commands, *argv);
  480. if (cmd < 0)
  481. invarg_1_to_2(*argv, argv[-1]);
  482. argv++;
  483. }
  484. memset(&msg, 0, sizeof(msg));
  485. if (AF_UNSPEC != 0)
  486. msg.tcm_family = AF_UNSPEC;
  487. ll_init_map(&rth);
  488. while (*argv) {
  489. arg = index_in_substrings(args, *argv);
  490. if (arg == ARG_dev) {
  491. NEXT_ARG();
  492. if (dev)
  493. duparg2("dev", *argv);
  494. dev = *argv++;
  495. msg.tcm_ifindex = xll_name_to_index(dev);
  496. if (cmd >= CMD_show)
  497. filter_ifindex = msg.tcm_ifindex;
  498. } else
  499. if ((arg == ARG_qdisc && obj == OBJ_class && cmd >= CMD_show)
  500. || (arg == ARG_handle && obj == OBJ_qdisc && cmd == CMD_change)
  501. ) {
  502. NEXT_ARG();
  503. /* We don't care about duparg2("qdisc handle",*argv) for now */
  504. if (get_qdisc_handle(&filter_qdisc, *argv))
  505. invarg_1_to_2(*argv, "qdisc");
  506. } else
  507. if (obj != OBJ_qdisc
  508. && (arg == ARG_root
  509. || arg == ARG_parent
  510. || (obj == OBJ_filter && arg >= ARG_pref)
  511. )
  512. ) {
  513. /* nothing */
  514. } else {
  515. invarg_1_to_2(*argv, "command");
  516. }
  517. NEXT_ARG();
  518. if (arg == ARG_root) {
  519. if (msg.tcm_parent)
  520. duparg("parent", *argv);
  521. msg.tcm_parent = TC_H_ROOT;
  522. if (obj == OBJ_filter)
  523. filter_parent = TC_H_ROOT;
  524. } else
  525. if (arg == ARG_parent) {
  526. uint32_t handle;
  527. if (msg.tcm_parent)
  528. duparg(*argv, "parent");
  529. if (get_tc_classid(&handle, *argv))
  530. invarg_1_to_2(*argv, "parent");
  531. msg.tcm_parent = handle;
  532. if (obj == OBJ_filter)
  533. filter_parent = handle;
  534. } else
  535. if (arg == ARG_handle) { /* filter::list */
  536. if (msg.tcm_handle)
  537. duparg(*argv, "handle");
  538. /* reject LONG_MIN || LONG_MAX */
  539. /* TODO: for fw
  540. slash = strchr(handle, '/');
  541. if (slash != NULL)
  542. *slash = '\0';
  543. */
  544. msg.tcm_handle = get_u32(*argv, "handle");
  545. /* if (slash) {if (get_u32(uint32_t &mask, slash+1, NULL)) inv mask; addattr32(n, MAX_MSG, TCA_FW_MASK, mask); */
  546. } else
  547. if (arg == ARG_classid
  548. && obj == OBJ_class
  549. && cmd == CMD_change
  550. ) {
  551. /* TODO */
  552. } else
  553. if (arg == ARG_pref || arg == ARG_prio) { /* filter::list */
  554. if (filter_prio)
  555. duparg(*argv, "priority");
  556. filter_prio = get_u32(*argv, "priority");
  557. } else
  558. if (arg == ARG_proto) { /* filter::list */
  559. uint16_t tmp;
  560. if (filter_proto)
  561. duparg(*argv, "protocol");
  562. if (ll_proto_a2n(&tmp, *argv))
  563. invarg_1_to_2(*argv, "protocol");
  564. filter_proto = tmp;
  565. }
  566. }
  567. if (cmd >= CMD_show) { /* show or list */
  568. if (obj == OBJ_filter)
  569. msg.tcm_info = TC_H_MAKE(filter_prio<<16, filter_proto);
  570. if (rtnl_dump_request(&rth, obj == OBJ_qdisc ? RTM_GETQDISC :
  571. obj == OBJ_class ? RTM_GETTCLASS : RTM_GETTFILTER,
  572. &msg, sizeof(msg)) < 0)
  573. bb_simple_perror_msg_and_die("can't send dump request");
  574. xrtnl_dump_filter(&rth, obj == OBJ_qdisc ? print_qdisc :
  575. obj == OBJ_class ? print_class : print_filter,
  576. NULL);
  577. }
  578. if (ENABLE_FEATURE_CLEAN_UP) {
  579. rtnl_close(&rth);
  580. }
  581. return ret;
  582. }