blob: f10e34a6844516db924303b29ade38f9f7e8f49d [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070025static struct Qdisc *ingress_leaf(struct Qdisc *sch, unsigned long arg)
26{
27 return NULL;
28}
29
Patrick McHardy58f4df42008-01-21 00:11:01 -080030static unsigned long ingress_get(struct Qdisc *sch, u32 classid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070031{
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 return TC_H_MIN(classid) + 1;
33}
34
Linus Torvalds1da177e2005-04-16 15:20:36 -070035static unsigned long ingress_bind_filter(struct Qdisc *sch,
Patrick McHardy58f4df42008-01-21 00:11:01 -080036 unsigned long parent, u32 classid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070037{
38 return ingress_get(sch, classid);
39}
40
Linus Torvalds1da177e2005-04-16 15:20:36 -070041static void ingress_put(struct Qdisc *sch, unsigned long cl)
42{
43}
44
Patrick McHardy58f4df42008-01-21 00:11:01 -080045static void ingress_walk(struct Qdisc *sch, struct qdisc_walker *walker)
Linus Torvalds1da177e2005-04-16 15:20:36 -070046{
Linus Torvalds1da177e2005-04-16 15:20:36 -070047}
48
Patrick McHardy58f4df42008-01-21 00:11:01 -080049static struct tcf_proto **ingress_find_tcf(struct Qdisc *sch, unsigned long cl)
Linus Torvalds1da177e2005-04-16 15:20:36 -070050{
Patrick McHardycb53c042008-01-21 00:11:48 -080051 struct ingress_qdisc_data *p = qdisc_priv(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53 return &p->filter_list;
54}
55
Linus Torvalds1da177e2005-04-16 15:20:36 -070056/* --------------------------- Qdisc operations ---------------------------- */
57
Patrick McHardy58f4df42008-01-21 00:11:01 -080058static int ingress_enqueue(struct sk_buff *skb, struct Qdisc *sch)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059{
Patrick McHardycb53c042008-01-21 00:11:48 -080060 struct ingress_qdisc_data *p = qdisc_priv(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 struct tcf_result res;
62 int result;
63
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 result = tc_classify(skb, p->filter_list, &res);
Patrick McHardya4781222008-01-21 00:11:21 -080065
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 sch->bstats.packets++;
Jussi Kivilinna0abf77e2008-07-20 00:08:27 -070067 sch->bstats.bytes += qdisc_pkt_len(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 switch (result) {
Patrick McHardy58f4df42008-01-21 00:11:01 -080069 case TC_ACT_SHOT:
70 result = TC_ACT_SHOT;
71 sch->qstats.drops++;
72 break;
73 case TC_ACT_STOLEN:
74 case TC_ACT_QUEUED:
75 result = TC_ACT_STOLEN;
76 break;
77 case TC_ACT_RECLASSIFY:
78 case TC_ACT_OK:
79 skb->tc_index = TC_H_MIN(res.classid);
80 default:
81 result = TC_ACT_OK;
82 break;
Stephen Hemminger3ff50b72007-04-20 17:09:22 -070083 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85 return result;
86}
87
Linus Torvalds1da177e2005-04-16 15:20:36 -070088/* ------------------------------------------------------------- */
89
Linus Torvalds1da177e2005-04-16 15:20:36 -070090static void ingress_destroy(struct Qdisc *sch)
91{
Patrick McHardycb53c042008-01-21 00:11:48 -080092 struct ingress_qdisc_data *p = qdisc_priv(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Patrick McHardyff31ab52008-07-01 19:52:38 -070094 tcf_destroy_chain(&p->filter_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095}
96
Linus Torvalds1da177e2005-04-16 15:20:36 -070097static int ingress_dump(struct Qdisc *sch, struct sk_buff *skb)
98{
Patrick McHardy4b3550ef2008-01-23 20:34:11 -080099 struct nlattr *nest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800101 nest = nla_nest_start(skb, TCA_OPTIONS);
102 if (nest == NULL)
103 goto nla_put_failure;
104 nla_nest_end(skb, nest);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 return skb->len;
106
Patrick McHardy1e904742008-01-22 22:11:17 -0800107nla_put_failure:
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800108 nla_nest_cancel(skb, nest);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 return -1;
110}
111
Eric Dumazet20fea082007-11-14 01:44:41 -0800112static const struct Qdisc_class_ops ingress_class_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 .leaf = ingress_leaf,
114 .get = ingress_get,
115 .put = ingress_put,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 .walk = ingress_walk,
117 .tcf_chain = ingress_find_tcf,
118 .bind_tcf = ingress_bind_filter,
119 .unbind_tcf = ingress_put,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120};
121
Eric Dumazet20fea082007-11-14 01:44:41 -0800122static struct Qdisc_ops ingress_qdisc_ops __read_mostly = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 .cl_ops = &ingress_class_ops,
124 .id = "ingress",
125 .priv_size = sizeof(struct ingress_qdisc_data),
126 .enqueue = ingress_enqueue,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 .destroy = ingress_destroy,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 .dump = ingress_dump,
129 .owner = THIS_MODULE,
130};
131
132static int __init ingress_module_init(void)
133{
Patrick McHardy89168762008-01-21 00:14:05 -0800134 return register_qdisc(&ingress_qdisc_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135}
Patrick McHardy58f4df42008-01-21 00:11:01 -0800136
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900137static void __exit ingress_module_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138{
139 unregister_qdisc(&ingress_qdisc_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140}
Patrick McHardy58f4df42008-01-21 00:11:01 -0800141
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142module_init(ingress_module_init)
143module_exit(ingress_module_exit)
144MODULE_LICENSE("GPL");