act_csum.c 16 KB

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