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