YOSHIFUJI Hideaki | 10297b9 | 2007-02-09 23:25:16 +0900 | [diff] [blame] | 1 | /* net/sched/sch_ingress.c - Ingress qdisc |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/module.h> |
| 11 | #include <linux/types.h> |
Patrick McHardy | 0ba4805 | 2007-07-02 22:49:07 -0700 | [diff] [blame] | 12 | #include <linux/list.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/skbuff.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/rtnetlink.h> |
Daniel Borkmann | d2788d3 | 2015-05-09 22:51:32 +0200 | [diff] [blame] | 15 | |
Arnaldo Carvalho de Melo | dc5fc57 | 2007-03-25 23:06:12 -0700 | [diff] [blame] | 16 | #include <net/netlink.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <net/pkt_sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | static struct Qdisc *ingress_leaf(struct Qdisc *sch, unsigned long arg) |
| 20 | { |
| 21 | return NULL; |
| 22 | } |
| 23 | |
Patrick McHardy | 58f4df4 | 2008-01-21 00:11:01 -0800 | [diff] [blame] | 24 | static unsigned long ingress_get(struct Qdisc *sch, u32 classid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | return TC_H_MIN(classid) + 1; |
| 27 | } |
| 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | static unsigned long ingress_bind_filter(struct Qdisc *sch, |
Patrick McHardy | 58f4df4 | 2008-01-21 00:11:01 -0800 | [diff] [blame] | 30 | unsigned long parent, u32 classid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | { |
| 32 | return ingress_get(sch, classid); |
| 33 | } |
| 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | static void ingress_put(struct Qdisc *sch, unsigned long cl) |
| 36 | { |
| 37 | } |
| 38 | |
Patrick McHardy | 58f4df4 | 2008-01-21 00:11:01 -0800 | [diff] [blame] | 39 | static void ingress_walk(struct Qdisc *sch, struct qdisc_walker *walker) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | } |
| 42 | |
John Fastabend | 25d8c0d | 2014-09-12 20:05:27 -0700 | [diff] [blame] | 43 | static struct tcf_proto __rcu **ingress_find_tcf(struct Qdisc *sch, |
| 44 | unsigned long cl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | { |
Daniel Borkmann | d2788d3 | 2015-05-09 22:51:32 +0200 | [diff] [blame] | 46 | struct net_device *dev = qdisc_dev(sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
Daniel Borkmann | d2788d3 | 2015-05-09 22:51:32 +0200 | [diff] [blame] | 48 | return &dev->ingress_cl_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Daniel Borkmann | 4577139 | 2015-04-10 23:07:54 +0200 | [diff] [blame] | 51 | static int ingress_init(struct Qdisc *sch, struct nlattr *opt) |
| 52 | { |
| 53 | net_inc_ingress_queue(); |
Alexei Starovoitov | 087c1a6 | 2015-04-30 20:14:07 -0700 | [diff] [blame] | 54 | sch->flags |= TCQ_F_CPUSTATS; |
Daniel Borkmann | 4577139 | 2015-04-10 23:07:54 +0200 | [diff] [blame] | 55 | |
| 56 | return 0; |
| 57 | } |
| 58 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | static void ingress_destroy(struct Qdisc *sch) |
| 60 | { |
Daniel Borkmann | d2788d3 | 2015-05-09 22:51:32 +0200 | [diff] [blame] | 61 | struct net_device *dev = qdisc_dev(sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
Daniel Borkmann | d2788d3 | 2015-05-09 22:51:32 +0200 | [diff] [blame] | 63 | tcf_destroy_chain(&dev->ingress_cl_list); |
Daniel Borkmann | 4577139 | 2015-04-10 23:07:54 +0200 | [diff] [blame] | 64 | net_dec_ingress_queue(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | static int ingress_dump(struct Qdisc *sch, struct sk_buff *skb) |
| 68 | { |
Patrick McHardy | 4b3550ef | 2008-01-23 20:34:11 -0800 | [diff] [blame] | 69 | struct nlattr *nest; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
Patrick McHardy | 4b3550ef | 2008-01-23 20:34:11 -0800 | [diff] [blame] | 71 | nest = nla_nest_start(skb, TCA_OPTIONS); |
| 72 | if (nest == NULL) |
| 73 | goto nla_put_failure; |
Daniel Borkmann | d2788d3 | 2015-05-09 22:51:32 +0200 | [diff] [blame] | 74 | |
Yang Yingliang | d59b7d8 | 2014-03-12 10:20:32 +0800 | [diff] [blame] | 75 | return nla_nest_end(skb, nest); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
Patrick McHardy | 1e90474 | 2008-01-22 22:11:17 -0800 | [diff] [blame] | 77 | nla_put_failure: |
Patrick McHardy | 4b3550ef | 2008-01-23 20:34:11 -0800 | [diff] [blame] | 78 | nla_nest_cancel(skb, nest); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | return -1; |
| 80 | } |
| 81 | |
Eric Dumazet | 20fea08 | 2007-11-14 01:44:41 -0800 | [diff] [blame] | 82 | static const struct Qdisc_class_ops ingress_class_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | .leaf = ingress_leaf, |
| 84 | .get = ingress_get, |
| 85 | .put = ingress_put, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | .walk = ingress_walk, |
| 87 | .tcf_chain = ingress_find_tcf, |
| 88 | .bind_tcf = ingress_bind_filter, |
| 89 | .unbind_tcf = ingress_put, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
Eric Dumazet | 20fea08 | 2007-11-14 01:44:41 -0800 | [diff] [blame] | 92 | static struct Qdisc_ops ingress_qdisc_ops __read_mostly = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | .cl_ops = &ingress_class_ops, |
| 94 | .id = "ingress", |
Daniel Borkmann | 4577139 | 2015-04-10 23:07:54 +0200 | [diff] [blame] | 95 | .init = ingress_init, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | .destroy = ingress_destroy, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | .dump = ingress_dump, |
| 98 | .owner = THIS_MODULE, |
| 99 | }; |
| 100 | |
| 101 | static int __init ingress_module_init(void) |
| 102 | { |
Patrick McHardy | 8916876 | 2008-01-21 00:14:05 -0800 | [diff] [blame] | 103 | return register_qdisc(&ingress_qdisc_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | } |
Patrick McHardy | 58f4df4 | 2008-01-21 00:11:01 -0800 | [diff] [blame] | 105 | |
YOSHIFUJI Hideaki | 10297b9 | 2007-02-09 23:25:16 +0900 | [diff] [blame] | 106 | static void __exit ingress_module_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | { |
| 108 | unregister_qdisc(&ingress_qdisc_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | } |
Patrick McHardy | 58f4df4 | 2008-01-21 00:11:01 -0800 | [diff] [blame] | 110 | |
Daniel Borkmann | d2788d3 | 2015-05-09 22:51:32 +0200 | [diff] [blame] | 111 | module_init(ingress_module_init); |
| 112 | module_exit(ingress_module_exit); |
| 113 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | MODULE_LICENSE("GPL"); |