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 | ||
58f4df42 PM |
25 | static int ingress_graft(struct Qdisc *sch, unsigned long arg, |
26 | struct Qdisc *new, struct Qdisc **old) | |
1da177e4 | 27 | { |
e0378347 | 28 | return -EOPNOTSUPP; |
1da177e4 LT |
29 | } |
30 | ||
1da177e4 LT |
31 | static struct Qdisc *ingress_leaf(struct Qdisc *sch, unsigned long arg) |
32 | { | |
33 | return NULL; | |
34 | } | |
35 | ||
58f4df42 | 36 | static unsigned long ingress_get(struct Qdisc *sch, u32 classid) |
1da177e4 | 37 | { |
1da177e4 LT |
38 | return TC_H_MIN(classid) + 1; |
39 | } | |
40 | ||
1da177e4 | 41 | static unsigned long ingress_bind_filter(struct Qdisc *sch, |
58f4df42 | 42 | unsigned long parent, u32 classid) |
1da177e4 LT |
43 | { |
44 | return ingress_get(sch, classid); | |
45 | } | |
46 | ||
1da177e4 LT |
47 | static void ingress_put(struct Qdisc *sch, unsigned long cl) |
48 | { | |
49 | } | |
50 | ||
1da177e4 | 51 | static int ingress_change(struct Qdisc *sch, u32 classid, u32 parent, |
1e90474c | 52 | struct nlattr **tca, unsigned long *arg) |
1da177e4 | 53 | { |
1da177e4 LT |
54 | return 0; |
55 | } | |
56 | ||
58f4df42 | 57 | static void ingress_walk(struct Qdisc *sch, struct qdisc_walker *walker) |
1da177e4 | 58 | { |
a4781221 | 59 | return; |
1da177e4 LT |
60 | } |
61 | ||
58f4df42 | 62 | static struct tcf_proto **ingress_find_tcf(struct Qdisc *sch, unsigned long cl) |
1da177e4 | 63 | { |
cb53c048 | 64 | struct ingress_qdisc_data *p = qdisc_priv(sch); |
1da177e4 LT |
65 | |
66 | return &p->filter_list; | |
67 | } | |
68 | ||
1da177e4 LT |
69 | /* --------------------------- Qdisc operations ---------------------------- */ |
70 | ||
58f4df42 | 71 | static int ingress_enqueue(struct sk_buff *skb, struct Qdisc *sch) |
1da177e4 | 72 | { |
cb53c048 | 73 | struct ingress_qdisc_data *p = qdisc_priv(sch); |
1da177e4 LT |
74 | struct tcf_result res; |
75 | int result; | |
76 | ||
1da177e4 | 77 | result = tc_classify(skb, p->filter_list, &res); |
a4781221 | 78 | |
1da177e4 | 79 | sch->bstats.packets++; |
0abf77e5 | 80 | sch->bstats.bytes += qdisc_pkt_len(skb); |
1da177e4 | 81 | switch (result) { |
58f4df42 PM |
82 | case TC_ACT_SHOT: |
83 | result = TC_ACT_SHOT; | |
84 | sch->qstats.drops++; | |
85 | break; | |
86 | case TC_ACT_STOLEN: | |
87 | case TC_ACT_QUEUED: | |
88 | result = TC_ACT_STOLEN; | |
89 | break; | |
90 | case TC_ACT_RECLASSIFY: | |
91 | case TC_ACT_OK: | |
92 | skb->tc_index = TC_H_MIN(res.classid); | |
93 | default: | |
94 | result = TC_ACT_OK; | |
95 | break; | |
3ff50b79 | 96 | } |
1da177e4 LT |
97 | |
98 | return result; | |
99 | } | |
100 | ||
1da177e4 LT |
101 | /* ------------------------------------------------------------- */ |
102 | ||
103 | static void ingress_destroy(struct Qdisc *sch) | |
104 | { | |
cb53c048 | 105 | struct ingress_qdisc_data *p = qdisc_priv(sch); |
1da177e4 | 106 | |
ff31ab56 | 107 | tcf_destroy_chain(&p->filter_list); |
1da177e4 LT |
108 | } |
109 | ||
1da177e4 LT |
110 | static int ingress_dump(struct Qdisc *sch, struct sk_buff *skb) |
111 | { | |
4b3550ef | 112 | struct nlattr *nest; |
1da177e4 | 113 | |
4b3550ef PM |
114 | nest = nla_nest_start(skb, TCA_OPTIONS); |
115 | if (nest == NULL) | |
116 | goto nla_put_failure; | |
117 | nla_nest_end(skb, nest); | |
1da177e4 LT |
118 | return skb->len; |
119 | ||
1e90474c | 120 | nla_put_failure: |
4b3550ef | 121 | nla_nest_cancel(skb, nest); |
1da177e4 LT |
122 | return -1; |
123 | } | |
124 | ||
20fea08b | 125 | static const struct Qdisc_class_ops ingress_class_ops = { |
1da177e4 LT |
126 | .graft = ingress_graft, |
127 | .leaf = ingress_leaf, | |
128 | .get = ingress_get, | |
129 | .put = ingress_put, | |
130 | .change = ingress_change, | |
1da177e4 LT |
131 | .walk = ingress_walk, |
132 | .tcf_chain = ingress_find_tcf, | |
133 | .bind_tcf = ingress_bind_filter, | |
134 | .unbind_tcf = ingress_put, | |
1da177e4 LT |
135 | }; |
136 | ||
20fea08b | 137 | static struct Qdisc_ops ingress_qdisc_ops __read_mostly = { |
1da177e4 LT |
138 | .cl_ops = &ingress_class_ops, |
139 | .id = "ingress", | |
140 | .priv_size = sizeof(struct ingress_qdisc_data), | |
141 | .enqueue = ingress_enqueue, | |
1da177e4 | 142 | .destroy = ingress_destroy, |
1da177e4 LT |
143 | .dump = ingress_dump, |
144 | .owner = THIS_MODULE, | |
145 | }; | |
146 | ||
147 | static int __init ingress_module_init(void) | |
148 | { | |
89168764 | 149 | return register_qdisc(&ingress_qdisc_ops); |
1da177e4 | 150 | } |
58f4df42 | 151 | |
10297b99 | 152 | static void __exit ingress_module_exit(void) |
1da177e4 LT |
153 | { |
154 | unregister_qdisc(&ingress_qdisc_ops); | |
1da177e4 | 155 | } |
58f4df42 | 156 | |
1da177e4 LT |
157 | module_init(ingress_module_init) |
158 | module_exit(ingress_module_exit) | |
159 | MODULE_LICENSE("GPL"); |