blob: b07c535ba8e7c6f8dcbc52f4eb69cf4a1ab3d0c2 [file] [log] [blame]
Grégoire Baroneb4d4062010-08-18 13:10:35 +00001/*
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
13#include <linux/types.h>
14#include <linux/init.h>
15#include <linux/kernel.h>
16#include <linux/module.h>
17#include <linux/spinlock.h>
18
19#include <linux/netlink.h>
20#include <net/netlink.h>
21#include <linux/rtnetlink.h>
22
23#include <linux/skbuff.h>
24
25#include <net/ip.h>
26#include <net/ipv6.h>
27#include <net/icmp.h>
28#include <linux/icmpv6.h>
29#include <linux/igmp.h>
30#include <net/tcp.h>
31#include <net/udp.h>
Stephen Rothwell24362432010-08-22 20:31:14 -070032#include <net/ip6_checksum.h>
Grégoire Baroneb4d4062010-08-18 13:10:35 +000033
34#include <net/act_api.h>
35
36#include <linux/tc_act/tc_csum.h>
37#include <net/tc_act/tc_csum.h>
38
39#define CSUM_TAB_MASK 15
Grégoire Baroneb4d4062010-08-18 13:10:35 +000040
41static const struct nla_policy csum_policy[TCA_CSUM_MAX + 1] = {
42 [TCA_CSUM_PARMS] = { .len = sizeof(struct tc_csum), },
43};
44
Benjamin LaHaisec1b52732013-01-14 05:15:39 +000045static int tcf_csum_init(struct net *n, struct nlattr *nla, struct nlattr *est,
Grégoire Baroneb4d4062010-08-18 13:10:35 +000046 struct tc_action *a, int ovr, int bind)
47{
48 struct nlattr *tb[TCA_CSUM_MAX + 1];
49 struct tc_csum *parm;
Grégoire Baroneb4d4062010-08-18 13:10:35 +000050 struct tcf_csum *p;
51 int ret = 0, err;
52
53 if (nla == NULL)
54 return -EINVAL;
55
Eric Dumazetcc7ec452011-01-19 19:26:56 +000056 err = nla_parse_nested(tb, TCA_CSUM_MAX, nla, csum_policy);
Grégoire Baroneb4d4062010-08-18 13:10:35 +000057 if (err < 0)
58 return err;
59
60 if (tb[TCA_CSUM_PARMS] == NULL)
61 return -EINVAL;
62 parm = nla_data(tb[TCA_CSUM_PARMS]);
63
WANG Cong86062032014-02-11 17:07:31 -080064 if (!tcf_hash_check(parm->index, a, bind)) {
Eric Dumazet519c8182015-07-06 05:18:04 -070065 ret = tcf_hash_create(parm->index, est, a, sizeof(*p),
66 bind, false);
WANG Cong86062032014-02-11 17:07:31 -080067 if (ret)
68 return ret;
Grégoire Baroneb4d4062010-08-18 13:10:35 +000069 ret = ACT_P_CREATED;
70 } else {
Jamal Hadi Salim1a293212013-12-23 08:02:11 -050071 if (bind)/* dont override defaults */
72 return 0;
WANG Cong86062032014-02-11 17:07:31 -080073 tcf_hash_release(a, bind);
Jamal Hadi Salim1a293212013-12-23 08:02:11 -050074 if (!ovr)
Grégoire Baroneb4d4062010-08-18 13:10:35 +000075 return -EEXIST;
Grégoire Baroneb4d4062010-08-18 13:10:35 +000076 }
77
WANG Cong86062032014-02-11 17:07:31 -080078 p = to_tcf_csum(a);
Grégoire Baroneb4d4062010-08-18 13:10:35 +000079 spin_lock_bh(&p->tcf_lock);
80 p->tcf_action = parm->action;
81 p->update_flags = parm->update_flags;
82 spin_unlock_bh(&p->tcf_lock);
83
84 if (ret == ACT_P_CREATED)
WANG Cong86062032014-02-11 17:07:31 -080085 tcf_hash_insert(a);
Grégoire Baroneb4d4062010-08-18 13:10:35 +000086
87 return ret;
88}
89
Grégoire Baroneb4d4062010-08-18 13:10:35 +000090/**
91 * tcf_csum_skb_nextlayer - Get next layer pointer
92 * @skb: sk_buff to use
93 * @ihl: previous summed headers length
94 * @ipl: complete packet length
95 * @jhl: next header length
96 *
97 * Check the expected next layer availability in the specified sk_buff.
98 * Return the next layer pointer if pass, NULL otherwise.
99 */
100static void *tcf_csum_skb_nextlayer(struct sk_buff *skb,
101 unsigned int ihl, unsigned int ipl,
102 unsigned int jhl)
103{
104 int ntkoff = skb_network_offset(skb);
105 int hl = ihl + jhl;
106
107 if (!pskb_may_pull(skb, ipl + ntkoff) || (ipl < hl) ||
108 (skb_cloned(skb) &&
109 !skb_clone_writable(skb, hl + ntkoff) &&
110 pskb_expand_head(skb, 0, 0, GFP_ATOMIC)))
111 return NULL;
112 else
113 return (void *)(skb_network_header(skb) + ihl);
114}
115
116static int tcf_csum_ipv4_icmp(struct sk_buff *skb,
117 unsigned int ihl, unsigned int ipl)
118{
119 struct icmphdr *icmph;
120
121 icmph = tcf_csum_skb_nextlayer(skb, ihl, ipl, sizeof(*icmph));
122 if (icmph == NULL)
123 return 0;
124
125 icmph->checksum = 0;
126 skb->csum = csum_partial(icmph, ipl - ihl, 0);
127 icmph->checksum = csum_fold(skb->csum);
128
129 skb->ip_summed = CHECKSUM_NONE;
130
131 return 1;
132}
133
134static int tcf_csum_ipv4_igmp(struct sk_buff *skb,
135 unsigned int ihl, unsigned int ipl)
136{
137 struct igmphdr *igmph;
138
139 igmph = tcf_csum_skb_nextlayer(skb, ihl, ipl, sizeof(*igmph));
140 if (igmph == NULL)
141 return 0;
142
143 igmph->csum = 0;
144 skb->csum = csum_partial(igmph, ipl - ihl, 0);
145 igmph->csum = csum_fold(skb->csum);
146
147 skb->ip_summed = CHECKSUM_NONE;
148
149 return 1;
150}
151
Eric Dumazetd14a4892013-04-12 11:07:47 -0700152static int tcf_csum_ipv6_icmp(struct sk_buff *skb,
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000153 unsigned int ihl, unsigned int ipl)
154{
155 struct icmp6hdr *icmp6h;
Eric Dumazetd14a4892013-04-12 11:07:47 -0700156 const struct ipv6hdr *ip6h;
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000157
158 icmp6h = tcf_csum_skb_nextlayer(skb, ihl, ipl, sizeof(*icmp6h));
159 if (icmp6h == NULL)
160 return 0;
161
Eric Dumazetd14a4892013-04-12 11:07:47 -0700162 ip6h = ipv6_hdr(skb);
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000163 icmp6h->icmp6_cksum = 0;
164 skb->csum = csum_partial(icmp6h, ipl - ihl, 0);
165 icmp6h->icmp6_cksum = csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
166 ipl - ihl, IPPROTO_ICMPV6,
167 skb->csum);
168
169 skb->ip_summed = CHECKSUM_NONE;
170
171 return 1;
172}
173
Eric Dumazetd14a4892013-04-12 11:07:47 -0700174static int tcf_csum_ipv4_tcp(struct sk_buff *skb,
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000175 unsigned int ihl, unsigned int ipl)
176{
177 struct tcphdr *tcph;
Eric Dumazetd14a4892013-04-12 11:07:47 -0700178 const struct iphdr *iph;
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000179
180 tcph = tcf_csum_skb_nextlayer(skb, ihl, ipl, sizeof(*tcph));
181 if (tcph == NULL)
182 return 0;
183
Eric Dumazetd14a4892013-04-12 11:07:47 -0700184 iph = ip_hdr(skb);
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000185 tcph->check = 0;
186 skb->csum = csum_partial(tcph, ipl - ihl, 0);
187 tcph->check = tcp_v4_check(ipl - ihl,
188 iph->saddr, iph->daddr, skb->csum);
189
190 skb->ip_summed = CHECKSUM_NONE;
191
192 return 1;
193}
194
Eric Dumazetd14a4892013-04-12 11:07:47 -0700195static int tcf_csum_ipv6_tcp(struct sk_buff *skb,
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000196 unsigned int ihl, unsigned int ipl)
197{
198 struct tcphdr *tcph;
Eric Dumazetd14a4892013-04-12 11:07:47 -0700199 const struct ipv6hdr *ip6h;
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000200
201 tcph = tcf_csum_skb_nextlayer(skb, ihl, ipl, sizeof(*tcph));
202 if (tcph == NULL)
203 return 0;
204
Eric Dumazetd14a4892013-04-12 11:07:47 -0700205 ip6h = ipv6_hdr(skb);
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000206 tcph->check = 0;
207 skb->csum = csum_partial(tcph, ipl - ihl, 0);
208 tcph->check = csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
209 ipl - ihl, IPPROTO_TCP,
210 skb->csum);
211
212 skb->ip_summed = CHECKSUM_NONE;
213
214 return 1;
215}
216
Eric Dumazetd14a4892013-04-12 11:07:47 -0700217static int tcf_csum_ipv4_udp(struct sk_buff *skb,
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000218 unsigned int ihl, unsigned int ipl, int udplite)
219{
220 struct udphdr *udph;
Eric Dumazetd14a4892013-04-12 11:07:47 -0700221 const struct iphdr *iph;
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000222 u16 ul;
223
Changli Gao0eec32f2010-08-23 03:27:58 +0000224 /*
225 * Support both UDP and UDPLITE checksum algorithms, Don't use
226 * udph->len to get the real length without any protocol check,
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000227 * UDPLITE uses udph->len for another thing,
228 * Use iph->tot_len, or just ipl.
229 */
230
231 udph = tcf_csum_skb_nextlayer(skb, ihl, ipl, sizeof(*udph));
232 if (udph == NULL)
233 return 0;
234
Eric Dumazetd14a4892013-04-12 11:07:47 -0700235 iph = ip_hdr(skb);
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000236 ul = ntohs(udph->len);
237
238 if (udplite || udph->check) {
239
240 udph->check = 0;
241
242 if (udplite) {
243 if (ul == 0)
244 skb->csum = csum_partial(udph, ipl - ihl, 0);
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000245 else if ((ul >= sizeof(*udph)) && (ul <= ipl - ihl))
246 skb->csum = csum_partial(udph, ul, 0);
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000247 else
248 goto ignore_obscure_skb;
249 } else {
250 if (ul != ipl - ihl)
251 goto ignore_obscure_skb;
252
253 skb->csum = csum_partial(udph, ul, 0);
254 }
255
256 udph->check = csum_tcpudp_magic(iph->saddr, iph->daddr,
257 ul, iph->protocol,
258 skb->csum);
259
260 if (!udph->check)
261 udph->check = CSUM_MANGLED_0;
262 }
263
264 skb->ip_summed = CHECKSUM_NONE;
265
266ignore_obscure_skb:
267 return 1;
268}
269
Eric Dumazetd14a4892013-04-12 11:07:47 -0700270static int tcf_csum_ipv6_udp(struct sk_buff *skb,
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000271 unsigned int ihl, unsigned int ipl, int udplite)
272{
273 struct udphdr *udph;
Eric Dumazetd14a4892013-04-12 11:07:47 -0700274 const struct ipv6hdr *ip6h;
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000275 u16 ul;
276
Changli Gao0eec32f2010-08-23 03:27:58 +0000277 /*
278 * Support both UDP and UDPLITE checksum algorithms, Don't use
279 * udph->len to get the real length without any protocol check,
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000280 * UDPLITE uses udph->len for another thing,
281 * Use ip6h->payload_len + sizeof(*ip6h) ... , or just ipl.
282 */
283
284 udph = tcf_csum_skb_nextlayer(skb, ihl, ipl, sizeof(*udph));
285 if (udph == NULL)
286 return 0;
287
Eric Dumazetd14a4892013-04-12 11:07:47 -0700288 ip6h = ipv6_hdr(skb);
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000289 ul = ntohs(udph->len);
290
291 udph->check = 0;
292
293 if (udplite) {
294 if (ul == 0)
295 skb->csum = csum_partial(udph, ipl - ihl, 0);
296
297 else if ((ul >= sizeof(*udph)) && (ul <= ipl - ihl))
298 skb->csum = csum_partial(udph, ul, 0);
299
300 else
301 goto ignore_obscure_skb;
302 } else {
303 if (ul != ipl - ihl)
304 goto ignore_obscure_skb;
305
306 skb->csum = csum_partial(udph, ul, 0);
307 }
308
309 udph->check = csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr, ul,
310 udplite ? IPPROTO_UDPLITE : IPPROTO_UDP,
311 skb->csum);
312
313 if (!udph->check)
314 udph->check = CSUM_MANGLED_0;
315
316 skb->ip_summed = CHECKSUM_NONE;
317
318ignore_obscure_skb:
319 return 1;
320}
321
322static int tcf_csum_ipv4(struct sk_buff *skb, u32 update_flags)
323{
Eric Dumazetd14a4892013-04-12 11:07:47 -0700324 const struct iphdr *iph;
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000325 int ntkoff;
326
327 ntkoff = skb_network_offset(skb);
328
329 if (!pskb_may_pull(skb, sizeof(*iph) + ntkoff))
330 goto fail;
331
332 iph = ip_hdr(skb);
333
334 switch (iph->frag_off & htons(IP_OFFSET) ? 0 : iph->protocol) {
335 case IPPROTO_ICMP:
336 if (update_flags & TCA_CSUM_UPDATE_FLAG_ICMP)
Changli Gao0eec32f2010-08-23 03:27:58 +0000337 if (!tcf_csum_ipv4_icmp(skb, iph->ihl * 4,
338 ntohs(iph->tot_len)))
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000339 goto fail;
340 break;
341 case IPPROTO_IGMP:
342 if (update_flags & TCA_CSUM_UPDATE_FLAG_IGMP)
Changli Gao0eec32f2010-08-23 03:27:58 +0000343 if (!tcf_csum_ipv4_igmp(skb, iph->ihl * 4,
344 ntohs(iph->tot_len)))
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000345 goto fail;
346 break;
347 case IPPROTO_TCP:
348 if (update_flags & TCA_CSUM_UPDATE_FLAG_TCP)
Eric Dumazetd14a4892013-04-12 11:07:47 -0700349 if (!tcf_csum_ipv4_tcp(skb, iph->ihl * 4,
Changli Gao0eec32f2010-08-23 03:27:58 +0000350 ntohs(iph->tot_len)))
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000351 goto fail;
352 break;
353 case IPPROTO_UDP:
354 if (update_flags & TCA_CSUM_UPDATE_FLAG_UDP)
Eric Dumazetd14a4892013-04-12 11:07:47 -0700355 if (!tcf_csum_ipv4_udp(skb, iph->ihl * 4,
Changli Gao0eec32f2010-08-23 03:27:58 +0000356 ntohs(iph->tot_len), 0))
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000357 goto fail;
358 break;
359 case IPPROTO_UDPLITE:
360 if (update_flags & TCA_CSUM_UPDATE_FLAG_UDPLITE)
Eric Dumazetd14a4892013-04-12 11:07:47 -0700361 if (!tcf_csum_ipv4_udp(skb, iph->ihl * 4,
Changli Gao0eec32f2010-08-23 03:27:58 +0000362 ntohs(iph->tot_len), 1))
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000363 goto fail;
364 break;
365 }
366
367 if (update_flags & TCA_CSUM_UPDATE_FLAG_IPV4HDR) {
368 if (skb_cloned(skb) &&
369 !skb_clone_writable(skb, sizeof(*iph) + ntkoff) &&
370 pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
371 goto fail;
372
Eric Dumazetd14a4892013-04-12 11:07:47 -0700373 ip_send_check(ip_hdr(skb));
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000374 }
375
376 return 1;
377
378fail:
379 return 0;
380}
381
382static int tcf_csum_ipv6_hopopts(struct ipv6_opt_hdr *ip6xh,
Changli Gao0eec32f2010-08-23 03:27:58 +0000383 unsigned int ixhl, unsigned int *pl)
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000384{
385 int off, len, optlen;
386 unsigned char *xh = (void *)ip6xh;
387
388 off = sizeof(*ip6xh);
389 len = ixhl - off;
390
391 while (len > 1) {
Changli Gao0eec32f2010-08-23 03:27:58 +0000392 switch (xh[off]) {
Eldad Zack1de5a712012-05-17 06:00:25 +0000393 case IPV6_TLV_PAD1:
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000394 optlen = 1;
395 break;
396 case IPV6_TLV_JUMBO:
397 optlen = xh[off + 1] + 2;
398 if (optlen != 6 || len < 6 || (off & 3) != 2)
399 /* wrong jumbo option length/alignment */
400 return 0;
401 *pl = ntohl(*(__be32 *)(xh + off + 2));
402 goto done;
403 default:
404 optlen = xh[off + 1] + 2;
405 if (optlen > len)
406 /* ignore obscure options */
407 goto done;
408 break;
409 }
410 off += optlen;
411 len -= optlen;
412 }
413
414done:
415 return 1;
416}
417
418static int tcf_csum_ipv6(struct sk_buff *skb, u32 update_flags)
419{
420 struct ipv6hdr *ip6h;
421 struct ipv6_opt_hdr *ip6xh;
422 unsigned int hl, ixhl;
423 unsigned int pl;
424 int ntkoff;
425 u8 nexthdr;
426
427 ntkoff = skb_network_offset(skb);
428
429 hl = sizeof(*ip6h);
430
431 if (!pskb_may_pull(skb, hl + ntkoff))
432 goto fail;
433
434 ip6h = ipv6_hdr(skb);
435
436 pl = ntohs(ip6h->payload_len);
437 nexthdr = ip6h->nexthdr;
438
439 do {
440 switch (nexthdr) {
441 case NEXTHDR_FRAGMENT:
442 goto ignore_skb;
443 case NEXTHDR_ROUTING:
444 case NEXTHDR_HOP:
445 case NEXTHDR_DEST:
446 if (!pskb_may_pull(skb, hl + sizeof(*ip6xh) + ntkoff))
447 goto fail;
448 ip6xh = (void *)(skb_network_header(skb) + hl);
449 ixhl = ipv6_optlen(ip6xh);
450 if (!pskb_may_pull(skb, hl + ixhl + ntkoff))
451 goto fail;
Eric Dumazetd14a4892013-04-12 11:07:47 -0700452 ip6xh = (void *)(skb_network_header(skb) + hl);
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000453 if ((nexthdr == NEXTHDR_HOP) &&
454 !(tcf_csum_ipv6_hopopts(ip6xh, ixhl, &pl)))
455 goto fail;
456 nexthdr = ip6xh->nexthdr;
457 hl += ixhl;
458 break;
459 case IPPROTO_ICMPV6:
460 if (update_flags & TCA_CSUM_UPDATE_FLAG_ICMP)
Eric Dumazetd14a4892013-04-12 11:07:47 -0700461 if (!tcf_csum_ipv6_icmp(skb,
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000462 hl, pl + sizeof(*ip6h)))
463 goto fail;
464 goto done;
465 case IPPROTO_TCP:
466 if (update_flags & TCA_CSUM_UPDATE_FLAG_TCP)
Eric Dumazetd14a4892013-04-12 11:07:47 -0700467 if (!tcf_csum_ipv6_tcp(skb,
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000468 hl, pl + sizeof(*ip6h)))
469 goto fail;
470 goto done;
471 case IPPROTO_UDP:
472 if (update_flags & TCA_CSUM_UPDATE_FLAG_UDP)
Eric Dumazetd14a4892013-04-12 11:07:47 -0700473 if (!tcf_csum_ipv6_udp(skb, hl,
Changli Gao0eec32f2010-08-23 03:27:58 +0000474 pl + sizeof(*ip6h), 0))
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000475 goto fail;
476 goto done;
477 case IPPROTO_UDPLITE:
478 if (update_flags & TCA_CSUM_UPDATE_FLAG_UDPLITE)
Eric Dumazetd14a4892013-04-12 11:07:47 -0700479 if (!tcf_csum_ipv6_udp(skb, hl,
Changli Gao0eec32f2010-08-23 03:27:58 +0000480 pl + sizeof(*ip6h), 1))
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000481 goto fail;
482 goto done;
483 default:
484 goto ignore_skb;
485 }
486 } while (pskb_may_pull(skb, hl + 1 + ntkoff));
487
488done:
489ignore_skb:
490 return 1;
491
492fail:
493 return 0;
494}
495
496static int tcf_csum(struct sk_buff *skb,
Eric Dumazetdc7f9f62011-07-05 23:25:42 +0000497 const struct tc_action *a, struct tcf_result *res)
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000498{
499 struct tcf_csum *p = a->priv;
500 int action;
501 u32 update_flags;
502
503 spin_lock(&p->tcf_lock);
504 p->tcf_tm.lastuse = jiffies;
Eric Dumazetbfe0d022011-01-09 08:30:54 +0000505 bstats_update(&p->tcf_bstats, skb);
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000506 action = p->tcf_action;
507 update_flags = p->update_flags;
508 spin_unlock(&p->tcf_lock);
509
510 if (unlikely(action == TC_ACT_SHOT))
511 goto drop;
512
Jiri Pirkod8b96052015-01-13 17:13:43 +0100513 switch (tc_skb_protocol(skb)) {
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000514 case cpu_to_be16(ETH_P_IP):
515 if (!tcf_csum_ipv4(skb, update_flags))
516 goto drop;
517 break;
518 case cpu_to_be16(ETH_P_IPV6):
519 if (!tcf_csum_ipv6(skb, update_flags))
520 goto drop;
521 break;
522 }
523
524 return action;
525
526drop:
527 spin_lock(&p->tcf_lock);
528 p->tcf_qstats.drops++;
529 spin_unlock(&p->tcf_lock);
530 return TC_ACT_SHOT;
531}
532
533static int tcf_csum_dump(struct sk_buff *skb,
534 struct tc_action *a, int bind, int ref)
535{
536 unsigned char *b = skb_tail_pointer(skb);
537 struct tcf_csum *p = a->priv;
538 struct tc_csum opt = {
539 .update_flags = p->update_flags,
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000540 .index = p->tcf_index,
541 .action = p->tcf_action,
542 .refcnt = p->tcf_refcnt - ref,
543 .bindcnt = p->tcf_bindcnt - bind,
544 };
545 struct tcf_t t;
546
David S. Miller1b34ec42012-03-29 05:11:39 -0400547 if (nla_put(skb, TCA_CSUM_PARMS, sizeof(opt), &opt))
548 goto nla_put_failure;
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000549 t.install = jiffies_to_clock_t(jiffies - p->tcf_tm.install);
550 t.lastuse = jiffies_to_clock_t(jiffies - p->tcf_tm.lastuse);
551 t.expires = jiffies_to_clock_t(p->tcf_tm.expires);
David S. Miller1b34ec42012-03-29 05:11:39 -0400552 if (nla_put(skb, TCA_CSUM_TM, sizeof(t), &t))
553 goto nla_put_failure;
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000554
555 return skb->len;
556
557nla_put_failure:
558 nlmsg_trim(skb, b);
559 return -1;
560}
561
562static struct tc_action_ops act_csum_ops = {
Changli Gao0eec32f2010-08-23 03:27:58 +0000563 .kind = "csum",
Changli Gao0eec32f2010-08-23 03:27:58 +0000564 .type = TCA_ACT_CSUM,
Changli Gao0eec32f2010-08-23 03:27:58 +0000565 .owner = THIS_MODULE,
566 .act = tcf_csum,
567 .dump = tcf_csum_dump,
Changli Gao0eec32f2010-08-23 03:27:58 +0000568 .init = tcf_csum_init,
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000569};
570
571MODULE_DESCRIPTION("Checksum updating actions");
572MODULE_LICENSE("GPL");
573
574static int __init csum_init_module(void)
575{
WANG Cong4f1e9d82014-02-11 17:07:33 -0800576 return tcf_register_action(&act_csum_ops, CSUM_TAB_MASK);
Grégoire Baroneb4d4062010-08-18 13:10:35 +0000577}
578
579static void __exit csum_cleanup_module(void)
580{
581 tcf_unregister_action(&act_csum_ops);
582}
583
584module_init(csum_init_module);
585module_exit(csum_cleanup_module);