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