cls_u32.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323
  1. /*
  2. * net/sched/cls_u32.c Ugly (or Universal) 32bit key Packet Classifier.
  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. *
  11. * The filters are packed to hash tables of key nodes
  12. * with a set of 32bit key/mask pairs at every node.
  13. * Nodes reference next level hash tables etc.
  14. *
  15. * This scheme is the best universal classifier I managed to
  16. * invent; it is not super-fast, but it is not slow (provided you
  17. * program it correctly), and general enough. And its relative
  18. * speed grows as the number of rules becomes larger.
  19. *
  20. * It seems that it represents the best middle point between
  21. * speed and manageability both by human and by machine.
  22. *
  23. * It is especially useful for link sharing combined with QoS;
  24. * pure RSVP doesn't need such a general approach and can use
  25. * much simpler (and faster) schemes, sort of cls_rsvp.c.
  26. *
  27. * JHS: We should remove the CONFIG_NET_CLS_IND from here
  28. * eventually when the meta match extension is made available
  29. *
  30. * nfmark match added by Catalin(ux aka Dino) BOIE <catab at umbrella.ro>
  31. */
  32. #include <linux/module.h>
  33. #include <linux/slab.h>
  34. #include <linux/types.h>
  35. #include <linux/kernel.h>
  36. #include <linux/string.h>
  37. #include <linux/errno.h>
  38. #include <linux/percpu.h>
  39. #include <linux/rtnetlink.h>
  40. #include <linux/skbuff.h>
  41. #include <linux/bitmap.h>
  42. #include <linux/netdevice.h>
  43. #include <linux/hash.h>
  44. #include <net/netlink.h>
  45. #include <net/act_api.h>
  46. #include <net/pkt_cls.h>
  47. #include <linux/netdevice.h>
  48. struct tc_u_knode {
  49. struct tc_u_knode __rcu *next;
  50. u32 handle;
  51. struct tc_u_hnode __rcu *ht_up;
  52. struct tcf_exts exts;
  53. #ifdef CONFIG_NET_CLS_IND
  54. int ifindex;
  55. #endif
  56. u8 fshift;
  57. struct tcf_result res;
  58. struct tc_u_hnode __rcu *ht_down;
  59. #ifdef CONFIG_CLS_U32_PERF
  60. struct tc_u32_pcnt __percpu *pf;
  61. #endif
  62. u32 flags;
  63. #ifdef CONFIG_CLS_U32_MARK
  64. u32 val;
  65. u32 mask;
  66. u32 __percpu *pcpu_success;
  67. #endif
  68. struct tcf_proto *tp;
  69. union {
  70. struct work_struct work;
  71. struct rcu_head rcu;
  72. };
  73. /* The 'sel' field MUST be the last field in structure to allow for
  74. * tc_u32_keys allocated at end of structure.
  75. */
  76. struct tc_u32_sel sel;
  77. };
  78. struct tc_u_hnode {
  79. struct tc_u_hnode __rcu *next;
  80. u32 handle;
  81. u32 prio;
  82. struct tc_u_common *tp_c;
  83. int refcnt;
  84. unsigned int divisor;
  85. struct rcu_head rcu;
  86. /* The 'ht' field MUST be the last field in structure to allow for
  87. * more entries allocated at end of structure.
  88. */
  89. struct tc_u_knode __rcu *ht[1];
  90. };
  91. struct tc_u_common {
  92. struct tc_u_hnode __rcu *hlist;
  93. struct Qdisc *q;
  94. int refcnt;
  95. u32 hgenerator;
  96. struct hlist_node hnode;
  97. struct rcu_head rcu;
  98. };
  99. static inline unsigned int u32_hash_fold(__be32 key,
  100. const struct tc_u32_sel *sel,
  101. u8 fshift)
  102. {
  103. unsigned int h = ntohl(key & sel->hmask) >> fshift;
  104. return h;
  105. }
  106. static int u32_classify(struct sk_buff *skb, const struct tcf_proto *tp,
  107. struct tcf_result *res)
  108. {
  109. struct {
  110. struct tc_u_knode *knode;
  111. unsigned int off;
  112. } stack[TC_U32_MAXDEPTH];
  113. struct tc_u_hnode *ht = rcu_dereference_bh(tp->root);
  114. unsigned int off = skb_network_offset(skb);
  115. struct tc_u_knode *n;
  116. int sdepth = 0;
  117. int off2 = 0;
  118. int sel = 0;
  119. #ifdef CONFIG_CLS_U32_PERF
  120. int j;
  121. #endif
  122. int i, r;
  123. next_ht:
  124. n = rcu_dereference_bh(ht->ht[sel]);
  125. next_knode:
  126. if (n) {
  127. struct tc_u32_key *key = n->sel.keys;
  128. #ifdef CONFIG_CLS_U32_PERF
  129. __this_cpu_inc(n->pf->rcnt);
  130. j = 0;
  131. #endif
  132. if (tc_skip_sw(n->flags)) {
  133. n = rcu_dereference_bh(n->next);
  134. goto next_knode;
  135. }
  136. #ifdef CONFIG_CLS_U32_MARK
  137. if ((skb->mark & n->mask) != n->val) {
  138. n = rcu_dereference_bh(n->next);
  139. goto next_knode;
  140. } else {
  141. __this_cpu_inc(*n->pcpu_success);
  142. }
  143. #endif
  144. for (i = n->sel.nkeys; i > 0; i--, key++) {
  145. int toff = off + key->off + (off2 & key->offmask);
  146. __be32 *data, hdata;
  147. if (skb_headroom(skb) + toff > INT_MAX)
  148. goto out;
  149. data = skb_header_pointer(skb, toff, 4, &hdata);
  150. if (!data)
  151. goto out;
  152. if ((*data ^ key->val) & key->mask) {
  153. n = rcu_dereference_bh(n->next);
  154. goto next_knode;
  155. }
  156. #ifdef CONFIG_CLS_U32_PERF
  157. __this_cpu_inc(n->pf->kcnts[j]);
  158. j++;
  159. #endif
  160. }
  161. ht = rcu_dereference_bh(n->ht_down);
  162. if (!ht) {
  163. check_terminal:
  164. if (n->sel.flags & TC_U32_TERMINAL) {
  165. *res = n->res;
  166. #ifdef CONFIG_NET_CLS_IND
  167. if (!tcf_match_indev(skb, n->ifindex)) {
  168. n = rcu_dereference_bh(n->next);
  169. goto next_knode;
  170. }
  171. #endif
  172. #ifdef CONFIG_CLS_U32_PERF
  173. __this_cpu_inc(n->pf->rhit);
  174. #endif
  175. r = tcf_exts_exec(skb, &n->exts, res);
  176. if (r < 0) {
  177. n = rcu_dereference_bh(n->next);
  178. goto next_knode;
  179. }
  180. return r;
  181. }
  182. n = rcu_dereference_bh(n->next);
  183. goto next_knode;
  184. }
  185. /* PUSH */
  186. if (sdepth >= TC_U32_MAXDEPTH)
  187. goto deadloop;
  188. stack[sdepth].knode = n;
  189. stack[sdepth].off = off;
  190. sdepth++;
  191. ht = rcu_dereference_bh(n->ht_down);
  192. sel = 0;
  193. if (ht->divisor) {
  194. __be32 *data, hdata;
  195. data = skb_header_pointer(skb, off + n->sel.hoff, 4,
  196. &hdata);
  197. if (!data)
  198. goto out;
  199. sel = ht->divisor & u32_hash_fold(*data, &n->sel,
  200. n->fshift);
  201. }
  202. if (!(n->sel.flags & (TC_U32_VAROFFSET | TC_U32_OFFSET | TC_U32_EAT)))
  203. goto next_ht;
  204. if (n->sel.flags & (TC_U32_OFFSET | TC_U32_VAROFFSET)) {
  205. off2 = n->sel.off + 3;
  206. if (n->sel.flags & TC_U32_VAROFFSET) {
  207. __be16 *data, hdata;
  208. data = skb_header_pointer(skb,
  209. off + n->sel.offoff,
  210. 2, &hdata);
  211. if (!data)
  212. goto out;
  213. off2 += ntohs(n->sel.offmask & *data) >>
  214. n->sel.offshift;
  215. }
  216. off2 &= ~3;
  217. }
  218. if (n->sel.flags & TC_U32_EAT) {
  219. off += off2;
  220. off2 = 0;
  221. }
  222. if (off < skb->len)
  223. goto next_ht;
  224. }
  225. /* POP */
  226. if (sdepth--) {
  227. n = stack[sdepth].knode;
  228. ht = rcu_dereference_bh(n->ht_up);
  229. off = stack[sdepth].off;
  230. goto check_terminal;
  231. }
  232. out:
  233. return -1;
  234. deadloop:
  235. net_warn_ratelimited("cls_u32: dead loop\n");
  236. return -1;
  237. }
  238. static struct tc_u_hnode *u32_lookup_ht(struct tc_u_common *tp_c, u32 handle)
  239. {
  240. struct tc_u_hnode *ht;
  241. for (ht = rtnl_dereference(tp_c->hlist);
  242. ht;
  243. ht = rtnl_dereference(ht->next))
  244. if (ht->handle == handle)
  245. break;
  246. return ht;
  247. }
  248. static struct tc_u_knode *u32_lookup_key(struct tc_u_hnode *ht, u32 handle)
  249. {
  250. unsigned int sel;
  251. struct tc_u_knode *n = NULL;
  252. sel = TC_U32_HASH(handle);
  253. if (sel > ht->divisor)
  254. goto out;
  255. for (n = rtnl_dereference(ht->ht[sel]);
  256. n;
  257. n = rtnl_dereference(n->next))
  258. if (n->handle == handle)
  259. break;
  260. out:
  261. return n;
  262. }
  263. static void *u32_get(struct tcf_proto *tp, u32 handle)
  264. {
  265. struct tc_u_hnode *ht;
  266. struct tc_u_common *tp_c = tp->data;
  267. if (TC_U32_HTID(handle) == TC_U32_ROOT)
  268. ht = rtnl_dereference(tp->root);
  269. else
  270. ht = u32_lookup_ht(tp_c, TC_U32_HTID(handle));
  271. if (!ht)
  272. return NULL;
  273. if (TC_U32_KEY(handle) == 0)
  274. return ht;
  275. return u32_lookup_key(ht, handle);
  276. }
  277. static u32 gen_new_htid(struct tc_u_common *tp_c)
  278. {
  279. int i = 0x800;
  280. /* hgenerator only used inside rtnl lock it is safe to increment
  281. * without read _copy_ update semantics
  282. */
  283. do {
  284. if (++tp_c->hgenerator == 0x7FF)
  285. tp_c->hgenerator = 1;
  286. } while (--i > 0 && u32_lookup_ht(tp_c, (tp_c->hgenerator|0x800)<<20));
  287. return i > 0 ? (tp_c->hgenerator|0x800)<<20 : 0;
  288. }
  289. static struct hlist_head *tc_u_common_hash;
  290. #define U32_HASH_SHIFT 10
  291. #define U32_HASH_SIZE (1 << U32_HASH_SHIFT)
  292. static unsigned int tc_u_hash(const struct tcf_proto *tp)
  293. {
  294. struct net_device *dev = tp->q->dev_queue->dev;
  295. u32 qhandle = tp->q->handle;
  296. int ifindex = dev->ifindex;
  297. return hash_64((u64)ifindex << 32 | qhandle, U32_HASH_SHIFT);
  298. }
  299. static struct tc_u_common *tc_u_common_find(const struct tcf_proto *tp)
  300. {
  301. struct tc_u_common *tc;
  302. unsigned int h;
  303. h = tc_u_hash(tp);
  304. hlist_for_each_entry(tc, &tc_u_common_hash[h], hnode) {
  305. if (tc->q == tp->q)
  306. return tc;
  307. }
  308. return NULL;
  309. }
  310. static int u32_init(struct tcf_proto *tp)
  311. {
  312. struct tc_u_hnode *root_ht;
  313. struct tc_u_common *tp_c;
  314. unsigned int h;
  315. tp_c = tc_u_common_find(tp);
  316. root_ht = kzalloc(sizeof(*root_ht), GFP_KERNEL);
  317. if (root_ht == NULL)
  318. return -ENOBUFS;
  319. root_ht->refcnt++;
  320. root_ht->handle = tp_c ? gen_new_htid(tp_c) : 0x80000000;
  321. root_ht->prio = tp->prio;
  322. if (tp_c == NULL) {
  323. tp_c = kzalloc(sizeof(*tp_c), GFP_KERNEL);
  324. if (tp_c == NULL) {
  325. kfree(root_ht);
  326. return -ENOBUFS;
  327. }
  328. tp_c->q = tp->q;
  329. INIT_HLIST_NODE(&tp_c->hnode);
  330. h = tc_u_hash(tp);
  331. hlist_add_head(&tp_c->hnode, &tc_u_common_hash[h]);
  332. }
  333. tp_c->refcnt++;
  334. RCU_INIT_POINTER(root_ht->next, tp_c->hlist);
  335. rcu_assign_pointer(tp_c->hlist, root_ht);
  336. root_ht->tp_c = tp_c;
  337. rcu_assign_pointer(tp->root, root_ht);
  338. tp->data = tp_c;
  339. return 0;
  340. }
  341. static int u32_destroy_key(struct tcf_proto *tp, struct tc_u_knode *n,
  342. bool free_pf)
  343. {
  344. tcf_exts_destroy(&n->exts);
  345. tcf_exts_put_net(&n->exts);
  346. if (n->ht_down)
  347. n->ht_down->refcnt--;
  348. #ifdef CONFIG_CLS_U32_PERF
  349. if (free_pf)
  350. free_percpu(n->pf);
  351. #endif
  352. #ifdef CONFIG_CLS_U32_MARK
  353. if (free_pf)
  354. free_percpu(n->pcpu_success);
  355. #endif
  356. kfree(n);
  357. return 0;
  358. }
  359. /* u32_delete_key_rcu should be called when free'ing a copied
  360. * version of a tc_u_knode obtained from u32_init_knode(). When
  361. * copies are obtained from u32_init_knode() the statistics are
  362. * shared between the old and new copies to allow readers to
  363. * continue to update the statistics during the copy. To support
  364. * this the u32_delete_key_rcu variant does not free the percpu
  365. * statistics.
  366. */
  367. static void u32_delete_key_work(struct work_struct *work)
  368. {
  369. struct tc_u_knode *key = container_of(work, struct tc_u_knode, work);
  370. rtnl_lock();
  371. u32_destroy_key(key->tp, key, false);
  372. rtnl_unlock();
  373. }
  374. static void u32_delete_key_rcu(struct rcu_head *rcu)
  375. {
  376. struct tc_u_knode *key = container_of(rcu, struct tc_u_knode, rcu);
  377. INIT_WORK(&key->work, u32_delete_key_work);
  378. tcf_queue_work(&key->work);
  379. }
  380. /* u32_delete_key_freepf_rcu is the rcu callback variant
  381. * that free's the entire structure including the statistics
  382. * percpu variables. Only use this if the key is not a copy
  383. * returned by u32_init_knode(). See u32_delete_key_rcu()
  384. * for the variant that should be used with keys return from
  385. * u32_init_knode()
  386. */
  387. static void u32_delete_key_freepf_work(struct work_struct *work)
  388. {
  389. struct tc_u_knode *key = container_of(work, struct tc_u_knode, work);
  390. rtnl_lock();
  391. u32_destroy_key(key->tp, key, true);
  392. rtnl_unlock();
  393. }
  394. static void u32_delete_key_freepf_rcu(struct rcu_head *rcu)
  395. {
  396. struct tc_u_knode *key = container_of(rcu, struct tc_u_knode, rcu);
  397. INIT_WORK(&key->work, u32_delete_key_freepf_work);
  398. tcf_queue_work(&key->work);
  399. }
  400. static int u32_delete_key(struct tcf_proto *tp, struct tc_u_knode *key)
  401. {
  402. struct tc_u_knode __rcu **kp;
  403. struct tc_u_knode *pkp;
  404. struct tc_u_hnode *ht = rtnl_dereference(key->ht_up);
  405. if (ht) {
  406. kp = &ht->ht[TC_U32_HASH(key->handle)];
  407. for (pkp = rtnl_dereference(*kp); pkp;
  408. kp = &pkp->next, pkp = rtnl_dereference(*kp)) {
  409. if (pkp == key) {
  410. RCU_INIT_POINTER(*kp, key->next);
  411. tcf_unbind_filter(tp, &key->res);
  412. tcf_exts_get_net(&key->exts);
  413. call_rcu(&key->rcu, u32_delete_key_freepf_rcu);
  414. return 0;
  415. }
  416. }
  417. }
  418. WARN_ON(1);
  419. return 0;
  420. }
  421. static void u32_remove_hw_knode(struct tcf_proto *tp, u32 handle)
  422. {
  423. struct net_device *dev = tp->q->dev_queue->dev;
  424. struct tc_cls_u32_offload cls_u32 = {};
  425. if (!tc_should_offload(dev, 0))
  426. return;
  427. tc_cls_common_offload_init(&cls_u32.common, tp);
  428. cls_u32.command = TC_CLSU32_DELETE_KNODE;
  429. cls_u32.knode.handle = handle;
  430. dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_CLSU32, &cls_u32);
  431. }
  432. static int u32_replace_hw_hnode(struct tcf_proto *tp, struct tc_u_hnode *h,
  433. u32 flags)
  434. {
  435. struct net_device *dev = tp->q->dev_queue->dev;
  436. struct tc_cls_u32_offload cls_u32 = {};
  437. int err;
  438. if (!tc_should_offload(dev, flags))
  439. return tc_skip_sw(flags) ? -EINVAL : 0;
  440. tc_cls_common_offload_init(&cls_u32.common, tp);
  441. cls_u32.command = TC_CLSU32_NEW_HNODE;
  442. cls_u32.hnode.divisor = h->divisor;
  443. cls_u32.hnode.handle = h->handle;
  444. cls_u32.hnode.prio = h->prio;
  445. err = dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_CLSU32, &cls_u32);
  446. if (tc_skip_sw(flags))
  447. return err;
  448. return 0;
  449. }
  450. static void u32_clear_hw_hnode(struct tcf_proto *tp, struct tc_u_hnode *h)
  451. {
  452. struct net_device *dev = tp->q->dev_queue->dev;
  453. struct tc_cls_u32_offload cls_u32 = {};
  454. if (!tc_should_offload(dev, 0))
  455. return;
  456. tc_cls_common_offload_init(&cls_u32.common, tp);
  457. cls_u32.command = TC_CLSU32_DELETE_HNODE;
  458. cls_u32.hnode.divisor = h->divisor;
  459. cls_u32.hnode.handle = h->handle;
  460. cls_u32.hnode.prio = h->prio;
  461. dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_CLSU32, &cls_u32);
  462. }
  463. static int u32_replace_hw_knode(struct tcf_proto *tp, struct tc_u_knode *n,
  464. u32 flags)
  465. {
  466. struct net_device *dev = tp->q->dev_queue->dev;
  467. struct tc_cls_u32_offload cls_u32 = {};
  468. int err;
  469. if (!tc_should_offload(dev, flags))
  470. return tc_skip_sw(flags) ? -EINVAL : 0;
  471. tc_cls_common_offload_init(&cls_u32.common, tp);
  472. cls_u32.command = TC_CLSU32_REPLACE_KNODE;
  473. cls_u32.knode.handle = n->handle;
  474. cls_u32.knode.fshift = n->fshift;
  475. #ifdef CONFIG_CLS_U32_MARK
  476. cls_u32.knode.val = n->val;
  477. cls_u32.knode.mask = n->mask;
  478. #else
  479. cls_u32.knode.val = 0;
  480. cls_u32.knode.mask = 0;
  481. #endif
  482. cls_u32.knode.sel = &n->sel;
  483. cls_u32.knode.exts = &n->exts;
  484. if (n->ht_down)
  485. cls_u32.knode.link_handle = n->ht_down->handle;
  486. err = dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_CLSU32, &cls_u32);
  487. if (!err)
  488. n->flags |= TCA_CLS_FLAGS_IN_HW;
  489. if (tc_skip_sw(flags))
  490. return err;
  491. return 0;
  492. }
  493. static void u32_clear_hnode(struct tcf_proto *tp, struct tc_u_hnode *ht)
  494. {
  495. struct tc_u_knode *n;
  496. unsigned int h;
  497. for (h = 0; h <= ht->divisor; h++) {
  498. while ((n = rtnl_dereference(ht->ht[h])) != NULL) {
  499. RCU_INIT_POINTER(ht->ht[h],
  500. rtnl_dereference(n->next));
  501. tcf_unbind_filter(tp, &n->res);
  502. u32_remove_hw_knode(tp, n->handle);
  503. if (tcf_exts_get_net(&n->exts))
  504. call_rcu(&n->rcu, u32_delete_key_freepf_rcu);
  505. else
  506. u32_destroy_key(n->tp, n, true);
  507. }
  508. }
  509. }
  510. static int u32_destroy_hnode(struct tcf_proto *tp, struct tc_u_hnode *ht)
  511. {
  512. struct tc_u_common *tp_c = tp->data;
  513. struct tc_u_hnode __rcu **hn;
  514. struct tc_u_hnode *phn;
  515. WARN_ON(ht->refcnt);
  516. u32_clear_hnode(tp, ht);
  517. hn = &tp_c->hlist;
  518. for (phn = rtnl_dereference(*hn);
  519. phn;
  520. hn = &phn->next, phn = rtnl_dereference(*hn)) {
  521. if (phn == ht) {
  522. u32_clear_hw_hnode(tp, ht);
  523. RCU_INIT_POINTER(*hn, ht->next);
  524. kfree_rcu(ht, rcu);
  525. return 0;
  526. }
  527. }
  528. return -ENOENT;
  529. }
  530. static bool ht_empty(struct tc_u_hnode *ht)
  531. {
  532. unsigned int h;
  533. for (h = 0; h <= ht->divisor; h++)
  534. if (rcu_access_pointer(ht->ht[h]))
  535. return false;
  536. return true;
  537. }
  538. static void u32_destroy(struct tcf_proto *tp)
  539. {
  540. struct tc_u_common *tp_c = tp->data;
  541. struct tc_u_hnode *root_ht = rtnl_dereference(tp->root);
  542. WARN_ON(root_ht == NULL);
  543. if (root_ht && --root_ht->refcnt == 0)
  544. u32_destroy_hnode(tp, root_ht);
  545. if (--tp_c->refcnt == 0) {
  546. struct tc_u_hnode *ht;
  547. hlist_del(&tp_c->hnode);
  548. for (ht = rtnl_dereference(tp_c->hlist);
  549. ht;
  550. ht = rtnl_dereference(ht->next)) {
  551. ht->refcnt--;
  552. u32_clear_hnode(tp, ht);
  553. }
  554. while ((ht = rtnl_dereference(tp_c->hlist)) != NULL) {
  555. RCU_INIT_POINTER(tp_c->hlist, ht->next);
  556. kfree_rcu(ht, rcu);
  557. }
  558. kfree(tp_c);
  559. }
  560. tp->data = NULL;
  561. }
  562. static int u32_delete(struct tcf_proto *tp, void *arg, bool *last)
  563. {
  564. struct tc_u_hnode *ht = arg;
  565. struct tc_u_hnode *root_ht = rtnl_dereference(tp->root);
  566. struct tc_u_common *tp_c = tp->data;
  567. int ret = 0;
  568. if (ht == NULL)
  569. goto out;
  570. if (TC_U32_KEY(ht->handle)) {
  571. u32_remove_hw_knode(tp, ht->handle);
  572. ret = u32_delete_key(tp, (struct tc_u_knode *)ht);
  573. goto out;
  574. }
  575. if (root_ht == ht)
  576. return -EINVAL;
  577. if (ht->refcnt == 1) {
  578. ht->refcnt--;
  579. u32_destroy_hnode(tp, ht);
  580. } else {
  581. return -EBUSY;
  582. }
  583. out:
  584. *last = true;
  585. if (root_ht) {
  586. if (root_ht->refcnt > 1) {
  587. *last = false;
  588. goto ret;
  589. }
  590. if (root_ht->refcnt == 1) {
  591. if (!ht_empty(root_ht)) {
  592. *last = false;
  593. goto ret;
  594. }
  595. }
  596. }
  597. if (tp_c->refcnt > 1) {
  598. *last = false;
  599. goto ret;
  600. }
  601. if (tp_c->refcnt == 1) {
  602. struct tc_u_hnode *ht;
  603. for (ht = rtnl_dereference(tp_c->hlist);
  604. ht;
  605. ht = rtnl_dereference(ht->next))
  606. if (!ht_empty(ht)) {
  607. *last = false;
  608. break;
  609. }
  610. }
  611. ret:
  612. return ret;
  613. }
  614. #define NR_U32_NODE (1<<12)
  615. static u32 gen_new_kid(struct tc_u_hnode *ht, u32 handle)
  616. {
  617. struct tc_u_knode *n;
  618. unsigned long i;
  619. unsigned long *bitmap = kzalloc(BITS_TO_LONGS(NR_U32_NODE) * sizeof(unsigned long),
  620. GFP_KERNEL);
  621. if (!bitmap)
  622. return handle | 0xFFF;
  623. for (n = rtnl_dereference(ht->ht[TC_U32_HASH(handle)]);
  624. n;
  625. n = rtnl_dereference(n->next))
  626. set_bit(TC_U32_NODE(n->handle), bitmap);
  627. i = find_next_zero_bit(bitmap, NR_U32_NODE, 0x800);
  628. if (i >= NR_U32_NODE)
  629. i = find_next_zero_bit(bitmap, NR_U32_NODE, 1);
  630. kfree(bitmap);
  631. return handle | (i >= NR_U32_NODE ? 0xFFF : i);
  632. }
  633. static const struct nla_policy u32_policy[TCA_U32_MAX + 1] = {
  634. [TCA_U32_CLASSID] = { .type = NLA_U32 },
  635. [TCA_U32_HASH] = { .type = NLA_U32 },
  636. [TCA_U32_LINK] = { .type = NLA_U32 },
  637. [TCA_U32_DIVISOR] = { .type = NLA_U32 },
  638. [TCA_U32_SEL] = { .len = sizeof(struct tc_u32_sel) },
  639. [TCA_U32_INDEV] = { .type = NLA_STRING, .len = IFNAMSIZ },
  640. [TCA_U32_MARK] = { .len = sizeof(struct tc_u32_mark) },
  641. [TCA_U32_FLAGS] = { .type = NLA_U32 },
  642. };
  643. static int u32_set_parms(struct net *net, struct tcf_proto *tp,
  644. unsigned long base, struct tc_u_hnode *ht,
  645. struct tc_u_knode *n, struct nlattr **tb,
  646. struct nlattr *est, bool ovr)
  647. {
  648. int err;
  649. err = tcf_exts_validate(net, tp, tb, est, &n->exts, ovr);
  650. if (err < 0)
  651. return err;
  652. if (tb[TCA_U32_LINK]) {
  653. u32 handle = nla_get_u32(tb[TCA_U32_LINK]);
  654. struct tc_u_hnode *ht_down = NULL, *ht_old;
  655. if (TC_U32_KEY(handle))
  656. return -EINVAL;
  657. if (handle) {
  658. ht_down = u32_lookup_ht(ht->tp_c, handle);
  659. if (ht_down == NULL)
  660. return -EINVAL;
  661. ht_down->refcnt++;
  662. }
  663. ht_old = rtnl_dereference(n->ht_down);
  664. rcu_assign_pointer(n->ht_down, ht_down);
  665. if (ht_old)
  666. ht_old->refcnt--;
  667. }
  668. if (tb[TCA_U32_CLASSID]) {
  669. n->res.classid = nla_get_u32(tb[TCA_U32_CLASSID]);
  670. tcf_bind_filter(tp, &n->res, base);
  671. }
  672. #ifdef CONFIG_NET_CLS_IND
  673. if (tb[TCA_U32_INDEV]) {
  674. int ret;
  675. ret = tcf_change_indev(net, tb[TCA_U32_INDEV]);
  676. if (ret < 0)
  677. return -EINVAL;
  678. n->ifindex = ret;
  679. }
  680. #endif
  681. return 0;
  682. }
  683. static void u32_replace_knode(struct tcf_proto *tp, struct tc_u_common *tp_c,
  684. struct tc_u_knode *n)
  685. {
  686. struct tc_u_knode __rcu **ins;
  687. struct tc_u_knode *pins;
  688. struct tc_u_hnode *ht;
  689. if (TC_U32_HTID(n->handle) == TC_U32_ROOT)
  690. ht = rtnl_dereference(tp->root);
  691. else
  692. ht = u32_lookup_ht(tp_c, TC_U32_HTID(n->handle));
  693. ins = &ht->ht[TC_U32_HASH(n->handle)];
  694. /* The node must always exist for it to be replaced if this is not the
  695. * case then something went very wrong elsewhere.
  696. */
  697. for (pins = rtnl_dereference(*ins); ;
  698. ins = &pins->next, pins = rtnl_dereference(*ins))
  699. if (pins->handle == n->handle)
  700. break;
  701. RCU_INIT_POINTER(n->next, pins->next);
  702. rcu_assign_pointer(*ins, n);
  703. }
  704. static struct tc_u_knode *u32_init_knode(struct tcf_proto *tp,
  705. struct tc_u_knode *n)
  706. {
  707. struct tc_u_knode *new;
  708. struct tc_u32_sel *s = &n->sel;
  709. new = kzalloc(sizeof(*n) + s->nkeys*sizeof(struct tc_u32_key),
  710. GFP_KERNEL);
  711. if (!new)
  712. return NULL;
  713. RCU_INIT_POINTER(new->next, n->next);
  714. new->handle = n->handle;
  715. RCU_INIT_POINTER(new->ht_up, n->ht_up);
  716. #ifdef CONFIG_NET_CLS_IND
  717. new->ifindex = n->ifindex;
  718. #endif
  719. new->fshift = n->fshift;
  720. new->res = n->res;
  721. new->flags = n->flags;
  722. RCU_INIT_POINTER(new->ht_down, n->ht_down);
  723. /* bump reference count as long as we hold pointer to structure */
  724. if (new->ht_down)
  725. new->ht_down->refcnt++;
  726. #ifdef CONFIG_CLS_U32_PERF
  727. /* Statistics may be incremented by readers during update
  728. * so we must keep them in tact. When the node is later destroyed
  729. * a special destroy call must be made to not free the pf memory.
  730. */
  731. new->pf = n->pf;
  732. #endif
  733. #ifdef CONFIG_CLS_U32_MARK
  734. new->val = n->val;
  735. new->mask = n->mask;
  736. /* Similarly success statistics must be moved as pointers */
  737. new->pcpu_success = n->pcpu_success;
  738. #endif
  739. new->tp = tp;
  740. memcpy(&new->sel, s, sizeof(*s) + s->nkeys*sizeof(struct tc_u32_key));
  741. if (tcf_exts_init(&new->exts, TCA_U32_ACT, TCA_U32_POLICE)) {
  742. kfree(new);
  743. return NULL;
  744. }
  745. return new;
  746. }
  747. static int u32_change(struct net *net, struct sk_buff *in_skb,
  748. struct tcf_proto *tp, unsigned long base, u32 handle,
  749. struct nlattr **tca, void **arg, bool ovr)
  750. {
  751. struct tc_u_common *tp_c = tp->data;
  752. struct tc_u_hnode *ht;
  753. struct tc_u_knode *n;
  754. struct tc_u32_sel *s;
  755. struct nlattr *opt = tca[TCA_OPTIONS];
  756. struct nlattr *tb[TCA_U32_MAX + 1];
  757. u32 htid, flags = 0;
  758. int err;
  759. #ifdef CONFIG_CLS_U32_PERF
  760. size_t size;
  761. #endif
  762. if (opt == NULL)
  763. return handle ? -EINVAL : 0;
  764. err = nla_parse_nested(tb, TCA_U32_MAX, opt, u32_policy, NULL);
  765. if (err < 0)
  766. return err;
  767. if (tb[TCA_U32_FLAGS]) {
  768. flags = nla_get_u32(tb[TCA_U32_FLAGS]);
  769. if (!tc_flags_valid(flags))
  770. return -EINVAL;
  771. }
  772. n = *arg;
  773. if (n) {
  774. struct tc_u_knode *new;
  775. if (TC_U32_KEY(n->handle) == 0)
  776. return -EINVAL;
  777. if (n->flags != flags)
  778. return -EINVAL;
  779. new = u32_init_knode(tp, n);
  780. if (!new)
  781. return -ENOMEM;
  782. err = u32_set_parms(net, tp, base,
  783. rtnl_dereference(n->ht_up), new, tb,
  784. tca[TCA_RATE], ovr);
  785. if (err) {
  786. u32_destroy_key(tp, new, false);
  787. return err;
  788. }
  789. err = u32_replace_hw_knode(tp, new, flags);
  790. if (err) {
  791. u32_destroy_key(tp, new, false);
  792. return err;
  793. }
  794. if (!tc_in_hw(new->flags))
  795. new->flags |= TCA_CLS_FLAGS_NOT_IN_HW;
  796. u32_replace_knode(tp, tp_c, new);
  797. tcf_unbind_filter(tp, &n->res);
  798. tcf_exts_get_net(&n->exts);
  799. call_rcu(&n->rcu, u32_delete_key_rcu);
  800. return 0;
  801. }
  802. if (tb[TCA_U32_DIVISOR]) {
  803. unsigned int divisor = nla_get_u32(tb[TCA_U32_DIVISOR]);
  804. if (--divisor > 0x100)
  805. return -EINVAL;
  806. if (TC_U32_KEY(handle))
  807. return -EINVAL;
  808. if (handle == 0) {
  809. handle = gen_new_htid(tp->data);
  810. if (handle == 0)
  811. return -ENOMEM;
  812. }
  813. ht = kzalloc(sizeof(*ht) + divisor*sizeof(void *), GFP_KERNEL);
  814. if (ht == NULL)
  815. return -ENOBUFS;
  816. ht->tp_c = tp_c;
  817. ht->refcnt = 1;
  818. ht->divisor = divisor;
  819. ht->handle = handle;
  820. ht->prio = tp->prio;
  821. err = u32_replace_hw_hnode(tp, ht, flags);
  822. if (err) {
  823. kfree(ht);
  824. return err;
  825. }
  826. RCU_INIT_POINTER(ht->next, tp_c->hlist);
  827. rcu_assign_pointer(tp_c->hlist, ht);
  828. *arg = ht;
  829. return 0;
  830. }
  831. if (tb[TCA_U32_HASH]) {
  832. htid = nla_get_u32(tb[TCA_U32_HASH]);
  833. if (TC_U32_HTID(htid) == TC_U32_ROOT) {
  834. ht = rtnl_dereference(tp->root);
  835. htid = ht->handle;
  836. } else {
  837. ht = u32_lookup_ht(tp->data, TC_U32_HTID(htid));
  838. if (ht == NULL)
  839. return -EINVAL;
  840. }
  841. } else {
  842. ht = rtnl_dereference(tp->root);
  843. htid = ht->handle;
  844. }
  845. if (ht->divisor < TC_U32_HASH(htid))
  846. return -EINVAL;
  847. if (handle) {
  848. if (TC_U32_HTID(handle) && TC_U32_HTID(handle^htid))
  849. return -EINVAL;
  850. handle = htid | TC_U32_NODE(handle);
  851. } else
  852. handle = gen_new_kid(ht, htid);
  853. if (tb[TCA_U32_SEL] == NULL)
  854. return -EINVAL;
  855. s = nla_data(tb[TCA_U32_SEL]);
  856. n = kzalloc(sizeof(*n) + s->nkeys*sizeof(struct tc_u32_key), GFP_KERNEL);
  857. if (n == NULL)
  858. return -ENOBUFS;
  859. #ifdef CONFIG_CLS_U32_PERF
  860. size = sizeof(struct tc_u32_pcnt) + s->nkeys * sizeof(u64);
  861. n->pf = __alloc_percpu(size, __alignof__(struct tc_u32_pcnt));
  862. if (!n->pf) {
  863. kfree(n);
  864. return -ENOBUFS;
  865. }
  866. #endif
  867. memcpy(&n->sel, s, sizeof(*s) + s->nkeys*sizeof(struct tc_u32_key));
  868. RCU_INIT_POINTER(n->ht_up, ht);
  869. n->handle = handle;
  870. n->fshift = s->hmask ? ffs(ntohl(s->hmask)) - 1 : 0;
  871. n->flags = flags;
  872. n->tp = tp;
  873. err = tcf_exts_init(&n->exts, TCA_U32_ACT, TCA_U32_POLICE);
  874. if (err < 0)
  875. goto errout;
  876. #ifdef CONFIG_CLS_U32_MARK
  877. n->pcpu_success = alloc_percpu(u32);
  878. if (!n->pcpu_success) {
  879. err = -ENOMEM;
  880. goto errout;
  881. }
  882. if (tb[TCA_U32_MARK]) {
  883. struct tc_u32_mark *mark;
  884. mark = nla_data(tb[TCA_U32_MARK]);
  885. n->val = mark->val;
  886. n->mask = mark->mask;
  887. }
  888. #endif
  889. err = u32_set_parms(net, tp, base, ht, n, tb, tca[TCA_RATE], ovr);
  890. if (err == 0) {
  891. struct tc_u_knode __rcu **ins;
  892. struct tc_u_knode *pins;
  893. err = u32_replace_hw_knode(tp, n, flags);
  894. if (err)
  895. goto errhw;
  896. if (!tc_in_hw(n->flags))
  897. n->flags |= TCA_CLS_FLAGS_NOT_IN_HW;
  898. ins = &ht->ht[TC_U32_HASH(handle)];
  899. for (pins = rtnl_dereference(*ins); pins;
  900. ins = &pins->next, pins = rtnl_dereference(*ins))
  901. if (TC_U32_NODE(handle) < TC_U32_NODE(pins->handle))
  902. break;
  903. RCU_INIT_POINTER(n->next, pins);
  904. rcu_assign_pointer(*ins, n);
  905. *arg = n;
  906. return 0;
  907. }
  908. errhw:
  909. #ifdef CONFIG_CLS_U32_MARK
  910. free_percpu(n->pcpu_success);
  911. #endif
  912. errout:
  913. tcf_exts_destroy(&n->exts);
  914. #ifdef CONFIG_CLS_U32_PERF
  915. free_percpu(n->pf);
  916. #endif
  917. kfree(n);
  918. return err;
  919. }
  920. static void u32_walk(struct tcf_proto *tp, struct tcf_walker *arg)
  921. {
  922. struct tc_u_common *tp_c = tp->data;
  923. struct tc_u_hnode *ht;
  924. struct tc_u_knode *n;
  925. unsigned int h;
  926. if (arg->stop)
  927. return;
  928. for (ht = rtnl_dereference(tp_c->hlist);
  929. ht;
  930. ht = rtnl_dereference(ht->next)) {
  931. if (ht->prio != tp->prio)
  932. continue;
  933. if (arg->count >= arg->skip) {
  934. if (arg->fn(tp, ht, arg) < 0) {
  935. arg->stop = 1;
  936. return;
  937. }
  938. }
  939. arg->count++;
  940. for (h = 0; h <= ht->divisor; h++) {
  941. for (n = rtnl_dereference(ht->ht[h]);
  942. n;
  943. n = rtnl_dereference(n->next)) {
  944. if (arg->count < arg->skip) {
  945. arg->count++;
  946. continue;
  947. }
  948. if (arg->fn(tp, n, arg) < 0) {
  949. arg->stop = 1;
  950. return;
  951. }
  952. arg->count++;
  953. }
  954. }
  955. }
  956. }
  957. static void u32_bind_class(void *fh, u32 classid, unsigned long cl)
  958. {
  959. struct tc_u_knode *n = fh;
  960. if (n && n->res.classid == classid)
  961. n->res.class = cl;
  962. }
  963. static int u32_dump(struct net *net, struct tcf_proto *tp, void *fh,
  964. struct sk_buff *skb, struct tcmsg *t)
  965. {
  966. struct tc_u_knode *n = fh;
  967. struct tc_u_hnode *ht_up, *ht_down;
  968. struct nlattr *nest;
  969. if (n == NULL)
  970. return skb->len;
  971. t->tcm_handle = n->handle;
  972. nest = nla_nest_start(skb, TCA_OPTIONS);
  973. if (nest == NULL)
  974. goto nla_put_failure;
  975. if (TC_U32_KEY(n->handle) == 0) {
  976. struct tc_u_hnode *ht = fh;
  977. u32 divisor = ht->divisor + 1;
  978. if (nla_put_u32(skb, TCA_U32_DIVISOR, divisor))
  979. goto nla_put_failure;
  980. } else {
  981. #ifdef CONFIG_CLS_U32_PERF
  982. struct tc_u32_pcnt *gpf;
  983. int cpu;
  984. #endif
  985. if (nla_put(skb, TCA_U32_SEL,
  986. sizeof(n->sel) + n->sel.nkeys*sizeof(struct tc_u32_key),
  987. &n->sel))
  988. goto nla_put_failure;
  989. ht_up = rtnl_dereference(n->ht_up);
  990. if (ht_up) {
  991. u32 htid = n->handle & 0xFFFFF000;
  992. if (nla_put_u32(skb, TCA_U32_HASH, htid))
  993. goto nla_put_failure;
  994. }
  995. if (n->res.classid &&
  996. nla_put_u32(skb, TCA_U32_CLASSID, n->res.classid))
  997. goto nla_put_failure;
  998. ht_down = rtnl_dereference(n->ht_down);
  999. if (ht_down &&
  1000. nla_put_u32(skb, TCA_U32_LINK, ht_down->handle))
  1001. goto nla_put_failure;
  1002. if (n->flags && nla_put_u32(skb, TCA_U32_FLAGS, n->flags))
  1003. goto nla_put_failure;
  1004. #ifdef CONFIG_CLS_U32_MARK
  1005. if ((n->val || n->mask)) {
  1006. struct tc_u32_mark mark = {.val = n->val,
  1007. .mask = n->mask,
  1008. .success = 0};
  1009. int cpum;
  1010. for_each_possible_cpu(cpum) {
  1011. __u32 cnt = *per_cpu_ptr(n->pcpu_success, cpum);
  1012. mark.success += cnt;
  1013. }
  1014. if (nla_put(skb, TCA_U32_MARK, sizeof(mark), &mark))
  1015. goto nla_put_failure;
  1016. }
  1017. #endif
  1018. if (tcf_exts_dump(skb, &n->exts) < 0)
  1019. goto nla_put_failure;
  1020. #ifdef CONFIG_NET_CLS_IND
  1021. if (n->ifindex) {
  1022. struct net_device *dev;
  1023. dev = __dev_get_by_index(net, n->ifindex);
  1024. if (dev && nla_put_string(skb, TCA_U32_INDEV, dev->name))
  1025. goto nla_put_failure;
  1026. }
  1027. #endif
  1028. #ifdef CONFIG_CLS_U32_PERF
  1029. gpf = kzalloc(sizeof(struct tc_u32_pcnt) +
  1030. n->sel.nkeys * sizeof(u64),
  1031. GFP_KERNEL);
  1032. if (!gpf)
  1033. goto nla_put_failure;
  1034. for_each_possible_cpu(cpu) {
  1035. int i;
  1036. struct tc_u32_pcnt *pf = per_cpu_ptr(n->pf, cpu);
  1037. gpf->rcnt += pf->rcnt;
  1038. gpf->rhit += pf->rhit;
  1039. for (i = 0; i < n->sel.nkeys; i++)
  1040. gpf->kcnts[i] += pf->kcnts[i];
  1041. }
  1042. if (nla_put_64bit(skb, TCA_U32_PCNT,
  1043. sizeof(struct tc_u32_pcnt) +
  1044. n->sel.nkeys * sizeof(u64),
  1045. gpf, TCA_U32_PAD)) {
  1046. kfree(gpf);
  1047. goto nla_put_failure;
  1048. }
  1049. kfree(gpf);
  1050. #endif
  1051. }
  1052. nla_nest_end(skb, nest);
  1053. if (TC_U32_KEY(n->handle))
  1054. if (tcf_exts_dump_stats(skb, &n->exts) < 0)
  1055. goto nla_put_failure;
  1056. return skb->len;
  1057. nla_put_failure:
  1058. nla_nest_cancel(skb, nest);
  1059. return -1;
  1060. }
  1061. static struct tcf_proto_ops cls_u32_ops __read_mostly = {
  1062. .kind = "u32",
  1063. .classify = u32_classify,
  1064. .init = u32_init,
  1065. .destroy = u32_destroy,
  1066. .get = u32_get,
  1067. .change = u32_change,
  1068. .delete = u32_delete,
  1069. .walk = u32_walk,
  1070. .dump = u32_dump,
  1071. .bind_class = u32_bind_class,
  1072. .owner = THIS_MODULE,
  1073. };
  1074. static int __init init_u32(void)
  1075. {
  1076. int i, ret;
  1077. pr_info("u32 classifier\n");
  1078. #ifdef CONFIG_CLS_U32_PERF
  1079. pr_info(" Performance counters on\n");
  1080. #endif
  1081. #ifdef CONFIG_NET_CLS_IND
  1082. pr_info(" input device check on\n");
  1083. #endif
  1084. #ifdef CONFIG_NET_CLS_ACT
  1085. pr_info(" Actions configured\n");
  1086. #endif
  1087. tc_u_common_hash = kvmalloc_array(U32_HASH_SIZE,
  1088. sizeof(struct hlist_head),
  1089. GFP_KERNEL);
  1090. if (!tc_u_common_hash)
  1091. return -ENOMEM;
  1092. for (i = 0; i < U32_HASH_SIZE; i++)
  1093. INIT_HLIST_HEAD(&tc_u_common_hash[i]);
  1094. ret = register_tcf_proto_ops(&cls_u32_ops);
  1095. if (ret)
  1096. kvfree(tc_u_common_hash);
  1097. return ret;
  1098. }
  1099. static void __exit exit_u32(void)
  1100. {
  1101. unregister_tcf_proto_ops(&cls_u32_ops);
  1102. kvfree(tc_u_common_hash);
  1103. }
  1104. module_init(init_u32)
  1105. module_exit(exit_u32)
  1106. MODULE_LICENSE("GPL");