tc.c 16 KB

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