cls_u32.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330
  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. struct tc_u_hnode *ht = rtnl_dereference(n->ht_down);
  345. tcf_exts_destroy(&n->exts);
  346. tcf_exts_put_net(&n->exts);
  347. if (ht && --ht->refcnt == 0)
  348. kfree(ht);
  349. #ifdef CONFIG_CLS_U32_PERF
  350. if (free_pf)
  351. free_percpu(n->pf);
  352. #endif
  353. #ifdef CONFIG_CLS_U32_MARK
  354. if (free_pf)
  355. free_percpu(n->pcpu_success);
  356. #endif
  357. kfree(n);
  358. return 0;
  359. }
  360. /* u32_delete_key_rcu should be called when free'ing a copied
  361. * version of a tc_u_knode obtained from u32_init_knode(). When
  362. * copies are obtained from u32_init_knode() the statistics are
  363. * shared between the old and new copies to allow readers to
  364. * continue to update the statistics during the copy. To support
  365. * this the u32_delete_key_rcu variant does not free the percpu
  366. * statistics.
  367. */
  368. static void u32_delete_key_work(struct work_struct *work)
  369. {
  370. struct tc_u_knode *key = container_of(work, struct tc_u_knode, work);
  371. rtnl_lock();
  372. u32_destroy_key(key->tp, key, false);
  373. rtnl_unlock();
  374. }
  375. static void u32_delete_key_rcu(struct rcu_head *rcu)
  376. {
  377. struct tc_u_knode *key = container_of(rcu, struct tc_u_knode, rcu);
  378. INIT_WORK(&key->work, u32_delete_key_work);
  379. tcf_queue_work(&key->work);
  380. }
  381. /* u32_delete_key_freepf_rcu is the rcu callback variant
  382. * that free's the entire structure including the statistics
  383. * percpu variables. Only use this if the key is not a copy
  384. * returned by u32_init_knode(). See u32_delete_key_rcu()
  385. * for the variant that should be used with keys return from
  386. * u32_init_knode()
  387. */
  388. static void u32_delete_key_freepf_work(struct work_struct *work)
  389. {
  390. struct tc_u_knode *key = container_of(work, struct tc_u_knode, work);
  391. rtnl_lock();
  392. u32_destroy_key(key->tp, key, true);
  393. rtnl_unlock();
  394. }
  395. static void u32_delete_key_freepf_rcu(struct rcu_head *rcu)
  396. {
  397. struct tc_u_knode *key = container_of(rcu, struct tc_u_knode, rcu);
  398. INIT_WORK(&key->work, u32_delete_key_freepf_work);
  399. tcf_queue_work(&key->work);
  400. }
  401. static int u32_delete_key(struct tcf_proto *tp, struct tc_u_knode *key)
  402. {
  403. struct tc_u_knode __rcu **kp;
  404. struct tc_u_knode *pkp;
  405. struct tc_u_hnode *ht = rtnl_dereference(key->ht_up);
  406. if (ht) {
  407. kp = &ht->ht[TC_U32_HASH(key->handle)];
  408. for (pkp = rtnl_dereference(*kp); pkp;
  409. kp = &pkp->next, pkp = rtnl_dereference(*kp)) {
  410. if (pkp == key) {
  411. RCU_INIT_POINTER(*kp, key->next);
  412. tcf_unbind_filter(tp, &key->res);
  413. tcf_exts_get_net(&key->exts);
  414. call_rcu(&key->rcu, u32_delete_key_freepf_rcu);
  415. return 0;
  416. }
  417. }
  418. }
  419. WARN_ON(1);
  420. return 0;
  421. }
  422. static void u32_remove_hw_knode(struct tcf_proto *tp, u32 handle)
  423. {
  424. struct net_device *dev = tp->q->dev_queue->dev;
  425. struct tc_cls_u32_offload cls_u32 = {};
  426. if (!tc_should_offload(dev, 0))
  427. return;
  428. tc_cls_common_offload_init(&cls_u32.common, tp);
  429. cls_u32.command = TC_CLSU32_DELETE_KNODE;
  430. cls_u32.knode.handle = handle;
  431. dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_CLSU32, &cls_u32);
  432. }
  433. static int u32_replace_hw_hnode(struct tcf_proto *tp, struct tc_u_hnode *h,
  434. u32 flags)
  435. {
  436. struct net_device *dev = tp->q->dev_queue->dev;
  437. struct tc_cls_u32_offload cls_u32 = {};
  438. int err;
  439. if (!tc_should_offload(dev, flags))
  440. return tc_skip_sw(flags) ? -EINVAL : 0;
  441. tc_cls_common_offload_init(&cls_u32.common, tp);
  442. cls_u32.command = TC_CLSU32_NEW_HNODE;
  443. cls_u32.hnode.divisor = h->divisor;
  444. cls_u32.hnode.handle = h->handle;
  445. cls_u32.hnode.prio = h->prio;
  446. err = dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_CLSU32, &cls_u32);
  447. if (tc_skip_sw(flags))
  448. return err;
  449. return 0;
  450. }
  451. static void u32_clear_hw_hnode(struct tcf_proto *tp, struct tc_u_hnode *h)
  452. {
  453. struct net_device *dev = tp->q->dev_queue->dev;
  454. struct tc_cls_u32_offload cls_u32 = {};
  455. if (!tc_should_offload(dev, 0))
  456. return;
  457. tc_cls_common_offload_init(&cls_u32.common, tp);
  458. cls_u32.command = TC_CLSU32_DELETE_HNODE;
  459. cls_u32.hnode.divisor = h->divisor;
  460. cls_u32.hnode.handle = h->handle;
  461. cls_u32.hnode.prio = h->prio;
  462. dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_CLSU32, &cls_u32);
  463. }
  464. static int u32_replace_hw_knode(struct tcf_proto *tp, struct tc_u_knode *n,
  465. u32 flags)
  466. {
  467. struct net_device *dev = tp->q->dev_queue->dev;
  468. struct tc_cls_u32_offload cls_u32 = {};
  469. int err;
  470. if (!tc_should_offload(dev, flags))
  471. return tc_skip_sw(flags) ? -EINVAL : 0;
  472. tc_cls_common_offload_init(&cls_u32.common, tp);
  473. cls_u32.command = TC_CLSU32_REPLACE_KNODE;
  474. cls_u32.knode.handle = n->handle;
  475. cls_u32.knode.fshift = n->fshift;
  476. #ifdef CONFIG_CLS_U32_MARK
  477. cls_u32.knode.val = n->val;
  478. cls_u32.knode.mask = n->mask;
  479. #else
  480. cls_u32.knode.val = 0;
  481. cls_u32.knode.mask = 0;
  482. #endif
  483. cls_u32.knode.sel = &n->sel;
  484. cls_u32.knode.exts = &n->exts;
  485. if (n->ht_down)
  486. cls_u32.knode.link_handle = n->ht_down->handle;
  487. err = dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_CLSU32, &cls_u32);
  488. if (!err)
  489. n->flags |= TCA_CLS_FLAGS_IN_HW;
  490. if (tc_skip_sw(flags))
  491. return err;
  492. return 0;
  493. }
  494. static void u32_clear_hnode(struct tcf_proto *tp, struct tc_u_hnode *ht)
  495. {
  496. struct tc_u_knode *n;
  497. unsigned int h;
  498. for (h = 0; h <= ht->divisor; h++) {
  499. while ((n = rtnl_dereference(ht->ht[h])) != NULL) {
  500. RCU_INIT_POINTER(ht->ht[h],
  501. rtnl_dereference(n->next));
  502. tcf_unbind_filter(tp, &n->res);
  503. u32_remove_hw_knode(tp, n->handle);
  504. if (tcf_exts_get_net(&n->exts))
  505. call_rcu(&n->rcu, u32_delete_key_freepf_rcu);
  506. else
  507. u32_destroy_key(n->tp, n, true);
  508. }
  509. }
  510. }
  511. static int u32_destroy_hnode(struct tcf_proto *tp, struct tc_u_hnode *ht)
  512. {
  513. struct tc_u_common *tp_c = tp->data;
  514. struct tc_u_hnode __rcu **hn;
  515. struct tc_u_hnode *phn;
  516. WARN_ON(ht->refcnt);
  517. u32_clear_hnode(tp, ht);
  518. hn = &tp_c->hlist;
  519. for (phn = rtnl_dereference(*hn);
  520. phn;
  521. hn = &phn->next, phn = rtnl_dereference(*hn)) {
  522. if (phn == ht) {
  523. u32_clear_hw_hnode(tp, ht);
  524. RCU_INIT_POINTER(*hn, ht->next);
  525. kfree_rcu(ht, rcu);
  526. return 0;
  527. }
  528. }
  529. return -ENOENT;
  530. }
  531. static bool ht_empty(struct tc_u_hnode *ht)
  532. {
  533. unsigned int h;
  534. for (h = 0; h <= ht->divisor; h++)
  535. if (rcu_access_pointer(ht->ht[h]))
  536. return false;
  537. return true;
  538. }
  539. static void u32_destroy(struct tcf_proto *tp)
  540. {
  541. struct tc_u_common *tp_c = tp->data;
  542. struct tc_u_hnode *root_ht = rtnl_dereference(tp->root);
  543. WARN_ON(root_ht == NULL);
  544. if (root_ht && --root_ht->refcnt == 0)
  545. u32_destroy_hnode(tp, root_ht);
  546. if (--tp_c->refcnt == 0) {
  547. struct tc_u_hnode *ht;
  548. hlist_del(&tp_c->hnode);
  549. while ((ht = rtnl_dereference(tp_c->hlist)) != NULL) {
  550. u32_clear_hnode(tp, ht);
  551. RCU_INIT_POINTER(tp_c->hlist, ht->next);
  552. /* u32_destroy_key() will later free ht for us, if it's
  553. * still referenced by some knode
  554. */
  555. if (--ht->refcnt == 0)
  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. size_t sel_size;
  759. int err;
  760. #ifdef CONFIG_CLS_U32_PERF
  761. size_t size;
  762. #endif
  763. if (opt == NULL)
  764. return handle ? -EINVAL : 0;
  765. err = nla_parse_nested(tb, TCA_U32_MAX, opt, u32_policy, NULL);
  766. if (err < 0)
  767. return err;
  768. if (tb[TCA_U32_FLAGS]) {
  769. flags = nla_get_u32(tb[TCA_U32_FLAGS]);
  770. if (!tc_flags_valid(flags))
  771. return -EINVAL;
  772. }
  773. n = *arg;
  774. if (n) {
  775. struct tc_u_knode *new;
  776. if (TC_U32_KEY(n->handle) == 0)
  777. return -EINVAL;
  778. if ((n->flags ^ flags) &
  779. ~(TCA_CLS_FLAGS_IN_HW | TCA_CLS_FLAGS_NOT_IN_HW))
  780. return -EINVAL;
  781. new = u32_init_knode(tp, n);
  782. if (!new)
  783. return -ENOMEM;
  784. err = u32_set_parms(net, tp, base,
  785. rtnl_dereference(n->ht_up), new, tb,
  786. tca[TCA_RATE], ovr);
  787. if (err) {
  788. u32_destroy_key(tp, new, false);
  789. return err;
  790. }
  791. err = u32_replace_hw_knode(tp, new, flags);
  792. if (err) {
  793. u32_destroy_key(tp, new, false);
  794. return err;
  795. }
  796. if (!tc_in_hw(new->flags))
  797. new->flags |= TCA_CLS_FLAGS_NOT_IN_HW;
  798. u32_replace_knode(tp, tp_c, new);
  799. tcf_unbind_filter(tp, &n->res);
  800. tcf_exts_get_net(&n->exts);
  801. call_rcu(&n->rcu, u32_delete_key_rcu);
  802. return 0;
  803. }
  804. if (tb[TCA_U32_DIVISOR]) {
  805. unsigned int divisor = nla_get_u32(tb[TCA_U32_DIVISOR]);
  806. if (--divisor > 0x100)
  807. return -EINVAL;
  808. if (TC_U32_KEY(handle))
  809. return -EINVAL;
  810. if (handle == 0) {
  811. handle = gen_new_htid(tp->data);
  812. if (handle == 0)
  813. return -ENOMEM;
  814. }
  815. ht = kzalloc(sizeof(*ht) + divisor*sizeof(void *), GFP_KERNEL);
  816. if (ht == NULL)
  817. return -ENOBUFS;
  818. ht->tp_c = tp_c;
  819. ht->refcnt = 1;
  820. ht->divisor = divisor;
  821. ht->handle = handle;
  822. ht->prio = tp->prio;
  823. err = u32_replace_hw_hnode(tp, ht, flags);
  824. if (err) {
  825. kfree(ht);
  826. return err;
  827. }
  828. RCU_INIT_POINTER(ht->next, tp_c->hlist);
  829. rcu_assign_pointer(tp_c->hlist, ht);
  830. *arg = ht;
  831. return 0;
  832. }
  833. if (tb[TCA_U32_HASH]) {
  834. htid = nla_get_u32(tb[TCA_U32_HASH]);
  835. if (TC_U32_HTID(htid) == TC_U32_ROOT) {
  836. ht = rtnl_dereference(tp->root);
  837. htid = ht->handle;
  838. } else {
  839. ht = u32_lookup_ht(tp->data, TC_U32_HTID(htid));
  840. if (ht == NULL)
  841. return -EINVAL;
  842. }
  843. } else {
  844. ht = rtnl_dereference(tp->root);
  845. htid = ht->handle;
  846. }
  847. if (ht->divisor < TC_U32_HASH(htid))
  848. return -EINVAL;
  849. if (handle) {
  850. if (TC_U32_HTID(handle) && TC_U32_HTID(handle^htid))
  851. return -EINVAL;
  852. handle = htid | TC_U32_NODE(handle);
  853. } else
  854. handle = gen_new_kid(ht, htid);
  855. if (tb[TCA_U32_SEL] == NULL)
  856. return -EINVAL;
  857. s = nla_data(tb[TCA_U32_SEL]);
  858. sel_size = sizeof(*s) + sizeof(*s->keys) * s->nkeys;
  859. if (nla_len(tb[TCA_U32_SEL]) < sel_size)
  860. return -EINVAL;
  861. n = kzalloc(offsetof(typeof(*n), sel) + sel_size, GFP_KERNEL);
  862. if (n == NULL)
  863. return -ENOBUFS;
  864. #ifdef CONFIG_CLS_U32_PERF
  865. size = sizeof(struct tc_u32_pcnt) + s->nkeys * sizeof(u64);
  866. n->pf = __alloc_percpu(size, __alignof__(struct tc_u32_pcnt));
  867. if (!n->pf) {
  868. kfree(n);
  869. return -ENOBUFS;
  870. }
  871. #endif
  872. memcpy(&n->sel, s, sel_size);
  873. RCU_INIT_POINTER(n->ht_up, ht);
  874. n->handle = handle;
  875. n->fshift = s->hmask ? ffs(ntohl(s->hmask)) - 1 : 0;
  876. n->flags = flags;
  877. n->tp = tp;
  878. err = tcf_exts_init(&n->exts, TCA_U32_ACT, TCA_U32_POLICE);
  879. if (err < 0)
  880. goto errout;
  881. #ifdef CONFIG_CLS_U32_MARK
  882. n->pcpu_success = alloc_percpu(u32);
  883. if (!n->pcpu_success) {
  884. err = -ENOMEM;
  885. goto errout;
  886. }
  887. if (tb[TCA_U32_MARK]) {
  888. struct tc_u32_mark *mark;
  889. mark = nla_data(tb[TCA_U32_MARK]);
  890. n->val = mark->val;
  891. n->mask = mark->mask;
  892. }
  893. #endif
  894. err = u32_set_parms(net, tp, base, ht, n, tb, tca[TCA_RATE], ovr);
  895. if (err == 0) {
  896. struct tc_u_knode __rcu **ins;
  897. struct tc_u_knode *pins;
  898. err = u32_replace_hw_knode(tp, n, flags);
  899. if (err)
  900. goto errhw;
  901. if (!tc_in_hw(n->flags))
  902. n->flags |= TCA_CLS_FLAGS_NOT_IN_HW;
  903. ins = &ht->ht[TC_U32_HASH(handle)];
  904. for (pins = rtnl_dereference(*ins); pins;
  905. ins = &pins->next, pins = rtnl_dereference(*ins))
  906. if (TC_U32_NODE(handle) < TC_U32_NODE(pins->handle))
  907. break;
  908. RCU_INIT_POINTER(n->next, pins);
  909. rcu_assign_pointer(*ins, n);
  910. *arg = n;
  911. return 0;
  912. }
  913. errhw:
  914. #ifdef CONFIG_CLS_U32_MARK
  915. free_percpu(n->pcpu_success);
  916. #endif
  917. errout:
  918. tcf_exts_destroy(&n->exts);
  919. #ifdef CONFIG_CLS_U32_PERF
  920. free_percpu(n->pf);
  921. #endif
  922. kfree(n);
  923. return err;
  924. }
  925. static void u32_walk(struct tcf_proto *tp, struct tcf_walker *arg)
  926. {
  927. struct tc_u_common *tp_c = tp->data;
  928. struct tc_u_hnode *ht;
  929. struct tc_u_knode *n;
  930. unsigned int h;
  931. if (arg->stop)
  932. return;
  933. for (ht = rtnl_dereference(tp_c->hlist);
  934. ht;
  935. ht = rtnl_dereference(ht->next)) {
  936. if (ht->prio != tp->prio)
  937. continue;
  938. if (arg->count >= arg->skip) {
  939. if (arg->fn(tp, ht, arg) < 0) {
  940. arg->stop = 1;
  941. return;
  942. }
  943. }
  944. arg->count++;
  945. for (h = 0; h <= ht->divisor; h++) {
  946. for (n = rtnl_dereference(ht->ht[h]);
  947. n;
  948. n = rtnl_dereference(n->next)) {
  949. if (arg->count < arg->skip) {
  950. arg->count++;
  951. continue;
  952. }
  953. if (arg->fn(tp, n, arg) < 0) {
  954. arg->stop = 1;
  955. return;
  956. }
  957. arg->count++;
  958. }
  959. }
  960. }
  961. }
  962. static void u32_bind_class(void *fh, u32 classid, unsigned long cl)
  963. {
  964. struct tc_u_knode *n = fh;
  965. if (n && n->res.classid == classid)
  966. n->res.class = cl;
  967. }
  968. static int u32_dump(struct net *net, struct tcf_proto *tp, void *fh,
  969. struct sk_buff *skb, struct tcmsg *t)
  970. {
  971. struct tc_u_knode *n = fh;
  972. struct tc_u_hnode *ht_up, *ht_down;
  973. struct nlattr *nest;
  974. if (n == NULL)
  975. return skb->len;
  976. t->tcm_handle = n->handle;
  977. nest = nla_nest_start(skb, TCA_OPTIONS);
  978. if (nest == NULL)
  979. goto nla_put_failure;
  980. if (TC_U32_KEY(n->handle) == 0) {
  981. struct tc_u_hnode *ht = fh;
  982. u32 divisor = ht->divisor + 1;
  983. if (nla_put_u32(skb, TCA_U32_DIVISOR, divisor))
  984. goto nla_put_failure;
  985. } else {
  986. #ifdef CONFIG_CLS_U32_PERF
  987. struct tc_u32_pcnt *gpf;
  988. int cpu;
  989. #endif
  990. if (nla_put(skb, TCA_U32_SEL,
  991. sizeof(n->sel) + n->sel.nkeys*sizeof(struct tc_u32_key),
  992. &n->sel))
  993. goto nla_put_failure;
  994. ht_up = rtnl_dereference(n->ht_up);
  995. if (ht_up) {
  996. u32 htid = n->handle & 0xFFFFF000;
  997. if (nla_put_u32(skb, TCA_U32_HASH, htid))
  998. goto nla_put_failure;
  999. }
  1000. if (n->res.classid &&
  1001. nla_put_u32(skb, TCA_U32_CLASSID, n->res.classid))
  1002. goto nla_put_failure;
  1003. ht_down = rtnl_dereference(n->ht_down);
  1004. if (ht_down &&
  1005. nla_put_u32(skb, TCA_U32_LINK, ht_down->handle))
  1006. goto nla_put_failure;
  1007. if (n->flags && nla_put_u32(skb, TCA_U32_FLAGS, n->flags))
  1008. goto nla_put_failure;
  1009. #ifdef CONFIG_CLS_U32_MARK
  1010. if ((n->val || n->mask)) {
  1011. struct tc_u32_mark mark = {.val = n->val,
  1012. .mask = n->mask,
  1013. .success = 0};
  1014. int cpum;
  1015. for_each_possible_cpu(cpum) {
  1016. __u32 cnt = *per_cpu_ptr(n->pcpu_success, cpum);
  1017. mark.success += cnt;
  1018. }
  1019. if (nla_put(skb, TCA_U32_MARK, sizeof(mark), &mark))
  1020. goto nla_put_failure;
  1021. }
  1022. #endif
  1023. if (tcf_exts_dump(skb, &n->exts) < 0)
  1024. goto nla_put_failure;
  1025. #ifdef CONFIG_NET_CLS_IND
  1026. if (n->ifindex) {
  1027. struct net_device *dev;
  1028. dev = __dev_get_by_index(net, n->ifindex);
  1029. if (dev && nla_put_string(skb, TCA_U32_INDEV, dev->name))
  1030. goto nla_put_failure;
  1031. }
  1032. #endif
  1033. #ifdef CONFIG_CLS_U32_PERF
  1034. gpf = kzalloc(sizeof(struct tc_u32_pcnt) +
  1035. n->sel.nkeys * sizeof(u64),
  1036. GFP_KERNEL);
  1037. if (!gpf)
  1038. goto nla_put_failure;
  1039. for_each_possible_cpu(cpu) {
  1040. int i;
  1041. struct tc_u32_pcnt *pf = per_cpu_ptr(n->pf, cpu);
  1042. gpf->rcnt += pf->rcnt;
  1043. gpf->rhit += pf->rhit;
  1044. for (i = 0; i < n->sel.nkeys; i++)
  1045. gpf->kcnts[i] += pf->kcnts[i];
  1046. }
  1047. if (nla_put_64bit(skb, TCA_U32_PCNT,
  1048. sizeof(struct tc_u32_pcnt) +
  1049. n->sel.nkeys * sizeof(u64),
  1050. gpf, TCA_U32_PAD)) {
  1051. kfree(gpf);
  1052. goto nla_put_failure;
  1053. }
  1054. kfree(gpf);
  1055. #endif
  1056. }
  1057. nla_nest_end(skb, nest);
  1058. if (TC_U32_KEY(n->handle))
  1059. if (tcf_exts_dump_stats(skb, &n->exts) < 0)
  1060. goto nla_put_failure;
  1061. return skb->len;
  1062. nla_put_failure:
  1063. nla_nest_cancel(skb, nest);
  1064. return -1;
  1065. }
  1066. static struct tcf_proto_ops cls_u32_ops __read_mostly = {
  1067. .kind = "u32",
  1068. .classify = u32_classify,
  1069. .init = u32_init,
  1070. .destroy = u32_destroy,
  1071. .get = u32_get,
  1072. .change = u32_change,
  1073. .delete = u32_delete,
  1074. .walk = u32_walk,
  1075. .dump = u32_dump,
  1076. .bind_class = u32_bind_class,
  1077. .owner = THIS_MODULE,
  1078. };
  1079. static int __init init_u32(void)
  1080. {
  1081. int i, ret;
  1082. pr_info("u32 classifier\n");
  1083. #ifdef CONFIG_CLS_U32_PERF
  1084. pr_info(" Performance counters on\n");
  1085. #endif
  1086. #ifdef CONFIG_NET_CLS_IND
  1087. pr_info(" input device check on\n");
  1088. #endif
  1089. #ifdef CONFIG_NET_CLS_ACT
  1090. pr_info(" Actions configured\n");
  1091. #endif
  1092. tc_u_common_hash = kvmalloc_array(U32_HASH_SIZE,
  1093. sizeof(struct hlist_head),
  1094. GFP_KERNEL);
  1095. if (!tc_u_common_hash)
  1096. return -ENOMEM;
  1097. for (i = 0; i < U32_HASH_SIZE; i++)
  1098. INIT_HLIST_HEAD(&tc_u_common_hash[i]);
  1099. ret = register_tcf_proto_ops(&cls_u32_ops);
  1100. if (ret)
  1101. kvfree(tc_u_common_hash);
  1102. return ret;
  1103. }
  1104. static void __exit exit_u32(void)
  1105. {
  1106. unregister_tcf_proto_ops(&cls_u32_ops);
  1107. kvfree(tc_u_common_hash);
  1108. }
  1109. module_init(init_u32)
  1110. module_exit(exit_u32)
  1111. MODULE_LICENSE("GPL");