act_csum.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. /*
  2. * Checksum updating actions
  3. *
  4. * Copyright (c) 2010 Gregoire Baron <baronchon@n7mm.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the Free
  8. * Software Foundation; either version 2 of the License, or (at your option)
  9. * any later version.
  10. *
  11. */
  12. #include <linux/types.h>
  13. #include <linux/init.h>
  14. #include <linux/kernel.h>
  15. #include <linux/module.h>
  16. #include <linux/spinlock.h>
  17. #include <linux/netlink.h>
  18. #include <net/netlink.h>
  19. #include <linux/rtnetlink.h>
  20. #include <linux/skbuff.h>
  21. #include <net/ip.h>
  22. #include <net/ipv6.h>
  23. #include <net/icmp.h>
  24. #include <linux/icmpv6.h>
  25. #include <linux/igmp.h>
  26. #include <net/tcp.h>
  27. #include <net/udp.h>
  28. #include <net/ip6_checksum.h>
  29. #include <net/sctp/checksum.h>
  30. #include <net/act_api.h>
  31. #include <linux/tc_act/tc_csum.h>
  32. #include <net/tc_act/tc_csum.h>
  33. static const struct nla_policy csum_policy[TCA_CSUM_MAX + 1] = {
  34. [TCA_CSUM_PARMS] = { .len = sizeof(struct tc_csum), },
  35. };
  36. static unsigned int csum_net_id;
  37. static struct tc_action_ops act_csum_ops;
  38. static int tcf_csum_init(struct net *net, struct nlattr *nla,
  39. struct nlattr *est, struct tc_action **a, int ovr,
  40. int bind, struct netlink_ext_ack *extack)
  41. {
  42. struct tc_action_net *tn = net_generic(net, csum_net_id);
  43. struct tcf_csum_params *params_old, *params_new;
  44. struct nlattr *tb[TCA_CSUM_MAX + 1];
  45. struct tc_csum *parm;
  46. struct tcf_csum *p;
  47. int ret = 0, err;
  48. if (nla == NULL)
  49. return -EINVAL;
  50. err = nla_parse_nested(tb, TCA_CSUM_MAX, nla, csum_policy, NULL);
  51. if (err < 0)
  52. return err;
  53. if (tb[TCA_CSUM_PARMS] == NULL)
  54. return -EINVAL;
  55. parm = nla_data(tb[TCA_CSUM_PARMS]);
  56. if (!tcf_idr_check(tn, parm->index, a, bind)) {
  57. ret = tcf_idr_create(tn, parm->index, est, a,
  58. &act_csum_ops, bind, true);
  59. if (ret)
  60. return ret;
  61. ret = ACT_P_CREATED;
  62. } else {
  63. if (bind)/* dont override defaults */
  64. return 0;
  65. tcf_idr_release(*a, bind);
  66. if (!ovr)
  67. return -EEXIST;
  68. }
  69. p = to_tcf_csum(*a);
  70. ASSERT_RTNL();
  71. params_new = kzalloc(sizeof(*params_new), GFP_KERNEL);
  72. if (unlikely(!params_new)) {
  73. if (ret == ACT_P_CREATED)
  74. tcf_idr_release(*a, bind);
  75. return -ENOMEM;
  76. }
  77. params_old = rtnl_dereference(p->params);
  78. params_new->action = parm->action;
  79. params_new->update_flags = parm->update_flags;
  80. rcu_assign_pointer(p->params, params_new);
  81. if (params_old)
  82. kfree_rcu(params_old, rcu);
  83. if (ret == ACT_P_CREATED)
  84. tcf_idr_insert(tn, *a);
  85. return ret;
  86. }
  87. /**
  88. * tcf_csum_skb_nextlayer - Get next layer pointer
  89. * @skb: sk_buff to use
  90. * @ihl: previous summed headers length
  91. * @ipl: complete packet length
  92. * @jhl: next header length
  93. *
  94. * Check the expected next layer availability in the specified sk_buff.
  95. * Return the next layer pointer if pass, NULL otherwise.
  96. */
  97. static void *tcf_csum_skb_nextlayer(struct sk_buff *skb,
  98. unsigned int ihl, unsigned int ipl,
  99. unsigned int jhl)
  100. {
  101. int ntkoff = skb_network_offset(skb);
  102. int hl = ihl + jhl;
  103. if (!pskb_may_pull(skb, ipl + ntkoff) || (ipl < hl) ||
  104. skb_try_make_writable(skb, hl + ntkoff))
  105. return NULL;
  106. else
  107. return (void *)(skb_network_header(skb) + ihl);
  108. }
  109. static int tcf_csum_ipv4_icmp(struct sk_buff *skb, unsigned int ihl,
  110. unsigned int ipl)
  111. {
  112. struct icmphdr *icmph;
  113. icmph = tcf_csum_skb_nextlayer(skb, ihl, ipl, sizeof(*icmph));
  114. if (icmph == NULL)
  115. return 0;
  116. icmph->checksum = 0;
  117. skb->csum = csum_partial(icmph, ipl - ihl, 0);
  118. icmph->checksum = csum_fold(skb->csum);
  119. skb->ip_summed = CHECKSUM_NONE;
  120. return 1;
  121. }
  122. static int tcf_csum_ipv4_igmp(struct sk_buff *skb,
  123. unsigned int ihl, unsigned int ipl)
  124. {
  125. struct igmphdr *igmph;
  126. igmph = tcf_csum_skb_nextlayer(skb, ihl, ipl, sizeof(*igmph));
  127. if (igmph == NULL)
  128. return 0;
  129. igmph->csum = 0;
  130. skb->csum = csum_partial(igmph, ipl - ihl, 0);
  131. igmph->csum = csum_fold(skb->csum);
  132. skb->ip_summed = CHECKSUM_NONE;
  133. return 1;
  134. }
  135. static int tcf_csum_ipv6_icmp(struct sk_buff *skb, unsigned int ihl,
  136. unsigned int ipl)
  137. {
  138. struct icmp6hdr *icmp6h;
  139. const struct ipv6hdr *ip6h;
  140. icmp6h = tcf_csum_skb_nextlayer(skb, ihl, ipl, sizeof(*icmp6h));
  141. if (icmp6h == NULL)
  142. return 0;
  143. ip6h = ipv6_hdr(skb);
  144. icmp6h->icmp6_cksum = 0;
  145. skb->csum = csum_partial(icmp6h, ipl - ihl, 0);
  146. icmp6h->icmp6_cksum = csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
  147. ipl - ihl, IPPROTO_ICMPV6,
  148. skb->csum);
  149. skb->ip_summed = CHECKSUM_NONE;
  150. return 1;
  151. }
  152. static int tcf_csum_ipv4_tcp(struct sk_buff *skb, unsigned int ihl,
  153. unsigned int ipl)
  154. {
  155. struct tcphdr *tcph;
  156. const struct iphdr *iph;
  157. if (skb_is_gso(skb) && skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4)
  158. return 1;
  159. tcph = tcf_csum_skb_nextlayer(skb, ihl, ipl, sizeof(*tcph));
  160. if (tcph == NULL)
  161. return 0;
  162. iph = ip_hdr(skb);
  163. tcph->check = 0;
  164. skb->csum = csum_partial(tcph, ipl - ihl, 0);
  165. tcph->check = tcp_v4_check(ipl - ihl,
  166. iph->saddr, iph->daddr, skb->csum);
  167. skb->ip_summed = CHECKSUM_NONE;
  168. return 1;
  169. }
  170. static int tcf_csum_ipv6_tcp(struct sk_buff *skb, unsigned int ihl,
  171. unsigned int ipl)
  172. {
  173. struct tcphdr *tcph;
  174. const struct ipv6hdr *ip6h;
  175. if (skb_is_gso(skb) && skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
  176. return 1;
  177. tcph = tcf_csum_skb_nextlayer(skb, ihl, ipl, sizeof(*tcph));
  178. if (tcph == NULL)
  179. return 0;
  180. ip6h = ipv6_hdr(skb);
  181. tcph->check = 0;
  182. skb->csum = csum_partial(tcph, ipl - ihl, 0);
  183. tcph->check = csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
  184. ipl - ihl, IPPROTO_TCP,
  185. skb->csum);
  186. skb->ip_summed = CHECKSUM_NONE;
  187. return 1;
  188. }
  189. static int tcf_csum_ipv4_udp(struct sk_buff *skb, unsigned int ihl,
  190. unsigned int ipl, int udplite)
  191. {
  192. struct udphdr *udph;
  193. const struct iphdr *iph;
  194. u16 ul;
  195. if (skb_is_gso(skb) && skb_shinfo(skb)->gso_type & SKB_GSO_UDP)
  196. return 1;
  197. /*
  198. * Support both UDP and UDPLITE checksum algorithms, Don't use
  199. * udph->len to get the real length without any protocol check,
  200. * UDPLITE uses udph->len for another thing,
  201. * Use iph->tot_len, or just ipl.
  202. */
  203. udph = tcf_csum_skb_nextlayer(skb, ihl, ipl, sizeof(*udph));
  204. if (udph == NULL)
  205. return 0;
  206. iph = ip_hdr(skb);
  207. ul = ntohs(udph->len);
  208. if (udplite || udph->check) {
  209. udph->check = 0;
  210. if (udplite) {
  211. if (ul == 0)
  212. skb->csum = csum_partial(udph, ipl - ihl, 0);
  213. else if ((ul >= sizeof(*udph)) && (ul <= ipl - ihl))
  214. skb->csum = csum_partial(udph, ul, 0);
  215. else
  216. goto ignore_obscure_skb;
  217. } else {
  218. if (ul != ipl - ihl)
  219. goto ignore_obscure_skb;
  220. skb->csum = csum_partial(udph, ul, 0);
  221. }
  222. udph->check = csum_tcpudp_magic(iph->saddr, iph->daddr,
  223. ul, iph->protocol,
  224. skb->csum);
  225. if (!udph->check)
  226. udph->check = CSUM_MANGLED_0;
  227. }
  228. skb->ip_summed = CHECKSUM_NONE;
  229. ignore_obscure_skb:
  230. return 1;
  231. }
  232. static int tcf_csum_ipv6_udp(struct sk_buff *skb, unsigned int ihl,
  233. unsigned int ipl, int udplite)
  234. {
  235. struct udphdr *udph;
  236. const struct ipv6hdr *ip6h;
  237. u16 ul;
  238. if (skb_is_gso(skb) && skb_shinfo(skb)->gso_type & SKB_GSO_UDP)
  239. return 1;
  240. /*
  241. * Support both UDP and UDPLITE checksum algorithms, Don't use
  242. * udph->len to get the real length without any protocol check,
  243. * UDPLITE uses udph->len for another thing,
  244. * Use ip6h->payload_len + sizeof(*ip6h) ... , or just ipl.
  245. */
  246. udph = tcf_csum_skb_nextlayer(skb, ihl, ipl, sizeof(*udph));
  247. if (udph == NULL)
  248. return 0;
  249. ip6h = ipv6_hdr(skb);
  250. ul = ntohs(udph->len);
  251. udph->check = 0;
  252. if (udplite) {
  253. if (ul == 0)
  254. skb->csum = csum_partial(udph, ipl - ihl, 0);
  255. else if ((ul >= sizeof(*udph)) && (ul <= ipl - ihl))
  256. skb->csum = csum_partial(udph, ul, 0);
  257. else
  258. goto ignore_obscure_skb;
  259. } else {
  260. if (ul != ipl - ihl)
  261. goto ignore_obscure_skb;
  262. skb->csum = csum_partial(udph, ul, 0);
  263. }
  264. udph->check = csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr, ul,
  265. udplite ? IPPROTO_UDPLITE : IPPROTO_UDP,
  266. skb->csum);
  267. if (!udph->check)
  268. udph->check = CSUM_MANGLED_0;
  269. skb->ip_summed = CHECKSUM_NONE;
  270. ignore_obscure_skb:
  271. return 1;
  272. }
  273. static int tcf_csum_sctp(struct sk_buff *skb, unsigned int ihl,
  274. unsigned int ipl)
  275. {
  276. struct sctphdr *sctph;
  277. if (skb_is_gso(skb) && skb_is_gso_sctp(skb))
  278. return 1;
  279. sctph = tcf_csum_skb_nextlayer(skb, ihl, ipl, sizeof(*sctph));
  280. if (!sctph)
  281. return 0;
  282. sctph->checksum = sctp_compute_cksum(skb,
  283. skb_network_offset(skb) + ihl);
  284. skb->ip_summed = CHECKSUM_NONE;
  285. skb->csum_not_inet = 0;
  286. return 1;
  287. }
  288. static int tcf_csum_ipv4(struct sk_buff *skb, u32 update_flags)
  289. {
  290. const struct iphdr *iph;
  291. int ntkoff;
  292. ntkoff = skb_network_offset(skb);
  293. if (!pskb_may_pull(skb, sizeof(*iph) + ntkoff))
  294. goto fail;
  295. iph = ip_hdr(skb);
  296. switch (iph->frag_off & htons(IP_OFFSET) ? 0 : iph->protocol) {
  297. case IPPROTO_ICMP:
  298. if (update_flags & TCA_CSUM_UPDATE_FLAG_ICMP)
  299. if (!tcf_csum_ipv4_icmp(skb, iph->ihl * 4,
  300. ntohs(iph->tot_len)))
  301. goto fail;
  302. break;
  303. case IPPROTO_IGMP:
  304. if (update_flags & TCA_CSUM_UPDATE_FLAG_IGMP)
  305. if (!tcf_csum_ipv4_igmp(skb, iph->ihl * 4,
  306. ntohs(iph->tot_len)))
  307. goto fail;
  308. break;
  309. case IPPROTO_TCP:
  310. if (update_flags & TCA_CSUM_UPDATE_FLAG_TCP)
  311. if (!tcf_csum_ipv4_tcp(skb, iph->ihl * 4,
  312. ntohs(iph->tot_len)))
  313. goto fail;
  314. break;
  315. case IPPROTO_UDP:
  316. if (update_flags & TCA_CSUM_UPDATE_FLAG_UDP)
  317. if (!tcf_csum_ipv4_udp(skb, iph->ihl * 4,
  318. ntohs(iph->tot_len), 0))
  319. goto fail;
  320. break;
  321. case IPPROTO_UDPLITE:
  322. if (update_flags & TCA_CSUM_UPDATE_FLAG_UDPLITE)
  323. if (!tcf_csum_ipv4_udp(skb, iph->ihl * 4,
  324. ntohs(iph->tot_len), 1))
  325. goto fail;
  326. break;
  327. case IPPROTO_SCTP:
  328. if ((update_flags & TCA_CSUM_UPDATE_FLAG_SCTP) &&
  329. !tcf_csum_sctp(skb, iph->ihl * 4, ntohs(iph->tot_len)))
  330. goto fail;
  331. break;
  332. }
  333. if (update_flags & TCA_CSUM_UPDATE_FLAG_IPV4HDR) {
  334. if (skb_try_make_writable(skb, sizeof(*iph) + ntkoff))
  335. goto fail;
  336. ip_send_check(ip_hdr(skb));
  337. }
  338. return 1;
  339. fail:
  340. return 0;
  341. }
  342. static int tcf_csum_ipv6_hopopts(struct ipv6_opt_hdr *ip6xh, unsigned int ixhl,
  343. unsigned int *pl)
  344. {
  345. int off, len, optlen;
  346. unsigned char *xh = (void *)ip6xh;
  347. off = sizeof(*ip6xh);
  348. len = ixhl - off;
  349. while (len > 1) {
  350. switch (xh[off]) {
  351. case IPV6_TLV_PAD1:
  352. optlen = 1;
  353. break;
  354. case IPV6_TLV_JUMBO:
  355. optlen = xh[off + 1] + 2;
  356. if (optlen != 6 || len < 6 || (off & 3) != 2)
  357. /* wrong jumbo option length/alignment */
  358. return 0;
  359. *pl = ntohl(*(__be32 *)(xh + off + 2));
  360. goto done;
  361. default:
  362. optlen = xh[off + 1] + 2;
  363. if (optlen > len)
  364. /* ignore obscure options */
  365. goto done;
  366. break;
  367. }
  368. off += optlen;
  369. len -= optlen;
  370. }
  371. done:
  372. return 1;
  373. }
  374. static int tcf_csum_ipv6(struct sk_buff *skb, u32 update_flags)
  375. {
  376. struct ipv6hdr *ip6h;
  377. struct ipv6_opt_hdr *ip6xh;
  378. unsigned int hl, ixhl;
  379. unsigned int pl;
  380. int ntkoff;
  381. u8 nexthdr;
  382. ntkoff = skb_network_offset(skb);
  383. hl = sizeof(*ip6h);
  384. if (!pskb_may_pull(skb, hl + ntkoff))
  385. goto fail;
  386. ip6h = ipv6_hdr(skb);
  387. pl = ntohs(ip6h->payload_len);
  388. nexthdr = ip6h->nexthdr;
  389. do {
  390. switch (nexthdr) {
  391. case NEXTHDR_FRAGMENT:
  392. goto ignore_skb;
  393. case NEXTHDR_ROUTING:
  394. case NEXTHDR_HOP:
  395. case NEXTHDR_DEST:
  396. if (!pskb_may_pull(skb, hl + sizeof(*ip6xh) + ntkoff))
  397. goto fail;
  398. ip6xh = (void *)(skb_network_header(skb) + hl);
  399. ixhl = ipv6_optlen(ip6xh);
  400. if (!pskb_may_pull(skb, hl + ixhl + ntkoff))
  401. goto fail;
  402. ip6xh = (void *)(skb_network_header(skb) + hl);
  403. if ((nexthdr == NEXTHDR_HOP) &&
  404. !(tcf_csum_ipv6_hopopts(ip6xh, ixhl, &pl)))
  405. goto fail;
  406. nexthdr = ip6xh->nexthdr;
  407. hl += ixhl;
  408. break;
  409. case IPPROTO_ICMPV6:
  410. if (update_flags & TCA_CSUM_UPDATE_FLAG_ICMP)
  411. if (!tcf_csum_ipv6_icmp(skb,
  412. hl, pl + sizeof(*ip6h)))
  413. goto fail;
  414. goto done;
  415. case IPPROTO_TCP:
  416. if (update_flags & TCA_CSUM_UPDATE_FLAG_TCP)
  417. if (!tcf_csum_ipv6_tcp(skb,
  418. hl, pl + sizeof(*ip6h)))
  419. goto fail;
  420. goto done;
  421. case IPPROTO_UDP:
  422. if (update_flags & TCA_CSUM_UPDATE_FLAG_UDP)
  423. if (!tcf_csum_ipv6_udp(skb, hl,
  424. pl + sizeof(*ip6h), 0))
  425. goto fail;
  426. goto done;
  427. case IPPROTO_UDPLITE:
  428. if (update_flags & TCA_CSUM_UPDATE_FLAG_UDPLITE)
  429. if (!tcf_csum_ipv6_udp(skb, hl,
  430. pl + sizeof(*ip6h), 1))
  431. goto fail;
  432. goto done;
  433. case IPPROTO_SCTP:
  434. if ((update_flags & TCA_CSUM_UPDATE_FLAG_SCTP) &&
  435. !tcf_csum_sctp(skb, hl, pl + sizeof(*ip6h)))
  436. goto fail;
  437. goto done;
  438. default:
  439. goto ignore_skb;
  440. }
  441. } while (pskb_may_pull(skb, hl + 1 + ntkoff));
  442. done:
  443. ignore_skb:
  444. return 1;
  445. fail:
  446. return 0;
  447. }
  448. static int tcf_csum(struct sk_buff *skb, const struct tc_action *a,
  449. struct tcf_result *res)
  450. {
  451. struct tcf_csum *p = to_tcf_csum(a);
  452. struct tcf_csum_params *params;
  453. u32 update_flags;
  454. int action;
  455. rcu_read_lock();
  456. params = rcu_dereference(p->params);
  457. tcf_lastuse_update(&p->tcf_tm);
  458. bstats_cpu_update(this_cpu_ptr(p->common.cpu_bstats), skb);
  459. action = params->action;
  460. if (unlikely(action == TC_ACT_SHOT))
  461. goto drop_stats;
  462. update_flags = params->update_flags;
  463. switch (tc_skb_protocol(skb)) {
  464. case cpu_to_be16(ETH_P_IP):
  465. if (!tcf_csum_ipv4(skb, update_flags))
  466. goto drop;
  467. break;
  468. case cpu_to_be16(ETH_P_IPV6):
  469. if (!tcf_csum_ipv6(skb, update_flags))
  470. goto drop;
  471. break;
  472. }
  473. unlock:
  474. rcu_read_unlock();
  475. return action;
  476. drop:
  477. action = TC_ACT_SHOT;
  478. drop_stats:
  479. qstats_drop_inc(this_cpu_ptr(p->common.cpu_qstats));
  480. goto unlock;
  481. }
  482. static int tcf_csum_dump(struct sk_buff *skb, struct tc_action *a, int bind,
  483. int ref)
  484. {
  485. unsigned char *b = skb_tail_pointer(skb);
  486. struct tcf_csum *p = to_tcf_csum(a);
  487. struct tcf_csum_params *params;
  488. struct tc_csum opt = {
  489. .index = p->tcf_index,
  490. .refcnt = p->tcf_refcnt - ref,
  491. .bindcnt = p->tcf_bindcnt - bind,
  492. };
  493. struct tcf_t t;
  494. params = rtnl_dereference(p->params);
  495. opt.action = params->action;
  496. opt.update_flags = params->update_flags;
  497. if (nla_put(skb, TCA_CSUM_PARMS, sizeof(opt), &opt))
  498. goto nla_put_failure;
  499. tcf_tm_dump(&t, &p->tcf_tm);
  500. if (nla_put_64bit(skb, TCA_CSUM_TM, sizeof(t), &t, TCA_CSUM_PAD))
  501. goto nla_put_failure;
  502. return skb->len;
  503. nla_put_failure:
  504. nlmsg_trim(skb, b);
  505. return -1;
  506. }
  507. static void tcf_csum_cleanup(struct tc_action *a)
  508. {
  509. struct tcf_csum *p = to_tcf_csum(a);
  510. struct tcf_csum_params *params;
  511. params = rcu_dereference_protected(p->params, 1);
  512. if (params)
  513. kfree_rcu(params, rcu);
  514. }
  515. static int tcf_csum_walker(struct net *net, struct sk_buff *skb,
  516. struct netlink_callback *cb, int type,
  517. const struct tc_action_ops *ops,
  518. struct netlink_ext_ack *extack)
  519. {
  520. struct tc_action_net *tn = net_generic(net, csum_net_id);
  521. return tcf_generic_walker(tn, skb, cb, type, ops, extack);
  522. }
  523. static int tcf_csum_search(struct net *net, struct tc_action **a, u32 index,
  524. struct netlink_ext_ack *extack)
  525. {
  526. struct tc_action_net *tn = net_generic(net, csum_net_id);
  527. return tcf_idr_search(tn, a, index);
  528. }
  529. static size_t tcf_csum_get_fill_size(const struct tc_action *act)
  530. {
  531. return nla_total_size(sizeof(struct tc_csum));
  532. }
  533. static struct tc_action_ops act_csum_ops = {
  534. .kind = "csum",
  535. .type = TCA_ACT_CSUM,
  536. .owner = THIS_MODULE,
  537. .act = tcf_csum,
  538. .dump = tcf_csum_dump,
  539. .init = tcf_csum_init,
  540. .cleanup = tcf_csum_cleanup,
  541. .walk = tcf_csum_walker,
  542. .lookup = tcf_csum_search,
  543. .get_fill_size = tcf_csum_get_fill_size,
  544. .size = sizeof(struct tcf_csum),
  545. };
  546. static __net_init int csum_init_net(struct net *net)
  547. {
  548. struct tc_action_net *tn = net_generic(net, csum_net_id);
  549. return tc_action_net_init(tn, &act_csum_ops);
  550. }
  551. static void __net_exit csum_exit_net(struct list_head *net_list)
  552. {
  553. tc_action_net_exit(net_list, csum_net_id);
  554. }
  555. static struct pernet_operations csum_net_ops = {
  556. .init = csum_init_net,
  557. .exit_batch = csum_exit_net,
  558. .id = &csum_net_id,
  559. .size = sizeof(struct tc_action_net),
  560. };
  561. MODULE_DESCRIPTION("Checksum updating actions");
  562. MODULE_LICENSE("GPL");
  563. static int __init csum_init_module(void)
  564. {
  565. return tcf_register_action(&act_csum_ops, &csum_net_ops);
  566. }
  567. static void __exit csum_cleanup_module(void)
  568. {
  569. tcf_unregister_action(&act_csum_ops, &csum_net_ops);
  570. }
  571. module_init(csum_init_module);
  572. module_exit(csum_cleanup_module);