blob: e7c648fa9dc3bfb8c8b4ae0b218d8c162aef83a5 [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>
Daniel Borkmannd2788d32015-05-09 22:51:32 +020015
Arnaldo Carvalho de Melodc5fc572007-03-25 23:06:12 -070016#include <net/netlink.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <net/pkt_sched.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
Linus Torvalds1da177e2005-04-16 15:20:36 -070019static struct Qdisc *ingress_leaf(struct Qdisc *sch, unsigned long arg)
20{
21 return NULL;
22}
23
Patrick McHardy58f4df42008-01-21 00:11:01 -080024static unsigned long ingress_get(struct Qdisc *sch, u32 classid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070025{
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 return TC_H_MIN(classid) + 1;
27}
28
Linus Torvalds1da177e2005-04-16 15:20:36 -070029static unsigned long ingress_bind_filter(struct Qdisc *sch,
Patrick McHardy58f4df42008-01-21 00:11:01 -080030 unsigned long parent, u32 classid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070031{
32 return ingress_get(sch, classid);
33}
34
Linus Torvalds1da177e2005-04-16 15:20:36 -070035static void ingress_put(struct Qdisc *sch, unsigned long cl)
36{
37}
38
Patrick McHardy58f4df42008-01-21 00:11:01 -080039static void ingress_walk(struct Qdisc *sch, struct qdisc_walker *walker)
Linus Torvalds1da177e2005-04-16 15:20:36 -070040{
Linus Torvalds1da177e2005-04-16 15:20:36 -070041}
42
John Fastabend25d8c0d2014-09-12 20:05:27 -070043static struct tcf_proto __rcu **ingress_find_tcf(struct Qdisc *sch,
44 unsigned long cl)
Linus Torvalds1da177e2005-04-16 15:20:36 -070045{
Daniel Borkmannd2788d32015-05-09 22:51:32 +020046 struct net_device *dev = qdisc_dev(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Daniel Borkmannd2788d32015-05-09 22:51:32 +020048 return &dev->ingress_cl_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049}
50
Daniel Borkmann45771392015-04-10 23:07:54 +020051static int ingress_init(struct Qdisc *sch, struct nlattr *opt)
52{
53 net_inc_ingress_queue();
Alexei Starovoitov087c1a62015-04-30 20:14:07 -070054 sch->flags |= TCQ_F_CPUSTATS;
Daniel Borkmann45771392015-04-10 23:07:54 +020055
56 return 0;
57}
58
Linus Torvalds1da177e2005-04-16 15:20:36 -070059static void ingress_destroy(struct Qdisc *sch)
60{
Daniel Borkmannd2788d32015-05-09 22:51:32 +020061 struct net_device *dev = qdisc_dev(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Daniel Borkmannd2788d32015-05-09 22:51:32 +020063 tcf_destroy_chain(&dev->ingress_cl_list);
Daniel Borkmann45771392015-04-10 23:07:54 +020064 net_dec_ingress_queue();
Linus Torvalds1da177e2005-04-16 15:20:36 -070065}
66
Linus Torvalds1da177e2005-04-16 15:20:36 -070067static int ingress_dump(struct Qdisc *sch, struct sk_buff *skb)
68{
Patrick McHardy4b3550ef2008-01-23 20:34:11 -080069 struct nlattr *nest;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Patrick McHardy4b3550ef2008-01-23 20:34:11 -080071 nest = nla_nest_start(skb, TCA_OPTIONS);
72 if (nest == NULL)
73 goto nla_put_failure;
Daniel Borkmannd2788d32015-05-09 22:51:32 +020074
Yang Yingliangd59b7d82014-03-12 10:20:32 +080075 return nla_nest_end(skb, nest);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Patrick McHardy1e904742008-01-22 22:11:17 -080077nla_put_failure:
Patrick McHardy4b3550ef2008-01-23 20:34:11 -080078 nla_nest_cancel(skb, nest);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 return -1;
80}
81
Eric Dumazet20fea082007-11-14 01:44:41 -080082static const struct Qdisc_class_ops ingress_class_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 .leaf = ingress_leaf,
84 .get = ingress_get,
85 .put = ingress_put,
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 .walk = ingress_walk,
87 .tcf_chain = ingress_find_tcf,
88 .bind_tcf = ingress_bind_filter,
89 .unbind_tcf = ingress_put,
Linus Torvalds1da177e2005-04-16 15:20:36 -070090};
91
Eric Dumazet20fea082007-11-14 01:44:41 -080092static struct Qdisc_ops ingress_qdisc_ops __read_mostly = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 .cl_ops = &ingress_class_ops,
94 .id = "ingress",
Daniel Borkmann45771392015-04-10 23:07:54 +020095 .init = ingress_init,
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 .destroy = ingress_destroy,
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 .dump = ingress_dump,
98 .owner = THIS_MODULE,
99};
100
101static int __init ingress_module_init(void)
102{
Patrick McHardy89168762008-01-21 00:14:05 -0800103 return register_qdisc(&ingress_qdisc_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104}
Patrick McHardy58f4df42008-01-21 00:11:01 -0800105
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900106static void __exit ingress_module_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107{
108 unregister_qdisc(&ingress_qdisc_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109}
Patrick McHardy58f4df42008-01-21 00:11:01 -0800110
Daniel Borkmannd2788d32015-05-09 22:51:32 +0200111module_init(ingress_module_init);
112module_exit(ingress_module_exit);
113
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114MODULE_LICENSE("GPL");