act_police.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. /*
  2. * net/sched/police.c Input police filter.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version
  7. * 2 of the License, or (at your option) any later version.
  8. *
  9. * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
  10. * J Hadi Salim (action changes)
  11. */
  12. #include <asm/uaccess.h>
  13. #include <asm/system.h>
  14. #include <linux/bitops.h>
  15. #include <linux/module.h>
  16. #include <linux/types.h>
  17. #include <linux/kernel.h>
  18. #include <linux/string.h>
  19. #include <linux/mm.h>
  20. #include <linux/socket.h>
  21. #include <linux/sockios.h>
  22. #include <linux/in.h>
  23. #include <linux/errno.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/netdevice.h>
  26. #include <linux/skbuff.h>
  27. #include <linux/module.h>
  28. #include <linux/rtnetlink.h>
  29. #include <linux/init.h>
  30. #include <net/sock.h>
  31. #include <net/act_api.h>
  32. #include <net/netlink.h>
  33. #define L2T(p,L) ((p)->tcfp_R_tab->data[(L)>>(p)->tcfp_R_tab->rate.cell_log])
  34. #define L2T_P(p,L) ((p)->tcfp_P_tab->data[(L)>>(p)->tcfp_P_tab->rate.cell_log])
  35. #define POL_TAB_MASK 15
  36. static struct tcf_common *tcf_police_ht[POL_TAB_MASK + 1];
  37. static u32 police_idx_gen;
  38. static DEFINE_RWLOCK(police_lock);
  39. static struct tcf_hashinfo police_hash_info = {
  40. .htab = tcf_police_ht,
  41. .hmask = POL_TAB_MASK,
  42. .lock = &police_lock,
  43. };
  44. /* old policer structure from before tc actions */
  45. struct tc_police_compat
  46. {
  47. u32 index;
  48. int action;
  49. u32 limit;
  50. u32 burst;
  51. u32 mtu;
  52. struct tc_ratespec rate;
  53. struct tc_ratespec peakrate;
  54. };
  55. /* Each policer is serialized by its individual spinlock */
  56. #ifdef CONFIG_NET_CLS_ACT
  57. static int tcf_act_police_walker(struct sk_buff *skb, struct netlink_callback *cb,
  58. int type, struct tc_action *a)
  59. {
  60. struct tcf_common *p;
  61. int err = 0, index = -1, i = 0, s_i = 0, n_i = 0;
  62. struct rtattr *r;
  63. read_lock(&police_lock);
  64. s_i = cb->args[0];
  65. for (i = 0; i < (POL_TAB_MASK + 1); i++) {
  66. p = tcf_police_ht[tcf_hash(i, POL_TAB_MASK)];
  67. for (; p; p = p->tcfc_next) {
  68. index++;
  69. if (index < s_i)
  70. continue;
  71. a->priv = p;
  72. a->order = index;
  73. r = (struct rtattr *)skb_tail_pointer(skb);
  74. RTA_PUT(skb, a->order, 0, NULL);
  75. if (type == RTM_DELACTION)
  76. err = tcf_action_dump_1(skb, a, 0, 1);
  77. else
  78. err = tcf_action_dump_1(skb, a, 0, 0);
  79. if (err < 0) {
  80. index--;
  81. nlmsg_trim(skb, r);
  82. goto done;
  83. }
  84. r->rta_len = skb_tail_pointer(skb) - (u8 *)r;
  85. n_i++;
  86. }
  87. }
  88. done:
  89. read_unlock(&police_lock);
  90. if (n_i)
  91. cb->args[0] += n_i;
  92. return n_i;
  93. rtattr_failure:
  94. nlmsg_trim(skb, r);
  95. goto done;
  96. }
  97. #endif
  98. void tcf_police_destroy(struct tcf_police *p)
  99. {
  100. unsigned int h = tcf_hash(p->tcf_index, POL_TAB_MASK);
  101. struct tcf_common **p1p;
  102. for (p1p = &tcf_police_ht[h]; *p1p; p1p = &(*p1p)->tcfc_next) {
  103. if (*p1p == &p->common) {
  104. write_lock_bh(&police_lock);
  105. *p1p = p->tcf_next;
  106. write_unlock_bh(&police_lock);
  107. #ifdef CONFIG_NET_ESTIMATOR
  108. gen_kill_estimator(&p->tcf_bstats,
  109. &p->tcf_rate_est);
  110. #endif
  111. if (p->tcfp_R_tab)
  112. qdisc_put_rtab(p->tcfp_R_tab);
  113. if (p->tcfp_P_tab)
  114. qdisc_put_rtab(p->tcfp_P_tab);
  115. kfree(p);
  116. return;
  117. }
  118. }
  119. BUG_TRAP(0);
  120. }
  121. #ifdef CONFIG_NET_CLS_ACT
  122. static int tcf_act_police_locate(struct rtattr *rta, struct rtattr *est,
  123. struct tc_action *a, int ovr, int bind)
  124. {
  125. unsigned h;
  126. int ret = 0, err;
  127. struct rtattr *tb[TCA_POLICE_MAX];
  128. struct tc_police *parm;
  129. struct tcf_police *police;
  130. struct qdisc_rate_table *R_tab = NULL, *P_tab = NULL;
  131. int size;
  132. if (rta == NULL || rtattr_parse_nested(tb, TCA_POLICE_MAX, rta) < 0)
  133. return -EINVAL;
  134. if (tb[TCA_POLICE_TBF-1] == NULL)
  135. return -EINVAL;
  136. size = RTA_PAYLOAD(tb[TCA_POLICE_TBF-1]);
  137. if (size != sizeof(*parm) && size != sizeof(struct tc_police_compat))
  138. return -EINVAL;
  139. parm = RTA_DATA(tb[TCA_POLICE_TBF-1]);
  140. if (tb[TCA_POLICE_RESULT-1] != NULL &&
  141. RTA_PAYLOAD(tb[TCA_POLICE_RESULT-1]) != sizeof(u32))
  142. return -EINVAL;
  143. if (tb[TCA_POLICE_RESULT-1] != NULL &&
  144. RTA_PAYLOAD(tb[TCA_POLICE_RESULT-1]) != sizeof(u32))
  145. return -EINVAL;
  146. if (parm->index) {
  147. struct tcf_common *pc;
  148. pc = tcf_hash_lookup(parm->index, &police_hash_info);
  149. if (pc != NULL) {
  150. a->priv = pc;
  151. police = to_police(pc);
  152. if (bind) {
  153. police->tcf_bindcnt += 1;
  154. police->tcf_refcnt += 1;
  155. }
  156. if (ovr)
  157. goto override;
  158. return ret;
  159. }
  160. }
  161. police = kzalloc(sizeof(*police), GFP_KERNEL);
  162. if (police == NULL)
  163. return -ENOMEM;
  164. ret = ACT_P_CREATED;
  165. police->tcf_refcnt = 1;
  166. spin_lock_init(&police->tcf_lock);
  167. police->tcf_stats_lock = &police->tcf_lock;
  168. if (bind)
  169. police->tcf_bindcnt = 1;
  170. override:
  171. if (parm->rate.rate) {
  172. err = -ENOMEM;
  173. R_tab = qdisc_get_rtab(&parm->rate, tb[TCA_POLICE_RATE-1]);
  174. if (R_tab == NULL)
  175. goto failure;
  176. if (parm->peakrate.rate) {
  177. P_tab = qdisc_get_rtab(&parm->peakrate,
  178. tb[TCA_POLICE_PEAKRATE-1]);
  179. if (P_tab == NULL) {
  180. qdisc_put_rtab(R_tab);
  181. goto failure;
  182. }
  183. }
  184. }
  185. /* No failure allowed after this point */
  186. spin_lock_bh(&police->tcf_lock);
  187. if (R_tab != NULL) {
  188. qdisc_put_rtab(police->tcfp_R_tab);
  189. police->tcfp_R_tab = R_tab;
  190. }
  191. if (P_tab != NULL) {
  192. qdisc_put_rtab(police->tcfp_P_tab);
  193. police->tcfp_P_tab = P_tab;
  194. }
  195. if (tb[TCA_POLICE_RESULT-1])
  196. police->tcfp_result = *(u32*)RTA_DATA(tb[TCA_POLICE_RESULT-1]);
  197. police->tcfp_toks = police->tcfp_burst = parm->burst;
  198. police->tcfp_mtu = parm->mtu;
  199. if (police->tcfp_mtu == 0) {
  200. police->tcfp_mtu = ~0;
  201. if (police->tcfp_R_tab)
  202. police->tcfp_mtu = 255<<police->tcfp_R_tab->rate.cell_log;
  203. }
  204. if (police->tcfp_P_tab)
  205. police->tcfp_ptoks = L2T_P(police, police->tcfp_mtu);
  206. police->tcf_action = parm->action;
  207. #ifdef CONFIG_NET_ESTIMATOR
  208. if (tb[TCA_POLICE_AVRATE-1])
  209. police->tcfp_ewma_rate =
  210. *(u32*)RTA_DATA(tb[TCA_POLICE_AVRATE-1]);
  211. if (est)
  212. gen_replace_estimator(&police->tcf_bstats,
  213. &police->tcf_rate_est,
  214. police->tcf_stats_lock, est);
  215. #endif
  216. spin_unlock_bh(&police->tcf_lock);
  217. if (ret != ACT_P_CREATED)
  218. return ret;
  219. police->tcfp_t_c = psched_get_time();
  220. police->tcf_index = parm->index ? parm->index :
  221. tcf_hash_new_index(&police_idx_gen, &police_hash_info);
  222. h = tcf_hash(police->tcf_index, POL_TAB_MASK);
  223. write_lock_bh(&police_lock);
  224. police->tcf_next = tcf_police_ht[h];
  225. tcf_police_ht[h] = &police->common;
  226. write_unlock_bh(&police_lock);
  227. a->priv = police;
  228. return ret;
  229. failure:
  230. if (ret == ACT_P_CREATED)
  231. kfree(police);
  232. return err;
  233. }
  234. static int tcf_act_police_cleanup(struct tc_action *a, int bind)
  235. {
  236. struct tcf_police *p = a->priv;
  237. if (p != NULL)
  238. return tcf_police_release(p, bind);
  239. return 0;
  240. }
  241. static int tcf_act_police(struct sk_buff *skb, struct tc_action *a,
  242. struct tcf_result *res)
  243. {
  244. struct tcf_police *police = a->priv;
  245. psched_time_t now;
  246. long toks;
  247. long ptoks = 0;
  248. spin_lock(&police->tcf_lock);
  249. police->tcf_bstats.bytes += skb->len;
  250. police->tcf_bstats.packets++;
  251. #ifdef CONFIG_NET_ESTIMATOR
  252. if (police->tcfp_ewma_rate &&
  253. police->tcf_rate_est.bps >= police->tcfp_ewma_rate) {
  254. police->tcf_qstats.overlimits++;
  255. spin_unlock(&police->tcf_lock);
  256. return police->tcf_action;
  257. }
  258. #endif
  259. if (skb->len <= police->tcfp_mtu) {
  260. if (police->tcfp_R_tab == NULL) {
  261. spin_unlock(&police->tcf_lock);
  262. return police->tcfp_result;
  263. }
  264. now = psched_get_time();
  265. toks = psched_tdiff_bounded(now, police->tcfp_t_c,
  266. police->tcfp_burst);
  267. if (police->tcfp_P_tab) {
  268. ptoks = toks + police->tcfp_ptoks;
  269. if (ptoks > (long)L2T_P(police, police->tcfp_mtu))
  270. ptoks = (long)L2T_P(police, police->tcfp_mtu);
  271. ptoks -= L2T_P(police, skb->len);
  272. }
  273. toks += police->tcfp_toks;
  274. if (toks > (long)police->tcfp_burst)
  275. toks = police->tcfp_burst;
  276. toks -= L2T(police, skb->len);
  277. if ((toks|ptoks) >= 0) {
  278. police->tcfp_t_c = now;
  279. police->tcfp_toks = toks;
  280. police->tcfp_ptoks = ptoks;
  281. spin_unlock(&police->tcf_lock);
  282. return police->tcfp_result;
  283. }
  284. }
  285. police->tcf_qstats.overlimits++;
  286. spin_unlock(&police->tcf_lock);
  287. return police->tcf_action;
  288. }
  289. static int
  290. tcf_act_police_dump(struct sk_buff *skb, struct tc_action *a, int bind, int ref)
  291. {
  292. unsigned char *b = skb_tail_pointer(skb);
  293. struct tcf_police *police = a->priv;
  294. struct tc_police opt;
  295. opt.index = police->tcf_index;
  296. opt.action = police->tcf_action;
  297. opt.mtu = police->tcfp_mtu;
  298. opt.burst = police->tcfp_burst;
  299. opt.refcnt = police->tcf_refcnt - ref;
  300. opt.bindcnt = police->tcf_bindcnt - bind;
  301. if (police->tcfp_R_tab)
  302. opt.rate = police->tcfp_R_tab->rate;
  303. else
  304. memset(&opt.rate, 0, sizeof(opt.rate));
  305. if (police->tcfp_P_tab)
  306. opt.peakrate = police->tcfp_P_tab->rate;
  307. else
  308. memset(&opt.peakrate, 0, sizeof(opt.peakrate));
  309. RTA_PUT(skb, TCA_POLICE_TBF, sizeof(opt), &opt);
  310. if (police->tcfp_result)
  311. RTA_PUT(skb, TCA_POLICE_RESULT, sizeof(int),
  312. &police->tcfp_result);
  313. #ifdef CONFIG_NET_ESTIMATOR
  314. if (police->tcfp_ewma_rate)
  315. RTA_PUT(skb, TCA_POLICE_AVRATE, 4, &police->tcfp_ewma_rate);
  316. #endif
  317. return skb->len;
  318. rtattr_failure:
  319. nlmsg_trim(skb, b);
  320. return -1;
  321. }
  322. MODULE_AUTHOR("Alexey Kuznetsov");
  323. MODULE_DESCRIPTION("Policing actions");
  324. MODULE_LICENSE("GPL");
  325. static struct tc_action_ops act_police_ops = {
  326. .kind = "police",
  327. .hinfo = &police_hash_info,
  328. .type = TCA_ID_POLICE,
  329. .capab = TCA_CAP_NONE,
  330. .owner = THIS_MODULE,
  331. .act = tcf_act_police,
  332. .dump = tcf_act_police_dump,
  333. .cleanup = tcf_act_police_cleanup,
  334. .lookup = tcf_hash_search,
  335. .init = tcf_act_police_locate,
  336. .walk = tcf_act_police_walker
  337. };
  338. static int __init
  339. police_init_module(void)
  340. {
  341. return tcf_register_action(&act_police_ops);
  342. }
  343. static void __exit
  344. police_cleanup_module(void)
  345. {
  346. tcf_unregister_action(&act_police_ops);
  347. }
  348. module_init(police_init_module);
  349. module_exit(police_cleanup_module);
  350. #else /* CONFIG_NET_CLS_ACT */
  351. static struct tcf_common *tcf_police_lookup(u32 index)
  352. {
  353. struct tcf_hashinfo *hinfo = &police_hash_info;
  354. struct tcf_common *p;
  355. read_lock(hinfo->lock);
  356. for (p = hinfo->htab[tcf_hash(index, hinfo->hmask)]; p;
  357. p = p->tcfc_next) {
  358. if (p->tcfc_index == index)
  359. break;
  360. }
  361. read_unlock(hinfo->lock);
  362. return p;
  363. }
  364. static u32 tcf_police_new_index(void)
  365. {
  366. u32 *idx_gen = &police_idx_gen;
  367. u32 val = *idx_gen;
  368. do {
  369. if (++val == 0)
  370. val = 1;
  371. } while (tcf_police_lookup(val));
  372. return (*idx_gen = val);
  373. }
  374. struct tcf_police *tcf_police_locate(struct rtattr *rta, struct rtattr *est)
  375. {
  376. unsigned int h;
  377. struct tcf_police *police;
  378. struct rtattr *tb[TCA_POLICE_MAX];
  379. struct tc_police *parm;
  380. int size;
  381. if (rtattr_parse_nested(tb, TCA_POLICE_MAX, rta) < 0)
  382. return NULL;
  383. if (tb[TCA_POLICE_TBF-1] == NULL)
  384. return NULL;
  385. size = RTA_PAYLOAD(tb[TCA_POLICE_TBF-1]);
  386. if (size != sizeof(*parm) && size != sizeof(struct tc_police_compat))
  387. return NULL;
  388. parm = RTA_DATA(tb[TCA_POLICE_TBF-1]);
  389. if (parm->index) {
  390. struct tcf_common *pc;
  391. pc = tcf_police_lookup(parm->index);
  392. if (pc) {
  393. police = to_police(pc);
  394. police->tcf_refcnt++;
  395. return police;
  396. }
  397. }
  398. police = kzalloc(sizeof(*police), GFP_KERNEL);
  399. if (unlikely(!police))
  400. return NULL;
  401. police->tcf_refcnt = 1;
  402. spin_lock_init(&police->tcf_lock);
  403. police->tcf_stats_lock = &police->tcf_lock;
  404. if (parm->rate.rate) {
  405. police->tcfp_R_tab =
  406. qdisc_get_rtab(&parm->rate, tb[TCA_POLICE_RATE-1]);
  407. if (police->tcfp_R_tab == NULL)
  408. goto failure;
  409. if (parm->peakrate.rate) {
  410. police->tcfp_P_tab =
  411. qdisc_get_rtab(&parm->peakrate,
  412. tb[TCA_POLICE_PEAKRATE-1]);
  413. if (police->tcfp_P_tab == NULL)
  414. goto failure;
  415. }
  416. }
  417. if (tb[TCA_POLICE_RESULT-1]) {
  418. if (RTA_PAYLOAD(tb[TCA_POLICE_RESULT-1]) != sizeof(u32))
  419. goto failure;
  420. police->tcfp_result = *(u32*)RTA_DATA(tb[TCA_POLICE_RESULT-1]);
  421. }
  422. #ifdef CONFIG_NET_ESTIMATOR
  423. if (tb[TCA_POLICE_AVRATE-1]) {
  424. if (RTA_PAYLOAD(tb[TCA_POLICE_AVRATE-1]) != sizeof(u32))
  425. goto failure;
  426. police->tcfp_ewma_rate =
  427. *(u32*)RTA_DATA(tb[TCA_POLICE_AVRATE-1]);
  428. }
  429. #endif
  430. police->tcfp_toks = police->tcfp_burst = parm->burst;
  431. police->tcfp_mtu = parm->mtu;
  432. if (police->tcfp_mtu == 0) {
  433. police->tcfp_mtu = ~0;
  434. if (police->tcfp_R_tab)
  435. police->tcfp_mtu = 255<<police->tcfp_R_tab->rate.cell_log;
  436. }
  437. if (police->tcfp_P_tab)
  438. police->tcfp_ptoks = L2T_P(police, police->tcfp_mtu);
  439. police->tcfp_t_c = psched_get_time();
  440. police->tcf_index = parm->index ? parm->index :
  441. tcf_police_new_index();
  442. police->tcf_action = parm->action;
  443. #ifdef CONFIG_NET_ESTIMATOR
  444. if (est)
  445. gen_new_estimator(&police->tcf_bstats, &police->tcf_rate_est,
  446. police->tcf_stats_lock, est);
  447. #endif
  448. h = tcf_hash(police->tcf_index, POL_TAB_MASK);
  449. write_lock_bh(&police_lock);
  450. police->tcf_next = tcf_police_ht[h];
  451. tcf_police_ht[h] = &police->common;
  452. write_unlock_bh(&police_lock);
  453. return police;
  454. failure:
  455. if (police->tcfp_R_tab)
  456. qdisc_put_rtab(police->tcfp_R_tab);
  457. kfree(police);
  458. return NULL;
  459. }
  460. int tcf_police(struct sk_buff *skb, struct tcf_police *police)
  461. {
  462. psched_time_t now;
  463. long toks;
  464. long ptoks = 0;
  465. spin_lock(&police->tcf_lock);
  466. police->tcf_bstats.bytes += skb->len;
  467. police->tcf_bstats.packets++;
  468. #ifdef CONFIG_NET_ESTIMATOR
  469. if (police->tcfp_ewma_rate &&
  470. police->tcf_rate_est.bps >= police->tcfp_ewma_rate) {
  471. police->tcf_qstats.overlimits++;
  472. spin_unlock(&police->tcf_lock);
  473. return police->tcf_action;
  474. }
  475. #endif
  476. if (skb->len <= police->tcfp_mtu) {
  477. if (police->tcfp_R_tab == NULL) {
  478. spin_unlock(&police->tcf_lock);
  479. return police->tcfp_result;
  480. }
  481. now = psched_get_time();
  482. toks = psched_tdiff_bounded(now, police->tcfp_t_c,
  483. police->tcfp_burst);
  484. if (police->tcfp_P_tab) {
  485. ptoks = toks + police->tcfp_ptoks;
  486. if (ptoks > (long)L2T_P(police, police->tcfp_mtu))
  487. ptoks = (long)L2T_P(police, police->tcfp_mtu);
  488. ptoks -= L2T_P(police, skb->len);
  489. }
  490. toks += police->tcfp_toks;
  491. if (toks > (long)police->tcfp_burst)
  492. toks = police->tcfp_burst;
  493. toks -= L2T(police, skb->len);
  494. if ((toks|ptoks) >= 0) {
  495. police->tcfp_t_c = now;
  496. police->tcfp_toks = toks;
  497. police->tcfp_ptoks = ptoks;
  498. spin_unlock(&police->tcf_lock);
  499. return police->tcfp_result;
  500. }
  501. }
  502. police->tcf_qstats.overlimits++;
  503. spin_unlock(&police->tcf_lock);
  504. return police->tcf_action;
  505. }
  506. EXPORT_SYMBOL(tcf_police);
  507. int tcf_police_dump(struct sk_buff *skb, struct tcf_police *police)
  508. {
  509. unsigned char *b = skb_tail_pointer(skb);
  510. struct tc_police opt;
  511. opt.index = police->tcf_index;
  512. opt.action = police->tcf_action;
  513. opt.mtu = police->tcfp_mtu;
  514. opt.burst = police->tcfp_burst;
  515. if (police->tcfp_R_tab)
  516. opt.rate = police->tcfp_R_tab->rate;
  517. else
  518. memset(&opt.rate, 0, sizeof(opt.rate));
  519. if (police->tcfp_P_tab)
  520. opt.peakrate = police->tcfp_P_tab->rate;
  521. else
  522. memset(&opt.peakrate, 0, sizeof(opt.peakrate));
  523. RTA_PUT(skb, TCA_POLICE_TBF, sizeof(opt), &opt);
  524. if (police->tcfp_result)
  525. RTA_PUT(skb, TCA_POLICE_RESULT, sizeof(int),
  526. &police->tcfp_result);
  527. #ifdef CONFIG_NET_ESTIMATOR
  528. if (police->tcfp_ewma_rate)
  529. RTA_PUT(skb, TCA_POLICE_AVRATE, 4, &police->tcfp_ewma_rate);
  530. #endif
  531. return skb->len;
  532. rtattr_failure:
  533. nlmsg_trim(skb, b);
  534. return -1;
  535. }
  536. int tcf_police_dump_stats(struct sk_buff *skb, struct tcf_police *police)
  537. {
  538. struct gnet_dump d;
  539. if (gnet_stats_start_copy_compat(skb, TCA_STATS2, TCA_STATS,
  540. TCA_XSTATS, police->tcf_stats_lock,
  541. &d) < 0)
  542. goto errout;
  543. if (gnet_stats_copy_basic(&d, &police->tcf_bstats) < 0 ||
  544. #ifdef CONFIG_NET_ESTIMATOR
  545. gnet_stats_copy_rate_est(&d, &police->tcf_rate_est) < 0 ||
  546. #endif
  547. gnet_stats_copy_queue(&d, &police->tcf_qstats) < 0)
  548. goto errout;
  549. if (gnet_stats_finish_copy(&d) < 0)
  550. goto errout;
  551. return 0;
  552. errout:
  553. return -1;
  554. }
  555. #endif /* CONFIG_NET_CLS_ACT */