3
0

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. #endif
  102. if (cid == TC_H_UNSPEC)
  103. return xasprintf("none");
  104. if (TC_H_MAJ(cid) == 0)
  105. return xasprintf(":%x", TC_H_MIN(cid));
  106. if (TC_H_MIN(cid) == 0)
  107. return xasprintf("%x:", TC_H_MAJ(cid)>>16);
  108. return xasprintf("%x:%x", TC_H_MAJ(cid)>>16, TC_H_MIN(cid));
  109. }
  110. /* Get a qdisc handle. Return 0 on success, !0 otherwise. */
  111. static int get_qdisc_handle(uint32_t *h, const char *str)
  112. {
  113. uint32_t maj;
  114. char *p;
  115. maj = TC_H_UNSPEC;
  116. if (strcmp(str, "none") == 0)
  117. goto ok;
  118. maj = strtoul(str, &p, 16);
  119. if (p == str)
  120. return 1;
  121. maj <<= 16;
  122. if (*p != ':' && *p != '\0')
  123. return 1;
  124. ok:
  125. *h = maj;
  126. return 0;
  127. }
  128. /* Get class ID. Return 0 on success, !0 otherwise. */
  129. static int get_tc_classid(uint32_t *h, const char *str)
  130. {
  131. uint32_t maj, min;
  132. char *p;
  133. maj = TC_H_ROOT;
  134. if (strcmp(str, "root") == 0)
  135. goto ok;
  136. maj = TC_H_UNSPEC;
  137. if (strcmp(str, "none") == 0)
  138. goto ok;
  139. maj = strtoul(str, &p, 16);
  140. if (p == str) {
  141. if (*p != ':')
  142. return 1;
  143. maj = 0;
  144. }
  145. if (*p == ':') {
  146. if (maj >= (1<<16))
  147. return 1;
  148. maj <<= 16;
  149. str = p + 1;
  150. min = strtoul(str, &p, 16);
  151. //FIXME: check for "" too?
  152. if (*p != '\0' || min >= (1<<16))
  153. return 1;
  154. maj |= min;
  155. } else if (*p != 0)
  156. return 1;
  157. ok:
  158. *h = maj;
  159. return 0;
  160. }
  161. static void print_rate(char *buf, int len, uint32_t rate)
  162. {
  163. double tmp = (double)rate*8;
  164. if (use_iec) {
  165. if (tmp >= 1000*1024*1024)
  166. snprintf(buf, len, "%.0fMibit", tmp/(1024*1024));
  167. else if (tmp >= 1000*1024)
  168. snprintf(buf, len, "%.0fKibit", tmp/1024);
  169. else
  170. snprintf(buf, len, "%.0fbit", tmp);
  171. } else {
  172. if (tmp >= 1000*1000000)
  173. snprintf(buf, len, "%.0fMbit", tmp/1000000);
  174. else if (tmp >= 1000*1000)
  175. snprintf(buf, len, "%.0fKbit", tmp/1000);
  176. else
  177. snprintf(buf, len, "%.0fbit", tmp);
  178. }
  179. }
  180. #if 0
  181. /* This is "pfifo_fast". */
  182. static int prio_parse_opt(int argc, char **argv, struct nlmsghdr *n)
  183. {
  184. return 0;
  185. }
  186. #endif
  187. static int prio_print_opt(struct rtattr *opt)
  188. {
  189. int i;
  190. struct tc_prio_qopt *qopt;
  191. struct rtattr *tb[TCA_PRIO_MAX+1];
  192. if (opt == NULL)
  193. return 0;
  194. parse_rtattr_nested_compat(tb, TCA_PRIO_MAX, opt, qopt, sizeof(*qopt));
  195. printf("bands %u priomap ", qopt->bands);
  196. for (i = 0; i <= TC_PRIO_MAX; i++)
  197. printf(" %d", qopt->priomap[i]);
  198. if (tb[TCA_PRIO_MQ])
  199. printf(" multiqueue: o%s ",
  200. *(unsigned char *)RTA_DATA(tb[TCA_PRIO_MQ]) ? "n" : "ff");
  201. return 0;
  202. }
  203. #if 0
  204. /* Class Based Queue */
  205. static int cbq_parse_opt(int argc, char **argv, struct nlmsghdr *n)
  206. {
  207. return 0;
  208. }
  209. #endif
  210. static int cbq_print_opt(struct rtattr *opt)
  211. {
  212. struct rtattr *tb[TCA_CBQ_MAX+1];
  213. struct tc_ratespec *r = NULL;
  214. struct tc_cbq_lssopt *lss = NULL;
  215. struct tc_cbq_wrropt *wrr = NULL;
  216. struct tc_cbq_fopt *fopt = NULL;
  217. struct tc_cbq_ovl *ovl = NULL;
  218. const char *const error = "CBQ: too short %s opt";
  219. char buf[64];
  220. if (opt == NULL)
  221. goto done;
  222. parse_rtattr_nested(tb, TCA_CBQ_MAX, opt);
  223. if (tb[TCA_CBQ_RATE]) {
  224. if (RTA_PAYLOAD(tb[TCA_CBQ_RATE]) < sizeof(*r))
  225. bb_error_msg(error, "rate");
  226. else
  227. r = RTA_DATA(tb[TCA_CBQ_RATE]);
  228. }
  229. if (tb[TCA_CBQ_LSSOPT]) {
  230. if (RTA_PAYLOAD(tb[TCA_CBQ_LSSOPT]) < sizeof(*lss))
  231. bb_error_msg(error, "lss");
  232. else
  233. lss = RTA_DATA(tb[TCA_CBQ_LSSOPT]);
  234. }
  235. if (tb[TCA_CBQ_WRROPT]) {
  236. if (RTA_PAYLOAD(tb[TCA_CBQ_WRROPT]) < sizeof(*wrr))
  237. bb_error_msg(error, "wrr");
  238. else
  239. wrr = RTA_DATA(tb[TCA_CBQ_WRROPT]);
  240. }
  241. if (tb[TCA_CBQ_FOPT]) {
  242. if (RTA_PAYLOAD(tb[TCA_CBQ_FOPT]) < sizeof(*fopt))
  243. bb_error_msg(error, "fopt");
  244. else
  245. fopt = RTA_DATA(tb[TCA_CBQ_FOPT]);
  246. }
  247. if (tb[TCA_CBQ_OVL_STRATEGY]) {
  248. if (RTA_PAYLOAD(tb[TCA_CBQ_OVL_STRATEGY]) < sizeof(*ovl))
  249. bb_error_msg("CBQ: too short overlimit strategy %u/%u",
  250. (unsigned) RTA_PAYLOAD(tb[TCA_CBQ_OVL_STRATEGY]),
  251. (unsigned) sizeof(*ovl));
  252. else
  253. ovl = RTA_DATA(tb[TCA_CBQ_OVL_STRATEGY]);
  254. }
  255. if (r) {
  256. print_rate(buf, sizeof(buf), r->rate);
  257. printf("rate %s ", buf);
  258. if (show_details) {
  259. printf("cell %ub ", 1<<r->cell_log);
  260. if (r->mpu)
  261. printf("mpu %ub ", r->mpu);
  262. if (r->overhead)
  263. printf("overhead %ub ", r->overhead);
  264. }
  265. }
  266. if (lss && lss->flags) {
  267. bool comma = false;
  268. bb_putchar('(');
  269. if (lss->flags&TCF_CBQ_LSS_BOUNDED) {
  270. printf("bounded");
  271. comma = true;
  272. }
  273. if (lss->flags&TCF_CBQ_LSS_ISOLATED) {
  274. if (comma)
  275. bb_putchar(',');
  276. printf("isolated");
  277. }
  278. printf(") ");
  279. }
  280. if (wrr) {
  281. if (wrr->priority != TC_CBQ_MAXPRIO)
  282. printf("prio %u", wrr->priority);
  283. else
  284. printf("prio no-transmit");
  285. if (show_details) {
  286. printf("/%u ", wrr->cpriority);
  287. if (wrr->weight != 1) {
  288. print_rate(buf, sizeof(buf), wrr->weight);
  289. printf("weight %s ", buf);
  290. }
  291. if (wrr->allot)
  292. printf("allot %ub ", wrr->allot);
  293. }
  294. }
  295. done:
  296. return 0;
  297. }
  298. static FAST_FUNC int print_qdisc(
  299. const struct sockaddr_nl *who UNUSED_PARAM,
  300. struct nlmsghdr *hdr,
  301. void *arg UNUSED_PARAM)
  302. {
  303. struct tcmsg *msg = NLMSG_DATA(hdr);
  304. int len = hdr->nlmsg_len;
  305. struct rtattr * tb[TCA_MAX+1];
  306. char *name;
  307. if (hdr->nlmsg_type != RTM_NEWQDISC && hdr->nlmsg_type != RTM_DELQDISC) {
  308. /* bb_error_msg("not a qdisc"); */
  309. return 0; /* ??? mimic upstream; should perhaps return -1 */
  310. }
  311. len -= NLMSG_LENGTH(sizeof(*msg));
  312. if (len < 0) {
  313. /* bb_error_msg("wrong len %d", len); */
  314. return -1;
  315. }
  316. /* not the desired interface? */
  317. if (filter_ifindex && filter_ifindex != msg->tcm_ifindex)
  318. return 0;
  319. memset (tb, 0, sizeof(tb));
  320. parse_rtattr(tb, TCA_MAX, TCA_RTA(msg), len);
  321. if (tb[TCA_KIND] == NULL) {
  322. /* bb_error_msg("%s: NULL kind", "qdisc"); */
  323. return -1;
  324. }
  325. if (hdr->nlmsg_type == RTM_DELQDISC)
  326. printf("deleted ");
  327. name = (char*)RTA_DATA(tb[TCA_KIND]);
  328. printf("qdisc %s %x: ", name, msg->tcm_handle>>16);
  329. if (filter_ifindex == 0)
  330. printf("dev %s ", ll_index_to_name(msg->tcm_ifindex));
  331. if (msg->tcm_parent == TC_H_ROOT)
  332. printf("root ");
  333. else if (msg->tcm_parent) {
  334. char *classid = print_tc_classid(msg->tcm_parent);
  335. printf("parent %s ", classid);
  336. if (ENABLE_FEATURE_CLEAN_UP)
  337. free(classid);
  338. }
  339. if (msg->tcm_info != 1)
  340. printf("refcnt %d ", msg->tcm_info);
  341. if (tb[TCA_OPTIONS]) {
  342. static const char _q_[] ALIGN1 = "pfifo_fast\0""cbq\0";
  343. int qqq = index_in_strings(_q_, name);
  344. if (qqq == 0) { /* pfifo_fast aka prio */
  345. prio_print_opt(tb[TCA_OPTIONS]);
  346. } else if (qqq == 1) { /* class based queuing */
  347. cbq_print_opt(tb[TCA_OPTIONS]);
  348. } else {
  349. /* don't know how to print options for this qdisc */
  350. printf("(options for %s)", name);
  351. }
  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_handle) : msg->tcm_handle);
  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. /* don't know how to print options for this class */
  416. printf("(options for %s)", name);
  417. }
  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. cmd = CMD_show; /* list (aka show) is the default */
  479. if (*argv) {
  480. cmd = index_in_substrings(commands, *argv);
  481. if (cmd < 0)
  482. invarg_1_to_2(*argv, argv[-1]);
  483. argv++;
  484. }
  485. memset(&msg, 0, sizeof(msg));
  486. if (AF_UNSPEC != 0)
  487. msg.tcm_family = AF_UNSPEC;
  488. ll_init_map(&rth);
  489. while (*argv) {
  490. arg = index_in_substrings(args, *argv);
  491. if (arg == ARG_dev) {
  492. NEXT_ARG();
  493. if (dev)
  494. duparg2("dev", *argv);
  495. dev = *argv++;
  496. msg.tcm_ifindex = xll_name_to_index(dev);
  497. if (cmd >= CMD_show)
  498. filter_ifindex = msg.tcm_ifindex;
  499. continue;
  500. }
  501. if ((arg == ARG_qdisc && obj == OBJ_class && cmd >= CMD_show) /* tc class show|list qdisc HANDLE */
  502. || (arg == ARG_handle && obj == OBJ_qdisc && cmd == CMD_change) /* tc qdisc change handle HANDLE */
  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 /* tc class|filter root|parent | tc filter preference|priority|protocol */
  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. }