14bba3925SPatrick McHardy /* 24bba3925SPatrick McHardy * net/sched/police.c Input police filter. 34bba3925SPatrick McHardy * 44bba3925SPatrick McHardy * This program is free software; you can redistribute it and/or 54bba3925SPatrick McHardy * modify it under the terms of the GNU General Public License 64bba3925SPatrick McHardy * as published by the Free Software Foundation; either version 74bba3925SPatrick McHardy * 2 of the License, or (at your option) any later version. 84bba3925SPatrick McHardy * 94bba3925SPatrick McHardy * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> 104bba3925SPatrick McHardy * J Hadi Salim (action changes) 114bba3925SPatrick McHardy */ 124bba3925SPatrick McHardy 134bba3925SPatrick McHardy #include <linux/module.h> 144bba3925SPatrick McHardy #include <linux/types.h> 154bba3925SPatrick McHardy #include <linux/kernel.h> 164bba3925SPatrick McHardy #include <linux/string.h> 174bba3925SPatrick McHardy #include <linux/errno.h> 184bba3925SPatrick McHardy #include <linux/skbuff.h> 194bba3925SPatrick McHardy #include <linux/rtnetlink.h> 204bba3925SPatrick McHardy #include <linux/init.h> 21*5a0e3ad6STejun Heo #include <linux/slab.h> 224bba3925SPatrick McHardy #include <net/act_api.h> 23dc5fc579SArnaldo Carvalho de Melo #include <net/netlink.h> 244bba3925SPatrick McHardy 25e9bef55dSJesper Dangaard Brouer #define L2T(p,L) qdisc_l2t((p)->tcfp_R_tab, L) 26e9bef55dSJesper Dangaard Brouer #define L2T_P(p,L) qdisc_l2t((p)->tcfp_P_tab, L) 274bba3925SPatrick McHardy 28e9ce1cd3SDavid S. Miller #define POL_TAB_MASK 15 29e9ce1cd3SDavid S. Miller static struct tcf_common *tcf_police_ht[POL_TAB_MASK + 1]; 30e9ce1cd3SDavid S. Miller static u32 police_idx_gen; 314bba3925SPatrick McHardy static DEFINE_RWLOCK(police_lock); 324bba3925SPatrick McHardy 33e9ce1cd3SDavid S. Miller static struct tcf_hashinfo police_hash_info = { 34e9ce1cd3SDavid S. Miller .htab = tcf_police_ht, 35e9ce1cd3SDavid S. Miller .hmask = POL_TAB_MASK, 36e9ce1cd3SDavid S. Miller .lock = &police_lock, 37e9ce1cd3SDavid S. Miller }; 38e9ce1cd3SDavid S. Miller 391e9b3d53SPatrick McHardy /* old policer structure from before tc actions */ 401e9b3d53SPatrick McHardy struct tc_police_compat 411e9b3d53SPatrick McHardy { 421e9b3d53SPatrick McHardy u32 index; 431e9b3d53SPatrick McHardy int action; 441e9b3d53SPatrick McHardy u32 limit; 451e9b3d53SPatrick McHardy u32 burst; 461e9b3d53SPatrick McHardy u32 mtu; 471e9b3d53SPatrick McHardy struct tc_ratespec rate; 481e9b3d53SPatrick McHardy struct tc_ratespec peakrate; 491e9b3d53SPatrick McHardy }; 501e9b3d53SPatrick McHardy 514bba3925SPatrick McHardy /* Each policer is serialized by its individual spinlock */ 524bba3925SPatrick McHardy 5383b950c8SJamal Hadi Salim static int tcf_act_police_walker(struct sk_buff *skb, struct netlink_callback *cb, 544bba3925SPatrick McHardy int type, struct tc_action *a) 554bba3925SPatrick McHardy { 56e9ce1cd3SDavid S. Miller struct tcf_common *p; 574bba3925SPatrick McHardy int err = 0, index = -1, i = 0, s_i = 0, n_i = 0; 584b3550efSPatrick McHardy struct nlattr *nest; 594bba3925SPatrick McHardy 60e1e992e5SJamal Hadi Salim read_lock_bh(&police_lock); 614bba3925SPatrick McHardy 624bba3925SPatrick McHardy s_i = cb->args[0]; 634bba3925SPatrick McHardy 64e9ce1cd3SDavid S. Miller for (i = 0; i < (POL_TAB_MASK + 1); i++) { 65e9ce1cd3SDavid S. Miller p = tcf_police_ht[tcf_hash(i, POL_TAB_MASK)]; 664bba3925SPatrick McHardy 67e9ce1cd3SDavid S. Miller for (; p; p = p->tcfc_next) { 684bba3925SPatrick McHardy index++; 694bba3925SPatrick McHardy if (index < s_i) 704bba3925SPatrick McHardy continue; 714bba3925SPatrick McHardy a->priv = p; 724bba3925SPatrick McHardy a->order = index; 734b3550efSPatrick McHardy nest = nla_nest_start(skb, a->order); 744b3550efSPatrick McHardy if (nest == NULL) 754b3550efSPatrick McHardy goto nla_put_failure; 764bba3925SPatrick McHardy if (type == RTM_DELACTION) 774bba3925SPatrick McHardy err = tcf_action_dump_1(skb, a, 0, 1); 784bba3925SPatrick McHardy else 794bba3925SPatrick McHardy err = tcf_action_dump_1(skb, a, 0, 0); 804bba3925SPatrick McHardy if (err < 0) { 814bba3925SPatrick McHardy index--; 824b3550efSPatrick McHardy nla_nest_cancel(skb, nest); 834bba3925SPatrick McHardy goto done; 844bba3925SPatrick McHardy } 854b3550efSPatrick McHardy nla_nest_end(skb, nest); 864bba3925SPatrick McHardy n_i++; 874bba3925SPatrick McHardy } 884bba3925SPatrick McHardy } 894bba3925SPatrick McHardy done: 90e1e992e5SJamal Hadi Salim read_unlock_bh(&police_lock); 914bba3925SPatrick McHardy if (n_i) 924bba3925SPatrick McHardy cb->args[0] += n_i; 934bba3925SPatrick McHardy return n_i; 944bba3925SPatrick McHardy 957ba699c6SPatrick McHardy nla_put_failure: 964b3550efSPatrick McHardy nla_nest_cancel(skb, nest); 974bba3925SPatrick McHardy goto done; 984bba3925SPatrick McHardy } 994bba3925SPatrick McHardy 100c3bc7cffSPatrick McHardy static void tcf_police_destroy(struct tcf_police *p) 1014bba3925SPatrick McHardy { 102e9ce1cd3SDavid S. Miller unsigned int h = tcf_hash(p->tcf_index, POL_TAB_MASK); 103e9ce1cd3SDavid S. Miller struct tcf_common **p1p; 1044bba3925SPatrick McHardy 105e9ce1cd3SDavid S. Miller for (p1p = &tcf_police_ht[h]; *p1p; p1p = &(*p1p)->tcfc_next) { 106e9ce1cd3SDavid S. Miller if (*p1p == &p->common) { 1074bba3925SPatrick McHardy write_lock_bh(&police_lock); 108e9ce1cd3SDavid S. Miller *p1p = p->tcf_next; 1094bba3925SPatrick McHardy write_unlock_bh(&police_lock); 110e9ce1cd3SDavid S. Miller gen_kill_estimator(&p->tcf_bstats, 111e9ce1cd3SDavid S. Miller &p->tcf_rate_est); 112e9ce1cd3SDavid S. Miller if (p->tcfp_R_tab) 113e9ce1cd3SDavid S. Miller qdisc_put_rtab(p->tcfp_R_tab); 114e9ce1cd3SDavid S. Miller if (p->tcfp_P_tab) 115e9ce1cd3SDavid S. Miller qdisc_put_rtab(p->tcfp_P_tab); 1164bba3925SPatrick McHardy kfree(p); 1174bba3925SPatrick McHardy return; 1184bba3925SPatrick McHardy } 1194bba3925SPatrick McHardy } 120547b792cSIlpo Järvinen WARN_ON(1); 1214bba3925SPatrick McHardy } 1224bba3925SPatrick McHardy 12353b2bf3fSPatrick McHardy static const struct nla_policy police_policy[TCA_POLICE_MAX + 1] = { 12453b2bf3fSPatrick McHardy [TCA_POLICE_RATE] = { .len = TC_RTAB_SIZE }, 12553b2bf3fSPatrick McHardy [TCA_POLICE_PEAKRATE] = { .len = TC_RTAB_SIZE }, 12653b2bf3fSPatrick McHardy [TCA_POLICE_AVRATE] = { .type = NLA_U32 }, 12753b2bf3fSPatrick McHardy [TCA_POLICE_RESULT] = { .type = NLA_U32 }, 12853b2bf3fSPatrick McHardy }; 12953b2bf3fSPatrick McHardy 1307ba699c6SPatrick McHardy static int tcf_act_police_locate(struct nlattr *nla, struct nlattr *est, 1314bba3925SPatrick McHardy struct tc_action *a, int ovr, int bind) 1324bba3925SPatrick McHardy { 1334bba3925SPatrick McHardy unsigned h; 1344bba3925SPatrick McHardy int ret = 0, err; 1357ba699c6SPatrick McHardy struct nlattr *tb[TCA_POLICE_MAX + 1]; 1364bba3925SPatrick McHardy struct tc_police *parm; 137e9ce1cd3SDavid S. Miller struct tcf_police *police; 1384bba3925SPatrick McHardy struct qdisc_rate_table *R_tab = NULL, *P_tab = NULL; 1391e9b3d53SPatrick McHardy int size; 1404bba3925SPatrick McHardy 141cee63723SPatrick McHardy if (nla == NULL) 1424bba3925SPatrick McHardy return -EINVAL; 1434bba3925SPatrick McHardy 14453b2bf3fSPatrick McHardy err = nla_parse_nested(tb, TCA_POLICE_MAX, nla, police_policy); 145cee63723SPatrick McHardy if (err < 0) 146cee63723SPatrick McHardy return err; 147cee63723SPatrick McHardy 1487ba699c6SPatrick McHardy if (tb[TCA_POLICE_TBF] == NULL) 1491e9b3d53SPatrick McHardy return -EINVAL; 1507ba699c6SPatrick McHardy size = nla_len(tb[TCA_POLICE_TBF]); 1511e9b3d53SPatrick McHardy if (size != sizeof(*parm) && size != sizeof(struct tc_police_compat)) 1524bba3925SPatrick McHardy return -EINVAL; 1537ba699c6SPatrick McHardy parm = nla_data(tb[TCA_POLICE_TBF]); 1544bba3925SPatrick McHardy 155e9ce1cd3SDavid S. Miller if (parm->index) { 156e9ce1cd3SDavid S. Miller struct tcf_common *pc; 157e9ce1cd3SDavid S. Miller 158e9ce1cd3SDavid S. Miller pc = tcf_hash_lookup(parm->index, &police_hash_info); 159e9ce1cd3SDavid S. Miller if (pc != NULL) { 160e9ce1cd3SDavid S. Miller a->priv = pc; 161e9ce1cd3SDavid S. Miller police = to_police(pc); 1624bba3925SPatrick McHardy if (bind) { 163e9ce1cd3SDavid S. Miller police->tcf_bindcnt += 1; 164e9ce1cd3SDavid S. Miller police->tcf_refcnt += 1; 1654bba3925SPatrick McHardy } 1664bba3925SPatrick McHardy if (ovr) 1674bba3925SPatrick McHardy goto override; 1684bba3925SPatrick McHardy return ret; 1694bba3925SPatrick McHardy } 170e9ce1cd3SDavid S. Miller } 1714bba3925SPatrick McHardy 172e9ce1cd3SDavid S. Miller police = kzalloc(sizeof(*police), GFP_KERNEL); 173e9ce1cd3SDavid S. Miller if (police == NULL) 1744bba3925SPatrick McHardy return -ENOMEM; 1754bba3925SPatrick McHardy ret = ACT_P_CREATED; 176e9ce1cd3SDavid S. Miller police->tcf_refcnt = 1; 177e9ce1cd3SDavid S. Miller spin_lock_init(&police->tcf_lock); 1784bba3925SPatrick McHardy if (bind) 179e9ce1cd3SDavid S. Miller police->tcf_bindcnt = 1; 1804bba3925SPatrick McHardy override: 1814bba3925SPatrick McHardy if (parm->rate.rate) { 1824bba3925SPatrick McHardy err = -ENOMEM; 1837ba699c6SPatrick McHardy R_tab = qdisc_get_rtab(&parm->rate, tb[TCA_POLICE_RATE]); 1844bba3925SPatrick McHardy if (R_tab == NULL) 1854bba3925SPatrick McHardy goto failure; 186c1b56878SStephen Hemminger 1874bba3925SPatrick McHardy if (parm->peakrate.rate) { 1884bba3925SPatrick McHardy P_tab = qdisc_get_rtab(&parm->peakrate, 1897ba699c6SPatrick McHardy tb[TCA_POLICE_PEAKRATE]); 19071bcb09aSStephen Hemminger if (P_tab == NULL) 1914bba3925SPatrick McHardy goto failure; 1924bba3925SPatrick McHardy } 1934bba3925SPatrick McHardy } 19471bcb09aSStephen Hemminger 195e9ce1cd3SDavid S. Miller spin_lock_bh(&police->tcf_lock); 19671bcb09aSStephen Hemminger if (est) { 19771bcb09aSStephen Hemminger err = gen_replace_estimator(&police->tcf_bstats, 19871bcb09aSStephen Hemminger &police->tcf_rate_est, 19971bcb09aSStephen Hemminger &police->tcf_lock, est); 20071bcb09aSStephen Hemminger if (err) 20171bcb09aSStephen Hemminger goto failure_unlock; 202a883bf56SJarek Poplawski } else if (tb[TCA_POLICE_AVRATE] && 203a883bf56SJarek Poplawski (ret == ACT_P_CREATED || 204a883bf56SJarek Poplawski !gen_estimator_active(&police->tcf_bstats, 205a883bf56SJarek Poplawski &police->tcf_rate_est))) { 206a883bf56SJarek Poplawski err = -EINVAL; 207a883bf56SJarek Poplawski goto failure_unlock; 20871bcb09aSStephen Hemminger } 20971bcb09aSStephen Hemminger 21071bcb09aSStephen Hemminger /* No failure allowed after this point */ 2114bba3925SPatrick McHardy if (R_tab != NULL) { 212e9ce1cd3SDavid S. Miller qdisc_put_rtab(police->tcfp_R_tab); 213e9ce1cd3SDavid S. Miller police->tcfp_R_tab = R_tab; 2144bba3925SPatrick McHardy } 2154bba3925SPatrick McHardy if (P_tab != NULL) { 216e9ce1cd3SDavid S. Miller qdisc_put_rtab(police->tcfp_P_tab); 217e9ce1cd3SDavid S. Miller police->tcfp_P_tab = P_tab; 2184bba3925SPatrick McHardy } 2194bba3925SPatrick McHardy 2207ba699c6SPatrick McHardy if (tb[TCA_POLICE_RESULT]) 2211587bac4SPatrick McHardy police->tcfp_result = nla_get_u32(tb[TCA_POLICE_RESULT]); 222e9ce1cd3SDavid S. Miller police->tcfp_toks = police->tcfp_burst = parm->burst; 223e9ce1cd3SDavid S. Miller police->tcfp_mtu = parm->mtu; 224e9ce1cd3SDavid S. Miller if (police->tcfp_mtu == 0) { 225e9ce1cd3SDavid S. Miller police->tcfp_mtu = ~0; 226e9ce1cd3SDavid S. Miller if (police->tcfp_R_tab) 227e9ce1cd3SDavid S. Miller police->tcfp_mtu = 255<<police->tcfp_R_tab->rate.cell_log; 2284bba3925SPatrick McHardy } 229e9ce1cd3SDavid S. Miller if (police->tcfp_P_tab) 230e9ce1cd3SDavid S. Miller police->tcfp_ptoks = L2T_P(police, police->tcfp_mtu); 231e9ce1cd3SDavid S. Miller police->tcf_action = parm->action; 2324bba3925SPatrick McHardy 2337ba699c6SPatrick McHardy if (tb[TCA_POLICE_AVRATE]) 2341587bac4SPatrick McHardy police->tcfp_ewma_rate = nla_get_u32(tb[TCA_POLICE_AVRATE]); 2354bba3925SPatrick McHardy 236e9ce1cd3SDavid S. Miller spin_unlock_bh(&police->tcf_lock); 2374bba3925SPatrick McHardy if (ret != ACT_P_CREATED) 2384bba3925SPatrick McHardy return ret; 2394bba3925SPatrick McHardy 2403bebcda2SPatrick McHardy police->tcfp_t_c = psched_get_time(); 241e9ce1cd3SDavid S. Miller police->tcf_index = parm->index ? parm->index : 242e9ce1cd3SDavid S. Miller tcf_hash_new_index(&police_idx_gen, &police_hash_info); 243e9ce1cd3SDavid S. Miller h = tcf_hash(police->tcf_index, POL_TAB_MASK); 2444bba3925SPatrick McHardy write_lock_bh(&police_lock); 245e9ce1cd3SDavid S. Miller police->tcf_next = tcf_police_ht[h]; 246e9ce1cd3SDavid S. Miller tcf_police_ht[h] = &police->common; 2474bba3925SPatrick McHardy write_unlock_bh(&police_lock); 2484bba3925SPatrick McHardy 249e9ce1cd3SDavid S. Miller a->priv = police; 2504bba3925SPatrick McHardy return ret; 2514bba3925SPatrick McHardy 25271bcb09aSStephen Hemminger failure_unlock: 25371bcb09aSStephen Hemminger spin_unlock_bh(&police->tcf_lock); 2544bba3925SPatrick McHardy failure: 25571bcb09aSStephen Hemminger if (P_tab) 25671bcb09aSStephen Hemminger qdisc_put_rtab(P_tab); 25771bcb09aSStephen Hemminger if (R_tab) 25871bcb09aSStephen Hemminger qdisc_put_rtab(R_tab); 2594bba3925SPatrick McHardy if (ret == ACT_P_CREATED) 260e9ce1cd3SDavid S. Miller kfree(police); 2614bba3925SPatrick McHardy return err; 2624bba3925SPatrick McHardy } 2634bba3925SPatrick McHardy 2644bba3925SPatrick McHardy static int tcf_act_police_cleanup(struct tc_action *a, int bind) 2654bba3925SPatrick McHardy { 266e9ce1cd3SDavid S. Miller struct tcf_police *p = a->priv; 267c3bc7cffSPatrick McHardy int ret = 0; 2684bba3925SPatrick McHardy 269c3bc7cffSPatrick McHardy if (p != NULL) { 270c3bc7cffSPatrick McHardy if (bind) 271c3bc7cffSPatrick McHardy p->tcf_bindcnt--; 272c3bc7cffSPatrick McHardy 273c3bc7cffSPatrick McHardy p->tcf_refcnt--; 274c3bc7cffSPatrick McHardy if (p->tcf_refcnt <= 0 && !p->tcf_bindcnt) { 275c3bc7cffSPatrick McHardy tcf_police_destroy(p); 276c3bc7cffSPatrick McHardy ret = 1; 277c3bc7cffSPatrick McHardy } 278c3bc7cffSPatrick McHardy } 279c3bc7cffSPatrick McHardy return ret; 2804bba3925SPatrick McHardy } 2814bba3925SPatrick McHardy 2824bba3925SPatrick McHardy static int tcf_act_police(struct sk_buff *skb, struct tc_action *a, 2834bba3925SPatrick McHardy struct tcf_result *res) 2844bba3925SPatrick McHardy { 285e9ce1cd3SDavid S. Miller struct tcf_police *police = a->priv; 2864bba3925SPatrick McHardy psched_time_t now; 2874bba3925SPatrick McHardy long toks; 2884bba3925SPatrick McHardy long ptoks = 0; 2894bba3925SPatrick McHardy 290e9ce1cd3SDavid S. Miller spin_lock(&police->tcf_lock); 2914bba3925SPatrick McHardy 2920abf77e5SJussi Kivilinna police->tcf_bstats.bytes += qdisc_pkt_len(skb); 293e9ce1cd3SDavid S. Miller police->tcf_bstats.packets++; 2944bba3925SPatrick McHardy 295e9ce1cd3SDavid S. Miller if (police->tcfp_ewma_rate && 296e9ce1cd3SDavid S. Miller police->tcf_rate_est.bps >= police->tcfp_ewma_rate) { 297e9ce1cd3SDavid S. Miller police->tcf_qstats.overlimits++; 298b9647580SJarek Poplawski if (police->tcf_action == TC_ACT_SHOT) 299b9647580SJarek Poplawski police->tcf_qstats.drops++; 300e9ce1cd3SDavid S. Miller spin_unlock(&police->tcf_lock); 301e9ce1cd3SDavid S. Miller return police->tcf_action; 3024bba3925SPatrick McHardy } 3034bba3925SPatrick McHardy 3040abf77e5SJussi Kivilinna if (qdisc_pkt_len(skb) <= police->tcfp_mtu) { 305e9ce1cd3SDavid S. Miller if (police->tcfp_R_tab == NULL) { 306e9ce1cd3SDavid S. Miller spin_unlock(&police->tcf_lock); 307e9ce1cd3SDavid S. Miller return police->tcfp_result; 3084bba3925SPatrick McHardy } 3094bba3925SPatrick McHardy 3103bebcda2SPatrick McHardy now = psched_get_time(); 31103cc45c0SPatrick McHardy toks = psched_tdiff_bounded(now, police->tcfp_t_c, 312e9ce1cd3SDavid S. Miller police->tcfp_burst); 313e9ce1cd3SDavid S. Miller if (police->tcfp_P_tab) { 314e9ce1cd3SDavid S. Miller ptoks = toks + police->tcfp_ptoks; 315e9ce1cd3SDavid S. Miller if (ptoks > (long)L2T_P(police, police->tcfp_mtu)) 316e9ce1cd3SDavid S. Miller ptoks = (long)L2T_P(police, police->tcfp_mtu); 3170abf77e5SJussi Kivilinna ptoks -= L2T_P(police, qdisc_pkt_len(skb)); 3184bba3925SPatrick McHardy } 319e9ce1cd3SDavid S. Miller toks += police->tcfp_toks; 320e9ce1cd3SDavid S. Miller if (toks > (long)police->tcfp_burst) 321e9ce1cd3SDavid S. Miller toks = police->tcfp_burst; 3220abf77e5SJussi Kivilinna toks -= L2T(police, qdisc_pkt_len(skb)); 3234bba3925SPatrick McHardy if ((toks|ptoks) >= 0) { 324e9ce1cd3SDavid S. Miller police->tcfp_t_c = now; 325e9ce1cd3SDavid S. Miller police->tcfp_toks = toks; 326e9ce1cd3SDavid S. Miller police->tcfp_ptoks = ptoks; 327e9ce1cd3SDavid S. Miller spin_unlock(&police->tcf_lock); 328e9ce1cd3SDavid S. Miller return police->tcfp_result; 3294bba3925SPatrick McHardy } 3304bba3925SPatrick McHardy } 3314bba3925SPatrick McHardy 332e9ce1cd3SDavid S. Miller police->tcf_qstats.overlimits++; 333b9647580SJarek Poplawski if (police->tcf_action == TC_ACT_SHOT) 334b9647580SJarek Poplawski police->tcf_qstats.drops++; 335e9ce1cd3SDavid S. Miller spin_unlock(&police->tcf_lock); 336e9ce1cd3SDavid S. Miller return police->tcf_action; 3374bba3925SPatrick McHardy } 3384bba3925SPatrick McHardy 3394bba3925SPatrick McHardy static int 3404bba3925SPatrick McHardy tcf_act_police_dump(struct sk_buff *skb, struct tc_action *a, int bind, int ref) 3414bba3925SPatrick McHardy { 34227a884dcSArnaldo Carvalho de Melo unsigned char *b = skb_tail_pointer(skb); 343e9ce1cd3SDavid S. Miller struct tcf_police *police = a->priv; 3444bba3925SPatrick McHardy struct tc_police opt; 3454bba3925SPatrick McHardy 346e9ce1cd3SDavid S. Miller opt.index = police->tcf_index; 347e9ce1cd3SDavid S. Miller opt.action = police->tcf_action; 348e9ce1cd3SDavid S. Miller opt.mtu = police->tcfp_mtu; 349e9ce1cd3SDavid S. Miller opt.burst = police->tcfp_burst; 350e9ce1cd3SDavid S. Miller opt.refcnt = police->tcf_refcnt - ref; 351e9ce1cd3SDavid S. Miller opt.bindcnt = police->tcf_bindcnt - bind; 352e9ce1cd3SDavid S. Miller if (police->tcfp_R_tab) 353e9ce1cd3SDavid S. Miller opt.rate = police->tcfp_R_tab->rate; 3544bba3925SPatrick McHardy else 3554bba3925SPatrick McHardy memset(&opt.rate, 0, sizeof(opt.rate)); 356e9ce1cd3SDavid S. Miller if (police->tcfp_P_tab) 357e9ce1cd3SDavid S. Miller opt.peakrate = police->tcfp_P_tab->rate; 3584bba3925SPatrick McHardy else 3594bba3925SPatrick McHardy memset(&opt.peakrate, 0, sizeof(opt.peakrate)); 3607ba699c6SPatrick McHardy NLA_PUT(skb, TCA_POLICE_TBF, sizeof(opt), &opt); 361e9ce1cd3SDavid S. Miller if (police->tcfp_result) 36224beeab5SPatrick McHardy NLA_PUT_U32(skb, TCA_POLICE_RESULT, police->tcfp_result); 363e9ce1cd3SDavid S. Miller if (police->tcfp_ewma_rate) 36424beeab5SPatrick McHardy NLA_PUT_U32(skb, TCA_POLICE_AVRATE, police->tcfp_ewma_rate); 3654bba3925SPatrick McHardy return skb->len; 3664bba3925SPatrick McHardy 3677ba699c6SPatrick McHardy nla_put_failure: 368dc5fc579SArnaldo Carvalho de Melo nlmsg_trim(skb, b); 3694bba3925SPatrick McHardy return -1; 3704bba3925SPatrick McHardy } 3714bba3925SPatrick McHardy 3724bba3925SPatrick McHardy MODULE_AUTHOR("Alexey Kuznetsov"); 3734bba3925SPatrick McHardy MODULE_DESCRIPTION("Policing actions"); 3744bba3925SPatrick McHardy MODULE_LICENSE("GPL"); 3754bba3925SPatrick McHardy 3764bba3925SPatrick McHardy static struct tc_action_ops act_police_ops = { 3774bba3925SPatrick McHardy .kind = "police", 378e9ce1cd3SDavid S. Miller .hinfo = &police_hash_info, 3794bba3925SPatrick McHardy .type = TCA_ID_POLICE, 3804bba3925SPatrick McHardy .capab = TCA_CAP_NONE, 3814bba3925SPatrick McHardy .owner = THIS_MODULE, 3824bba3925SPatrick McHardy .act = tcf_act_police, 3834bba3925SPatrick McHardy .dump = tcf_act_police_dump, 3844bba3925SPatrick McHardy .cleanup = tcf_act_police_cleanup, 385e9ce1cd3SDavid S. Miller .lookup = tcf_hash_search, 3864bba3925SPatrick McHardy .init = tcf_act_police_locate, 38783b950c8SJamal Hadi Salim .walk = tcf_act_police_walker 3884bba3925SPatrick McHardy }; 3894bba3925SPatrick McHardy 3904bba3925SPatrick McHardy static int __init 3914bba3925SPatrick McHardy police_init_module(void) 3924bba3925SPatrick McHardy { 3934bba3925SPatrick McHardy return tcf_register_action(&act_police_ops); 3944bba3925SPatrick McHardy } 3954bba3925SPatrick McHardy 3964bba3925SPatrick McHardy static void __exit 3974bba3925SPatrick McHardy police_cleanup_module(void) 3984bba3925SPatrick McHardy { 3994bba3925SPatrick McHardy tcf_unregister_action(&act_police_ops); 4004bba3925SPatrick McHardy } 4014bba3925SPatrick McHardy 4024bba3925SPatrick McHardy module_init(police_init_module); 4034bba3925SPatrick McHardy module_exit(police_cleanup_module); 404