Blame view

net/sched/sch_ingress.c 7.46 KB
2874c5fd2   Thomas Gleixner   treewide: Replace...
1
  // SPDX-License-Identifier: GPL-2.0-or-later
1f211a1b9   Daniel Borkmann   net, sched: add c...
2
3
  /* net/sched/sch_ingress.c - Ingress and clsact qdisc
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
4
5
   * Authors:     Jamal Hadi Salim 1999
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
6
7
  #include <linux/module.h>
  #include <linux/types.h>
0ba480538   Patrick McHardy   [NET_SCHED]: Remo...
8
  #include <linux/list.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
9
  #include <linux/skbuff.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
10
  #include <linux/rtnetlink.h>
d2788d348   Daniel Borkmann   net: sched: furth...
11

dc5fc579b   Arnaldo Carvalho de Melo   [NETLINK]: Use nl...
12
  #include <net/netlink.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
13
  #include <net/pkt_sched.h>
cf1facda2   Jiri Pirko   sched: move tcf_p...
14
  #include <net/pkt_cls.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
15

6529eaba3   Jiri Pirko   net: sched: intro...
16
17
  struct ingress_sched_data {
  	struct tcf_block *block;
6e40cf2d4   Jiri Pirko   net: sched: use e...
18
  	struct tcf_block_ext_info block_info;
46209401f   Jiri Pirko   net: core: introd...
19
  	struct mini_Qdisc_pair miniqp;
6529eaba3   Jiri Pirko   net: sched: intro...
20
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
21
22
23
24
  static struct Qdisc *ingress_leaf(struct Qdisc *sch, unsigned long arg)
  {
  	return NULL;
  }
143976ce9   WANG Cong   net_sched: remove...
25
  static unsigned long ingress_find(struct Qdisc *sch, u32 classid)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
26
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
27
28
  	return TC_H_MIN(classid) + 1;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
29
  static unsigned long ingress_bind_filter(struct Qdisc *sch,
58f4df423   Patrick McHardy   [NET_SCHED]: sch_...
30
  					 unsigned long parent, u32 classid)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
31
  {
143976ce9   WANG Cong   net_sched: remove...
32
  	return ingress_find(sch, classid);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
33
  }
143976ce9   WANG Cong   net_sched: remove...
34
  static void ingress_unbind_filter(struct Qdisc *sch, unsigned long cl)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
35
36
  {
  }
58f4df423   Patrick McHardy   [NET_SCHED]: sch_...
37
  static void ingress_walk(struct Qdisc *sch, struct qdisc_walker *walker)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
38
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
39
  }
cbaacc4e8   Alexander Aring   net: sched: sch: ...
40
41
  static struct tcf_block *ingress_tcf_block(struct Qdisc *sch, unsigned long cl,
  					   struct netlink_ext_ack *extack)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
42
  {
6529eaba3   Jiri Pirko   net: sched: intro...
43
  	struct ingress_sched_data *q = qdisc_priv(sch);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
44

6529eaba3   Jiri Pirko   net: sched: intro...
45
  	return q->block;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
46
  }
c7eb7d723   Jiri Pirko   net: sched: intro...
47
48
  static void clsact_chain_head_change(struct tcf_proto *tp_head, void *priv)
  {
46209401f   Jiri Pirko   net: core: introd...
49
  	struct mini_Qdisc_pair *miniqp = priv;
c7eb7d723   Jiri Pirko   net: sched: intro...
50

46209401f   Jiri Pirko   net: core: introd...
51
  	mini_qdisc_pair_swap(miniqp, tp_head);
51ab2994c   Jiri Pirko   net: sched: allow...
52
53
54
55
56
57
58
59
60
61
62
63
64
65
  };
  
  static void ingress_ingress_block_set(struct Qdisc *sch, u32 block_index)
  {
  	struct ingress_sched_data *q = qdisc_priv(sch);
  
  	q->block_info.block_index = block_index;
  }
  
  static u32 ingress_ingress_block_get(struct Qdisc *sch)
  {
  	struct ingress_sched_data *q = qdisc_priv(sch);
  
  	return q->block_info.block_index;
c7eb7d723   Jiri Pirko   net: sched: intro...
66
  }
e63d7dfd2   Alexander Aring   net: sched: sch: ...
67
68
  static int ingress_init(struct Qdisc *sch, struct nlattr *opt,
  			struct netlink_ext_ack *extack)
4577139b2   Daniel Borkmann   net: use jump lab...
69
  {
6529eaba3   Jiri Pirko   net: sched: intro...
70
71
  	struct ingress_sched_data *q = qdisc_priv(sch);
  	struct net_device *dev = qdisc_dev(sch);
7d17c544c   Paul Blakey   net: sched: Pass ...
72
  	int err;
6529eaba3   Jiri Pirko   net: sched: intro...
73

b59e6979a   Jiri Pirko   net: sched: fix s...
74
  	net_inc_ingress_queue();
46209401f   Jiri Pirko   net: core: introd...
75
  	mini_qdisc_pair_init(&q->miniqp, sch, &dev->miniq_ingress);
32f8c4093   Pablo Neira Ayuso   net: flow_offload...
76
  	q->block_info.binder_type = FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS;
c7eb7d723   Jiri Pirko   net: sched: intro...
77
  	q->block_info.chain_head_change = clsact_chain_head_change;
46209401f   Jiri Pirko   net: core: introd...
78
  	q->block_info.chain_head_change_priv = &q->miniqp;
6e40cf2d4   Jiri Pirko   net: sched: use e...
79

7d17c544c   Paul Blakey   net: sched: Pass ...
80
81
82
83
84
85
86
  	err = tcf_block_get_ext(&q->block, sch, &q->block_info, extack);
  	if (err)
  		return err;
  
  	mini_qdisc_pair_block_init(&q->miniqp, q->block);
  
  	return 0;
4577139b2   Daniel Borkmann   net: use jump lab...
87
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
88
89
  static void ingress_destroy(struct Qdisc *sch)
  {
6529eaba3   Jiri Pirko   net: sched: intro...
90
  	struct ingress_sched_data *q = qdisc_priv(sch);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
91

c7eb7d723   Jiri Pirko   net: sched: intro...
92
  	tcf_block_put_ext(q->block, sch, &q->block_info);
4577139b2   Daniel Borkmann   net: use jump lab...
93
  	net_dec_ingress_queue();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
94
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
95
96
  static int ingress_dump(struct Qdisc *sch, struct sk_buff *skb)
  {
4b3550ef5   Patrick McHardy   [NET_SCHED]: Use ...
97
  	struct nlattr *nest;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
98

ae0be8de9   Michal Kubecek   netlink: make nla...
99
  	nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
4b3550ef5   Patrick McHardy   [NET_SCHED]: Use ...
100
101
  	if (nest == NULL)
  		goto nla_put_failure;
d2788d348   Daniel Borkmann   net: sched: furth...
102

d59b7d805   Yang Yingliang   net_sched: return...
103
  	return nla_nest_end(skb, nest);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
104

1e90474c3   Patrick McHardy   [NET_SCHED]: Conv...
105
  nla_put_failure:
4b3550ef5   Patrick McHardy   [NET_SCHED]: Use ...
106
  	nla_nest_cancel(skb, nest);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
107
108
  	return -1;
  }
20fea08b5   Eric Dumazet   [NET]: Move Qdisc...
109
  static const struct Qdisc_class_ops ingress_class_ops = {
7a096d579   Vlad Buslov   net: sched: ingre...
110
  	.flags		=	QDISC_CLASS_OPS_DOIT_UNLOCKED,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
111
  	.leaf		=	ingress_leaf,
143976ce9   WANG Cong   net_sched: remove...
112
  	.find		=	ingress_find,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
113
  	.walk		=	ingress_walk,
6529eaba3   Jiri Pirko   net: sched: intro...
114
  	.tcf_block	=	ingress_tcf_block,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
115
  	.bind_tcf	=	ingress_bind_filter,
143976ce9   WANG Cong   net_sched: remove...
116
  	.unbind_tcf	=	ingress_unbind_filter,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
117
  };
20fea08b5   Eric Dumazet   [NET]: Move Qdisc...
118
  static struct Qdisc_ops ingress_qdisc_ops __read_mostly = {
51ab2994c   Jiri Pirko   net: sched: allow...
119
120
121
122
123
124
125
126
127
128
  	.cl_ops			=	&ingress_class_ops,
  	.id			=	"ingress",
  	.priv_size		=	sizeof(struct ingress_sched_data),
  	.static_flags		=	TCQ_F_CPUSTATS,
  	.init			=	ingress_init,
  	.destroy		=	ingress_destroy,
  	.dump			=	ingress_dump,
  	.ingress_block_set	=	ingress_ingress_block_set,
  	.ingress_block_get	=	ingress_ingress_block_get,
  	.owner			=	THIS_MODULE,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
129
  };
6529eaba3   Jiri Pirko   net: sched: intro...
130
131
132
  struct clsact_sched_data {
  	struct tcf_block *ingress_block;
  	struct tcf_block *egress_block;
6e40cf2d4   Jiri Pirko   net: sched: use e...
133
134
  	struct tcf_block_ext_info ingress_block_info;
  	struct tcf_block_ext_info egress_block_info;
46209401f   Jiri Pirko   net: core: introd...
135
136
  	struct mini_Qdisc_pair miniqp_ingress;
  	struct mini_Qdisc_pair miniqp_egress;
6529eaba3   Jiri Pirko   net: sched: intro...
137
  };
143976ce9   WANG Cong   net_sched: remove...
138
  static unsigned long clsact_find(struct Qdisc *sch, u32 classid)
1f211a1b9   Daniel Borkmann   net, sched: add c...
139
140
141
142
143
144
145
146
147
148
149
150
151
  {
  	switch (TC_H_MIN(classid)) {
  	case TC_H_MIN(TC_H_MIN_INGRESS):
  	case TC_H_MIN(TC_H_MIN_EGRESS):
  		return TC_H_MIN(classid);
  	default:
  		return 0;
  	}
  }
  
  static unsigned long clsact_bind_filter(struct Qdisc *sch,
  					unsigned long parent, u32 classid)
  {
143976ce9   WANG Cong   net_sched: remove...
152
  	return clsact_find(sch, classid);
1f211a1b9   Daniel Borkmann   net, sched: add c...
153
  }
cbaacc4e8   Alexander Aring   net: sched: sch: ...
154
155
  static struct tcf_block *clsact_tcf_block(struct Qdisc *sch, unsigned long cl,
  					  struct netlink_ext_ack *extack)
1f211a1b9   Daniel Borkmann   net, sched: add c...
156
  {
6529eaba3   Jiri Pirko   net: sched: intro...
157
  	struct clsact_sched_data *q = qdisc_priv(sch);
1f211a1b9   Daniel Borkmann   net, sched: add c...
158
159
160
  
  	switch (cl) {
  	case TC_H_MIN(TC_H_MIN_INGRESS):
6529eaba3   Jiri Pirko   net: sched: intro...
161
  		return q->ingress_block;
1f211a1b9   Daniel Borkmann   net, sched: add c...
162
  	case TC_H_MIN(TC_H_MIN_EGRESS):
6529eaba3   Jiri Pirko   net: sched: intro...
163
  		return q->egress_block;
1f211a1b9   Daniel Borkmann   net, sched: add c...
164
165
166
167
  	default:
  		return NULL;
  	}
  }
51ab2994c   Jiri Pirko   net: sched: allow...
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
  static void clsact_ingress_block_set(struct Qdisc *sch, u32 block_index)
  {
  	struct clsact_sched_data *q = qdisc_priv(sch);
  
  	q->ingress_block_info.block_index = block_index;
  }
  
  static void clsact_egress_block_set(struct Qdisc *sch, u32 block_index)
  {
  	struct clsact_sched_data *q = qdisc_priv(sch);
  
  	q->egress_block_info.block_index = block_index;
  }
  
  static u32 clsact_ingress_block_get(struct Qdisc *sch)
  {
  	struct clsact_sched_data *q = qdisc_priv(sch);
  
  	return q->ingress_block_info.block_index;
  }
  
  static u32 clsact_egress_block_get(struct Qdisc *sch)
  {
  	struct clsact_sched_data *q = qdisc_priv(sch);
  
  	return q->egress_block_info.block_index;
  }
e63d7dfd2   Alexander Aring   net: sched: sch: ...
195
196
  static int clsact_init(struct Qdisc *sch, struct nlattr *opt,
  		       struct netlink_ext_ack *extack)
1f211a1b9   Daniel Borkmann   net, sched: add c...
197
  {
6529eaba3   Jiri Pirko   net: sched: intro...
198
199
200
  	struct clsact_sched_data *q = qdisc_priv(sch);
  	struct net_device *dev = qdisc_dev(sch);
  	int err;
b59e6979a   Jiri Pirko   net: sched: fix s...
201
202
  	net_inc_ingress_queue();
  	net_inc_egress_queue();
46209401f   Jiri Pirko   net: core: introd...
203
  	mini_qdisc_pair_init(&q->miniqp_ingress, sch, &dev->miniq_ingress);
32f8c4093   Pablo Neira Ayuso   net: flow_offload...
204
  	q->ingress_block_info.binder_type = FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS;
c7eb7d723   Jiri Pirko   net: sched: intro...
205
  	q->ingress_block_info.chain_head_change = clsact_chain_head_change;
46209401f   Jiri Pirko   net: core: introd...
206
  	q->ingress_block_info.chain_head_change_priv = &q->miniqp_ingress;
6e40cf2d4   Jiri Pirko   net: sched: use e...
207

8d1a77f97   Alexander Aring   net: sch: api: ad...
208
209
  	err = tcf_block_get_ext(&q->ingress_block, sch, &q->ingress_block_info,
  				extack);
6529eaba3   Jiri Pirko   net: sched: intro...
210
211
  	if (err)
  		return err;
7d17c544c   Paul Blakey   net: sched: Pass ...
212
  	mini_qdisc_pair_block_init(&q->miniqp_ingress, q->ingress_block);
46209401f   Jiri Pirko   net: core: introd...
213
  	mini_qdisc_pair_init(&q->miniqp_egress, sch, &dev->miniq_egress);
32f8c4093   Pablo Neira Ayuso   net: flow_offload...
214
  	q->egress_block_info.binder_type = FLOW_BLOCK_BINDER_TYPE_CLSACT_EGRESS;
c7eb7d723   Jiri Pirko   net: sched: intro...
215
  	q->egress_block_info.chain_head_change = clsact_chain_head_change;
46209401f   Jiri Pirko   net: core: introd...
216
  	q->egress_block_info.chain_head_change_priv = &q->miniqp_egress;
6e40cf2d4   Jiri Pirko   net: sched: use e...
217

c02b3741e   David S. Miller   Merge git://git.k...
218
  	return tcf_block_get_ext(&q->egress_block, sch, &q->egress_block_info, extack);
1f211a1b9   Daniel Borkmann   net, sched: add c...
219
220
221
222
  }
  
  static void clsact_destroy(struct Qdisc *sch)
  {
6529eaba3   Jiri Pirko   net: sched: intro...
223
  	struct clsact_sched_data *q = qdisc_priv(sch);
1f211a1b9   Daniel Borkmann   net, sched: add c...
224

c7eb7d723   Jiri Pirko   net: sched: intro...
225
226
  	tcf_block_put_ext(q->egress_block, sch, &q->egress_block_info);
  	tcf_block_put_ext(q->ingress_block, sch, &q->ingress_block_info);
1f211a1b9   Daniel Borkmann   net, sched: add c...
227
228
229
230
231
232
  
  	net_dec_ingress_queue();
  	net_dec_egress_queue();
  }
  
  static const struct Qdisc_class_ops clsact_class_ops = {
87f373921   Vlad Buslov   net: sched: ingre...
233
  	.flags		=	QDISC_CLASS_OPS_DOIT_UNLOCKED,
1f211a1b9   Daniel Borkmann   net, sched: add c...
234
  	.leaf		=	ingress_leaf,
143976ce9   WANG Cong   net_sched: remove...
235
  	.find		=	clsact_find,
1f211a1b9   Daniel Borkmann   net, sched: add c...
236
  	.walk		=	ingress_walk,
6529eaba3   Jiri Pirko   net: sched: intro...
237
  	.tcf_block	=	clsact_tcf_block,
1f211a1b9   Daniel Borkmann   net, sched: add c...
238
  	.bind_tcf	=	clsact_bind_filter,
143976ce9   WANG Cong   net_sched: remove...
239
  	.unbind_tcf	=	ingress_unbind_filter,
1f211a1b9   Daniel Borkmann   net, sched: add c...
240
241
242
  };
  
  static struct Qdisc_ops clsact_qdisc_ops __read_mostly = {
51ab2994c   Jiri Pirko   net: sched: allow...
243
244
245
246
247
248
249
250
251
252
253
254
  	.cl_ops			=	&clsact_class_ops,
  	.id			=	"clsact",
  	.priv_size		=	sizeof(struct clsact_sched_data),
  	.static_flags		=	TCQ_F_CPUSTATS,
  	.init			=	clsact_init,
  	.destroy		=	clsact_destroy,
  	.dump			=	ingress_dump,
  	.ingress_block_set	=	clsact_ingress_block_set,
  	.egress_block_set	=	clsact_egress_block_set,
  	.ingress_block_get	=	clsact_ingress_block_get,
  	.egress_block_get	=	clsact_egress_block_get,
  	.owner			=	THIS_MODULE,
1f211a1b9   Daniel Borkmann   net, sched: add c...
255
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
256
257
  static int __init ingress_module_init(void)
  {
1f211a1b9   Daniel Borkmann   net, sched: add c...
258
259
260
261
262
263
264
265
266
267
  	int ret;
  
  	ret = register_qdisc(&ingress_qdisc_ops);
  	if (!ret) {
  		ret = register_qdisc(&clsact_qdisc_ops);
  		if (ret)
  			unregister_qdisc(&ingress_qdisc_ops);
  	}
  
  	return ret;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
268
  }
58f4df423   Patrick McHardy   [NET_SCHED]: sch_...
269

10297b993   YOSHIFUJI Hideaki   [NET] SCHED: Fix ...
270
  static void __exit ingress_module_exit(void)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
271
272
  {
  	unregister_qdisc(&ingress_qdisc_ops);
1f211a1b9   Daniel Borkmann   net, sched: add c...
273
  	unregister_qdisc(&clsact_qdisc_ops);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
274
  }
58f4df423   Patrick McHardy   [NET_SCHED]: sch_...
275

d2788d348   Daniel Borkmann   net: sched: furth...
276
277
  module_init(ingress_module_init);
  module_exit(ingress_module_exit);
1f211a1b9   Daniel Borkmann   net, sched: add c...
278
  MODULE_ALIAS("sch_clsact");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
279
  MODULE_LICENSE("GPL");