cls_tcindex.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. /*
  2. * net/sched/cls_tcindex.c Packet classifier for skb->tc_index
  3. *
  4. * Written 1998,1999 by Werner Almesberger, EPFL ICA
  5. */
  6. #include <linux/module.h>
  7. #include <linux/types.h>
  8. #include <linux/kernel.h>
  9. #include <linux/skbuff.h>
  10. #include <linux/errno.h>
  11. #include <linux/slab.h>
  12. #include <net/act_api.h>
  13. #include <net/netlink.h>
  14. #include <net/pkt_cls.h>
  15. #include <net/sch_generic.h>
  16. /*
  17. * Passing parameters to the root seems to be done more awkwardly than really
  18. * necessary. At least, u32 doesn't seem to use such dirty hacks. To be
  19. * verified. FIXME.
  20. */
  21. #define PERFECT_HASH_THRESHOLD 64 /* use perfect hash if not bigger */
  22. #define DEFAULT_HASH_SIZE 64 /* optimized for diffserv */
  23. struct tcindex_filter_result {
  24. struct tcf_exts exts;
  25. struct tcf_result res;
  26. struct rcu_work rwork;
  27. };
  28. struct tcindex_filter {
  29. u16 key;
  30. struct tcindex_filter_result result;
  31. struct tcindex_filter __rcu *next;
  32. struct rcu_work rwork;
  33. };
  34. struct tcindex_data {
  35. struct tcindex_filter_result *perfect; /* perfect hash; NULL if none */
  36. struct tcindex_filter __rcu **h; /* imperfect hash; */
  37. struct tcf_proto *tp;
  38. u16 mask; /* AND key with mask */
  39. u32 shift; /* shift ANDed key to the right */
  40. u32 hash; /* hash table size; 0 if undefined */
  41. u32 alloc_hash; /* allocated size */
  42. u32 fall_through; /* 0: only classify if explicit match */
  43. struct rcu_work rwork;
  44. };
  45. static inline int tcindex_filter_is_set(struct tcindex_filter_result *r)
  46. {
  47. return tcf_exts_has_actions(&r->exts) || r->res.classid;
  48. }
  49. static struct tcindex_filter_result *tcindex_lookup(struct tcindex_data *p,
  50. u16 key)
  51. {
  52. if (p->perfect) {
  53. struct tcindex_filter_result *f = p->perfect + key;
  54. return tcindex_filter_is_set(f) ? f : NULL;
  55. } else if (p->h) {
  56. struct tcindex_filter __rcu **fp;
  57. struct tcindex_filter *f;
  58. fp = &p->h[key % p->hash];
  59. for (f = rcu_dereference_bh_rtnl(*fp);
  60. f;
  61. fp = &f->next, f = rcu_dereference_bh_rtnl(*fp))
  62. if (f->key == key)
  63. return &f->result;
  64. }
  65. return NULL;
  66. }
  67. static int tcindex_classify(struct sk_buff *skb, const struct tcf_proto *tp,
  68. struct tcf_result *res)
  69. {
  70. struct tcindex_data *p = rcu_dereference_bh(tp->root);
  71. struct tcindex_filter_result *f;
  72. int key = (skb->tc_index & p->mask) >> p->shift;
  73. pr_debug("tcindex_classify(skb %p,tp %p,res %p),p %p\n",
  74. skb, tp, res, p);
  75. f = tcindex_lookup(p, key);
  76. if (!f) {
  77. struct Qdisc *q = tcf_block_q(tp->chain->block);
  78. if (!p->fall_through)
  79. return -1;
  80. res->classid = TC_H_MAKE(TC_H_MAJ(q->handle), key);
  81. res->class = 0;
  82. pr_debug("alg 0x%x\n", res->classid);
  83. return 0;
  84. }
  85. *res = f->res;
  86. pr_debug("map 0x%x\n", res->classid);
  87. return tcf_exts_exec(skb, &f->exts, res);
  88. }
  89. static void *tcindex_get(struct tcf_proto *tp, u32 handle)
  90. {
  91. struct tcindex_data *p = rtnl_dereference(tp->root);
  92. struct tcindex_filter_result *r;
  93. pr_debug("tcindex_get(tp %p,handle 0x%08x)\n", tp, handle);
  94. if (p->perfect && handle >= p->alloc_hash)
  95. return NULL;
  96. r = tcindex_lookup(p, handle);
  97. return r && tcindex_filter_is_set(r) ? r : NULL;
  98. }
  99. static int tcindex_init(struct tcf_proto *tp)
  100. {
  101. struct tcindex_data *p;
  102. pr_debug("tcindex_init(tp %p)\n", tp);
  103. p = kzalloc(sizeof(struct tcindex_data), GFP_KERNEL);
  104. if (!p)
  105. return -ENOMEM;
  106. p->mask = 0xffff;
  107. p->hash = DEFAULT_HASH_SIZE;
  108. p->fall_through = 1;
  109. rcu_assign_pointer(tp->root, p);
  110. return 0;
  111. }
  112. static void __tcindex_destroy_rexts(struct tcindex_filter_result *r)
  113. {
  114. tcf_exts_destroy(&r->exts);
  115. tcf_exts_put_net(&r->exts);
  116. }
  117. static void tcindex_destroy_rexts_work(struct work_struct *work)
  118. {
  119. struct tcindex_filter_result *r;
  120. r = container_of(to_rcu_work(work),
  121. struct tcindex_filter_result,
  122. rwork);
  123. rtnl_lock();
  124. __tcindex_destroy_rexts(r);
  125. rtnl_unlock();
  126. }
  127. static void __tcindex_destroy_fexts(struct tcindex_filter *f)
  128. {
  129. tcf_exts_destroy(&f->result.exts);
  130. tcf_exts_put_net(&f->result.exts);
  131. kfree(f);
  132. }
  133. static void tcindex_destroy_fexts_work(struct work_struct *work)
  134. {
  135. struct tcindex_filter *f = container_of(to_rcu_work(work),
  136. struct tcindex_filter,
  137. rwork);
  138. rtnl_lock();
  139. __tcindex_destroy_fexts(f);
  140. rtnl_unlock();
  141. }
  142. static int tcindex_delete(struct tcf_proto *tp, void *arg, bool *last,
  143. struct netlink_ext_ack *extack)
  144. {
  145. struct tcindex_data *p = rtnl_dereference(tp->root);
  146. struct tcindex_filter_result *r = arg;
  147. struct tcindex_filter __rcu **walk;
  148. struct tcindex_filter *f = NULL;
  149. pr_debug("tcindex_delete(tp %p,arg %p),p %p\n", tp, arg, p);
  150. if (p->perfect) {
  151. if (!r->res.class)
  152. return -ENOENT;
  153. } else {
  154. int i;
  155. for (i = 0; i < p->hash; i++) {
  156. walk = p->h + i;
  157. for (f = rtnl_dereference(*walk); f;
  158. walk = &f->next, f = rtnl_dereference(*walk)) {
  159. if (&f->result == r)
  160. goto found;
  161. }
  162. }
  163. return -ENOENT;
  164. found:
  165. rcu_assign_pointer(*walk, rtnl_dereference(f->next));
  166. }
  167. tcf_unbind_filter(tp, &r->res);
  168. /* all classifiers are required to call tcf_exts_destroy() after rcu
  169. * grace period, since converted-to-rcu actions are relying on that
  170. * in cleanup() callback
  171. */
  172. if (f) {
  173. if (tcf_exts_get_net(&f->result.exts))
  174. tcf_queue_work(&f->rwork, tcindex_destroy_fexts_work);
  175. else
  176. __tcindex_destroy_fexts(f);
  177. } else {
  178. if (tcf_exts_get_net(&r->exts))
  179. tcf_queue_work(&r->rwork, tcindex_destroy_rexts_work);
  180. else
  181. __tcindex_destroy_rexts(r);
  182. }
  183. *last = false;
  184. return 0;
  185. }
  186. static void tcindex_destroy_work(struct work_struct *work)
  187. {
  188. struct tcindex_data *p = container_of(to_rcu_work(work),
  189. struct tcindex_data,
  190. rwork);
  191. kfree(p->perfect);
  192. kfree(p->h);
  193. kfree(p);
  194. }
  195. static inline int
  196. valid_perfect_hash(struct tcindex_data *p)
  197. {
  198. return p->hash > (p->mask >> p->shift);
  199. }
  200. static const struct nla_policy tcindex_policy[TCA_TCINDEX_MAX + 1] = {
  201. [TCA_TCINDEX_HASH] = { .type = NLA_U32 },
  202. [TCA_TCINDEX_MASK] = { .type = NLA_U16 },
  203. [TCA_TCINDEX_SHIFT] = { .type = NLA_U32 },
  204. [TCA_TCINDEX_FALL_THROUGH] = { .type = NLA_U32 },
  205. [TCA_TCINDEX_CLASSID] = { .type = NLA_U32 },
  206. };
  207. static int tcindex_filter_result_init(struct tcindex_filter_result *r)
  208. {
  209. memset(r, 0, sizeof(*r));
  210. return tcf_exts_init(&r->exts, TCA_TCINDEX_ACT, TCA_TCINDEX_POLICE);
  211. }
  212. static void tcindex_partial_destroy_work(struct work_struct *work)
  213. {
  214. struct tcindex_data *p = container_of(to_rcu_work(work),
  215. struct tcindex_data,
  216. rwork);
  217. kfree(p->perfect);
  218. kfree(p);
  219. }
  220. static void tcindex_free_perfect_hash(struct tcindex_data *cp)
  221. {
  222. int i;
  223. for (i = 0; i < cp->hash; i++)
  224. tcf_exts_destroy(&cp->perfect[i].exts);
  225. kfree(cp->perfect);
  226. }
  227. static int tcindex_alloc_perfect_hash(struct net *net, struct tcindex_data *cp)
  228. {
  229. int i, err = 0;
  230. cp->perfect = kcalloc(cp->hash, sizeof(struct tcindex_filter_result),
  231. GFP_KERNEL);
  232. if (!cp->perfect)
  233. return -ENOMEM;
  234. for (i = 0; i < cp->hash; i++) {
  235. err = tcf_exts_init(&cp->perfect[i].exts,
  236. TCA_TCINDEX_ACT, TCA_TCINDEX_POLICE);
  237. if (err < 0)
  238. goto errout;
  239. #ifdef CONFIG_NET_CLS_ACT
  240. cp->perfect[i].exts.net = net;
  241. #endif
  242. }
  243. return 0;
  244. errout:
  245. tcindex_free_perfect_hash(cp);
  246. return err;
  247. }
  248. static int
  249. tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base,
  250. u32 handle, struct tcindex_data *p,
  251. struct tcindex_filter_result *r, struct nlattr **tb,
  252. struct nlattr *est, bool ovr, struct netlink_ext_ack *extack)
  253. {
  254. struct tcindex_filter_result new_filter_result, *old_r = r;
  255. struct tcindex_data *cp = NULL, *oldp;
  256. struct tcindex_filter *f = NULL; /* make gcc behave */
  257. struct tcf_result cr = {};
  258. int err, balloc = 0;
  259. struct tcf_exts e;
  260. err = tcf_exts_init(&e, TCA_TCINDEX_ACT, TCA_TCINDEX_POLICE);
  261. if (err < 0)
  262. return err;
  263. err = tcf_exts_validate(net, tp, tb, est, &e, ovr, extack);
  264. if (err < 0)
  265. goto errout;
  266. err = -ENOMEM;
  267. /* tcindex_data attributes must look atomic to classifier/lookup so
  268. * allocate new tcindex data and RCU assign it onto root. Keeping
  269. * perfect hash and hash pointers from old data.
  270. */
  271. cp = kzalloc(sizeof(*cp), GFP_KERNEL);
  272. if (!cp)
  273. goto errout;
  274. cp->mask = p->mask;
  275. cp->shift = p->shift;
  276. cp->hash = p->hash;
  277. cp->alloc_hash = p->alloc_hash;
  278. cp->fall_through = p->fall_through;
  279. cp->tp = tp;
  280. if (tb[TCA_TCINDEX_HASH])
  281. cp->hash = nla_get_u32(tb[TCA_TCINDEX_HASH]);
  282. if (tb[TCA_TCINDEX_MASK])
  283. cp->mask = nla_get_u16(tb[TCA_TCINDEX_MASK]);
  284. if (tb[TCA_TCINDEX_SHIFT]) {
  285. cp->shift = nla_get_u32(tb[TCA_TCINDEX_SHIFT]);
  286. if (cp->shift > 16) {
  287. err = -EINVAL;
  288. goto errout;
  289. }
  290. }
  291. if (!cp->hash) {
  292. /* Hash not specified, use perfect hash if the upper limit
  293. * of the hashing index is below the threshold.
  294. */
  295. if ((cp->mask >> cp->shift) < PERFECT_HASH_THRESHOLD)
  296. cp->hash = (cp->mask >> cp->shift) + 1;
  297. else
  298. cp->hash = DEFAULT_HASH_SIZE;
  299. }
  300. if (p->perfect) {
  301. int i;
  302. if (tcindex_alloc_perfect_hash(net, cp) < 0)
  303. goto errout;
  304. cp->alloc_hash = cp->hash;
  305. for (i = 0; i < min(cp->hash, p->hash); i++)
  306. cp->perfect[i].res = p->perfect[i].res;
  307. balloc = 1;
  308. }
  309. cp->h = p->h;
  310. err = tcindex_filter_result_init(&new_filter_result);
  311. if (err < 0)
  312. goto errout_alloc;
  313. if (old_r)
  314. cr = r->res;
  315. err = -EBUSY;
  316. /* Hash already allocated, make sure that we still meet the
  317. * requirements for the allocated hash.
  318. */
  319. if (cp->perfect) {
  320. if (!valid_perfect_hash(cp) ||
  321. cp->hash > cp->alloc_hash)
  322. goto errout_alloc;
  323. } else if (cp->h && cp->hash != cp->alloc_hash) {
  324. goto errout_alloc;
  325. }
  326. err = -EINVAL;
  327. if (tb[TCA_TCINDEX_FALL_THROUGH])
  328. cp->fall_through = nla_get_u32(tb[TCA_TCINDEX_FALL_THROUGH]);
  329. if (!cp->perfect && !cp->h)
  330. cp->alloc_hash = cp->hash;
  331. /* Note: this could be as restrictive as if (handle & ~(mask >> shift))
  332. * but then, we'd fail handles that may become valid after some future
  333. * mask change. While this is extremely unlikely to ever matter,
  334. * the check below is safer (and also more backwards-compatible).
  335. */
  336. if (cp->perfect || valid_perfect_hash(cp))
  337. if (handle >= cp->alloc_hash)
  338. goto errout_alloc;
  339. err = -ENOMEM;
  340. if (!cp->perfect && !cp->h) {
  341. if (valid_perfect_hash(cp)) {
  342. if (tcindex_alloc_perfect_hash(net, cp) < 0)
  343. goto errout_alloc;
  344. balloc = 1;
  345. } else {
  346. struct tcindex_filter __rcu **hash;
  347. hash = kcalloc(cp->hash,
  348. sizeof(struct tcindex_filter *),
  349. GFP_KERNEL);
  350. if (!hash)
  351. goto errout_alloc;
  352. cp->h = hash;
  353. balloc = 2;
  354. }
  355. }
  356. if (cp->perfect)
  357. r = cp->perfect + handle;
  358. else
  359. r = tcindex_lookup(cp, handle) ? : &new_filter_result;
  360. if (r == &new_filter_result) {
  361. f = kzalloc(sizeof(*f), GFP_KERNEL);
  362. if (!f)
  363. goto errout_alloc;
  364. f->key = handle;
  365. f->next = NULL;
  366. err = tcindex_filter_result_init(&f->result);
  367. if (err < 0) {
  368. kfree(f);
  369. goto errout_alloc;
  370. }
  371. }
  372. if (tb[TCA_TCINDEX_CLASSID]) {
  373. cr.classid = nla_get_u32(tb[TCA_TCINDEX_CLASSID]);
  374. tcf_bind_filter(tp, &cr, base);
  375. }
  376. if (old_r && old_r != r) {
  377. err = tcindex_filter_result_init(old_r);
  378. if (err < 0) {
  379. kfree(f);
  380. goto errout_alloc;
  381. }
  382. }
  383. oldp = p;
  384. r->res = cr;
  385. tcf_exts_change(&r->exts, &e);
  386. rcu_assign_pointer(tp->root, cp);
  387. if (r == &new_filter_result) {
  388. struct tcindex_filter *nfp;
  389. struct tcindex_filter __rcu **fp;
  390. f->result.res = r->res;
  391. tcf_exts_change(&f->result.exts, &r->exts);
  392. fp = cp->h + (handle % cp->hash);
  393. for (nfp = rtnl_dereference(*fp);
  394. nfp;
  395. fp = &nfp->next, nfp = rtnl_dereference(*fp))
  396. ; /* nothing */
  397. rcu_assign_pointer(*fp, f);
  398. } else {
  399. tcf_exts_destroy(&new_filter_result.exts);
  400. }
  401. if (oldp)
  402. tcf_queue_work(&oldp->rwork, tcindex_partial_destroy_work);
  403. return 0;
  404. errout_alloc:
  405. if (balloc == 1)
  406. tcindex_free_perfect_hash(cp);
  407. else if (balloc == 2)
  408. kfree(cp->h);
  409. tcf_exts_destroy(&new_filter_result.exts);
  410. errout:
  411. kfree(cp);
  412. tcf_exts_destroy(&e);
  413. return err;
  414. }
  415. static int
  416. tcindex_change(struct net *net, struct sk_buff *in_skb,
  417. struct tcf_proto *tp, unsigned long base, u32 handle,
  418. struct nlattr **tca, void **arg, bool ovr,
  419. struct netlink_ext_ack *extack)
  420. {
  421. struct nlattr *opt = tca[TCA_OPTIONS];
  422. struct nlattr *tb[TCA_TCINDEX_MAX + 1];
  423. struct tcindex_data *p = rtnl_dereference(tp->root);
  424. struct tcindex_filter_result *r = *arg;
  425. int err;
  426. pr_debug("tcindex_change(tp %p,handle 0x%08x,tca %p,arg %p),opt %p,"
  427. "p %p,r %p,*arg %p\n",
  428. tp, handle, tca, arg, opt, p, r, arg ? *arg : NULL);
  429. if (!opt)
  430. return 0;
  431. err = nla_parse_nested(tb, TCA_TCINDEX_MAX, opt, tcindex_policy, NULL);
  432. if (err < 0)
  433. return err;
  434. return tcindex_set_parms(net, tp, base, handle, p, r, tb,
  435. tca[TCA_RATE], ovr, extack);
  436. }
  437. static void tcindex_walk(struct tcf_proto *tp, struct tcf_walker *walker)
  438. {
  439. struct tcindex_data *p = rtnl_dereference(tp->root);
  440. struct tcindex_filter *f, *next;
  441. int i;
  442. pr_debug("tcindex_walk(tp %p,walker %p),p %p\n", tp, walker, p);
  443. if (p->perfect) {
  444. for (i = 0; i < p->hash; i++) {
  445. if (!p->perfect[i].res.class)
  446. continue;
  447. if (walker->count >= walker->skip) {
  448. if (walker->fn(tp, p->perfect + i, walker) < 0) {
  449. walker->stop = 1;
  450. return;
  451. }
  452. }
  453. walker->count++;
  454. }
  455. }
  456. if (!p->h)
  457. return;
  458. for (i = 0; i < p->hash; i++) {
  459. for (f = rtnl_dereference(p->h[i]); f; f = next) {
  460. next = rtnl_dereference(f->next);
  461. if (walker->count >= walker->skip) {
  462. if (walker->fn(tp, &f->result, walker) < 0) {
  463. walker->stop = 1;
  464. return;
  465. }
  466. }
  467. walker->count++;
  468. }
  469. }
  470. }
  471. static void tcindex_destroy(struct tcf_proto *tp,
  472. struct netlink_ext_ack *extack)
  473. {
  474. struct tcindex_data *p = rtnl_dereference(tp->root);
  475. int i;
  476. pr_debug("tcindex_destroy(tp %p),p %p\n", tp, p);
  477. if (p->perfect) {
  478. for (i = 0; i < p->hash; i++) {
  479. struct tcindex_filter_result *r = p->perfect + i;
  480. tcf_unbind_filter(tp, &r->res);
  481. if (tcf_exts_get_net(&r->exts))
  482. tcf_queue_work(&r->rwork,
  483. tcindex_destroy_rexts_work);
  484. else
  485. __tcindex_destroy_rexts(r);
  486. }
  487. }
  488. for (i = 0; p->h && i < p->hash; i++) {
  489. struct tcindex_filter *f, *next;
  490. bool last;
  491. for (f = rtnl_dereference(p->h[i]); f; f = next) {
  492. next = rtnl_dereference(f->next);
  493. tcindex_delete(tp, &f->result, &last, NULL);
  494. }
  495. }
  496. tcf_queue_work(&p->rwork, tcindex_destroy_work);
  497. }
  498. static int tcindex_dump(struct net *net, struct tcf_proto *tp, void *fh,
  499. struct sk_buff *skb, struct tcmsg *t)
  500. {
  501. struct tcindex_data *p = rtnl_dereference(tp->root);
  502. struct tcindex_filter_result *r = fh;
  503. struct nlattr *nest;
  504. pr_debug("tcindex_dump(tp %p,fh %p,skb %p,t %p),p %p,r %p\n",
  505. tp, fh, skb, t, p, r);
  506. pr_debug("p->perfect %p p->h %p\n", p->perfect, p->h);
  507. nest = nla_nest_start(skb, TCA_OPTIONS);
  508. if (nest == NULL)
  509. goto nla_put_failure;
  510. if (!fh) {
  511. t->tcm_handle = ~0; /* whatever ... */
  512. if (nla_put_u32(skb, TCA_TCINDEX_HASH, p->hash) ||
  513. nla_put_u16(skb, TCA_TCINDEX_MASK, p->mask) ||
  514. nla_put_u32(skb, TCA_TCINDEX_SHIFT, p->shift) ||
  515. nla_put_u32(skb, TCA_TCINDEX_FALL_THROUGH, p->fall_through))
  516. goto nla_put_failure;
  517. nla_nest_end(skb, nest);
  518. } else {
  519. if (p->perfect) {
  520. t->tcm_handle = r - p->perfect;
  521. } else {
  522. struct tcindex_filter *f;
  523. struct tcindex_filter __rcu **fp;
  524. int i;
  525. t->tcm_handle = 0;
  526. for (i = 0; !t->tcm_handle && i < p->hash; i++) {
  527. fp = &p->h[i];
  528. for (f = rtnl_dereference(*fp);
  529. !t->tcm_handle && f;
  530. fp = &f->next, f = rtnl_dereference(*fp)) {
  531. if (&f->result == r)
  532. t->tcm_handle = f->key;
  533. }
  534. }
  535. }
  536. pr_debug("handle = %d\n", t->tcm_handle);
  537. if (r->res.class &&
  538. nla_put_u32(skb, TCA_TCINDEX_CLASSID, r->res.classid))
  539. goto nla_put_failure;
  540. if (tcf_exts_dump(skb, &r->exts) < 0)
  541. goto nla_put_failure;
  542. nla_nest_end(skb, nest);
  543. if (tcf_exts_dump_stats(skb, &r->exts) < 0)
  544. goto nla_put_failure;
  545. }
  546. return skb->len;
  547. nla_put_failure:
  548. nla_nest_cancel(skb, nest);
  549. return -1;
  550. }
  551. static void tcindex_bind_class(void *fh, u32 classid, unsigned long cl,
  552. void *q, unsigned long base)
  553. {
  554. struct tcindex_filter_result *r = fh;
  555. if (r && r->res.classid == classid) {
  556. if (cl)
  557. __tcf_bind_filter(q, &r->res, base);
  558. else
  559. __tcf_unbind_filter(q, &r->res);
  560. }
  561. }
  562. static struct tcf_proto_ops cls_tcindex_ops __read_mostly = {
  563. .kind = "tcindex",
  564. .classify = tcindex_classify,
  565. .init = tcindex_init,
  566. .destroy = tcindex_destroy,
  567. .get = tcindex_get,
  568. .change = tcindex_change,
  569. .delete = tcindex_delete,
  570. .walk = tcindex_walk,
  571. .dump = tcindex_dump,
  572. .bind_class = tcindex_bind_class,
  573. .owner = THIS_MODULE,
  574. };
  575. static int __init init_tcindex(void)
  576. {
  577. return register_tcf_proto_ops(&cls_tcindex_ops);
  578. }
  579. static void __exit exit_tcindex(void)
  580. {
  581. unregister_tcf_proto_ops(&cls_tcindex_ops);
  582. }
  583. module_init(init_tcindex)
  584. module_exit(exit_tcindex)
  585. MODULE_LICENSE("GPL");