Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * net/sched/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 | * |
| 9 | * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> |
| 10 | * J Hadi Salim (action changes) |
| 11 | */ |
| 12 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/module.h> |
| 14 | #include <linux/types.h> |
| 15 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/string.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/errno.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/skbuff.h> |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/rtnetlink.h> |
| 21 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <net/act_api.h> |
Arnaldo Carvalho de Melo | dc5fc57 | 2007-03-25 23:06:12 -0700 | [diff] [blame] | 23 | #include <net/netlink.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 25 | #define L2T(p,L) ((p)->tcfp_R_tab->data[(L)>>(p)->tcfp_R_tab->rate.cell_log]) |
| 26 | #define L2T_P(p,L) ((p)->tcfp_P_tab->data[(L)>>(p)->tcfp_P_tab->rate.cell_log]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 28 | #define POL_TAB_MASK 15 |
| 29 | static struct tcf_common *tcf_police_ht[POL_TAB_MASK + 1]; |
| 30 | static u32 police_idx_gen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | static DEFINE_RWLOCK(police_lock); |
| 32 | |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 33 | static struct tcf_hashinfo police_hash_info = { |
| 34 | .htab = tcf_police_ht, |
| 35 | .hmask = POL_TAB_MASK, |
| 36 | .lock = &police_lock, |
| 37 | }; |
| 38 | |
Patrick McHardy | 1e9b3d5 | 2006-11-30 19:54:05 -0800 | [diff] [blame] | 39 | /* old policer structure from before tc actions */ |
| 40 | struct tc_police_compat |
| 41 | { |
| 42 | u32 index; |
| 43 | int action; |
| 44 | u32 limit; |
| 45 | u32 burst; |
| 46 | u32 mtu; |
| 47 | struct tc_ratespec rate; |
| 48 | struct tc_ratespec peakrate; |
| 49 | }; |
| 50 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | /* Each policer is serialized by its individual spinlock */ |
| 52 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #ifdef CONFIG_NET_CLS_ACT |
Jamal Hadi Salim | 83b950c | 2006-04-06 22:24:22 -0700 | [diff] [blame] | 54 | static int tcf_act_police_walker(struct sk_buff *skb, struct netlink_callback *cb, |
YOSHIFUJI Hideaki | 10297b9 | 2007-02-09 23:25:16 +0900 | [diff] [blame] | 55 | int type, struct tc_action *a) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | { |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 57 | struct tcf_common *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | int err = 0, index = -1, i = 0, s_i = 0, n_i = 0; |
| 59 | struct rtattr *r; |
| 60 | |
| 61 | read_lock(&police_lock); |
| 62 | |
| 63 | s_i = cb->args[0]; |
| 64 | |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 65 | for (i = 0; i < (POL_TAB_MASK + 1); i++) { |
| 66 | p = tcf_police_ht[tcf_hash(i, POL_TAB_MASK)]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 68 | for (; p; p = p->tcfc_next) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | index++; |
| 70 | if (index < s_i) |
| 71 | continue; |
| 72 | a->priv = p; |
| 73 | a->order = index; |
Arnaldo Carvalho de Melo | 27a884d | 2007-04-19 20:29:13 -0700 | [diff] [blame] | 74 | r = (struct rtattr *)skb_tail_pointer(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | RTA_PUT(skb, a->order, 0, NULL); |
| 76 | if (type == RTM_DELACTION) |
| 77 | err = tcf_action_dump_1(skb, a, 0, 1); |
| 78 | else |
| 79 | err = tcf_action_dump_1(skb, a, 0, 0); |
| 80 | if (err < 0) { |
| 81 | index--; |
Arnaldo Carvalho de Melo | dc5fc57 | 2007-03-25 23:06:12 -0700 | [diff] [blame] | 82 | nlmsg_trim(skb, r); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | goto done; |
| 84 | } |
Arnaldo Carvalho de Melo | 27a884d | 2007-04-19 20:29:13 -0700 | [diff] [blame] | 85 | r->rta_len = skb_tail_pointer(skb) - (u8 *)r; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | n_i++; |
| 87 | } |
| 88 | } |
| 89 | done: |
| 90 | read_unlock(&police_lock); |
| 91 | if (n_i) |
| 92 | cb->args[0] += n_i; |
| 93 | return n_i; |
| 94 | |
| 95 | rtattr_failure: |
Arnaldo Carvalho de Melo | dc5fc57 | 2007-03-25 23:06:12 -0700 | [diff] [blame] | 96 | nlmsg_trim(skb, r); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | goto done; |
| 98 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | #endif |
| 100 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | void tcf_police_destroy(struct tcf_police *p) |
| 102 | { |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 103 | unsigned int h = tcf_hash(p->tcf_index, POL_TAB_MASK); |
| 104 | struct tcf_common **p1p; |
YOSHIFUJI Hideaki | 10297b9 | 2007-02-09 23:25:16 +0900 | [diff] [blame] | 105 | |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 106 | for (p1p = &tcf_police_ht[h]; *p1p; p1p = &(*p1p)->tcfc_next) { |
| 107 | if (*p1p == &p->common) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | write_lock_bh(&police_lock); |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 109 | *p1p = p->tcf_next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | write_unlock_bh(&police_lock); |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 111 | gen_kill_estimator(&p->tcf_bstats, |
| 112 | &p->tcf_rate_est); |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 113 | if (p->tcfp_R_tab) |
| 114 | qdisc_put_rtab(p->tcfp_R_tab); |
| 115 | if (p->tcfp_P_tab) |
| 116 | qdisc_put_rtab(p->tcfp_P_tab); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | kfree(p); |
| 118 | return; |
| 119 | } |
| 120 | } |
| 121 | BUG_TRAP(0); |
| 122 | } |
| 123 | |
| 124 | #ifdef CONFIG_NET_CLS_ACT |
| 125 | static int tcf_act_police_locate(struct rtattr *rta, struct rtattr *est, |
YOSHIFUJI Hideaki | 10297b9 | 2007-02-09 23:25:16 +0900 | [diff] [blame] | 126 | struct tc_action *a, int ovr, int bind) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | { |
| 128 | unsigned h; |
| 129 | int ret = 0, err; |
| 130 | struct rtattr *tb[TCA_POLICE_MAX]; |
| 131 | struct tc_police *parm; |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 132 | struct tcf_police *police; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | struct qdisc_rate_table *R_tab = NULL, *P_tab = NULL; |
Patrick McHardy | 1e9b3d5 | 2006-11-30 19:54:05 -0800 | [diff] [blame] | 134 | int size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
| 136 | if (rta == NULL || rtattr_parse_nested(tb, TCA_POLICE_MAX, rta) < 0) |
| 137 | return -EINVAL; |
| 138 | |
Patrick McHardy | 1e9b3d5 | 2006-11-30 19:54:05 -0800 | [diff] [blame] | 139 | if (tb[TCA_POLICE_TBF-1] == NULL) |
| 140 | return -EINVAL; |
| 141 | size = RTA_PAYLOAD(tb[TCA_POLICE_TBF-1]); |
| 142 | if (size != sizeof(*parm) && size != sizeof(struct tc_police_compat)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | return -EINVAL; |
| 144 | parm = RTA_DATA(tb[TCA_POLICE_TBF-1]); |
| 145 | |
| 146 | if (tb[TCA_POLICE_RESULT-1] != NULL && |
| 147 | RTA_PAYLOAD(tb[TCA_POLICE_RESULT-1]) != sizeof(u32)) |
| 148 | return -EINVAL; |
| 149 | if (tb[TCA_POLICE_RESULT-1] != NULL && |
| 150 | RTA_PAYLOAD(tb[TCA_POLICE_RESULT-1]) != sizeof(u32)) |
| 151 | return -EINVAL; |
| 152 | |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 153 | if (parm->index) { |
| 154 | struct tcf_common *pc; |
| 155 | |
| 156 | pc = tcf_hash_lookup(parm->index, &police_hash_info); |
| 157 | if (pc != NULL) { |
| 158 | a->priv = pc; |
| 159 | police = to_police(pc); |
| 160 | if (bind) { |
| 161 | police->tcf_bindcnt += 1; |
| 162 | police->tcf_refcnt += 1; |
| 163 | } |
| 164 | if (ovr) |
| 165 | goto override; |
| 166 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | } |
| 169 | |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 170 | police = kzalloc(sizeof(*police), GFP_KERNEL); |
| 171 | if (police == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | ret = ACT_P_CREATED; |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 174 | police->tcf_refcnt = 1; |
| 175 | spin_lock_init(&police->tcf_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | if (bind) |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 177 | police->tcf_bindcnt = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | override: |
| 179 | if (parm->rate.rate) { |
| 180 | err = -ENOMEM; |
| 181 | R_tab = qdisc_get_rtab(&parm->rate, tb[TCA_POLICE_RATE-1]); |
| 182 | if (R_tab == NULL) |
| 183 | goto failure; |
| 184 | if (parm->peakrate.rate) { |
| 185 | P_tab = qdisc_get_rtab(&parm->peakrate, |
| 186 | tb[TCA_POLICE_PEAKRATE-1]); |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 187 | if (P_tab == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | qdisc_put_rtab(R_tab); |
| 189 | goto failure; |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | /* No failure allowed after this point */ |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 194 | spin_lock_bh(&police->tcf_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | if (R_tab != NULL) { |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 196 | qdisc_put_rtab(police->tcfp_R_tab); |
| 197 | police->tcfp_R_tab = R_tab; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | } |
| 199 | if (P_tab != NULL) { |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 200 | qdisc_put_rtab(police->tcfp_P_tab); |
| 201 | police->tcfp_P_tab = P_tab; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | if (tb[TCA_POLICE_RESULT-1]) |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 205 | police->tcfp_result = *(u32*)RTA_DATA(tb[TCA_POLICE_RESULT-1]); |
| 206 | police->tcfp_toks = police->tcfp_burst = parm->burst; |
| 207 | police->tcfp_mtu = parm->mtu; |
| 208 | if (police->tcfp_mtu == 0) { |
| 209 | police->tcfp_mtu = ~0; |
| 210 | if (police->tcfp_R_tab) |
| 211 | police->tcfp_mtu = 255<<police->tcfp_R_tab->rate.cell_log; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | } |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 213 | if (police->tcfp_P_tab) |
| 214 | police->tcfp_ptoks = L2T_P(police, police->tcfp_mtu); |
| 215 | police->tcf_action = parm->action; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | if (tb[TCA_POLICE_AVRATE-1]) |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 218 | police->tcfp_ewma_rate = |
| 219 | *(u32*)RTA_DATA(tb[TCA_POLICE_AVRATE-1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | if (est) |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 221 | gen_replace_estimator(&police->tcf_bstats, |
| 222 | &police->tcf_rate_est, |
Patrick McHardy | 4bdf399 | 2007-07-02 22:47:37 -0700 | [diff] [blame] | 223 | &police->tcf_lock, est); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 225 | spin_unlock_bh(&police->tcf_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | if (ret != ACT_P_CREATED) |
| 227 | return ret; |
| 228 | |
Patrick McHardy | 3bebcda | 2007-03-23 11:29:25 -0700 | [diff] [blame] | 229 | police->tcfp_t_c = psched_get_time(); |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 230 | police->tcf_index = parm->index ? parm->index : |
| 231 | tcf_hash_new_index(&police_idx_gen, &police_hash_info); |
| 232 | h = tcf_hash(police->tcf_index, POL_TAB_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | write_lock_bh(&police_lock); |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 234 | police->tcf_next = tcf_police_ht[h]; |
| 235 | tcf_police_ht[h] = &police->common; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | write_unlock_bh(&police_lock); |
| 237 | |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 238 | a->priv = police; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | return ret; |
| 240 | |
| 241 | failure: |
| 242 | if (ret == ACT_P_CREATED) |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 243 | kfree(police); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | return err; |
| 245 | } |
| 246 | |
| 247 | static int tcf_act_police_cleanup(struct tc_action *a, int bind) |
| 248 | { |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 249 | struct tcf_police *p = a->priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | |
| 251 | if (p != NULL) |
| 252 | return tcf_police_release(p, bind); |
| 253 | return 0; |
| 254 | } |
| 255 | |
Patrick McHardy | f43c5a0 | 2006-01-08 22:15:34 -0800 | [diff] [blame] | 256 | static int tcf_act_police(struct sk_buff *skb, struct tc_action *a, |
YOSHIFUJI Hideaki | 10297b9 | 2007-02-09 23:25:16 +0900 | [diff] [blame] | 257 | struct tcf_result *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | { |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 259 | struct tcf_police *police = a->priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | psched_time_t now; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | long toks; |
| 262 | long ptoks = 0; |
| 263 | |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 264 | spin_lock(&police->tcf_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 266 | police->tcf_bstats.bytes += skb->len; |
| 267 | police->tcf_bstats.packets++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 269 | if (police->tcfp_ewma_rate && |
| 270 | police->tcf_rate_est.bps >= police->tcfp_ewma_rate) { |
| 271 | police->tcf_qstats.overlimits++; |
| 272 | spin_unlock(&police->tcf_lock); |
| 273 | return police->tcf_action; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 276 | if (skb->len <= police->tcfp_mtu) { |
| 277 | if (police->tcfp_R_tab == NULL) { |
| 278 | spin_unlock(&police->tcf_lock); |
| 279 | return police->tcfp_result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | } |
| 281 | |
Patrick McHardy | 3bebcda | 2007-03-23 11:29:25 -0700 | [diff] [blame] | 282 | now = psched_get_time(); |
Patrick McHardy | 03cc45c | 2007-03-23 11:29:11 -0700 | [diff] [blame] | 283 | toks = psched_tdiff_bounded(now, police->tcfp_t_c, |
| 284 | police->tcfp_burst); |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 285 | if (police->tcfp_P_tab) { |
| 286 | ptoks = toks + police->tcfp_ptoks; |
| 287 | if (ptoks > (long)L2T_P(police, police->tcfp_mtu)) |
| 288 | ptoks = (long)L2T_P(police, police->tcfp_mtu); |
| 289 | ptoks -= L2T_P(police, skb->len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | } |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 291 | toks += police->tcfp_toks; |
| 292 | if (toks > (long)police->tcfp_burst) |
| 293 | toks = police->tcfp_burst; |
| 294 | toks -= L2T(police, skb->len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | if ((toks|ptoks) >= 0) { |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 296 | police->tcfp_t_c = now; |
| 297 | police->tcfp_toks = toks; |
| 298 | police->tcfp_ptoks = ptoks; |
| 299 | spin_unlock(&police->tcf_lock); |
| 300 | return police->tcfp_result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | } |
| 302 | } |
| 303 | |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 304 | police->tcf_qstats.overlimits++; |
| 305 | spin_unlock(&police->tcf_lock); |
| 306 | return police->tcf_action; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | static int |
| 310 | tcf_act_police_dump(struct sk_buff *skb, struct tc_action *a, int bind, int ref) |
| 311 | { |
Arnaldo Carvalho de Melo | 27a884d | 2007-04-19 20:29:13 -0700 | [diff] [blame] | 312 | unsigned char *b = skb_tail_pointer(skb); |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 313 | struct tcf_police *police = a->priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | struct tc_police opt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 316 | opt.index = police->tcf_index; |
| 317 | opt.action = police->tcf_action; |
| 318 | opt.mtu = police->tcfp_mtu; |
| 319 | opt.burst = police->tcfp_burst; |
| 320 | opt.refcnt = police->tcf_refcnt - ref; |
| 321 | opt.bindcnt = police->tcf_bindcnt - bind; |
| 322 | if (police->tcfp_R_tab) |
| 323 | opt.rate = police->tcfp_R_tab->rate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | else |
| 325 | memset(&opt.rate, 0, sizeof(opt.rate)); |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 326 | if (police->tcfp_P_tab) |
| 327 | opt.peakrate = police->tcfp_P_tab->rate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | else |
| 329 | memset(&opt.peakrate, 0, sizeof(opt.peakrate)); |
| 330 | RTA_PUT(skb, TCA_POLICE_TBF, sizeof(opt), &opt); |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 331 | if (police->tcfp_result) |
| 332 | RTA_PUT(skb, TCA_POLICE_RESULT, sizeof(int), |
| 333 | &police->tcfp_result); |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 334 | if (police->tcfp_ewma_rate) |
| 335 | RTA_PUT(skb, TCA_POLICE_AVRATE, 4, &police->tcfp_ewma_rate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | return skb->len; |
| 337 | |
| 338 | rtattr_failure: |
Arnaldo Carvalho de Melo | dc5fc57 | 2007-03-25 23:06:12 -0700 | [diff] [blame] | 339 | nlmsg_trim(skb, b); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | return -1; |
| 341 | } |
| 342 | |
| 343 | MODULE_AUTHOR("Alexey Kuznetsov"); |
| 344 | MODULE_DESCRIPTION("Policing actions"); |
| 345 | MODULE_LICENSE("GPL"); |
| 346 | |
| 347 | static struct tc_action_ops act_police_ops = { |
| 348 | .kind = "police", |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 349 | .hinfo = &police_hash_info, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | .type = TCA_ID_POLICE, |
| 351 | .capab = TCA_CAP_NONE, |
| 352 | .owner = THIS_MODULE, |
| 353 | .act = tcf_act_police, |
| 354 | .dump = tcf_act_police_dump, |
| 355 | .cleanup = tcf_act_police_cleanup, |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 356 | .lookup = tcf_hash_search, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | .init = tcf_act_police_locate, |
Jamal Hadi Salim | 83b950c | 2006-04-06 22:24:22 -0700 | [diff] [blame] | 358 | .walk = tcf_act_police_walker |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | }; |
| 360 | |
| 361 | static int __init |
| 362 | police_init_module(void) |
| 363 | { |
| 364 | return tcf_register_action(&act_police_ops); |
| 365 | } |
| 366 | |
| 367 | static void __exit |
| 368 | police_cleanup_module(void) |
| 369 | { |
| 370 | tcf_unregister_action(&act_police_ops); |
| 371 | } |
| 372 | |
| 373 | module_init(police_init_module); |
| 374 | module_exit(police_cleanup_module); |
| 375 | |
Patrick McHardy | 31bd06e | 2006-01-08 22:16:25 -0800 | [diff] [blame] | 376 | #else /* CONFIG_NET_CLS_ACT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 378 | static struct tcf_common *tcf_police_lookup(u32 index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | { |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 380 | struct tcf_hashinfo *hinfo = &police_hash_info; |
| 381 | struct tcf_common *p; |
| 382 | |
| 383 | read_lock(hinfo->lock); |
| 384 | for (p = hinfo->htab[tcf_hash(index, hinfo->hmask)]; p; |
| 385 | p = p->tcfc_next) { |
| 386 | if (p->tcfc_index == index) |
| 387 | break; |
| 388 | } |
| 389 | read_unlock(hinfo->lock); |
| 390 | |
| 391 | return p; |
| 392 | } |
| 393 | |
| 394 | static u32 tcf_police_new_index(void) |
| 395 | { |
| 396 | u32 *idx_gen = &police_idx_gen; |
| 397 | u32 val = *idx_gen; |
| 398 | |
| 399 | do { |
| 400 | if (++val == 0) |
| 401 | val = 1; |
| 402 | } while (tcf_police_lookup(val)); |
| 403 | |
| 404 | return (*idx_gen = val); |
| 405 | } |
| 406 | |
| 407 | struct tcf_police *tcf_police_locate(struct rtattr *rta, struct rtattr *est) |
| 408 | { |
| 409 | unsigned int h; |
| 410 | struct tcf_police *police; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | struct rtattr *tb[TCA_POLICE_MAX]; |
| 412 | struct tc_police *parm; |
Patrick McHardy | 1e9b3d5 | 2006-11-30 19:54:05 -0800 | [diff] [blame] | 413 | int size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
| 415 | if (rtattr_parse_nested(tb, TCA_POLICE_MAX, rta) < 0) |
| 416 | return NULL; |
| 417 | |
Patrick McHardy | 1e9b3d5 | 2006-11-30 19:54:05 -0800 | [diff] [blame] | 418 | if (tb[TCA_POLICE_TBF-1] == NULL) |
| 419 | return NULL; |
| 420 | size = RTA_PAYLOAD(tb[TCA_POLICE_TBF-1]); |
| 421 | if (size != sizeof(*parm) && size != sizeof(struct tc_police_compat)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | return NULL; |
| 423 | |
| 424 | parm = RTA_DATA(tb[TCA_POLICE_TBF-1]); |
| 425 | |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 426 | if (parm->index) { |
| 427 | struct tcf_common *pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 429 | pc = tcf_police_lookup(parm->index); |
| 430 | if (pc) { |
| 431 | police = to_police(pc); |
| 432 | police->tcf_refcnt++; |
| 433 | return police; |
| 434 | } |
| 435 | } |
| 436 | police = kzalloc(sizeof(*police), GFP_KERNEL); |
| 437 | if (unlikely(!police)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | return NULL; |
| 439 | |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 440 | police->tcf_refcnt = 1; |
| 441 | spin_lock_init(&police->tcf_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | if (parm->rate.rate) { |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 443 | police->tcfp_R_tab = |
| 444 | qdisc_get_rtab(&parm->rate, tb[TCA_POLICE_RATE-1]); |
| 445 | if (police->tcfp_R_tab == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | goto failure; |
| 447 | if (parm->peakrate.rate) { |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 448 | police->tcfp_P_tab = |
| 449 | qdisc_get_rtab(&parm->peakrate, |
| 450 | tb[TCA_POLICE_PEAKRATE-1]); |
| 451 | if (police->tcfp_P_tab == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | goto failure; |
| 453 | } |
| 454 | } |
| 455 | if (tb[TCA_POLICE_RESULT-1]) { |
| 456 | if (RTA_PAYLOAD(tb[TCA_POLICE_RESULT-1]) != sizeof(u32)) |
| 457 | goto failure; |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 458 | police->tcfp_result = *(u32*)RTA_DATA(tb[TCA_POLICE_RESULT-1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | if (tb[TCA_POLICE_AVRATE-1]) { |
| 461 | if (RTA_PAYLOAD(tb[TCA_POLICE_AVRATE-1]) != sizeof(u32)) |
| 462 | goto failure; |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 463 | police->tcfp_ewma_rate = |
| 464 | *(u32*)RTA_DATA(tb[TCA_POLICE_AVRATE-1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | } |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 466 | police->tcfp_toks = police->tcfp_burst = parm->burst; |
| 467 | police->tcfp_mtu = parm->mtu; |
| 468 | if (police->tcfp_mtu == 0) { |
| 469 | police->tcfp_mtu = ~0; |
| 470 | if (police->tcfp_R_tab) |
| 471 | police->tcfp_mtu = 255<<police->tcfp_R_tab->rate.cell_log; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | } |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 473 | if (police->tcfp_P_tab) |
| 474 | police->tcfp_ptoks = L2T_P(police, police->tcfp_mtu); |
Patrick McHardy | 3bebcda | 2007-03-23 11:29:25 -0700 | [diff] [blame] | 475 | police->tcfp_t_c = psched_get_time(); |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 476 | police->tcf_index = parm->index ? parm->index : |
| 477 | tcf_police_new_index(); |
| 478 | police->tcf_action = parm->action; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | if (est) |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 480 | gen_new_estimator(&police->tcf_bstats, &police->tcf_rate_est, |
Patrick McHardy | 4bdf399 | 2007-07-02 22:47:37 -0700 | [diff] [blame] | 481 | &police->tcf_lock, est); |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 482 | h = tcf_hash(police->tcf_index, POL_TAB_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | write_lock_bh(&police_lock); |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 484 | police->tcf_next = tcf_police_ht[h]; |
| 485 | tcf_police_ht[h] = &police->common; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | write_unlock_bh(&police_lock); |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 487 | return police; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | |
| 489 | failure: |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 490 | if (police->tcfp_R_tab) |
| 491 | qdisc_put_rtab(police->tcfp_R_tab); |
| 492 | kfree(police); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | return NULL; |
| 494 | } |
| 495 | |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 496 | int tcf_police(struct sk_buff *skb, struct tcf_police *police) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | { |
| 498 | psched_time_t now; |
| 499 | long toks; |
| 500 | long ptoks = 0; |
| 501 | |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 502 | spin_lock(&police->tcf_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 504 | police->tcf_bstats.bytes += skb->len; |
| 505 | police->tcf_bstats.packets++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 507 | if (police->tcfp_ewma_rate && |
| 508 | police->tcf_rate_est.bps >= police->tcfp_ewma_rate) { |
| 509 | police->tcf_qstats.overlimits++; |
| 510 | spin_unlock(&police->tcf_lock); |
| 511 | return police->tcf_action; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | } |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 513 | if (skb->len <= police->tcfp_mtu) { |
| 514 | if (police->tcfp_R_tab == NULL) { |
| 515 | spin_unlock(&police->tcf_lock); |
| 516 | return police->tcfp_result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | } |
| 518 | |
Patrick McHardy | 3bebcda | 2007-03-23 11:29:25 -0700 | [diff] [blame] | 519 | now = psched_get_time(); |
Patrick McHardy | 03cc45c | 2007-03-23 11:29:11 -0700 | [diff] [blame] | 520 | toks = psched_tdiff_bounded(now, police->tcfp_t_c, |
| 521 | police->tcfp_burst); |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 522 | if (police->tcfp_P_tab) { |
| 523 | ptoks = toks + police->tcfp_ptoks; |
| 524 | if (ptoks > (long)L2T_P(police, police->tcfp_mtu)) |
| 525 | ptoks = (long)L2T_P(police, police->tcfp_mtu); |
| 526 | ptoks -= L2T_P(police, skb->len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | } |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 528 | toks += police->tcfp_toks; |
| 529 | if (toks > (long)police->tcfp_burst) |
| 530 | toks = police->tcfp_burst; |
| 531 | toks -= L2T(police, skb->len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | if ((toks|ptoks) >= 0) { |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 533 | police->tcfp_t_c = now; |
| 534 | police->tcfp_toks = toks; |
| 535 | police->tcfp_ptoks = ptoks; |
| 536 | spin_unlock(&police->tcf_lock); |
| 537 | return police->tcfp_result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | } |
| 539 | } |
| 540 | |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 541 | police->tcf_qstats.overlimits++; |
| 542 | spin_unlock(&police->tcf_lock); |
| 543 | return police->tcf_action; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | } |
Patrick McHardy | 31bd06e | 2006-01-08 22:16:25 -0800 | [diff] [blame] | 545 | EXPORT_SYMBOL(tcf_police); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 547 | int tcf_police_dump(struct sk_buff *skb, struct tcf_police *police) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | { |
Arnaldo Carvalho de Melo | 27a884d | 2007-04-19 20:29:13 -0700 | [diff] [blame] | 549 | unsigned char *b = skb_tail_pointer(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | struct tc_police opt; |
| 551 | |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 552 | opt.index = police->tcf_index; |
| 553 | opt.action = police->tcf_action; |
| 554 | opt.mtu = police->tcfp_mtu; |
| 555 | opt.burst = police->tcfp_burst; |
| 556 | if (police->tcfp_R_tab) |
| 557 | opt.rate = police->tcfp_R_tab->rate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | else |
| 559 | memset(&opt.rate, 0, sizeof(opt.rate)); |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 560 | if (police->tcfp_P_tab) |
| 561 | opt.peakrate = police->tcfp_P_tab->rate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | else |
| 563 | memset(&opt.peakrate, 0, sizeof(opt.peakrate)); |
| 564 | RTA_PUT(skb, TCA_POLICE_TBF, sizeof(opt), &opt); |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 565 | if (police->tcfp_result) |
| 566 | RTA_PUT(skb, TCA_POLICE_RESULT, sizeof(int), |
| 567 | &police->tcfp_result); |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 568 | if (police->tcfp_ewma_rate) |
| 569 | RTA_PUT(skb, TCA_POLICE_AVRATE, 4, &police->tcfp_ewma_rate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | return skb->len; |
| 571 | |
| 572 | rtattr_failure: |
Arnaldo Carvalho de Melo | dc5fc57 | 2007-03-25 23:06:12 -0700 | [diff] [blame] | 573 | nlmsg_trim(skb, b); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | return -1; |
| 575 | } |
| 576 | |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 577 | int tcf_police_dump_stats(struct sk_buff *skb, struct tcf_police *police) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | { |
| 579 | struct gnet_dump d; |
YOSHIFUJI Hideaki | 10297b9 | 2007-02-09 23:25:16 +0900 | [diff] [blame] | 580 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | if (gnet_stats_start_copy_compat(skb, TCA_STATS2, TCA_STATS, |
Patrick McHardy | 4bdf399 | 2007-07-02 22:47:37 -0700 | [diff] [blame] | 582 | TCA_XSTATS, &police->tcf_lock, |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 583 | &d) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | goto errout; |
YOSHIFUJI Hideaki | 10297b9 | 2007-02-09 23:25:16 +0900 | [diff] [blame] | 585 | |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 586 | if (gnet_stats_copy_basic(&d, &police->tcf_bstats) < 0 || |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 587 | gnet_stats_copy_rate_est(&d, &police->tcf_rate_est) < 0 || |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 588 | gnet_stats_copy_queue(&d, &police->tcf_qstats) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | goto errout; |
| 590 | |
| 591 | if (gnet_stats_finish_copy(&d) < 0) |
| 592 | goto errout; |
| 593 | |
| 594 | return 0; |
| 595 | |
| 596 | errout: |
| 597 | return -1; |
| 598 | } |
| 599 | |
Patrick McHardy | 31bd06e | 2006-01-08 22:16:25 -0800 | [diff] [blame] | 600 | #endif /* CONFIG_NET_CLS_ACT */ |