cls_tcindex.c 16 KB

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