#include <asm/uaccess.h>
#include <asm/system.h>
-#include <linux/bitops.h>
+#include <asm/bitops.h>
#include <linux/config.h>
#include <linux/module.h>
#include <linux/types.h>
#include <net/route.h>
#include <linux/skbuff.h>
#include <net/sock.h>
-#include <net/act_api.h>
-#include <net/pkt_cls.h>
+#include <net/pkt_sched.h>
struct tc_u_knode
struct tc_u_common *tp_c;
int refcnt;
unsigned divisor;
+ u32 hgenerator;
struct tc_u_knode *ht[1];
};
*res = n->res;
#ifdef CONFIG_NET_CLS_IND
- if (!tcf_match_indev(skb, n->indev)) {
- n = n->next;
- goto next_knode;
+ /* yes, i know it sucks but the feature is
+ ** optional dammit! - JHS */
+ if (0 != n->indev[0]) {
+ if (NULL == skb->input_dev) {
+ n = n->next;
+ goto next_knode;
+ } else {
+ if (0 != strcmp(n->indev, skb->input_dev->name)) {
+ n = n->next;
+ goto next_knode;
+ }
+ }
}
#endif
#ifdef CONFIG_CLS_U32_PERF
static int u32_destroy_key(struct tcf_proto *tp, struct tc_u_knode *n)
{
- tcf_unbind_filter(tp, &n->res);
+ unsigned long cl;
+
+ if ((cl = __cls_set_class(&n->res.class, 0)) != 0)
+ tp->q->ops->cl_ops->unbind_tcf(tp->q, cl);
#ifdef CONFIG_NET_CLS_ACT
if (n->action) {
tcf_action_destroy(n->action, TCA_ACT_UNBIND);
return handle|(i>0xFFF ? 0xFFF : i);
}
-static int u32_set_parms(struct tcf_proto *tp, unsigned long base,
+static int u32_set_parms(struct Qdisc *q, unsigned long base,
struct tc_u_hnode *ht,
struct tc_u_knode *n, struct rtattr **tb,
struct rtattr *est)
{
+#ifdef CONFIG_NET_CLS_ACT
+ struct tc_action *act = NULL;
+ int ret;
+#endif
if (tb[TCA_U32_LINK-1]) {
u32 handle = *(u32*)RTA_DATA(tb[TCA_U32_LINK-1]);
struct tc_u_hnode *ht_down = NULL;
ht_down->refcnt++;
}
- tcf_tree_lock(tp);
+ sch_tree_lock(q);
ht_down = xchg(&n->ht_down, ht_down);
- tcf_tree_unlock(tp);
+ sch_tree_unlock(q);
if (ht_down)
ht_down->refcnt--;
}
if (tb[TCA_U32_CLASSID-1]) {
+ unsigned long cl;
+
n->res.classid = *(u32*)RTA_DATA(tb[TCA_U32_CLASSID-1]);
- tcf_bind_filter(tp, &n->res, base);
+ sch_tree_lock(q);
+ cl = __cls_set_class(&n->res.class, q->ops->cl_ops->bind_tcf(q, base, n->res.classid));
+ sch_tree_unlock(q);
+ if (cl)
+ q->ops->cl_ops->unbind_tcf(q, cl);
}
#ifdef CONFIG_NET_CLS_ACT
- if (tb[TCA_U32_POLICE-1]) {
- int err = tcf_change_act_police(tp, &n->action, tb[TCA_U32_POLICE-1], est);
- if (err < 0)
- return err;
+ /*backward compatibility */
+ if (tb[TCA_U32_POLICE-1])
+ {
+ act = kmalloc(sizeof(*act),GFP_KERNEL);
+ if (NULL == act)
+ return -ENOMEM;
+
+ memset(act,0,sizeof(*act));
+ ret = tcf_action_init_1(tb[TCA_U32_POLICE-1], est,act,"police", TCA_ACT_NOREPLACE, TCA_ACT_BIND);
+ if (0 > ret){
+ tcf_action_destroy(act, TCA_ACT_UNBIND);
+ return ret;
+ }
+ act->type = TCA_OLD_COMPAT;
+
+ sch_tree_lock(q);
+ act = xchg(&n->action, act);
+ sch_tree_unlock(q);
+
+ tcf_action_destroy(act, TCA_ACT_UNBIND);
+
}
- if (tb[TCA_U32_ACT-1]) {
- int err = tcf_change_act(tp, &n->action, tb[TCA_U32_ACT-1], est);
- if (err < 0)
- return err;
+ if(tb[TCA_U32_ACT-1]) {
+ act = kmalloc(sizeof(*act),GFP_KERNEL);
+ if (NULL == act)
+ return -ENOMEM;
+ memset(act,0,sizeof(*act));
+ ret = tcf_action_init(tb[TCA_U32_ACT-1], est,act,NULL,TCA_ACT_NOREPLACE, TCA_ACT_BIND);
+ if (0 > ret) {
+ tcf_action_destroy(act, TCA_ACT_UNBIND);
+ return ret;
+ }
+
+ sch_tree_lock(q);
+ act = xchg(&n->action, act);
+ sch_tree_unlock(q);
+
+ tcf_action_destroy(act, TCA_ACT_UNBIND);
}
+
+
#else
#ifdef CONFIG_NET_CLS_POLICE
if (tb[TCA_U32_POLICE-1]) {
- int err = tcf_change_police(tp, &n->police, tb[TCA_U32_POLICE-1], est);
- if (err < 0)
- return err;
+ struct tcf_police *police = tcf_police_locate(tb[TCA_U32_POLICE-1], est);
+ sch_tree_lock(q);
+ police = xchg(&n->police, police);
+ sch_tree_unlock(q);
+ tcf_police_release(police, TCA_ACT_UNBIND);
}
#endif
#endif
#ifdef CONFIG_NET_CLS_IND
- if (tb[TCA_U32_INDEV-1]) {
- int err = tcf_change_indev(tp, n->indev, tb[TCA_U32_INDEV-1]);
- if (err < 0)
- return err;
+ n->indev[0] = 0;
+ if(tb[TCA_U32_INDEV-1]) {
+ struct rtattr *input_dev = tb[TCA_U32_INDEV-1];
+ if (RTA_PAYLOAD(input_dev) >= IFNAMSIZ) {
+ printk("cls_u32: bad indev name %s\n",(char*)RTA_DATA(input_dev));
+ /* should we clear state first? */
+ return -EINVAL;
+ }
+ sprintf(n->indev, "%s", (char*)RTA_DATA(input_dev));
+ printk("got IND %s\n",n->indev);
}
#endif
if (TC_U32_KEY(n->handle) == 0)
return -EINVAL;
- return u32_set_parms(tp, base, n->ht_up, n, tb, tca[TCA_RATE-1]);
+ return u32_set_parms(tp->q, base, n->ht_up, n, tb, tca[TCA_RATE-1]);
}
if (tb[TCA_U32_DIVISOR-1]) {
}
n->fshift = i;
}
- err = u32_set_parms(tp, base, ht, n, tb, tca[TCA_RATE-1]);
+ err = u32_set_parms(tp->q, base, ht, n, tb, tca[TCA_RATE-1]);
if (err == 0) {
struct tc_u_knode **ins;
for (ins = &ht->ht[TC_U32_HASH(handle)]; *ins; ins = &(*ins)->next)
if (n->ht_down)
RTA_PUT(skb, TCA_U32_LINK, 4, &n->ht_down->handle);
#ifdef CONFIG_NET_CLS_ACT
- if (tcf_dump_act(skb, n->action, TCA_U32_ACT, TCA_U32_POLICE) < 0)
- goto rtattr_failure;
+ /* again for backward compatible mode - we want
+ * to work with both old and new modes of entering
+ * tc data even if iproute2 was newer - jhs
+ */
+ if (n->action) {
+ struct rtattr * p_rta = (struct rtattr*)skb->tail;
+
+ if (n->action->type != TCA_OLD_COMPAT) {
+ RTA_PUT(skb, TCA_U32_ACT, 0, NULL);
+ if (tcf_action_dump(skb,n->action, 0, 0) < 0) {
+ goto rtattr_failure;
+ }
+ } else {
+ RTA_PUT(skb, TCA_U32_POLICE, 0, NULL);
+ if (tcf_action_dump_old(skb,n->action,0,0) < 0) {
+ goto rtattr_failure;
+ }
+ }
+
+ p_rta->rta_len = skb->tail - (u8*)p_rta;
+ }
+
#else
#ifdef CONFIG_NET_CLS_POLICE
- if (tcf_dump_police(skb, n->police, TCA_U32_POLICE) < 0)
- goto rtattr_failure;
+ if (n->police) {
+ struct rtattr * p_rta = (struct rtattr*)skb->tail;
+ RTA_PUT(skb, TCA_U32_POLICE, 0, NULL);
+
+ if (tcf_police_dump(skb, n->police) < 0)
+ goto rtattr_failure;
+
+ p_rta->rta_len = skb->tail - (u8*)p_rta;
+
+ }
#endif
#endif
#ifdef CONFIG_NET_CLS_IND
- if(strlen(n->indev))
+ if(strlen(n->indev)) {
+ struct rtattr * p_rta = (struct rtattr*)skb->tail;
RTA_PUT(skb, TCA_U32_INDEV, IFNAMSIZ, n->indev);
+ p_rta->rta_len = skb->tail - (u8*)p_rta;
+ }
#endif
#ifdef CONFIG_CLS_U32_PERF
RTA_PUT(skb, TCA_U32_PCNT,
}
#else
#ifdef CONFIG_NET_CLS_POLICE
- if (TC_U32_KEY(n->handle) && n->police)
- if (tcf_police_dump_stats(skb, n->police) < 0)
+ if (TC_U32_KEY(n->handle) && n->police) {
+ if (qdisc_copy_stats(skb, &n->police->stats,
+ n->police->stats_lock))
goto rtattr_failure;
+ }
#endif
#endif
return skb->len;