aboutsummaryrefslogtreecommitdiffstats
path: root/net/sched/act_police.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/sched/act_police.c')
-rw-r--r--net/sched/act_police.c40
1 files changed, 20 insertions, 20 deletions
diff --git a/net/sched/act_police.c b/net/sched/act_police.c
index 330f14e302e8..c557789765dc 100644
--- a/net/sched/act_police.c
+++ b/net/sched/act_police.c
@@ -38,7 +38,7 @@ struct tcf_police {
38 bool peak_present; 38 bool peak_present;
39}; 39};
40#define to_police(pc) \ 40#define to_police(pc) \
41 container_of(pc, struct tcf_police, common) 41 container_of(pc->priv, struct tcf_police, common)
42 42
43#define POL_TAB_MASK 15 43#define POL_TAB_MASK 15
44 44
@@ -119,14 +119,12 @@ static int tcf_act_police_locate(struct net *net, struct nlattr *nla,
119 struct nlattr *est, struct tc_action *a, 119 struct nlattr *est, struct tc_action *a,
120 int ovr, int bind) 120 int ovr, int bind)
121{ 121{
122 unsigned int h;
123 int ret = 0, err; 122 int ret = 0, err;
124 struct nlattr *tb[TCA_POLICE_MAX + 1]; 123 struct nlattr *tb[TCA_POLICE_MAX + 1];
125 struct tc_police *parm; 124 struct tc_police *parm;
126 struct tcf_police *police; 125 struct tcf_police *police;
127 struct qdisc_rate_table *R_tab = NULL, *P_tab = NULL; 126 struct qdisc_rate_table *R_tab = NULL, *P_tab = NULL;
128 struct tc_action_net *tn = net_generic(net, police_net_id); 127 struct tc_action_net *tn = net_generic(net, police_net_id);
129 struct tcf_hashinfo *hinfo = tn->hinfo;
130 int size; 128 int size;
131 129
132 if (nla == NULL) 130 if (nla == NULL)
@@ -145,7 +143,7 @@ static int tcf_act_police_locate(struct net *net, struct nlattr *nla,
145 143
146 if (parm->index) { 144 if (parm->index) {
147 if (tcf_hash_search(tn, a, parm->index)) { 145 if (tcf_hash_search(tn, a, parm->index)) {
148 police = to_police(a->priv); 146 police = to_police(a);
149 if (bind) { 147 if (bind) {
150 police->tcf_bindcnt += 1; 148 police->tcf_bindcnt += 1;
151 police->tcf_refcnt += 1; 149 police->tcf_refcnt += 1;
@@ -156,16 +154,15 @@ static int tcf_act_police_locate(struct net *net, struct nlattr *nla,
156 /* not replacing */ 154 /* not replacing */
157 return -EEXIST; 155 return -EEXIST;
158 } 156 }
157 } else {
158 ret = tcf_hash_create(tn, parm->index, NULL, a,
159 sizeof(*police), bind, false);
160 if (ret)
161 return ret;
162 ret = ACT_P_CREATED;
159 } 163 }
160 164
161 police = kzalloc(sizeof(*police), GFP_KERNEL); 165 police = to_police(a);
162 if (police == NULL)
163 return -ENOMEM;
164 ret = ACT_P_CREATED;
165 police->tcf_refcnt = 1;
166 spin_lock_init(&police->tcf_lock);
167 if (bind)
168 police->tcf_bindcnt = 1;
169override: 166override:
170 if (parm->rate.rate) { 167 if (parm->rate.rate) {
171 err = -ENOMEM; 168 err = -ENOMEM;
@@ -237,14 +234,8 @@ override:
237 return ret; 234 return ret;
238 235
239 police->tcfp_t_c = ktime_get_ns(); 236 police->tcfp_t_c = ktime_get_ns();
240 police->tcf_index = parm->index ? parm->index : 237 tcf_hash_insert(tn, a);
241 tcf_hash_new_index(tn);
242 h = tcf_hash(police->tcf_index, POL_TAB_MASK);
243 spin_lock_bh(&hinfo->lock);
244 hlist_add_head(&police->tcf_head, &hinfo->htab[h]);
245 spin_unlock_bh(&hinfo->lock);
246 238
247 a->priv = police;
248 return ret; 239 return ret;
249 240
250failure_unlock: 241failure_unlock:
@@ -253,7 +244,7 @@ failure:
253 qdisc_put_rtab(P_tab); 244 qdisc_put_rtab(P_tab);
254 qdisc_put_rtab(R_tab); 245 qdisc_put_rtab(R_tab);
255 if (ret == ACT_P_CREATED) 246 if (ret == ACT_P_CREATED)
256 kfree(police); 247 tcf_hash_cleanup(a, est);
257 return err; 248 return err;
258} 249}
259 250
@@ -268,6 +259,7 @@ static int tcf_act_police(struct sk_buff *skb, const struct tc_action *a,
268 spin_lock(&police->tcf_lock); 259 spin_lock(&police->tcf_lock);
269 260
270 bstats_update(&police->tcf_bstats, skb); 261 bstats_update(&police->tcf_bstats, skb);
262 tcf_lastuse_update(&police->tcf_tm);
271 263
272 if (police->tcfp_ewma_rate && 264 if (police->tcfp_ewma_rate &&
273 police->tcf_rate_est.bps >= police->tcfp_ewma_rate) { 265 police->tcf_rate_est.bps >= police->tcfp_ewma_rate) {
@@ -327,6 +319,7 @@ tcf_act_police_dump(struct sk_buff *skb, struct tc_action *a, int bind, int ref)
327 .refcnt = police->tcf_refcnt - ref, 319 .refcnt = police->tcf_refcnt - ref,
328 .bindcnt = police->tcf_bindcnt - bind, 320 .bindcnt = police->tcf_bindcnt - bind,
329 }; 321 };
322 struct tcf_t t;
330 323
331 if (police->rate_present) 324 if (police->rate_present)
332 psched_ratecfg_getrate(&opt.rate, &police->rate); 325 psched_ratecfg_getrate(&opt.rate, &police->rate);
@@ -340,6 +333,13 @@ tcf_act_police_dump(struct sk_buff *skb, struct tc_action *a, int bind, int ref)
340 if (police->tcfp_ewma_rate && 333 if (police->tcfp_ewma_rate &&
341 nla_put_u32(skb, TCA_POLICE_AVRATE, police->tcfp_ewma_rate)) 334 nla_put_u32(skb, TCA_POLICE_AVRATE, police->tcfp_ewma_rate))
342 goto nla_put_failure; 335 goto nla_put_failure;
336
337 t.install = jiffies_to_clock_t(jiffies - police->tcf_tm.install);
338 t.lastuse = jiffies_to_clock_t(jiffies - police->tcf_tm.lastuse);
339 t.expires = jiffies_to_clock_t(police->tcf_tm.expires);
340 if (nla_put_64bit(skb, TCA_POLICE_TM, sizeof(t), &t, TCA_POLICE_PAD))
341 goto nla_put_failure;
342
343 return skb->len; 343 return skb->len;
344 344
345nla_put_failure: 345nla_put_failure: