3
0

tc.c 16 KB

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