| 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> | 
| Arnaldo Carvalho de Melo | dc5fc57 | 2007-03-25 23:06:12 -0700 | [diff] [blame] | 15 | #include <net/netlink.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <net/pkt_sched.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 |  | 
 | 18 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | struct ingress_qdisc_data { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | 	struct tcf_proto	*filter_list; | 
 | 21 | }; | 
 | 22 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | /* ------------------------- Class/flow operations ------------------------- */ | 
 | 24 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | static struct Qdisc *ingress_leaf(struct Qdisc *sch, unsigned long arg) | 
 | 26 | { | 
 | 27 | 	return NULL; | 
 | 28 | } | 
 | 29 |  | 
| Patrick McHardy | 58f4df4 | 2008-01-21 00:11:01 -0800 | [diff] [blame] | 30 | static unsigned long ingress_get(struct Qdisc *sch, u32 classid) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | 	return TC_H_MIN(classid) + 1; | 
 | 33 | } | 
 | 34 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | static unsigned long ingress_bind_filter(struct Qdisc *sch, | 
| Patrick McHardy | 58f4df4 | 2008-01-21 00:11:01 -0800 | [diff] [blame] | 36 | 					 unsigned long parent, u32 classid) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | { | 
 | 38 | 	return ingress_get(sch, classid); | 
 | 39 | } | 
 | 40 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | static void ingress_put(struct Qdisc *sch, unsigned long cl) | 
 | 42 | { | 
 | 43 | } | 
 | 44 |  | 
| Patrick McHardy | 58f4df4 | 2008-01-21 00:11:01 -0800 | [diff] [blame] | 45 | static void ingress_walk(struct Qdisc *sch, struct qdisc_walker *walker) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | } | 
 | 48 |  | 
| Patrick McHardy | 58f4df4 | 2008-01-21 00:11:01 -0800 | [diff] [blame] | 49 | static struct tcf_proto **ingress_find_tcf(struct Qdisc *sch, unsigned long cl) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | { | 
| Patrick McHardy | cb53c04 | 2008-01-21 00:11:48 -0800 | [diff] [blame] | 51 | 	struct ingress_qdisc_data *p = qdisc_priv(sch); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 |  | 
 | 53 | 	return &p->filter_list; | 
 | 54 | } | 
 | 55 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | /* --------------------------- Qdisc operations ---------------------------- */ | 
 | 57 |  | 
| Patrick McHardy | 58f4df4 | 2008-01-21 00:11:01 -0800 | [diff] [blame] | 58 | static int ingress_enqueue(struct sk_buff *skb, struct Qdisc *sch) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | { | 
| Patrick McHardy | cb53c04 | 2008-01-21 00:11:48 -0800 | [diff] [blame] | 60 | 	struct ingress_qdisc_data *p = qdisc_priv(sch); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | 	struct tcf_result res; | 
 | 62 | 	int result; | 
 | 63 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | 	result = tc_classify(skb, p->filter_list, &res); | 
| Patrick McHardy | a478122 | 2008-01-21 00:11:21 -0800 | [diff] [blame] | 65 |  | 
| Eric Dumazet | bfe0d02 | 2011-01-09 08:30:54 +0000 | [diff] [blame] | 66 | 	qdisc_bstats_update(sch, skb); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | 	switch (result) { | 
| Patrick McHardy | 58f4df4 | 2008-01-21 00:11:01 -0800 | [diff] [blame] | 68 | 	case TC_ACT_SHOT: | 
 | 69 | 		result = TC_ACT_SHOT; | 
 | 70 | 		sch->qstats.drops++; | 
 | 71 | 		break; | 
 | 72 | 	case TC_ACT_STOLEN: | 
 | 73 | 	case TC_ACT_QUEUED: | 
 | 74 | 		result = TC_ACT_STOLEN; | 
 | 75 | 		break; | 
 | 76 | 	case TC_ACT_RECLASSIFY: | 
 | 77 | 	case TC_ACT_OK: | 
 | 78 | 		skb->tc_index = TC_H_MIN(res.classid); | 
 | 79 | 	default: | 
 | 80 | 		result = TC_ACT_OK; | 
 | 81 | 		break; | 
| Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 82 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 |  | 
 | 84 | 	return result; | 
 | 85 | } | 
 | 86 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | /* ------------------------------------------------------------- */ | 
 | 88 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | static void ingress_destroy(struct Qdisc *sch) | 
 | 90 | { | 
| Patrick McHardy | cb53c04 | 2008-01-21 00:11:48 -0800 | [diff] [blame] | 91 | 	struct ingress_qdisc_data *p = qdisc_priv(sch); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 |  | 
| Patrick McHardy | ff31ab5 | 2008-07-01 19:52:38 -0700 | [diff] [blame] | 93 | 	tcf_destroy_chain(&p->filter_list); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | } | 
 | 95 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | static int ingress_dump(struct Qdisc *sch, struct sk_buff *skb) | 
 | 97 | { | 
| Patrick McHardy | 4b3550ef | 2008-01-23 20:34:11 -0800 | [diff] [blame] | 98 | 	struct nlattr *nest; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 |  | 
| Patrick McHardy | 4b3550ef | 2008-01-23 20:34:11 -0800 | [diff] [blame] | 100 | 	nest = nla_nest_start(skb, TCA_OPTIONS); | 
 | 101 | 	if (nest == NULL) | 
 | 102 | 		goto nla_put_failure; | 
 | 103 | 	nla_nest_end(skb, nest); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | 	return skb->len; | 
 | 105 |  | 
| Patrick McHardy | 1e90474 | 2008-01-22 22:11:17 -0800 | [diff] [blame] | 106 | nla_put_failure: | 
| Patrick McHardy | 4b3550ef | 2008-01-23 20:34:11 -0800 | [diff] [blame] | 107 | 	nla_nest_cancel(skb, nest); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | 	return -1; | 
 | 109 | } | 
 | 110 |  | 
| Eric Dumazet | 20fea08 | 2007-11-14 01:44:41 -0800 | [diff] [blame] | 111 | static const struct Qdisc_class_ops ingress_class_ops = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | 	.leaf		=	ingress_leaf, | 
 | 113 | 	.get		=	ingress_get, | 
 | 114 | 	.put		=	ingress_put, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | 	.walk		=	ingress_walk, | 
 | 116 | 	.tcf_chain	=	ingress_find_tcf, | 
 | 117 | 	.bind_tcf	=	ingress_bind_filter, | 
 | 118 | 	.unbind_tcf	=	ingress_put, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | }; | 
 | 120 |  | 
| Eric Dumazet | 20fea08 | 2007-11-14 01:44:41 -0800 | [diff] [blame] | 121 | static struct Qdisc_ops ingress_qdisc_ops __read_mostly = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | 	.cl_ops		=	&ingress_class_ops, | 
 | 123 | 	.id		=	"ingress", | 
 | 124 | 	.priv_size	=	sizeof(struct ingress_qdisc_data), | 
 | 125 | 	.enqueue	=	ingress_enqueue, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | 	.destroy	=	ingress_destroy, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | 	.dump		=	ingress_dump, | 
 | 128 | 	.owner		=	THIS_MODULE, | 
 | 129 | }; | 
 | 130 |  | 
 | 131 | static int __init ingress_module_init(void) | 
 | 132 | { | 
| Patrick McHardy | 8916876 | 2008-01-21 00:14:05 -0800 | [diff] [blame] | 133 | 	return register_qdisc(&ingress_qdisc_ops); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | } | 
| Patrick McHardy | 58f4df4 | 2008-01-21 00:11:01 -0800 | [diff] [blame] | 135 |  | 
| YOSHIFUJI Hideaki | 10297b9 | 2007-02-09 23:25:16 +0900 | [diff] [blame] | 136 | static void __exit ingress_module_exit(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | { | 
 | 138 | 	unregister_qdisc(&ingress_qdisc_ops); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | } | 
| Patrick McHardy | 58f4df4 | 2008-01-21 00:11:01 -0800 | [diff] [blame] | 140 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | module_init(ingress_module_init) | 
 | 142 | module_exit(ingress_module_exit) | 
 | 143 | MODULE_LICENSE("GPL"); |