]>
Commit | Line | Data |
---|---|---|
10297b99 | 1 | /* net/sched/sch_ingress.c - Ingress qdisc |
1da177e4 LT |
2 | * This program is free software; you can redistribute it and/or |
3 | * modify it under the terms of the GNU General Public License | |
4 | * as published by the Free Software Foundation; either version | |
5 | * 2 of the License, or (at your option) any later version. | |
6 | * | |
7 | * Authors: Jamal Hadi Salim 1999 | |
8 | */ | |
9 | ||
1da177e4 LT |
10 | #include <linux/module.h> |
11 | #include <linux/types.h> | |
0ba48053 | 12 | #include <linux/list.h> |
1da177e4 | 13 | #include <linux/skbuff.h> |
1da177e4 | 14 | #include <linux/rtnetlink.h> |
dc5fc579 | 15 | #include <net/netlink.h> |
1da177e4 | 16 | #include <net/pkt_sched.h> |
1da177e4 LT |
17 | |
18 | ||
1da177e4 | 19 | struct ingress_qdisc_data { |
1da177e4 LT |
20 | struct tcf_proto *filter_list; |
21 | }; | |
22 | ||
1da177e4 LT |
23 | /* ------------------------- Class/flow operations ------------------------- */ |
24 | ||
1da177e4 LT |
25 | static struct Qdisc *ingress_leaf(struct Qdisc *sch, unsigned long arg) |
26 | { | |
27 | return NULL; | |
28 | } | |
29 | ||
58f4df42 | 30 | static unsigned long ingress_get(struct Qdisc *sch, u32 classid) |
1da177e4 | 31 | { |
1da177e4 LT |
32 | return TC_H_MIN(classid) + 1; |
33 | } | |
34 | ||
1da177e4 | 35 | static unsigned long ingress_bind_filter(struct Qdisc *sch, |
58f4df42 | 36 | unsigned long parent, u32 classid) |
1da177e4 LT |
37 | { |
38 | return ingress_get(sch, classid); | |
39 | } | |
40 | ||
1da177e4 LT |
41 | static void ingress_put(struct Qdisc *sch, unsigned long cl) |
42 | { | |
43 | } | |
44 | ||
58f4df42 | 45 | static void ingress_walk(struct Qdisc *sch, struct qdisc_walker *walker) |
1da177e4 | 46 | { |
1da177e4 LT |
47 | } |
48 | ||
58f4df42 | 49 | static struct tcf_proto **ingress_find_tcf(struct Qdisc *sch, unsigned long cl) |
1da177e4 | 50 | { |
cb53c048 | 51 | struct ingress_qdisc_data *p = qdisc_priv(sch); |
1da177e4 LT |
52 | |
53 | return &p->filter_list; | |
54 | } | |
55 | ||
1da177e4 LT |
56 | /* --------------------------- Qdisc operations ---------------------------- */ |
57 | ||
58f4df42 | 58 | static int ingress_enqueue(struct sk_buff *skb, struct Qdisc *sch) |
1da177e4 | 59 | { |
cb53c048 | 60 | struct ingress_qdisc_data *p = qdisc_priv(sch); |
1da177e4 LT |
61 | struct tcf_result res; |
62 | int result; | |
63 | ||
1da177e4 | 64 | result = tc_classify(skb, p->filter_list, &res); |
a4781221 | 65 | |
bfe0d029 | 66 | qdisc_bstats_update(sch, skb); |
1da177e4 | 67 | switch (result) { |
58f4df42 PM |
68 | case TC_ACT_SHOT: |
69 | result = TC_ACT_SHOT; | |
70 | sch->qstats.drops++; | |
71 | break; | |
72 | case TC_ACT_STOLEN: | |
73 | case TC_ACT_QUEUED: | |
74 | result = TC_ACT_STOLEN; | |
75 | break; | |
76 | case TC_ACT_RECLASSIFY: | |
77 | case TC_ACT_OK: | |
78 | skb->tc_index = TC_H_MIN(res.classid); | |
79 | default: | |
80 | result = TC_ACT_OK; | |
81 | break; | |
3ff50b79 | 82 | } |
1da177e4 LT |
83 | |
84 | return result; | |
85 | } | |
86 | ||
1da177e4 LT |
87 | /* ------------------------------------------------------------- */ |
88 | ||
89 | static void ingress_destroy(struct Qdisc *sch) | |
90 | { | |
cb53c048 | 91 | struct ingress_qdisc_data *p = qdisc_priv(sch); |
1da177e4 | 92 | |
ff31ab56 | 93 | tcf_destroy_chain(&p->filter_list); |
1da177e4 LT |
94 | } |
95 | ||
1da177e4 LT |
96 | static int ingress_dump(struct Qdisc *sch, struct sk_buff *skb) |
97 | { | |
4b3550ef | 98 | struct nlattr *nest; |
1da177e4 | 99 | |
4b3550ef PM |
100 | nest = nla_nest_start(skb, TCA_OPTIONS); |
101 | if (nest == NULL) | |
102 | goto nla_put_failure; | |
103 | nla_nest_end(skb, nest); | |
1da177e4 LT |
104 | return skb->len; |
105 | ||
1e90474c | 106 | nla_put_failure: |
4b3550ef | 107 | nla_nest_cancel(skb, nest); |
1da177e4 LT |
108 | return -1; |
109 | } | |
110 | ||
20fea08b | 111 | static const struct Qdisc_class_ops ingress_class_ops = { |
1da177e4 LT |
112 | .leaf = ingress_leaf, |
113 | .get = ingress_get, | |
114 | .put = ingress_put, | |
1da177e4 LT |
115 | .walk = ingress_walk, |
116 | .tcf_chain = ingress_find_tcf, | |
117 | .bind_tcf = ingress_bind_filter, | |
118 | .unbind_tcf = ingress_put, | |
1da177e4 LT |
119 | }; |
120 | ||
20fea08b | 121 | static struct Qdisc_ops ingress_qdisc_ops __read_mostly = { |
1da177e4 LT |
122 | .cl_ops = &ingress_class_ops, |
123 | .id = "ingress", | |
124 | .priv_size = sizeof(struct ingress_qdisc_data), | |
125 | .enqueue = ingress_enqueue, | |
1da177e4 | 126 | .destroy = ingress_destroy, |
1da177e4 LT |
127 | .dump = ingress_dump, |
128 | .owner = THIS_MODULE, | |
129 | }; | |
130 | ||
131 | static int __init ingress_module_init(void) | |
132 | { | |
89168764 | 133 | return register_qdisc(&ingress_qdisc_ops); |
1da177e4 | 134 | } |
58f4df42 | 135 | |
10297b99 | 136 | static void __exit ingress_module_exit(void) |
1da177e4 LT |
137 | { |
138 | unregister_qdisc(&ingress_qdisc_ops); | |
1da177e4 | 139 | } |
58f4df42 | 140 | |
1da177e4 LT |
141 | module_init(ingress_module_init) |
142 | module_exit(ingress_module_exit) | |
143 | MODULE_LICENSE("GPL"); |