ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / include / net / pkt_cls.h
1 #ifndef __NET_PKT_CLS_H
2 #define __NET_PKT_CLS_H
3
4
5 #include <linux/pkt_cls.h>
6
7 struct rtattr;
8 struct tcmsg;
9
10 /* Basic packet classifier frontend definitions. */
11
12 struct tcf_result
13 {
14         unsigned long   class;
15         u32             classid;
16 };
17
18 struct tcf_proto
19 {
20         /* Fast access part */
21         struct tcf_proto        *next;
22         void                    *root;
23         int                     (*classify)(struct sk_buff*, struct tcf_proto*, struct tcf_result *);
24         u32                     protocol;
25
26         /* All the rest */
27         u32                     prio;
28         u32                     classid;
29         struct Qdisc            *q;
30         void                    *data;
31         struct tcf_proto_ops    *ops;
32 };
33
34 struct tcf_walker
35 {
36         int     stop;
37         int     skip;
38         int     count;
39         int     (*fn)(struct tcf_proto *, unsigned long node, struct tcf_walker *);
40 };
41
42 struct module;
43
44 struct tcf_proto_ops
45 {
46         struct tcf_proto_ops    *next;
47         char                    kind[IFNAMSIZ];
48
49         int                     (*classify)(struct sk_buff*, struct tcf_proto*, struct tcf_result *);
50         int                     (*init)(struct tcf_proto*);
51         void                    (*destroy)(struct tcf_proto*);
52
53         unsigned long           (*get)(struct tcf_proto*, u32 handle);
54         void                    (*put)(struct tcf_proto*, unsigned long);
55         int                     (*change)(struct tcf_proto*, unsigned long, u32 handle, struct rtattr **, unsigned long *);
56         int                     (*delete)(struct tcf_proto*, unsigned long);
57         void                    (*walk)(struct tcf_proto*, struct tcf_walker *arg);
58
59         /* rtnetlink specific */
60         int                     (*dump)(struct tcf_proto*, unsigned long, struct sk_buff *skb, struct tcmsg*);
61
62         struct module           *owner;
63 };
64
65 /* Main classifier routine: scans classifier chain attached
66    to this qdisc, (optionally) tests for protocol and asks
67    specific classifiers.
68  */
69
70 static inline int tc_classify(struct sk_buff *skb, struct tcf_proto *tp, struct tcf_result *res)
71 {
72         int err = 0;
73         u32 protocol = skb->protocol;
74
75         for ( ; tp; tp = tp->next) {
76                 if ((tp->protocol == protocol ||
77                      tp->protocol == __constant_htons(ETH_P_ALL)) &&
78                     (err = tp->classify(skb, tp, res)) >= 0)
79                         return err;
80         }
81         return -1;
82 }
83
84 static inline void tcf_destroy(struct tcf_proto *tp)
85 {
86         tp->ops->destroy(tp);
87         module_put(tp->ops->owner);
88         kfree(tp);
89 }
90
91 extern int register_tcf_proto_ops(struct tcf_proto_ops *ops);
92 extern int unregister_tcf_proto_ops(struct tcf_proto_ops *ops);
93
94
95
96 #endif