Commit 2f10247f authored by Thomas Graf's avatar Thomas Graf Committed by David S. Miller

[PKT_SCHED]: cls_u32: Use generic routines for class binding and police config/dump

Signed-off-by: default avatarThomas Graf <tgraf@suug.ch>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent d8cf0d5e
...@@ -156,18 +156,9 @@ static int u32_classify(struct sk_buff *skb, struct tcf_proto *tp, struct tcf_re ...@@ -156,18 +156,9 @@ static int u32_classify(struct sk_buff *skb, struct tcf_proto *tp, struct tcf_re
*res = n->res; *res = n->res;
#ifdef CONFIG_NET_CLS_IND #ifdef CONFIG_NET_CLS_IND
/* yes, i know it sucks but the feature is if (!tcf_match_indev(skb, n->indev)) {
** optional dammit! - JHS */ n = n->next;
if (0 != n->indev[0]) { goto next_knode;
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 #endif
#ifdef CONFIG_CLS_U32_PERF #ifdef CONFIG_CLS_U32_PERF
...@@ -346,10 +337,7 @@ static int u32_init(struct tcf_proto *tp) ...@@ -346,10 +337,7 @@ static int u32_init(struct tcf_proto *tp)
static int u32_destroy_key(struct tcf_proto *tp, struct tc_u_knode *n) static int u32_destroy_key(struct tcf_proto *tp, struct tc_u_knode *n)
{ {
unsigned long cl; tcf_unbind_filter(tp, &n->res);
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 #ifdef CONFIG_NET_CLS_ACT
if (n->action) { if (n->action) {
tcf_action_destroy(n->action, TCA_ACT_UNBIND); tcf_action_destroy(n->action, TCA_ACT_UNBIND);
...@@ -495,15 +483,11 @@ static u32 gen_new_kid(struct tc_u_hnode *ht, u32 handle) ...@@ -495,15 +483,11 @@ static u32 gen_new_kid(struct tc_u_hnode *ht, u32 handle)
return handle|(i>0xFFF ? 0xFFF : i); return handle|(i>0xFFF ? 0xFFF : i);
} }
static int u32_set_parms(struct Qdisc *q, unsigned long base, static int u32_set_parms(struct tcf_proto *tp, unsigned long base,
struct tc_u_hnode *ht, struct tc_u_hnode *ht,
struct tc_u_knode *n, struct rtattr **tb, struct tc_u_knode *n, struct rtattr **tb,
struct rtattr *est) struct rtattr *est)
{ {
#ifdef CONFIG_NET_CLS_ACT
struct tc_action *act = NULL;
int ret;
#endif
if (tb[TCA_U32_LINK-1]) { if (tb[TCA_U32_LINK-1]) {
u32 handle = *(u32*)RTA_DATA(tb[TCA_U32_LINK-1]); u32 handle = *(u32*)RTA_DATA(tb[TCA_U32_LINK-1]);
struct tc_u_hnode *ht_down = NULL; struct tc_u_hnode *ht_down = NULL;
...@@ -519,88 +503,43 @@ static int u32_set_parms(struct Qdisc *q, unsigned long base, ...@@ -519,88 +503,43 @@ static int u32_set_parms(struct Qdisc *q, unsigned long base,
ht_down->refcnt++; ht_down->refcnt++;
} }
sch_tree_lock(q); tcf_tree_lock(tp);
ht_down = xchg(&n->ht_down, ht_down); ht_down = xchg(&n->ht_down, ht_down);
sch_tree_unlock(q); tcf_tree_unlock(tp);
if (ht_down) if (ht_down)
ht_down->refcnt--; ht_down->refcnt--;
} }
if (tb[TCA_U32_CLASSID-1]) { if (tb[TCA_U32_CLASSID-1]) {
unsigned long cl;
n->res.classid = *(u32*)RTA_DATA(tb[TCA_U32_CLASSID-1]); n->res.classid = *(u32*)RTA_DATA(tb[TCA_U32_CLASSID-1]);
sch_tree_lock(q); tcf_bind_filter(tp, &n->res, base);
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 #ifdef CONFIG_NET_CLS_ACT
/*backward compatibility */ if (tb[TCA_U32_POLICE-1]) {
if (tb[TCA_U32_POLICE-1]) int err = tcf_change_act_police(tp, &n->action, tb[TCA_U32_POLICE-1], est);
{ if (err < 0)
act = kmalloc(sizeof(*act),GFP_KERNEL); return err;
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]) { if (tb[TCA_U32_ACT-1]) {
act = kmalloc(sizeof(*act),GFP_KERNEL); int err = tcf_change_act(tp, &n->action, tb[TCA_U32_ACT-1], est);
if (NULL == act) if (err < 0)
return -ENOMEM; return err;
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 #else
#ifdef CONFIG_NET_CLS_POLICE #ifdef CONFIG_NET_CLS_POLICE
if (tb[TCA_U32_POLICE-1]) { if (tb[TCA_U32_POLICE-1]) {
struct tcf_police *police = tcf_police_locate(tb[TCA_U32_POLICE-1], est); int err = tcf_change_police(tp, &n->police, tb[TCA_U32_POLICE-1], est);
sch_tree_lock(q); if (err < 0)
police = xchg(&n->police, police); return err;
sch_tree_unlock(q);
tcf_police_release(police, TCA_ACT_UNBIND);
} }
#endif #endif
#endif #endif
#ifdef CONFIG_NET_CLS_IND #ifdef CONFIG_NET_CLS_IND
n->indev[0] = 0; if (tb[TCA_U32_INDEV-1]) {
if(tb[TCA_U32_INDEV-1]) { int err = tcf_change_indev(tp, n->indev, tb[TCA_U32_INDEV-1]);
struct rtattr *input_dev = tb[TCA_U32_INDEV-1]; if (err < 0)
if (RTA_PAYLOAD(input_dev) >= IFNAMSIZ) { return err;
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 #endif
...@@ -630,7 +569,7 @@ static int u32_change(struct tcf_proto *tp, unsigned long base, u32 handle, ...@@ -630,7 +569,7 @@ static int u32_change(struct tcf_proto *tp, unsigned long base, u32 handle,
if (TC_U32_KEY(n->handle) == 0) if (TC_U32_KEY(n->handle) == 0)
return -EINVAL; return -EINVAL;
return u32_set_parms(tp->q, base, n->ht_up, n, tb, tca[TCA_RATE-1]); return u32_set_parms(tp, base, n->ht_up, n, tb, tca[TCA_RATE-1]);
} }
if (tb[TCA_U32_DIVISOR-1]) { if (tb[TCA_U32_DIVISOR-1]) {
...@@ -718,7 +657,7 @@ static int u32_change(struct tcf_proto *tp, unsigned long base, u32 handle, ...@@ -718,7 +657,7 @@ static int u32_change(struct tcf_proto *tp, unsigned long base, u32 handle,
} }
n->fshift = i; n->fshift = i;
} }
err = u32_set_parms(tp->q, base, ht, n, tb, tca[TCA_RATE-1]); err = u32_set_parms(tp, base, ht, n, tb, tca[TCA_RATE-1]);
if (err == 0) { if (err == 0) {
struct tc_u_knode **ins; struct tc_u_knode **ins;
for (ins = &ht->ht[TC_U32_HASH(handle)]; *ins; ins = &(*ins)->next) for (ins = &ht->ht[TC_U32_HASH(handle)]; *ins; ins = &(*ins)->next)
...@@ -806,49 +745,18 @@ static int u32_dump(struct tcf_proto *tp, unsigned long fh, ...@@ -806,49 +745,18 @@ static int u32_dump(struct tcf_proto *tp, unsigned long fh,
if (n->ht_down) if (n->ht_down)
RTA_PUT(skb, TCA_U32_LINK, 4, &n->ht_down->handle); RTA_PUT(skb, TCA_U32_LINK, 4, &n->ht_down->handle);
#ifdef CONFIG_NET_CLS_ACT #ifdef CONFIG_NET_CLS_ACT
/* again for backward compatible mode - we want if (tcf_dump_act(skb, n->action, TCA_U32_ACT, TCA_U32_POLICE) < 0)
* to work with both old and new modes of entering goto rtattr_failure;
* 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 #else
#ifdef CONFIG_NET_CLS_POLICE #ifdef CONFIG_NET_CLS_POLICE
if (n->police) { if (tcf_dump_police(skb, n->police, TCA_U32_POLICE) < 0)
struct rtattr * p_rta = (struct rtattr*)skb->tail; goto rtattr_failure;
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
#endif #endif
#ifdef CONFIG_NET_CLS_IND #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); RTA_PUT(skb, TCA_U32_INDEV, IFNAMSIZ, n->indev);
p_rta->rta_len = skb->tail - (u8*)p_rta;
}
#endif #endif
#ifdef CONFIG_CLS_U32_PERF #ifdef CONFIG_CLS_U32_PERF
RTA_PUT(skb, TCA_U32_PCNT, RTA_PUT(skb, TCA_U32_PCNT,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment