.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Checksum updating actions |
---|
3 | 4 | * |
---|
4 | 5 | * 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 | 6 | */ |
---|
12 | 7 | |
---|
13 | 8 | #include <linux/types.h> |
---|
.. | .. |
---|
33 | 28 | #include <net/sctp/checksum.h> |
---|
34 | 29 | |
---|
35 | 30 | #include <net/act_api.h> |
---|
| 31 | +#include <net/pkt_cls.h> |
---|
36 | 32 | |
---|
37 | 33 | #include <linux/tc_act/tc_csum.h> |
---|
38 | 34 | #include <net/tc_act/tc_csum.h> |
---|
.. | .. |
---|
46 | 42 | |
---|
47 | 43 | static int tcf_csum_init(struct net *net, struct nlattr *nla, |
---|
48 | 44 | struct nlattr *est, struct tc_action **a, int ovr, |
---|
49 | | - int bind, bool rtnl_held, |
---|
50 | | - struct netlink_ext_ack *extack) |
---|
| 45 | + int bind, bool rtnl_held, struct tcf_proto *tp, |
---|
| 46 | + u32 flags, struct netlink_ext_ack *extack) |
---|
51 | 47 | { |
---|
52 | 48 | struct tc_action_net *tn = net_generic(net, csum_net_id); |
---|
53 | 49 | struct tcf_csum_params *params_new; |
---|
54 | 50 | struct nlattr *tb[TCA_CSUM_MAX + 1]; |
---|
| 51 | + struct tcf_chain *goto_ch = NULL; |
---|
55 | 52 | struct tc_csum *parm; |
---|
56 | 53 | struct tcf_csum *p; |
---|
57 | 54 | int ret = 0, err; |
---|
.. | .. |
---|
60 | 57 | if (nla == NULL) |
---|
61 | 58 | return -EINVAL; |
---|
62 | 59 | |
---|
63 | | - err = nla_parse_nested(tb, TCA_CSUM_MAX, nla, csum_policy, NULL); |
---|
| 60 | + err = nla_parse_nested_deprecated(tb, TCA_CSUM_MAX, nla, csum_policy, |
---|
| 61 | + NULL); |
---|
64 | 62 | if (err < 0) |
---|
65 | 63 | return err; |
---|
66 | 64 | |
---|
.. | .. |
---|
70 | 68 | index = parm->index; |
---|
71 | 69 | err = tcf_idr_check_alloc(tn, &index, a, bind); |
---|
72 | 70 | if (!err) { |
---|
73 | | - ret = tcf_idr_create(tn, index, est, a, |
---|
74 | | - &act_csum_ops, bind, true); |
---|
| 71 | + ret = tcf_idr_create_from_flags(tn, index, est, a, |
---|
| 72 | + &act_csum_ops, bind, flags); |
---|
75 | 73 | if (ret) { |
---|
76 | 74 | tcf_idr_cleanup(tn, index); |
---|
77 | 75 | return ret; |
---|
.. | .. |
---|
88 | 86 | return err; |
---|
89 | 87 | } |
---|
90 | 88 | |
---|
| 89 | + err = tcf_action_check_ctrlact(parm->action, tp, &goto_ch, extack); |
---|
| 90 | + if (err < 0) |
---|
| 91 | + goto release_idr; |
---|
| 92 | + |
---|
91 | 93 | p = to_tcf_csum(*a); |
---|
92 | 94 | |
---|
93 | 95 | params_new = kzalloc(sizeof(*params_new), GFP_KERNEL); |
---|
94 | 96 | if (unlikely(!params_new)) { |
---|
95 | | - tcf_idr_release(*a, bind); |
---|
96 | | - return -ENOMEM; |
---|
| 97 | + err = -ENOMEM; |
---|
| 98 | + goto put_chain; |
---|
97 | 99 | } |
---|
98 | 100 | params_new->update_flags = parm->update_flags; |
---|
99 | 101 | |
---|
100 | 102 | spin_lock_bh(&p->tcf_lock); |
---|
101 | | - p->tcf_action = parm->action; |
---|
102 | | - rcu_swap_protected(p->params, params_new, |
---|
103 | | - lockdep_is_held(&p->tcf_lock)); |
---|
| 103 | + goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch); |
---|
| 104 | + params_new = rcu_replace_pointer(p->params, params_new, |
---|
| 105 | + lockdep_is_held(&p->tcf_lock)); |
---|
104 | 106 | spin_unlock_bh(&p->tcf_lock); |
---|
105 | 107 | |
---|
| 108 | + if (goto_ch) |
---|
| 109 | + tcf_chain_put_by_act(goto_ch); |
---|
106 | 110 | if (params_new) |
---|
107 | 111 | kfree_rcu(params_new, rcu); |
---|
108 | 112 | |
---|
109 | | - if (ret == ACT_P_CREATED) |
---|
110 | | - tcf_idr_insert(tn, *a); |
---|
111 | | - |
---|
112 | 113 | return ret; |
---|
| 114 | +put_chain: |
---|
| 115 | + if (goto_ch) |
---|
| 116 | + tcf_chain_put_by_act(goto_ch); |
---|
| 117 | +release_idr: |
---|
| 118 | + tcf_idr_release(*a, bind); |
---|
| 119 | + return err; |
---|
113 | 120 | } |
---|
114 | 121 | |
---|
115 | 122 | /** |
---|
.. | .. |
---|
570 | 577 | params = rcu_dereference_bh(p->params); |
---|
571 | 578 | |
---|
572 | 579 | tcf_lastuse_update(&p->tcf_tm); |
---|
573 | | - bstats_cpu_update(this_cpu_ptr(p->common.cpu_bstats), skb); |
---|
| 580 | + tcf_action_update_bstats(&p->common, skb); |
---|
574 | 581 | |
---|
575 | 582 | action = READ_ONCE(p->tcf_action); |
---|
576 | 583 | if (unlikely(action == TC_ACT_SHOT)) |
---|
.. | .. |
---|
588 | 595 | if (!tcf_csum_ipv6(skb, update_flags)) |
---|
589 | 596 | goto drop; |
---|
590 | 597 | break; |
---|
591 | | - case cpu_to_be16(ETH_P_8021AD): /* fall through */ |
---|
| 598 | + case cpu_to_be16(ETH_P_8021AD): |
---|
| 599 | + fallthrough; |
---|
592 | 600 | case cpu_to_be16(ETH_P_8021Q): |
---|
593 | 601 | if (skb_vlan_tag_present(skb) && !orig_vlan_tag_present) { |
---|
594 | 602 | protocol = skb->protocol; |
---|
.. | .. |
---|
614 | 622 | return action; |
---|
615 | 623 | |
---|
616 | 624 | drop: |
---|
617 | | - qstats_drop_inc(this_cpu_ptr(p->common.cpu_qstats)); |
---|
| 625 | + tcf_action_inc_drop_qstats(&p->common); |
---|
618 | 626 | action = TC_ACT_SHOT; |
---|
619 | 627 | goto out; |
---|
620 | 628 | } |
---|
.. | .. |
---|
674 | 682 | return tcf_generic_walker(tn, skb, cb, type, ops, extack); |
---|
675 | 683 | } |
---|
676 | 684 | |
---|
677 | | -static int tcf_csum_search(struct net *net, struct tc_action **a, u32 index, |
---|
678 | | - struct netlink_ext_ack *extack) |
---|
| 685 | +static int tcf_csum_search(struct net *net, struct tc_action **a, u32 index) |
---|
679 | 686 | { |
---|
680 | 687 | struct tc_action_net *tn = net_generic(net, csum_net_id); |
---|
681 | 688 | |
---|
.. | .. |
---|
689 | 696 | |
---|
690 | 697 | static struct tc_action_ops act_csum_ops = { |
---|
691 | 698 | .kind = "csum", |
---|
692 | | - .type = TCA_ACT_CSUM, |
---|
| 699 | + .id = TCA_ID_CSUM, |
---|
693 | 700 | .owner = THIS_MODULE, |
---|
694 | 701 | .act = tcf_csum_act, |
---|
695 | 702 | .dump = tcf_csum_dump, |
---|