blob: 4a2b773743589733533d7ca48ca902f44b5980fa [file] [log] [blame]
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +09001/* net/sched/sch_ingress.c - Ingress qdisc
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/module.h>
11#include <linux/types.h>
Patrick McHardy0ba48052007-07-02 22:49:07 -070012#include <linux/list.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/skbuff.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/rtnetlink.h>
Arnaldo Carvalho de Melodc5fc572007-03-25 23:06:12 -070015#include <net/netlink.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <net/pkt_sched.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18
Linus Torvalds1da177e2005-04-16 15:20:36 -070019struct ingress_qdisc_data {
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 struct tcf_proto *filter_list;
21};
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023/* ------------------------- Class/flow operations ------------------------- */
24
Patrick McHardy58f4df42008-01-21 00:11:01 -080025static int ingress_graft(struct Qdisc *sch, unsigned long arg,
26 struct Qdisc *new, struct Qdisc **old)
Linus Torvalds1da177e2005-04-16 15:20:36 -070027{
Patrick McHardye0378342008-01-21 00:12:32 -080028 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -070029}
30
Linus Torvalds1da177e2005-04-16 15:20:36 -070031static struct Qdisc *ingress_leaf(struct Qdisc *sch, unsigned long arg)
32{
33 return NULL;
34}
35
Patrick McHardy58f4df42008-01-21 00:11:01 -080036static unsigned long ingress_get(struct Qdisc *sch, u32 classid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070037{
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 return TC_H_MIN(classid) + 1;
39}
40
Linus Torvalds1da177e2005-04-16 15:20:36 -070041static unsigned long ingress_bind_filter(struct Qdisc *sch,
Patrick McHardy58f4df42008-01-21 00:11:01 -080042 unsigned long parent, u32 classid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070043{
44 return ingress_get(sch, classid);
45}
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047static void ingress_put(struct Qdisc *sch, unsigned long cl)
48{
49}
50
Linus Torvalds1da177e2005-04-16 15:20:36 -070051static int ingress_change(struct Qdisc *sch, u32 classid, u32 parent,
Patrick McHardy1e904742008-01-22 22:11:17 -080052 struct nlattr **tca, unsigned long *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -070053{
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 return 0;
55}
56
Patrick McHardy58f4df42008-01-21 00:11:01 -080057static void ingress_walk(struct Qdisc *sch, struct qdisc_walker *walker)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058{
Patrick McHardya4781222008-01-21 00:11:21 -080059 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060}
61
Patrick McHardy58f4df42008-01-21 00:11:01 -080062static struct tcf_proto **ingress_find_tcf(struct Qdisc *sch, unsigned long cl)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063{
Patrick McHardycb53c042008-01-21 00:11:48 -080064 struct ingress_qdisc_data *p = qdisc_priv(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66 return &p->filter_list;
67}
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069/* --------------------------- Qdisc operations ---------------------------- */
70
Patrick McHardy58f4df42008-01-21 00:11:01 -080071static int ingress_enqueue(struct sk_buff *skb, struct Qdisc *sch)
Linus Torvalds1da177e2005-04-16 15:20:36 -070072{
Patrick McHardycb53c042008-01-21 00:11:48 -080073 struct ingress_qdisc_data *p = qdisc_priv(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 struct tcf_result res;
75 int result;
76
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 result = tc_classify(skb, p->filter_list, &res);
Patrick McHardya4781222008-01-21 00:11:21 -080078
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 sch->bstats.packets++;
Jussi Kivilinna0abf77e2008-07-20 00:08:27 -070080 sch->bstats.bytes += qdisc_pkt_len(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 switch (result) {
Patrick McHardy58f4df42008-01-21 00:11:01 -080082 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;
Stephen Hemminger3ff50b72007-04-20 17:09:22 -070096 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
98 return result;
99}
100
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101/* ------------------------------------------------------------- */
102
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103static void ingress_destroy(struct Qdisc *sch)
104{
Patrick McHardycb53c042008-01-21 00:11:48 -0800105 struct ingress_qdisc_data *p = qdisc_priv(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Patrick McHardyff31ab52008-07-01 19:52:38 -0700107 tcf_destroy_chain(&p->filter_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108}
109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110static int ingress_dump(struct Qdisc *sch, struct sk_buff *skb)
111{
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800112 struct nlattr *nest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800114 nest = nla_nest_start(skb, TCA_OPTIONS);
115 if (nest == NULL)
116 goto nla_put_failure;
117 nla_nest_end(skb, nest);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 return skb->len;
119
Patrick McHardy1e904742008-01-22 22:11:17 -0800120nla_put_failure:
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800121 nla_nest_cancel(skb, nest);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 return -1;
123}
124
Eric Dumazet20fea082007-11-14 01:44:41 -0800125static const struct Qdisc_class_ops ingress_class_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 .graft = ingress_graft,
127 .leaf = ingress_leaf,
128 .get = ingress_get,
129 .put = ingress_put,
130 .change = ingress_change,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 .walk = ingress_walk,
132 .tcf_chain = ingress_find_tcf,
133 .bind_tcf = ingress_bind_filter,
134 .unbind_tcf = ingress_put,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135};
136
Eric Dumazet20fea082007-11-14 01:44:41 -0800137static struct Qdisc_ops ingress_qdisc_ops __read_mostly = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 .cl_ops = &ingress_class_ops,
139 .id = "ingress",
140 .priv_size = sizeof(struct ingress_qdisc_data),
141 .enqueue = ingress_enqueue,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 .destroy = ingress_destroy,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 .dump = ingress_dump,
144 .owner = THIS_MODULE,
145};
146
147static int __init ingress_module_init(void)
148{
Patrick McHardy89168762008-01-21 00:14:05 -0800149 return register_qdisc(&ingress_qdisc_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150}
Patrick McHardy58f4df42008-01-21 00:11:01 -0800151
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900152static void __exit ingress_module_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153{
154 unregister_qdisc(&ingress_qdisc_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155}
Patrick McHardy58f4df42008-01-21 00:11:01 -0800156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157module_init(ingress_module_init)
158module_exit(ingress_module_exit)
159MODULE_LICENSE("GPL");