| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * net/sched/act_gact.c Generic actions |
|---|
| 3 | 4 | * |
|---|
| 4 | | - * This program is free software; you can redistribute it and/or |
|---|
| 5 | | - * modify it under the terms of the GNU General Public License |
|---|
| 6 | | - * as published by the Free Software Foundation; either version |
|---|
| 7 | | - * 2 of the License, or (at your option) any later version. |
|---|
| 8 | | - * |
|---|
| 9 | 5 | * copyright Jamal Hadi Salim (2002-4) |
|---|
| 10 | | - * |
|---|
| 11 | 6 | */ |
|---|
| 12 | 7 | |
|---|
| 13 | 8 | #include <linux/types.h> |
|---|
| .. | .. |
|---|
| 20 | 15 | #include <linux/init.h> |
|---|
| 21 | 16 | #include <net/netlink.h> |
|---|
| 22 | 17 | #include <net/pkt_sched.h> |
|---|
| 18 | +#include <net/pkt_cls.h> |
|---|
| 23 | 19 | #include <linux/tc_act/tc_gact.h> |
|---|
| 24 | 20 | #include <net/tc_act/tc_gact.h> |
|---|
| 25 | 21 | |
|---|
| .. | .. |
|---|
| 57 | 53 | static int tcf_gact_init(struct net *net, struct nlattr *nla, |
|---|
| 58 | 54 | struct nlattr *est, struct tc_action **a, |
|---|
| 59 | 55 | int ovr, int bind, bool rtnl_held, |
|---|
| 56 | + struct tcf_proto *tp, u32 flags, |
|---|
| 60 | 57 | struct netlink_ext_ack *extack) |
|---|
| 61 | 58 | { |
|---|
| 62 | 59 | struct tc_action_net *tn = net_generic(net, gact_net_id); |
|---|
| 63 | 60 | struct nlattr *tb[TCA_GACT_MAX + 1]; |
|---|
| 61 | + struct tcf_chain *goto_ch = NULL; |
|---|
| 64 | 62 | struct tc_gact *parm; |
|---|
| 65 | 63 | struct tcf_gact *gact; |
|---|
| 66 | 64 | int ret = 0; |
|---|
| .. | .. |
|---|
| 73 | 71 | if (nla == NULL) |
|---|
| 74 | 72 | return -EINVAL; |
|---|
| 75 | 73 | |
|---|
| 76 | | - err = nla_parse_nested(tb, TCA_GACT_MAX, nla, gact_policy, NULL); |
|---|
| 74 | + err = nla_parse_nested_deprecated(tb, TCA_GACT_MAX, nla, gact_policy, |
|---|
| 75 | + NULL); |
|---|
| 77 | 76 | if (err < 0) |
|---|
| 78 | 77 | return err; |
|---|
| 79 | 78 | |
|---|
| .. | .. |
|---|
| 90 | 89 | p_parm = nla_data(tb[TCA_GACT_PROB]); |
|---|
| 91 | 90 | if (p_parm->ptype >= MAX_RAND) |
|---|
| 92 | 91 | return -EINVAL; |
|---|
| 92 | + if (TC_ACT_EXT_CMP(p_parm->paction, TC_ACT_GOTO_CHAIN)) { |
|---|
| 93 | + NL_SET_ERR_MSG(extack, |
|---|
| 94 | + "goto chain not allowed on fallback"); |
|---|
| 95 | + return -EINVAL; |
|---|
| 96 | + } |
|---|
| 93 | 97 | } |
|---|
| 94 | 98 | #endif |
|---|
| 95 | 99 | |
|---|
| 96 | 100 | err = tcf_idr_check_alloc(tn, &index, a, bind); |
|---|
| 97 | 101 | if (!err) { |
|---|
| 98 | | - ret = tcf_idr_create(tn, index, est, a, |
|---|
| 99 | | - &act_gact_ops, bind, true); |
|---|
| 102 | + ret = tcf_idr_create_from_flags(tn, index, est, a, |
|---|
| 103 | + &act_gact_ops, bind, flags); |
|---|
| 100 | 104 | if (ret) { |
|---|
| 101 | 105 | tcf_idr_cleanup(tn, index); |
|---|
| 102 | 106 | return ret; |
|---|
| .. | .. |
|---|
| 113 | 117 | return err; |
|---|
| 114 | 118 | } |
|---|
| 115 | 119 | |
|---|
| 120 | + err = tcf_action_check_ctrlact(parm->action, tp, &goto_ch, extack); |
|---|
| 121 | + if (err < 0) |
|---|
| 122 | + goto release_idr; |
|---|
| 116 | 123 | gact = to_gact(*a); |
|---|
| 117 | 124 | |
|---|
| 118 | 125 | spin_lock_bh(&gact->tcf_lock); |
|---|
| 119 | | - gact->tcf_action = parm->action; |
|---|
| 126 | + goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch); |
|---|
| 120 | 127 | #ifdef CONFIG_GACT_PROB |
|---|
| 121 | 128 | if (p_parm) { |
|---|
| 122 | 129 | gact->tcfg_paction = p_parm->paction; |
|---|
| .. | .. |
|---|
| 130 | 137 | #endif |
|---|
| 131 | 138 | spin_unlock_bh(&gact->tcf_lock); |
|---|
| 132 | 139 | |
|---|
| 133 | | - if (ret == ACT_P_CREATED) |
|---|
| 134 | | - tcf_idr_insert(tn, *a); |
|---|
| 140 | + if (goto_ch) |
|---|
| 141 | + tcf_chain_put_by_act(goto_ch); |
|---|
| 142 | + |
|---|
| 135 | 143 | return ret; |
|---|
| 144 | +release_idr: |
|---|
| 145 | + tcf_idr_release(*a, bind); |
|---|
| 146 | + return err; |
|---|
| 136 | 147 | } |
|---|
| 137 | 148 | |
|---|
| 138 | 149 | static int tcf_gact_act(struct sk_buff *skb, const struct tc_action *a, |
|---|
| .. | .. |
|---|
| 149 | 160 | action = gact_rand[ptype](gact); |
|---|
| 150 | 161 | } |
|---|
| 151 | 162 | #endif |
|---|
| 152 | | - bstats_cpu_update(this_cpu_ptr(gact->common.cpu_bstats), skb); |
|---|
| 163 | + tcf_action_update_bstats(&gact->common, skb); |
|---|
| 153 | 164 | if (action == TC_ACT_SHOT) |
|---|
| 154 | | - qstats_drop_inc(this_cpu_ptr(gact->common.cpu_qstats)); |
|---|
| 165 | + tcf_action_inc_drop_qstats(&gact->common); |
|---|
| 155 | 166 | |
|---|
| 156 | 167 | tcf_lastuse_update(&gact->tcf_tm); |
|---|
| 157 | 168 | |
|---|
| 158 | 169 | return action; |
|---|
| 159 | 170 | } |
|---|
| 160 | 171 | |
|---|
| 161 | | -static void tcf_gact_stats_update(struct tc_action *a, u64 bytes, u32 packets, |
|---|
| 162 | | - u64 lastuse) |
|---|
| 172 | +static void tcf_gact_stats_update(struct tc_action *a, u64 bytes, u64 packets, |
|---|
| 173 | + u64 drops, u64 lastuse, bool hw) |
|---|
| 163 | 174 | { |
|---|
| 164 | 175 | struct tcf_gact *gact = to_gact(a); |
|---|
| 165 | 176 | int action = READ_ONCE(gact->tcf_action); |
|---|
| 166 | 177 | struct tcf_t *tm = &gact->tcf_tm; |
|---|
| 167 | 178 | |
|---|
| 168 | | - _bstats_cpu_update(this_cpu_ptr(gact->common.cpu_bstats), bytes, |
|---|
| 169 | | - packets); |
|---|
| 170 | | - if (action == TC_ACT_SHOT) |
|---|
| 171 | | - this_cpu_ptr(gact->common.cpu_qstats)->drops += packets; |
|---|
| 172 | | - |
|---|
| 179 | + tcf_action_update_stats(a, bytes, packets, |
|---|
| 180 | + action == TC_ACT_SHOT ? packets : drops, hw); |
|---|
| 173 | 181 | tm->lastuse = max_t(u64, tm->lastuse, lastuse); |
|---|
| 174 | 182 | } |
|---|
| 175 | 183 | |
|---|
| .. | .. |
|---|
| 224 | 232 | return tcf_generic_walker(tn, skb, cb, type, ops, extack); |
|---|
| 225 | 233 | } |
|---|
| 226 | 234 | |
|---|
| 227 | | -static int tcf_gact_search(struct net *net, struct tc_action **a, u32 index, |
|---|
| 228 | | - struct netlink_ext_ack *extack) |
|---|
| 235 | +static int tcf_gact_search(struct net *net, struct tc_action **a, u32 index) |
|---|
| 229 | 236 | { |
|---|
| 230 | 237 | struct tc_action_net *tn = net_generic(net, gact_net_id); |
|---|
| 231 | 238 | |
|---|
| .. | .. |
|---|
| 247 | 254 | |
|---|
| 248 | 255 | static struct tc_action_ops act_gact_ops = { |
|---|
| 249 | 256 | .kind = "gact", |
|---|
| 250 | | - .type = TCA_ACT_GACT, |
|---|
| 257 | + .id = TCA_ID_GACT, |
|---|
| 251 | 258 | .owner = THIS_MODULE, |
|---|
| 252 | 259 | .act = tcf_gact_act, |
|---|
| 253 | 260 | .stats_update = tcf_gact_stats_update, |
|---|