1 #ifndef __NET_PKT_CLS_H
2 #define __NET_PKT_CLS_H
4 #include <linux/pkt_cls.h>
5 #include <net/sch_generic.h>
6 #include <net/act_api.h>
8 /* Basic packet classifier frontend definitions. */
15 int (*fn)(struct tcf_proto *, unsigned long node, struct tcf_walker *);
18 extern int register_tcf_proto_ops(struct tcf_proto_ops *ops);
19 extern int unregister_tcf_proto_ops(struct tcf_proto_ops *ops);
20 extern int ing_filter(struct sk_buff *skb);
22 static inline unsigned long
23 __cls_set_class(unsigned long *clp, unsigned long cl)
32 static inline unsigned long
33 cls_set_class(struct tcf_proto *tp, unsigned long *clp,
39 old_cl = __cls_set_class(clp, cl);
46 tcf_bind_filter(struct tcf_proto *tp, struct tcf_result *r, unsigned long base)
50 cl = tp->q->ops->cl_ops->bind_tcf(tp->q, base, r->classid);
51 cl = cls_set_class(tp, &r->class, cl);
53 tp->q->ops->cl_ops->unbind_tcf(tp->q, cl);
57 tcf_unbind_filter(struct tcf_proto *tp, struct tcf_result *r)
61 if ((cl = __cls_set_class(&r->class, 0)) != 0)
62 tp->q->ops->cl_ops->unbind_tcf(tp->q, cl);
65 #ifdef CONFIG_NET_CLS_ACT
67 tcf_change_act_police(struct tcf_proto *tp, struct tc_action **action,
68 struct rtattr *act_police_tlv, struct rtattr *rate_tlv)
71 struct tc_action *act;
73 act = kmalloc(sizeof(*act), GFP_KERNEL);
76 memset(act, 0, sizeof(*act));
78 ret = tcf_action_init_1(act_police_tlv, rate_tlv, act, "police",
79 TCA_ACT_NOREPLACE, TCA_ACT_BIND);
81 tcf_action_destroy(act, TCA_ACT_UNBIND);
85 act->type = TCA_OLD_COMPAT;
89 act = xchg(action, act);
92 tcf_action_destroy(act, TCA_ACT_UNBIND);
100 tcf_change_act(struct tcf_proto *tp, struct tc_action **action,
101 struct rtattr *act_tlv, struct rtattr *rate_tlv)
104 struct tc_action *act;
106 act = kmalloc(sizeof(*act), GFP_KERNEL);
109 memset(act, 0, sizeof(*act));
111 ret = tcf_action_init(act_tlv, rate_tlv, act, NULL,
112 TCA_ACT_NOREPLACE, TCA_ACT_BIND);
114 tcf_action_destroy(act, TCA_ACT_UNBIND);
120 act = xchg(action, act);
123 tcf_action_destroy(act, TCA_ACT_UNBIND);
131 tcf_dump_act(struct sk_buff *skb, struct tc_action *action,
132 int act_type, int compat_type)
135 * again for backward compatible mode - we want
136 * to work with both old and new modes of entering
137 * tc data even if iproute2 was newer - jhs
140 struct rtattr * p_rta = (struct rtattr*) skb->tail;
142 if (action->type != TCA_OLD_COMPAT) {
143 RTA_PUT(skb, act_type, 0, NULL);
144 if (tcf_action_dump(skb, action, 0, 0) < 0)
147 RTA_PUT(skb, compat_type, 0, NULL);
148 if (tcf_action_dump_old(skb, action, 0, 0) < 0)
152 p_rta->rta_len = skb->tail - (u8*)p_rta;
159 #endif /* CONFIG_NET_CLS_ACT */
161 #ifdef CONFIG_NET_CLS_IND
163 tcf_change_indev(struct tcf_proto *tp, char *indev, struct rtattr *indev_tlv)
165 if (RTA_PAYLOAD(indev_tlv) >= IFNAMSIZ) {
166 printk("cls: bad indev name %s\n", (char *) RTA_DATA(indev_tlv));
170 memset(indev, 0, IFNAMSIZ);
171 sprintf(indev, "%s", (char *) RTA_DATA(indev_tlv));
177 tcf_match_indev(struct sk_buff *skb, char *indev)
180 if (NULL == skb->input_dev)
182 else if (0 != strcmp(indev, skb->input_dev->name))
188 #endif /* CONFIG_NET_CLS_IND */
190 #ifdef CONFIG_NET_CLS_POLICE
192 tcf_change_police(struct tcf_proto *tp, struct tcf_police **police,
193 struct rtattr *police_tlv, struct rtattr *rate_tlv)
195 struct tcf_police *p = tcf_police_locate(police_tlv, rate_tlv);
202 tcf_police_release(p, TCA_ACT_UNBIND);
210 tcf_dump_police(struct sk_buff *skb, struct tcf_police *police,
214 struct rtattr * p_rta = (struct rtattr*) skb->tail;
216 RTA_PUT(skb, police_type, 0, NULL);
218 if (tcf_police_dump(skb, police) < 0)
221 p_rta->rta_len = skb->tail - (u8*)p_rta;
228 #endif /* CONFIG_NET_CLS_POLICE */