Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 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 | |
| 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 Rothwell | 2436243 | 2010-08-22 20:31:14 -0700 | [diff] [blame] | 32 | #include <net/ip6_checksum.h> |
Davide Caratti | c008b33 | 2017-01-09 11:24:21 +0100 | [diff] [blame] | 33 | #include <net/sctp/checksum.h> |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 34 | |
| 35 | #include <net/act_api.h> |
| 36 | |
| 37 | #include <linux/tc_act/tc_csum.h> |
| 38 | #include <net/tc_act/tc_csum.h> |
| 39 | |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 40 | static const struct nla_policy csum_policy[TCA_CSUM_MAX + 1] = { |
| 41 | [TCA_CSUM_PARMS] = { .len = sizeof(struct tc_csum), }, |
| 42 | }; |
| 43 | |
Alexey Dobriyan | c7d03a0 | 2016-11-17 04:58:21 +0300 | [diff] [blame] | 44 | static unsigned int csum_net_id; |
WANG Cong | a85a970 | 2016-07-25 16:09:41 -0700 | [diff] [blame] | 45 | static struct tc_action_ops act_csum_ops; |
WANG Cong | ddf97cc | 2016-02-22 15:57:53 -0800 | [diff] [blame] | 46 | |
| 47 | static int tcf_csum_init(struct net *net, struct nlattr *nla, |
WANG Cong | a85a970 | 2016-07-25 16:09:41 -0700 | [diff] [blame] | 48 | struct nlattr *est, struct tc_action **a, int ovr, |
Vlad Buslov | 789871b | 2018-07-05 17:24:25 +0300 | [diff] [blame] | 49 | int bind, bool rtnl_held, |
| 50 | struct netlink_ext_ack *extack) |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 51 | { |
WANG Cong | ddf97cc | 2016-02-22 15:57:53 -0800 | [diff] [blame] | 52 | struct tc_action_net *tn = net_generic(net, csum_net_id); |
Vlad Buslov | b6a2b97 | 2018-08-10 20:51:42 +0300 | [diff] [blame] | 53 | struct tcf_csum_params *params_new; |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 54 | struct nlattr *tb[TCA_CSUM_MAX + 1]; |
| 55 | struct tc_csum *parm; |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 56 | struct tcf_csum *p; |
| 57 | int ret = 0, err; |
| 58 | |
| 59 | if (nla == NULL) |
| 60 | return -EINVAL; |
| 61 | |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 62 | err = nla_parse_nested(tb, TCA_CSUM_MAX, nla, csum_policy, NULL); |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 63 | if (err < 0) |
| 64 | return err; |
| 65 | |
| 66 | if (tb[TCA_CSUM_PARMS] == NULL) |
| 67 | return -EINVAL; |
| 68 | parm = nla_data(tb[TCA_CSUM_PARMS]); |
| 69 | |
Vlad Buslov | 0190c1d | 2018-07-05 17:24:32 +0300 | [diff] [blame] | 70 | err = tcf_idr_check_alloc(tn, &parm->index, a, bind); |
| 71 | if (!err) { |
Chris Mi | 65a206c | 2017-08-30 02:31:59 -0400 | [diff] [blame] | 72 | ret = tcf_idr_create(tn, parm->index, est, a, |
Davide Caratti | f6052cf | 2018-01-22 18:14:31 +0100 | [diff] [blame] | 73 | &act_csum_ops, bind, true); |
Vlad Buslov | 0190c1d | 2018-07-05 17:24:32 +0300 | [diff] [blame] | 74 | if (ret) { |
| 75 | tcf_idr_cleanup(tn, parm->index); |
WANG Cong | 8606203 | 2014-02-11 17:07:31 -0800 | [diff] [blame] | 76 | return ret; |
Vlad Buslov | 0190c1d | 2018-07-05 17:24:32 +0300 | [diff] [blame] | 77 | } |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 78 | ret = ACT_P_CREATED; |
Vlad Buslov | 0190c1d | 2018-07-05 17:24:32 +0300 | [diff] [blame] | 79 | } else if (err > 0) { |
Jamal Hadi Salim | 1a29321 | 2013-12-23 08:02:11 -0500 | [diff] [blame] | 80 | if (bind)/* dont override defaults */ |
| 81 | return 0; |
Vlad Buslov | 4e8ddd7 | 2018-07-05 17:24:30 +0300 | [diff] [blame] | 82 | if (!ovr) { |
| 83 | tcf_idr_release(*a, bind); |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 84 | return -EEXIST; |
Vlad Buslov | 4e8ddd7 | 2018-07-05 17:24:30 +0300 | [diff] [blame] | 85 | } |
Vlad Buslov | 0190c1d | 2018-07-05 17:24:32 +0300 | [diff] [blame] | 86 | } else { |
| 87 | return err; |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 88 | } |
| 89 | |
WANG Cong | a85a970 | 2016-07-25 16:09:41 -0700 | [diff] [blame] | 90 | p = to_tcf_csum(*a); |
Davide Caratti | 9c5f69b | 2018-01-22 18:14:32 +0100 | [diff] [blame] | 91 | |
| 92 | params_new = kzalloc(sizeof(*params_new), GFP_KERNEL); |
| 93 | if (unlikely(!params_new)) { |
Vlad Buslov | 4e8ddd7 | 2018-07-05 17:24:30 +0300 | [diff] [blame] | 94 | tcf_idr_release(*a, bind); |
Davide Caratti | 9c5f69b | 2018-01-22 18:14:32 +0100 | [diff] [blame] | 95 | return -ENOMEM; |
| 96 | } |
Davide Caratti | 9c5f69b | 2018-01-22 18:14:32 +0100 | [diff] [blame] | 97 | params_new->update_flags = parm->update_flags; |
Vlad Buslov | b6a2b97 | 2018-08-10 20:51:42 +0300 | [diff] [blame] | 98 | |
Vlad Buslov | 653cd28 | 2018-08-14 21:46:16 +0300 | [diff] [blame] | 99 | spin_lock_bh(&p->tcf_lock); |
Vlad Buslov | b6a2b97 | 2018-08-10 20:51:42 +0300 | [diff] [blame] | 100 | p->tcf_action = parm->action; |
| 101 | rcu_swap_protected(p->params, params_new, |
| 102 | lockdep_is_held(&p->tcf_lock)); |
Vlad Buslov | 653cd28 | 2018-08-14 21:46:16 +0300 | [diff] [blame] | 103 | spin_unlock_bh(&p->tcf_lock); |
Vlad Buslov | b6a2b97 | 2018-08-10 20:51:42 +0300 | [diff] [blame] | 104 | |
| 105 | if (params_new) |
| 106 | kfree_rcu(params_new, rcu); |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 107 | |
| 108 | if (ret == ACT_P_CREATED) |
Chris Mi | 65a206c | 2017-08-30 02:31:59 -0400 | [diff] [blame] | 109 | tcf_idr_insert(tn, *a); |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 110 | |
| 111 | return ret; |
| 112 | } |
| 113 | |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 114 | /** |
| 115 | * tcf_csum_skb_nextlayer - Get next layer pointer |
| 116 | * @skb: sk_buff to use |
| 117 | * @ihl: previous summed headers length |
| 118 | * @ipl: complete packet length |
| 119 | * @jhl: next header length |
| 120 | * |
| 121 | * Check the expected next layer availability in the specified sk_buff. |
| 122 | * Return the next layer pointer if pass, NULL otherwise. |
| 123 | */ |
| 124 | static void *tcf_csum_skb_nextlayer(struct sk_buff *skb, |
| 125 | unsigned int ihl, unsigned int ipl, |
| 126 | unsigned int jhl) |
| 127 | { |
| 128 | int ntkoff = skb_network_offset(skb); |
| 129 | int hl = ihl + jhl; |
| 130 | |
| 131 | if (!pskb_may_pull(skb, ipl + ntkoff) || (ipl < hl) || |
Daniel Borkmann | 3697649 | 2016-02-19 23:05:25 +0100 | [diff] [blame] | 132 | skb_try_make_writable(skb, hl + ntkoff)) |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 133 | return NULL; |
| 134 | else |
| 135 | return (void *)(skb_network_header(skb) + ihl); |
| 136 | } |
| 137 | |
Jamal Hadi Salim | 5a7a555 | 2016-09-18 08:45:33 -0400 | [diff] [blame] | 138 | static int tcf_csum_ipv4_icmp(struct sk_buff *skb, unsigned int ihl, |
| 139 | unsigned int ipl) |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 140 | { |
| 141 | struct icmphdr *icmph; |
| 142 | |
| 143 | icmph = tcf_csum_skb_nextlayer(skb, ihl, ipl, sizeof(*icmph)); |
| 144 | if (icmph == NULL) |
| 145 | return 0; |
| 146 | |
| 147 | icmph->checksum = 0; |
| 148 | skb->csum = csum_partial(icmph, ipl - ihl, 0); |
| 149 | icmph->checksum = csum_fold(skb->csum); |
| 150 | |
| 151 | skb->ip_summed = CHECKSUM_NONE; |
| 152 | |
| 153 | return 1; |
| 154 | } |
| 155 | |
| 156 | static int tcf_csum_ipv4_igmp(struct sk_buff *skb, |
| 157 | unsigned int ihl, unsigned int ipl) |
| 158 | { |
| 159 | struct igmphdr *igmph; |
| 160 | |
| 161 | igmph = tcf_csum_skb_nextlayer(skb, ihl, ipl, sizeof(*igmph)); |
| 162 | if (igmph == NULL) |
| 163 | return 0; |
| 164 | |
| 165 | igmph->csum = 0; |
| 166 | skb->csum = csum_partial(igmph, ipl - ihl, 0); |
| 167 | igmph->csum = csum_fold(skb->csum); |
| 168 | |
| 169 | skb->ip_summed = CHECKSUM_NONE; |
| 170 | |
| 171 | return 1; |
| 172 | } |
| 173 | |
Jamal Hadi Salim | 5a7a555 | 2016-09-18 08:45:33 -0400 | [diff] [blame] | 174 | static int tcf_csum_ipv6_icmp(struct sk_buff *skb, unsigned int ihl, |
| 175 | unsigned int ipl) |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 176 | { |
| 177 | struct icmp6hdr *icmp6h; |
Eric Dumazet | d14a489 | 2013-04-12 11:07:47 -0700 | [diff] [blame] | 178 | const struct ipv6hdr *ip6h; |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 179 | |
| 180 | icmp6h = tcf_csum_skb_nextlayer(skb, ihl, ipl, sizeof(*icmp6h)); |
| 181 | if (icmp6h == NULL) |
| 182 | return 0; |
| 183 | |
Eric Dumazet | d14a489 | 2013-04-12 11:07:47 -0700 | [diff] [blame] | 184 | ip6h = ipv6_hdr(skb); |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 185 | icmp6h->icmp6_cksum = 0; |
| 186 | skb->csum = csum_partial(icmp6h, ipl - ihl, 0); |
| 187 | icmp6h->icmp6_cksum = csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr, |
| 188 | ipl - ihl, IPPROTO_ICMPV6, |
| 189 | skb->csum); |
| 190 | |
| 191 | skb->ip_summed = CHECKSUM_NONE; |
| 192 | |
| 193 | return 1; |
| 194 | } |
| 195 | |
Jamal Hadi Salim | 5a7a555 | 2016-09-18 08:45:33 -0400 | [diff] [blame] | 196 | static int tcf_csum_ipv4_tcp(struct sk_buff *skb, unsigned int ihl, |
| 197 | unsigned int ipl) |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 198 | { |
| 199 | struct tcphdr *tcph; |
Eric Dumazet | d14a489 | 2013-04-12 11:07:47 -0700 | [diff] [blame] | 200 | const struct iphdr *iph; |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 201 | |
Davide Caratti | add641e | 2017-03-23 10:39:40 +0100 | [diff] [blame] | 202 | if (skb_is_gso(skb) && skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4) |
| 203 | return 1; |
| 204 | |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 205 | tcph = tcf_csum_skb_nextlayer(skb, ihl, ipl, sizeof(*tcph)); |
| 206 | if (tcph == NULL) |
| 207 | return 0; |
| 208 | |
Eric Dumazet | d14a489 | 2013-04-12 11:07:47 -0700 | [diff] [blame] | 209 | iph = ip_hdr(skb); |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 210 | tcph->check = 0; |
| 211 | skb->csum = csum_partial(tcph, ipl - ihl, 0); |
| 212 | tcph->check = tcp_v4_check(ipl - ihl, |
| 213 | iph->saddr, iph->daddr, skb->csum); |
| 214 | |
| 215 | skb->ip_summed = CHECKSUM_NONE; |
| 216 | |
| 217 | return 1; |
| 218 | } |
| 219 | |
Jamal Hadi Salim | 5a7a555 | 2016-09-18 08:45:33 -0400 | [diff] [blame] | 220 | static int tcf_csum_ipv6_tcp(struct sk_buff *skb, unsigned int ihl, |
| 221 | unsigned int ipl) |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 222 | { |
| 223 | struct tcphdr *tcph; |
Eric Dumazet | d14a489 | 2013-04-12 11:07:47 -0700 | [diff] [blame] | 224 | const struct ipv6hdr *ip6h; |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 225 | |
Davide Caratti | add641e | 2017-03-23 10:39:40 +0100 | [diff] [blame] | 226 | if (skb_is_gso(skb) && skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6) |
| 227 | return 1; |
| 228 | |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 229 | tcph = tcf_csum_skb_nextlayer(skb, ihl, ipl, sizeof(*tcph)); |
| 230 | if (tcph == NULL) |
| 231 | return 0; |
| 232 | |
Eric Dumazet | d14a489 | 2013-04-12 11:07:47 -0700 | [diff] [blame] | 233 | ip6h = ipv6_hdr(skb); |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 234 | tcph->check = 0; |
| 235 | skb->csum = csum_partial(tcph, ipl - ihl, 0); |
| 236 | tcph->check = csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr, |
| 237 | ipl - ihl, IPPROTO_TCP, |
| 238 | skb->csum); |
| 239 | |
| 240 | skb->ip_summed = CHECKSUM_NONE; |
| 241 | |
| 242 | return 1; |
| 243 | } |
| 244 | |
Jamal Hadi Salim | 5a7a555 | 2016-09-18 08:45:33 -0400 | [diff] [blame] | 245 | static int tcf_csum_ipv4_udp(struct sk_buff *skb, unsigned int ihl, |
| 246 | unsigned int ipl, int udplite) |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 247 | { |
| 248 | struct udphdr *udph; |
Eric Dumazet | d14a489 | 2013-04-12 11:07:47 -0700 | [diff] [blame] | 249 | const struct iphdr *iph; |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 250 | u16 ul; |
| 251 | |
Willem de Bruijn | 0c19f846 | 2017-11-21 10:22:25 -0500 | [diff] [blame] | 252 | if (skb_is_gso(skb) && skb_shinfo(skb)->gso_type & SKB_GSO_UDP) |
| 253 | return 1; |
| 254 | |
Changli Gao | 0eec32f | 2010-08-23 03:27:58 +0000 | [diff] [blame] | 255 | /* |
| 256 | * Support both UDP and UDPLITE checksum algorithms, Don't use |
| 257 | * udph->len to get the real length without any protocol check, |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 258 | * UDPLITE uses udph->len for another thing, |
| 259 | * Use iph->tot_len, or just ipl. |
| 260 | */ |
| 261 | |
| 262 | udph = tcf_csum_skb_nextlayer(skb, ihl, ipl, sizeof(*udph)); |
| 263 | if (udph == NULL) |
| 264 | return 0; |
| 265 | |
Eric Dumazet | d14a489 | 2013-04-12 11:07:47 -0700 | [diff] [blame] | 266 | iph = ip_hdr(skb); |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 267 | ul = ntohs(udph->len); |
| 268 | |
| 269 | if (udplite || udph->check) { |
| 270 | |
| 271 | udph->check = 0; |
| 272 | |
| 273 | if (udplite) { |
| 274 | if (ul == 0) |
| 275 | skb->csum = csum_partial(udph, ipl - ihl, 0); |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 276 | else if ((ul >= sizeof(*udph)) && (ul <= ipl - ihl)) |
| 277 | skb->csum = csum_partial(udph, ul, 0); |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 278 | else |
| 279 | goto ignore_obscure_skb; |
| 280 | } else { |
| 281 | if (ul != ipl - ihl) |
| 282 | goto ignore_obscure_skb; |
| 283 | |
| 284 | skb->csum = csum_partial(udph, ul, 0); |
| 285 | } |
| 286 | |
| 287 | udph->check = csum_tcpudp_magic(iph->saddr, iph->daddr, |
| 288 | ul, iph->protocol, |
| 289 | skb->csum); |
| 290 | |
| 291 | if (!udph->check) |
| 292 | udph->check = CSUM_MANGLED_0; |
| 293 | } |
| 294 | |
| 295 | skb->ip_summed = CHECKSUM_NONE; |
| 296 | |
| 297 | ignore_obscure_skb: |
| 298 | return 1; |
| 299 | } |
| 300 | |
Jamal Hadi Salim | 5a7a555 | 2016-09-18 08:45:33 -0400 | [diff] [blame] | 301 | static int tcf_csum_ipv6_udp(struct sk_buff *skb, unsigned int ihl, |
| 302 | unsigned int ipl, int udplite) |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 303 | { |
| 304 | struct udphdr *udph; |
Eric Dumazet | d14a489 | 2013-04-12 11:07:47 -0700 | [diff] [blame] | 305 | const struct ipv6hdr *ip6h; |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 306 | u16 ul; |
| 307 | |
Willem de Bruijn | 0c19f846 | 2017-11-21 10:22:25 -0500 | [diff] [blame] | 308 | if (skb_is_gso(skb) && skb_shinfo(skb)->gso_type & SKB_GSO_UDP) |
| 309 | return 1; |
| 310 | |
Changli Gao | 0eec32f | 2010-08-23 03:27:58 +0000 | [diff] [blame] | 311 | /* |
| 312 | * Support both UDP and UDPLITE checksum algorithms, Don't use |
| 313 | * udph->len to get the real length without any protocol check, |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 314 | * UDPLITE uses udph->len for another thing, |
| 315 | * Use ip6h->payload_len + sizeof(*ip6h) ... , or just ipl. |
| 316 | */ |
| 317 | |
| 318 | udph = tcf_csum_skb_nextlayer(skb, ihl, ipl, sizeof(*udph)); |
| 319 | if (udph == NULL) |
| 320 | return 0; |
| 321 | |
Eric Dumazet | d14a489 | 2013-04-12 11:07:47 -0700 | [diff] [blame] | 322 | ip6h = ipv6_hdr(skb); |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 323 | ul = ntohs(udph->len); |
| 324 | |
| 325 | udph->check = 0; |
| 326 | |
| 327 | if (udplite) { |
| 328 | if (ul == 0) |
| 329 | skb->csum = csum_partial(udph, ipl - ihl, 0); |
| 330 | |
| 331 | else if ((ul >= sizeof(*udph)) && (ul <= ipl - ihl)) |
| 332 | skb->csum = csum_partial(udph, ul, 0); |
| 333 | |
| 334 | else |
| 335 | goto ignore_obscure_skb; |
| 336 | } else { |
| 337 | if (ul != ipl - ihl) |
| 338 | goto ignore_obscure_skb; |
| 339 | |
| 340 | skb->csum = csum_partial(udph, ul, 0); |
| 341 | } |
| 342 | |
| 343 | udph->check = csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr, ul, |
| 344 | udplite ? IPPROTO_UDPLITE : IPPROTO_UDP, |
| 345 | skb->csum); |
| 346 | |
| 347 | if (!udph->check) |
| 348 | udph->check = CSUM_MANGLED_0; |
| 349 | |
| 350 | skb->ip_summed = CHECKSUM_NONE; |
| 351 | |
| 352 | ignore_obscure_skb: |
| 353 | return 1; |
| 354 | } |
| 355 | |
Davide Caratti | c008b33 | 2017-01-09 11:24:21 +0100 | [diff] [blame] | 356 | static int tcf_csum_sctp(struct sk_buff *skb, unsigned int ihl, |
| 357 | unsigned int ipl) |
| 358 | { |
| 359 | struct sctphdr *sctph; |
| 360 | |
Daniel Axtens | 1dd27cd | 2018-03-09 14:06:09 +1100 | [diff] [blame] | 361 | if (skb_is_gso(skb) && skb_is_gso_sctp(skb)) |
Davide Caratti | c008b33 | 2017-01-09 11:24:21 +0100 | [diff] [blame] | 362 | return 1; |
| 363 | |
| 364 | sctph = tcf_csum_skb_nextlayer(skb, ihl, ipl, sizeof(*sctph)); |
| 365 | if (!sctph) |
| 366 | return 0; |
| 367 | |
| 368 | sctph->checksum = sctp_compute_cksum(skb, |
| 369 | skb_network_offset(skb) + ihl); |
| 370 | skb->ip_summed = CHECKSUM_NONE; |
Davide Caratti | dba0030 | 2017-05-18 15:44:40 +0200 | [diff] [blame] | 371 | skb->csum_not_inet = 0; |
Davide Caratti | c008b33 | 2017-01-09 11:24:21 +0100 | [diff] [blame] | 372 | |
| 373 | return 1; |
| 374 | } |
| 375 | |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 376 | static int tcf_csum_ipv4(struct sk_buff *skb, u32 update_flags) |
| 377 | { |
Eric Dumazet | d14a489 | 2013-04-12 11:07:47 -0700 | [diff] [blame] | 378 | const struct iphdr *iph; |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 379 | int ntkoff; |
| 380 | |
| 381 | ntkoff = skb_network_offset(skb); |
| 382 | |
| 383 | if (!pskb_may_pull(skb, sizeof(*iph) + ntkoff)) |
| 384 | goto fail; |
| 385 | |
| 386 | iph = ip_hdr(skb); |
| 387 | |
| 388 | switch (iph->frag_off & htons(IP_OFFSET) ? 0 : iph->protocol) { |
| 389 | case IPPROTO_ICMP: |
| 390 | if (update_flags & TCA_CSUM_UPDATE_FLAG_ICMP) |
Changli Gao | 0eec32f | 2010-08-23 03:27:58 +0000 | [diff] [blame] | 391 | if (!tcf_csum_ipv4_icmp(skb, iph->ihl * 4, |
| 392 | ntohs(iph->tot_len))) |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 393 | goto fail; |
| 394 | break; |
| 395 | case IPPROTO_IGMP: |
| 396 | if (update_flags & TCA_CSUM_UPDATE_FLAG_IGMP) |
Changli Gao | 0eec32f | 2010-08-23 03:27:58 +0000 | [diff] [blame] | 397 | if (!tcf_csum_ipv4_igmp(skb, iph->ihl * 4, |
| 398 | ntohs(iph->tot_len))) |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 399 | goto fail; |
| 400 | break; |
| 401 | case IPPROTO_TCP: |
| 402 | if (update_flags & TCA_CSUM_UPDATE_FLAG_TCP) |
Eric Dumazet | d14a489 | 2013-04-12 11:07:47 -0700 | [diff] [blame] | 403 | if (!tcf_csum_ipv4_tcp(skb, iph->ihl * 4, |
Changli Gao | 0eec32f | 2010-08-23 03:27:58 +0000 | [diff] [blame] | 404 | ntohs(iph->tot_len))) |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 405 | goto fail; |
| 406 | break; |
| 407 | case IPPROTO_UDP: |
| 408 | if (update_flags & TCA_CSUM_UPDATE_FLAG_UDP) |
Eric Dumazet | d14a489 | 2013-04-12 11:07:47 -0700 | [diff] [blame] | 409 | if (!tcf_csum_ipv4_udp(skb, iph->ihl * 4, |
Changli Gao | 0eec32f | 2010-08-23 03:27:58 +0000 | [diff] [blame] | 410 | ntohs(iph->tot_len), 0)) |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 411 | goto fail; |
| 412 | break; |
| 413 | case IPPROTO_UDPLITE: |
| 414 | if (update_flags & TCA_CSUM_UPDATE_FLAG_UDPLITE) |
Eric Dumazet | d14a489 | 2013-04-12 11:07:47 -0700 | [diff] [blame] | 415 | if (!tcf_csum_ipv4_udp(skb, iph->ihl * 4, |
Changli Gao | 0eec32f | 2010-08-23 03:27:58 +0000 | [diff] [blame] | 416 | ntohs(iph->tot_len), 1)) |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 417 | goto fail; |
| 418 | break; |
Davide Caratti | c008b33 | 2017-01-09 11:24:21 +0100 | [diff] [blame] | 419 | case IPPROTO_SCTP: |
| 420 | if ((update_flags & TCA_CSUM_UPDATE_FLAG_SCTP) && |
| 421 | !tcf_csum_sctp(skb, iph->ihl * 4, ntohs(iph->tot_len))) |
| 422 | goto fail; |
| 423 | break; |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | if (update_flags & TCA_CSUM_UPDATE_FLAG_IPV4HDR) { |
Daniel Borkmann | 3697649 | 2016-02-19 23:05:25 +0100 | [diff] [blame] | 427 | if (skb_try_make_writable(skb, sizeof(*iph) + ntkoff)) |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 428 | goto fail; |
| 429 | |
Eric Dumazet | d14a489 | 2013-04-12 11:07:47 -0700 | [diff] [blame] | 430 | ip_send_check(ip_hdr(skb)); |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | return 1; |
| 434 | |
| 435 | fail: |
| 436 | return 0; |
| 437 | } |
| 438 | |
Jamal Hadi Salim | 5a7a555 | 2016-09-18 08:45:33 -0400 | [diff] [blame] | 439 | static int tcf_csum_ipv6_hopopts(struct ipv6_opt_hdr *ip6xh, unsigned int ixhl, |
| 440 | unsigned int *pl) |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 441 | { |
| 442 | int off, len, optlen; |
| 443 | unsigned char *xh = (void *)ip6xh; |
| 444 | |
| 445 | off = sizeof(*ip6xh); |
| 446 | len = ixhl - off; |
| 447 | |
| 448 | while (len > 1) { |
Changli Gao | 0eec32f | 2010-08-23 03:27:58 +0000 | [diff] [blame] | 449 | switch (xh[off]) { |
Eldad Zack | 1de5a71 | 2012-05-17 06:00:25 +0000 | [diff] [blame] | 450 | case IPV6_TLV_PAD1: |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 451 | optlen = 1; |
| 452 | break; |
| 453 | case IPV6_TLV_JUMBO: |
| 454 | optlen = xh[off + 1] + 2; |
| 455 | if (optlen != 6 || len < 6 || (off & 3) != 2) |
| 456 | /* wrong jumbo option length/alignment */ |
| 457 | return 0; |
| 458 | *pl = ntohl(*(__be32 *)(xh + off + 2)); |
| 459 | goto done; |
| 460 | default: |
| 461 | optlen = xh[off + 1] + 2; |
| 462 | if (optlen > len) |
| 463 | /* ignore obscure options */ |
| 464 | goto done; |
| 465 | break; |
| 466 | } |
| 467 | off += optlen; |
| 468 | len -= optlen; |
| 469 | } |
| 470 | |
| 471 | done: |
| 472 | return 1; |
| 473 | } |
| 474 | |
| 475 | static int tcf_csum_ipv6(struct sk_buff *skb, u32 update_flags) |
| 476 | { |
| 477 | struct ipv6hdr *ip6h; |
| 478 | struct ipv6_opt_hdr *ip6xh; |
| 479 | unsigned int hl, ixhl; |
| 480 | unsigned int pl; |
| 481 | int ntkoff; |
| 482 | u8 nexthdr; |
| 483 | |
| 484 | ntkoff = skb_network_offset(skb); |
| 485 | |
| 486 | hl = sizeof(*ip6h); |
| 487 | |
| 488 | if (!pskb_may_pull(skb, hl + ntkoff)) |
| 489 | goto fail; |
| 490 | |
| 491 | ip6h = ipv6_hdr(skb); |
| 492 | |
| 493 | pl = ntohs(ip6h->payload_len); |
| 494 | nexthdr = ip6h->nexthdr; |
| 495 | |
| 496 | do { |
| 497 | switch (nexthdr) { |
| 498 | case NEXTHDR_FRAGMENT: |
| 499 | goto ignore_skb; |
| 500 | case NEXTHDR_ROUTING: |
| 501 | case NEXTHDR_HOP: |
| 502 | case NEXTHDR_DEST: |
| 503 | if (!pskb_may_pull(skb, hl + sizeof(*ip6xh) + ntkoff)) |
| 504 | goto fail; |
| 505 | ip6xh = (void *)(skb_network_header(skb) + hl); |
| 506 | ixhl = ipv6_optlen(ip6xh); |
| 507 | if (!pskb_may_pull(skb, hl + ixhl + ntkoff)) |
| 508 | goto fail; |
Eric Dumazet | d14a489 | 2013-04-12 11:07:47 -0700 | [diff] [blame] | 509 | ip6xh = (void *)(skb_network_header(skb) + hl); |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 510 | if ((nexthdr == NEXTHDR_HOP) && |
| 511 | !(tcf_csum_ipv6_hopopts(ip6xh, ixhl, &pl))) |
| 512 | goto fail; |
| 513 | nexthdr = ip6xh->nexthdr; |
| 514 | hl += ixhl; |
| 515 | break; |
| 516 | case IPPROTO_ICMPV6: |
| 517 | if (update_flags & TCA_CSUM_UPDATE_FLAG_ICMP) |
Eric Dumazet | d14a489 | 2013-04-12 11:07:47 -0700 | [diff] [blame] | 518 | if (!tcf_csum_ipv6_icmp(skb, |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 519 | hl, pl + sizeof(*ip6h))) |
| 520 | goto fail; |
| 521 | goto done; |
| 522 | case IPPROTO_TCP: |
| 523 | if (update_flags & TCA_CSUM_UPDATE_FLAG_TCP) |
Eric Dumazet | d14a489 | 2013-04-12 11:07:47 -0700 | [diff] [blame] | 524 | if (!tcf_csum_ipv6_tcp(skb, |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 525 | hl, pl + sizeof(*ip6h))) |
| 526 | goto fail; |
| 527 | goto done; |
| 528 | case IPPROTO_UDP: |
| 529 | if (update_flags & TCA_CSUM_UPDATE_FLAG_UDP) |
Eric Dumazet | d14a489 | 2013-04-12 11:07:47 -0700 | [diff] [blame] | 530 | if (!tcf_csum_ipv6_udp(skb, hl, |
Changli Gao | 0eec32f | 2010-08-23 03:27:58 +0000 | [diff] [blame] | 531 | pl + sizeof(*ip6h), 0)) |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 532 | goto fail; |
| 533 | goto done; |
| 534 | case IPPROTO_UDPLITE: |
| 535 | if (update_flags & TCA_CSUM_UPDATE_FLAG_UDPLITE) |
Eric Dumazet | d14a489 | 2013-04-12 11:07:47 -0700 | [diff] [blame] | 536 | if (!tcf_csum_ipv6_udp(skb, hl, |
Changli Gao | 0eec32f | 2010-08-23 03:27:58 +0000 | [diff] [blame] | 537 | pl + sizeof(*ip6h), 1)) |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 538 | goto fail; |
| 539 | goto done; |
Davide Caratti | c008b33 | 2017-01-09 11:24:21 +0100 | [diff] [blame] | 540 | case IPPROTO_SCTP: |
| 541 | if ((update_flags & TCA_CSUM_UPDATE_FLAG_SCTP) && |
| 542 | !tcf_csum_sctp(skb, hl, pl + sizeof(*ip6h))) |
| 543 | goto fail; |
| 544 | goto done; |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 545 | default: |
| 546 | goto ignore_skb; |
| 547 | } |
| 548 | } while (pskb_may_pull(skb, hl + 1 + ntkoff)); |
| 549 | |
| 550 | done: |
| 551 | ignore_skb: |
| 552 | return 1; |
| 553 | |
| 554 | fail: |
| 555 | return 0; |
| 556 | } |
| 557 | |
Jamal Hadi Salim | c831549 | 2018-08-12 09:34:51 -0400 | [diff] [blame] | 558 | static int tcf_csum_act(struct sk_buff *skb, const struct tc_action *a, |
| 559 | struct tcf_result *res) |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 560 | { |
WANG Cong | a85a970 | 2016-07-25 16:09:41 -0700 | [diff] [blame] | 561 | struct tcf_csum *p = to_tcf_csum(a); |
Davide Caratti | 9c5f69b | 2018-01-22 18:14:32 +0100 | [diff] [blame] | 562 | struct tcf_csum_params *params; |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 563 | u32 update_flags; |
Davide Caratti | 9c5f69b | 2018-01-22 18:14:32 +0100 | [diff] [blame] | 564 | int action; |
| 565 | |
Paolo Abeni | 7fd4b28 | 2018-07-30 14:30:43 +0200 | [diff] [blame] | 566 | params = rcu_dereference_bh(p->params); |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 567 | |
Jamal Hadi Salim | 9c4a4e4 | 2016-06-06 06:32:53 -0400 | [diff] [blame] | 568 | tcf_lastuse_update(&p->tcf_tm); |
Davide Caratti | f6052cf | 2018-01-22 18:14:31 +0100 | [diff] [blame] | 569 | bstats_cpu_update(this_cpu_ptr(p->common.cpu_bstats), skb); |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 570 | |
Davide Caratti | 11a245e | 2018-07-06 21:01:05 +0200 | [diff] [blame] | 571 | action = READ_ONCE(p->tcf_action); |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 572 | if (unlikely(action == TC_ACT_SHOT)) |
Paolo Abeni | 7fd4b28 | 2018-07-30 14:30:43 +0200 | [diff] [blame] | 573 | goto drop; |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 574 | |
Davide Caratti | 9c5f69b | 2018-01-22 18:14:32 +0100 | [diff] [blame] | 575 | update_flags = params->update_flags; |
Jiri Pirko | d8b9605 | 2015-01-13 17:13:43 +0100 | [diff] [blame] | 576 | switch (tc_skb_protocol(skb)) { |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 577 | case cpu_to_be16(ETH_P_IP): |
| 578 | if (!tcf_csum_ipv4(skb, update_flags)) |
| 579 | goto drop; |
| 580 | break; |
| 581 | case cpu_to_be16(ETH_P_IPV6): |
| 582 | if (!tcf_csum_ipv6(skb, update_flags)) |
| 583 | goto drop; |
| 584 | break; |
| 585 | } |
| 586 | |
| 587 | return action; |
| 588 | |
| 589 | drop: |
Davide Caratti | f6052cf | 2018-01-22 18:14:31 +0100 | [diff] [blame] | 590 | qstats_drop_inc(this_cpu_ptr(p->common.cpu_qstats)); |
Paolo Abeni | 7fd4b28 | 2018-07-30 14:30:43 +0200 | [diff] [blame] | 591 | return TC_ACT_SHOT; |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 592 | } |
| 593 | |
Jamal Hadi Salim | 5a7a555 | 2016-09-18 08:45:33 -0400 | [diff] [blame] | 594 | static int tcf_csum_dump(struct sk_buff *skb, struct tc_action *a, int bind, |
| 595 | int ref) |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 596 | { |
| 597 | unsigned char *b = skb_tail_pointer(skb); |
WANG Cong | a85a970 | 2016-07-25 16:09:41 -0700 | [diff] [blame] | 598 | struct tcf_csum *p = to_tcf_csum(a); |
Davide Caratti | 9c5f69b | 2018-01-22 18:14:32 +0100 | [diff] [blame] | 599 | struct tcf_csum_params *params; |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 600 | struct tc_csum opt = { |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 601 | .index = p->tcf_index, |
Vlad Buslov | 036bb44 | 2018-07-05 17:24:24 +0300 | [diff] [blame] | 602 | .refcnt = refcount_read(&p->tcf_refcnt) - ref, |
| 603 | .bindcnt = atomic_read(&p->tcf_bindcnt) - bind, |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 604 | }; |
| 605 | struct tcf_t t; |
| 606 | |
Vlad Buslov | 653cd28 | 2018-08-14 21:46:16 +0300 | [diff] [blame] | 607 | spin_lock_bh(&p->tcf_lock); |
Vlad Buslov | b6a2b97 | 2018-08-10 20:51:42 +0300 | [diff] [blame] | 608 | params = rcu_dereference_protected(p->params, |
| 609 | lockdep_is_held(&p->tcf_lock)); |
| 610 | opt.action = p->tcf_action; |
Davide Caratti | 9c5f69b | 2018-01-22 18:14:32 +0100 | [diff] [blame] | 611 | opt.update_flags = params->update_flags; |
| 612 | |
David S. Miller | 1b34ec4 | 2012-03-29 05:11:39 -0400 | [diff] [blame] | 613 | if (nla_put(skb, TCA_CSUM_PARMS, sizeof(opt), &opt)) |
| 614 | goto nla_put_failure; |
Jamal Hadi Salim | 48d8ee1 | 2016-06-06 06:32:55 -0400 | [diff] [blame] | 615 | |
| 616 | tcf_tm_dump(&t, &p->tcf_tm); |
Nicolas Dichtel | 9854518 | 2016-04-26 10:06:18 +0200 | [diff] [blame] | 617 | if (nla_put_64bit(skb, TCA_CSUM_TM, sizeof(t), &t, TCA_CSUM_PAD)) |
David S. Miller | 1b34ec4 | 2012-03-29 05:11:39 -0400 | [diff] [blame] | 618 | goto nla_put_failure; |
Vlad Buslov | 653cd28 | 2018-08-14 21:46:16 +0300 | [diff] [blame] | 619 | spin_unlock_bh(&p->tcf_lock); |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 620 | |
| 621 | return skb->len; |
| 622 | |
| 623 | nla_put_failure: |
Vlad Buslov | 653cd28 | 2018-08-14 21:46:16 +0300 | [diff] [blame] | 624 | spin_unlock_bh(&p->tcf_lock); |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 625 | nlmsg_trim(skb, b); |
| 626 | return -1; |
| 627 | } |
| 628 | |
Davide Caratti | 9c5f69b | 2018-01-22 18:14:32 +0100 | [diff] [blame] | 629 | static void tcf_csum_cleanup(struct tc_action *a) |
| 630 | { |
| 631 | struct tcf_csum *p = to_tcf_csum(a); |
| 632 | struct tcf_csum_params *params; |
| 633 | |
| 634 | params = rcu_dereference_protected(p->params, 1); |
Davide Caratti | aab378a | 2018-03-16 00:00:54 +0100 | [diff] [blame] | 635 | if (params) |
| 636 | kfree_rcu(params, rcu); |
Davide Caratti | 9c5f69b | 2018-01-22 18:14:32 +0100 | [diff] [blame] | 637 | } |
| 638 | |
WANG Cong | ddf97cc | 2016-02-22 15:57:53 -0800 | [diff] [blame] | 639 | static int tcf_csum_walker(struct net *net, struct sk_buff *skb, |
| 640 | struct netlink_callback *cb, int type, |
Alexander Aring | 4178010 | 2018-02-15 10:54:58 -0500 | [diff] [blame] | 641 | const struct tc_action_ops *ops, |
| 642 | struct netlink_ext_ack *extack) |
WANG Cong | ddf97cc | 2016-02-22 15:57:53 -0800 | [diff] [blame] | 643 | { |
| 644 | struct tc_action_net *tn = net_generic(net, csum_net_id); |
| 645 | |
Alexander Aring | b362014 | 2018-02-15 10:54:59 -0500 | [diff] [blame] | 646 | return tcf_generic_walker(tn, skb, cb, type, ops, extack); |
WANG Cong | ddf97cc | 2016-02-22 15:57:53 -0800 | [diff] [blame] | 647 | } |
| 648 | |
Cong Wang | f061b48 | 2018-08-29 10:15:35 -0700 | [diff] [blame] | 649 | static int tcf_csum_search(struct net *net, struct tc_action **a, u32 index) |
WANG Cong | ddf97cc | 2016-02-22 15:57:53 -0800 | [diff] [blame] | 650 | { |
| 651 | struct tc_action_net *tn = net_generic(net, csum_net_id); |
| 652 | |
Chris Mi | 65a206c | 2017-08-30 02:31:59 -0400 | [diff] [blame] | 653 | return tcf_idr_search(tn, a, index); |
WANG Cong | ddf97cc | 2016-02-22 15:57:53 -0800 | [diff] [blame] | 654 | } |
| 655 | |
Craig Dillabaugh | 29e6eee | 2018-05-01 10:17:43 -0400 | [diff] [blame] | 656 | static size_t tcf_csum_get_fill_size(const struct tc_action *act) |
| 657 | { |
| 658 | return nla_total_size(sizeof(struct tc_csum)); |
| 659 | } |
| 660 | |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 661 | static struct tc_action_ops act_csum_ops = { |
Changli Gao | 0eec32f | 2010-08-23 03:27:58 +0000 | [diff] [blame] | 662 | .kind = "csum", |
Changli Gao | 0eec32f | 2010-08-23 03:27:58 +0000 | [diff] [blame] | 663 | .type = TCA_ACT_CSUM, |
Changli Gao | 0eec32f | 2010-08-23 03:27:58 +0000 | [diff] [blame] | 664 | .owner = THIS_MODULE, |
Jamal Hadi Salim | c831549 | 2018-08-12 09:34:51 -0400 | [diff] [blame] | 665 | .act = tcf_csum_act, |
Changli Gao | 0eec32f | 2010-08-23 03:27:58 +0000 | [diff] [blame] | 666 | .dump = tcf_csum_dump, |
Changli Gao | 0eec32f | 2010-08-23 03:27:58 +0000 | [diff] [blame] | 667 | .init = tcf_csum_init, |
Davide Caratti | 9c5f69b | 2018-01-22 18:14:32 +0100 | [diff] [blame] | 668 | .cleanup = tcf_csum_cleanup, |
WANG Cong | ddf97cc | 2016-02-22 15:57:53 -0800 | [diff] [blame] | 669 | .walk = tcf_csum_walker, |
| 670 | .lookup = tcf_csum_search, |
Craig Dillabaugh | 29e6eee | 2018-05-01 10:17:43 -0400 | [diff] [blame] | 671 | .get_fill_size = tcf_csum_get_fill_size, |
WANG Cong | a85a970 | 2016-07-25 16:09:41 -0700 | [diff] [blame] | 672 | .size = sizeof(struct tcf_csum), |
WANG Cong | ddf97cc | 2016-02-22 15:57:53 -0800 | [diff] [blame] | 673 | }; |
| 674 | |
| 675 | static __net_init int csum_init_net(struct net *net) |
| 676 | { |
| 677 | struct tc_action_net *tn = net_generic(net, csum_net_id); |
| 678 | |
Cong Wang | c7e460c | 2017-11-06 13:47:18 -0800 | [diff] [blame] | 679 | return tc_action_net_init(tn, &act_csum_ops); |
WANG Cong | ddf97cc | 2016-02-22 15:57:53 -0800 | [diff] [blame] | 680 | } |
| 681 | |
Cong Wang | 039af9c | 2017-12-11 15:35:03 -0800 | [diff] [blame] | 682 | static void __net_exit csum_exit_net(struct list_head *net_list) |
WANG Cong | ddf97cc | 2016-02-22 15:57:53 -0800 | [diff] [blame] | 683 | { |
Cong Wang | 039af9c | 2017-12-11 15:35:03 -0800 | [diff] [blame] | 684 | tc_action_net_exit(net_list, csum_net_id); |
WANG Cong | ddf97cc | 2016-02-22 15:57:53 -0800 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | static struct pernet_operations csum_net_ops = { |
| 688 | .init = csum_init_net, |
Cong Wang | 039af9c | 2017-12-11 15:35:03 -0800 | [diff] [blame] | 689 | .exit_batch = csum_exit_net, |
WANG Cong | ddf97cc | 2016-02-22 15:57:53 -0800 | [diff] [blame] | 690 | .id = &csum_net_id, |
| 691 | .size = sizeof(struct tc_action_net), |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 692 | }; |
| 693 | |
| 694 | MODULE_DESCRIPTION("Checksum updating actions"); |
| 695 | MODULE_LICENSE("GPL"); |
| 696 | |
| 697 | static int __init csum_init_module(void) |
| 698 | { |
WANG Cong | ddf97cc | 2016-02-22 15:57:53 -0800 | [diff] [blame] | 699 | return tcf_register_action(&act_csum_ops, &csum_net_ops); |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | static void __exit csum_cleanup_module(void) |
| 703 | { |
WANG Cong | ddf97cc | 2016-02-22 15:57:53 -0800 | [diff] [blame] | 704 | tcf_unregister_action(&act_csum_ops, &csum_net_ops); |
Grégoire Baron | eb4d406 | 2010-08-18 13:10:35 +0000 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | module_init(csum_init_module); |
| 708 | module_exit(csum_cleanup_module); |