act_police.c (85d0966fa57e0ef2d30d913c98ca93674f7a03c9) | act_police.c (d6124d6ba697413efc53ff6919b1e0c250f1902a) |
---|---|
1/* 2 * net/sched/act_police.c Input police filter 3 * 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 * --- 7 unchanged lines hidden (view full) --- 16#include <linux/string.h> 17#include <linux/errno.h> 18#include <linux/skbuff.h> 19#include <linux/rtnetlink.h> 20#include <linux/init.h> 21#include <linux/slab.h> 22#include <net/act_api.h> 23#include <net/netlink.h> | 1/* 2 * net/sched/act_police.c Input police filter 3 * 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 * --- 7 unchanged lines hidden (view full) --- 16#include <linux/string.h> 17#include <linux/errno.h> 18#include <linux/skbuff.h> 19#include <linux/rtnetlink.h> 20#include <linux/init.h> 21#include <linux/slab.h> 22#include <net/act_api.h> 23#include <net/netlink.h> |
24#include <net/pkt_cls.h> |
|
24 25struct tcf_police_params { 26 int tcfp_result; 27 u32 tcfp_ewma_rate; 28 s64 tcfp_burst; 29 u32 tcfp_mtu; 30 s64 tcfp_mtu_ptoks; 31 struct psched_ratecfg rate; --- 51 unchanged lines hidden (view full) --- 83static int tcf_police_init(struct net *net, struct nlattr *nla, 84 struct nlattr *est, struct tc_action **a, 85 int ovr, int bind, bool rtnl_held, 86 struct tcf_proto *tp, 87 struct netlink_ext_ack *extack) 88{ 89 int ret = 0, tcfp_result = TC_ACT_OK, err, size; 90 struct nlattr *tb[TCA_POLICE_MAX + 1]; | 25 26struct tcf_police_params { 27 int tcfp_result; 28 u32 tcfp_ewma_rate; 29 s64 tcfp_burst; 30 u32 tcfp_mtu; 31 s64 tcfp_mtu_ptoks; 32 struct psched_ratecfg rate; --- 51 unchanged lines hidden (view full) --- 84static int tcf_police_init(struct net *net, struct nlattr *nla, 85 struct nlattr *est, struct tc_action **a, 86 int ovr, int bind, bool rtnl_held, 87 struct tcf_proto *tp, 88 struct netlink_ext_ack *extack) 89{ 90 int ret = 0, tcfp_result = TC_ACT_OK, err, size; 91 struct nlattr *tb[TCA_POLICE_MAX + 1]; |
92 struct tcf_chain *goto_ch = NULL; |
|
91 struct tc_police *parm; 92 struct tcf_police *police; 93 struct qdisc_rate_table *R_tab = NULL, *P_tab = NULL; 94 struct tc_action_net *tn = net_generic(net, police_net_id); 95 struct tcf_police_params *new; 96 bool exists = false; 97 98 if (nla == NULL) --- 25 unchanged lines hidden (view full) --- 124 return ret; 125 } 126 ret = ACT_P_CREATED; 127 spin_lock_init(&(to_police(*a)->tcfp_lock)); 128 } else if (!ovr) { 129 tcf_idr_release(*a, bind); 130 return -EEXIST; 131 } | 93 struct tc_police *parm; 94 struct tcf_police *police; 95 struct qdisc_rate_table *R_tab = NULL, *P_tab = NULL; 96 struct tc_action_net *tn = net_generic(net, police_net_id); 97 struct tcf_police_params *new; 98 bool exists = false; 99 100 if (nla == NULL) --- 25 unchanged lines hidden (view full) --- 126 return ret; 127 } 128 ret = ACT_P_CREATED; 129 spin_lock_init(&(to_police(*a)->tcfp_lock)); 130 } else if (!ovr) { 131 tcf_idr_release(*a, bind); 132 return -EEXIST; 133 } |
134 err = tcf_action_check_ctrlact(parm->action, tp, &goto_ch, extack); 135 if (err < 0) 136 goto release_idr; |
|
132 133 police = to_police(*a); 134 if (parm->rate.rate) { 135 err = -ENOMEM; 136 R_tab = qdisc_get_rtab(&parm->rate, tb[TCA_POLICE_RATE], NULL); 137 if (R_tab == NULL) 138 goto failure; 139 --- 69 unchanged lines hidden (view full) --- 209 210 spin_lock_bh(&police->tcf_lock); 211 spin_lock_bh(&police->tcfp_lock); 212 police->tcfp_t_c = ktime_get_ns(); 213 police->tcfp_toks = new->tcfp_burst; 214 if (new->peak_present) 215 police->tcfp_ptoks = new->tcfp_mtu_ptoks; 216 spin_unlock_bh(&police->tcfp_lock); | 137 138 police = to_police(*a); 139 if (parm->rate.rate) { 140 err = -ENOMEM; 141 R_tab = qdisc_get_rtab(&parm->rate, tb[TCA_POLICE_RATE], NULL); 142 if (R_tab == NULL) 143 goto failure; 144 --- 69 unchanged lines hidden (view full) --- 214 215 spin_lock_bh(&police->tcf_lock); 216 spin_lock_bh(&police->tcfp_lock); 217 police->tcfp_t_c = ktime_get_ns(); 218 police->tcfp_toks = new->tcfp_burst; 219 if (new->peak_present) 220 police->tcfp_ptoks = new->tcfp_mtu_ptoks; 221 spin_unlock_bh(&police->tcfp_lock); |
217 police->tcf_action = parm->action; | 222 goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch); |
218 rcu_swap_protected(police->params, 219 new, 220 lockdep_is_held(&police->tcf_lock)); 221 spin_unlock_bh(&police->tcf_lock); 222 | 223 rcu_swap_protected(police->params, 224 new, 225 lockdep_is_held(&police->tcf_lock)); 226 spin_unlock_bh(&police->tcf_lock); 227 |
228 if (goto_ch) 229 tcf_chain_put_by_act(goto_ch); |
|
223 if (new) 224 kfree_rcu(new, rcu); 225 226 if (ret == ACT_P_CREATED) 227 tcf_idr_insert(tn, *a); 228 return ret; 229 230failure: 231 qdisc_put_rtab(P_tab); 232 qdisc_put_rtab(R_tab); | 230 if (new) 231 kfree_rcu(new, rcu); 232 233 if (ret == ACT_P_CREATED) 234 tcf_idr_insert(tn, *a); 235 return ret; 236 237failure: 238 qdisc_put_rtab(P_tab); 239 qdisc_put_rtab(R_tab); |
240 if (goto_ch) 241 tcf_chain_put_by_act(goto_ch); 242release_idr: |
|
233 tcf_idr_release(*a, bind); 234 return err; 235} 236 237static int tcf_police_act(struct sk_buff *skb, const struct tc_action *a, 238 struct tcf_result *res) 239{ 240 struct tcf_police *police = to_police(a); --- 171 unchanged lines hidden --- | 243 tcf_idr_release(*a, bind); 244 return err; 245} 246 247static int tcf_police_act(struct sk_buff *skb, const struct tc_action *a, 248 struct tcf_result *res) 249{ 250 struct tcf_police *police = to_police(a); --- 171 unchanged lines hidden --- |