blob: a89cc3278bfb4b045955c71a2a98d97c647a0725 [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 {
John Fastabend25d8c0d2014-09-12 20:05:27 -070020 struct tcf_proto __rcu *filter_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -070021};
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
John Fastabend25d8c0d2014-09-12 20:05:27 -070049static struct tcf_proto __rcu **ingress_find_tcf(struct Qdisc *sch,
50 unsigned long cl)
Linus Torvalds1da177e2005-04-16 15:20:36 -070051{
Patrick McHardycb53c042008-01-21 00:11:48 -080052 struct ingress_qdisc_data *p = qdisc_priv(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54 return &p->filter_list;
55}
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057/* --------------------------- Qdisc operations ---------------------------- */
58
Patrick McHardy58f4df42008-01-21 00:11:01 -080059static int ingress_enqueue(struct sk_buff *skb, struct Qdisc *sch)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
Patrick McHardycb53c042008-01-21 00:11:48 -080061 struct ingress_qdisc_data *p = qdisc_priv(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 struct tcf_result res;
John Fastabend25d8c0d2014-09-12 20:05:27 -070063 struct tcf_proto *fl = rcu_dereference_bh(p->filter_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 int result;
65
John Fastabend25d8c0d2014-09-12 20:05:27 -070066 result = tc_classify(skb, fl, &res);
Patrick McHardya4781222008-01-21 00:11:21 -080067
Alexei Starovoitov087c1a62015-04-30 20:14:07 -070068 qdisc_bstats_update_cpu(sch, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 switch (result) {
Patrick McHardy58f4df42008-01-21 00:11:01 -080070 case TC_ACT_SHOT:
71 result = TC_ACT_SHOT;
Alexei Starovoitov087c1a62015-04-30 20:14:07 -070072 qdisc_qstats_drop_cpu(sch);
Patrick McHardy58f4df42008-01-21 00:11:01 -080073 break;
74 case TC_ACT_STOLEN:
75 case TC_ACT_QUEUED:
76 result = TC_ACT_STOLEN;
77 break;
78 case TC_ACT_RECLASSIFY:
79 case TC_ACT_OK:
80 skb->tc_index = TC_H_MIN(res.classid);
81 default:
82 result = TC_ACT_OK;
83 break;
Stephen Hemminger3ff50b72007-04-20 17:09:22 -070084 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
86 return result;
87}
88
Linus Torvalds1da177e2005-04-16 15:20:36 -070089/* ------------------------------------------------------------- */
90
Daniel Borkmann45771392015-04-10 23:07:54 +020091static int ingress_init(struct Qdisc *sch, struct nlattr *opt)
92{
93 net_inc_ingress_queue();
Alexei Starovoitov087c1a62015-04-30 20:14:07 -070094 sch->flags |= TCQ_F_CPUSTATS;
Daniel Borkmann45771392015-04-10 23:07:54 +020095
96 return 0;
97}
98
Linus Torvalds1da177e2005-04-16 15:20:36 -070099static void ingress_destroy(struct Qdisc *sch)
100{
Patrick McHardycb53c042008-01-21 00:11:48 -0800101 struct ingress_qdisc_data *p = qdisc_priv(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
Patrick McHardyff31ab52008-07-01 19:52:38 -0700103 tcf_destroy_chain(&p->filter_list);
Daniel Borkmann45771392015-04-10 23:07:54 +0200104 net_dec_ingress_queue();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105}
106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107static int ingress_dump(struct Qdisc *sch, struct sk_buff *skb)
108{
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800109 struct nlattr *nest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800111 nest = nla_nest_start(skb, TCA_OPTIONS);
112 if (nest == NULL)
113 goto nla_put_failure;
Yang Yingliangd59b7d82014-03-12 10:20:32 +0800114 return nla_nest_end(skb, nest);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Patrick McHardy1e904742008-01-22 22:11:17 -0800116nla_put_failure:
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800117 nla_nest_cancel(skb, nest);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 return -1;
119}
120
Eric Dumazet20fea082007-11-14 01:44:41 -0800121static const struct Qdisc_class_ops ingress_class_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 .leaf = ingress_leaf,
123 .get = ingress_get,
124 .put = ingress_put,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 .walk = ingress_walk,
126 .tcf_chain = ingress_find_tcf,
127 .bind_tcf = ingress_bind_filter,
128 .unbind_tcf = ingress_put,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129};
130
Eric Dumazet20fea082007-11-14 01:44:41 -0800131static struct Qdisc_ops ingress_qdisc_ops __read_mostly = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 .cl_ops = &ingress_class_ops,
133 .id = "ingress",
134 .priv_size = sizeof(struct ingress_qdisc_data),
135 .enqueue = ingress_enqueue,
Daniel Borkmann45771392015-04-10 23:07:54 +0200136 .init = ingress_init,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 .destroy = ingress_destroy,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 .dump = ingress_dump,
139 .owner = THIS_MODULE,
140};
141
142static int __init ingress_module_init(void)
143{
Patrick McHardy89168762008-01-21 00:14:05 -0800144 return register_qdisc(&ingress_qdisc_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145}
Patrick McHardy58f4df42008-01-21 00:11:01 -0800146
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900147static void __exit ingress_module_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148{
149 unregister_qdisc(&ingress_qdisc_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150}
Patrick McHardy58f4df42008-01-21 00:11:01 -0800151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152module_init(ingress_module_init)
153module_exit(ingress_module_exit)
154MODULE_LICENSE("GPL");