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