blob: eacaaf803914cdc77372d9e661d8d1bb63096be3 [file] [log] [blame]
Jiri Pirko77b99002015-05-12 14:56:21 +02001/*
2 * net/sched/cls_flower.c Flower classifier
3 *
4 * Copyright (c) 2015 Jiri Pirko <jiri@resnulli.us>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12#include <linux/kernel.h>
13#include <linux/init.h>
14#include <linux/module.h>
15#include <linux/rhashtable.h>
Daniel Borkmannd9363772016-11-27 01:18:01 +010016#include <linux/workqueue.h>
Jiri Pirko77b99002015-05-12 14:56:21 +020017
18#include <linux/if_ether.h>
19#include <linux/in6.h>
20#include <linux/ip.h>
Benjamin LaHaisea577d8f2017-04-22 16:52:47 -040021#include <linux/mpls.h>
Jiri Pirko77b99002015-05-12 14:56:21 +020022
23#include <net/sch_generic.h>
24#include <net/pkt_cls.h>
25#include <net/ip.h>
26#include <net/flow_dissector.h>
27
Amir Vadaibc3103f2016-09-08 16:23:47 +030028#include <net/dst.h>
29#include <net/dst_metadata.h>
30
Jiri Pirko77b99002015-05-12 14:56:21 +020031struct fl_flow_key {
32 int indev_ifindex;
Tom Herbert42aecaa2015-06-04 09:16:39 -070033 struct flow_dissector_key_control control;
Amir Vadaibc3103f2016-09-08 16:23:47 +030034 struct flow_dissector_key_control enc_control;
Jiri Pirko77b99002015-05-12 14:56:21 +020035 struct flow_dissector_key_basic basic;
36 struct flow_dissector_key_eth_addrs eth;
Hadar Hen Zion9399ae92016-08-17 13:36:13 +030037 struct flow_dissector_key_vlan vlan;
Jiri Pirko77b99002015-05-12 14:56:21 +020038 union {
Tom Herbertc3f83242015-06-04 09:16:40 -070039 struct flow_dissector_key_ipv4_addrs ipv4;
Jiri Pirko77b99002015-05-12 14:56:21 +020040 struct flow_dissector_key_ipv6_addrs ipv6;
41 };
42 struct flow_dissector_key_ports tp;
Simon Horman7b684882016-12-07 13:48:28 +010043 struct flow_dissector_key_icmp icmp;
Simon Horman99d31322017-01-11 14:05:43 +010044 struct flow_dissector_key_arp arp;
Amir Vadaibc3103f2016-09-08 16:23:47 +030045 struct flow_dissector_key_keyid enc_key_id;
46 union {
47 struct flow_dissector_key_ipv4_addrs enc_ipv4;
48 struct flow_dissector_key_ipv6_addrs enc_ipv6;
49 };
Hadar Hen Zionf4d997f2016-11-07 15:14:39 +020050 struct flow_dissector_key_ports enc_tp;
Benjamin LaHaisea577d8f2017-04-22 16:52:47 -040051 struct flow_dissector_key_mpls mpls;
Jiri Pirkofdfc7dd2017-05-23 18:40:45 +020052 struct flow_dissector_key_tcp tcp;
Or Gerlitz4d80cc02017-06-01 21:37:38 +030053 struct flow_dissector_key_ip ip;
Jiri Pirko77b99002015-05-12 14:56:21 +020054} __aligned(BITS_PER_LONG / 8); /* Ensure that we can do comparisons as longs. */
55
56struct fl_flow_mask_range {
57 unsigned short int start;
58 unsigned short int end;
59};
60
61struct fl_flow_mask {
62 struct fl_flow_key key;
63 struct fl_flow_mask_range range;
Paul Blakey05cd2712018-04-30 14:28:30 +030064 struct rhash_head ht_node;
65 struct rhashtable ht;
66 struct rhashtable_params filter_ht_params;
67 struct flow_dissector dissector;
68 struct list_head filters;
69 struct rcu_head rcu;
70 struct list_head list;
Jiri Pirko77b99002015-05-12 14:56:21 +020071};
72
73struct cls_fl_head {
74 struct rhashtable ht;
Paul Blakey05cd2712018-04-30 14:28:30 +030075 struct list_head masks;
Daniel Borkmannd9363772016-11-27 01:18:01 +010076 union {
77 struct work_struct work;
78 struct rcu_head rcu;
79 };
Chris Mic15ab232017-08-30 02:31:58 -040080 struct idr handle_idr;
Jiri Pirko77b99002015-05-12 14:56:21 +020081};
82
83struct cls_fl_filter {
Paul Blakey05cd2712018-04-30 14:28:30 +030084 struct fl_flow_mask *mask;
Jiri Pirko77b99002015-05-12 14:56:21 +020085 struct rhash_head ht_node;
86 struct fl_flow_key mkey;
87 struct tcf_exts exts;
88 struct tcf_result res;
89 struct fl_flow_key key;
90 struct list_head list;
91 u32 handle;
Amir Vadaie69985c2016-06-05 17:11:18 +030092 u32 flags;
Cong Wang0552c8a2017-10-26 18:24:33 -070093 union {
94 struct work_struct work;
95 struct rcu_head rcu;
96 };
Hadar Hen Zion7091d8c2016-12-01 14:06:37 +020097 struct net_device *hw_dev;
Jiri Pirko77b99002015-05-12 14:56:21 +020098};
99
Paul Blakey05cd2712018-04-30 14:28:30 +0300100static const struct rhashtable_params mask_ht_params = {
101 .key_offset = offsetof(struct fl_flow_mask, key),
102 .key_len = sizeof(struct fl_flow_key),
103 .head_offset = offsetof(struct fl_flow_mask, ht_node),
104 .automatic_shrinking = true,
105};
106
Jiri Pirko77b99002015-05-12 14:56:21 +0200107static unsigned short int fl_mask_range(const struct fl_flow_mask *mask)
108{
109 return mask->range.end - mask->range.start;
110}
111
112static void fl_mask_update_range(struct fl_flow_mask *mask)
113{
114 const u8 *bytes = (const u8 *) &mask->key;
115 size_t size = sizeof(mask->key);
Paul Blakey05cd2712018-04-30 14:28:30 +0300116 size_t i, first = 0, last;
Jiri Pirko77b99002015-05-12 14:56:21 +0200117
Paul Blakey05cd2712018-04-30 14:28:30 +0300118 for (i = 0; i < size; i++) {
Jiri Pirko77b99002015-05-12 14:56:21 +0200119 if (bytes[i]) {
Paul Blakey05cd2712018-04-30 14:28:30 +0300120 first = i;
121 break;
122 }
123 }
124 last = first;
125 for (i = size - 1; i != first; i--) {
126 if (bytes[i]) {
Jiri Pirko77b99002015-05-12 14:56:21 +0200127 last = i;
Paul Blakey05cd2712018-04-30 14:28:30 +0300128 break;
Jiri Pirko77b99002015-05-12 14:56:21 +0200129 }
130 }
131 mask->range.start = rounddown(first, sizeof(long));
132 mask->range.end = roundup(last + 1, sizeof(long));
133}
134
135static void *fl_key_get_start(struct fl_flow_key *key,
136 const struct fl_flow_mask *mask)
137{
138 return (u8 *) key + mask->range.start;
139}
140
141static void fl_set_masked_key(struct fl_flow_key *mkey, struct fl_flow_key *key,
142 struct fl_flow_mask *mask)
143{
144 const long *lkey = fl_key_get_start(key, mask);
145 const long *lmask = fl_key_get_start(&mask->key, mask);
146 long *lmkey = fl_key_get_start(mkey, mask);
147 int i;
148
149 for (i = 0; i < fl_mask_range(mask); i += sizeof(long))
150 *lmkey++ = *lkey++ & *lmask++;
151}
152
153static void fl_clear_masked_range(struct fl_flow_key *key,
154 struct fl_flow_mask *mask)
155{
156 memset(fl_key_get_start(key, mask), 0, fl_mask_range(mask));
157}
158
Paul Blakey05cd2712018-04-30 14:28:30 +0300159static struct cls_fl_filter *fl_lookup(struct fl_flow_mask *mask,
Paul Blakeya3308d82017-01-16 10:45:13 +0200160 struct fl_flow_key *mkey)
161{
Paul Blakey05cd2712018-04-30 14:28:30 +0300162 return rhashtable_lookup_fast(&mask->ht, fl_key_get_start(mkey, mask),
163 mask->filter_ht_params);
Paul Blakeya3308d82017-01-16 10:45:13 +0200164}
165
Jiri Pirko77b99002015-05-12 14:56:21 +0200166static int fl_classify(struct sk_buff *skb, const struct tcf_proto *tp,
167 struct tcf_result *res)
168{
169 struct cls_fl_head *head = rcu_dereference_bh(tp->root);
170 struct cls_fl_filter *f;
Paul Blakey05cd2712018-04-30 14:28:30 +0300171 struct fl_flow_mask *mask;
Jiri Pirko77b99002015-05-12 14:56:21 +0200172 struct fl_flow_key skb_key;
173 struct fl_flow_key skb_mkey;
174
Paul Blakey05cd2712018-04-30 14:28:30 +0300175 list_for_each_entry_rcu(mask, &head->masks, list) {
176 fl_clear_masked_range(&skb_key, mask);
Amir Vadaie69985c2016-06-05 17:11:18 +0300177
Paul Blakey05cd2712018-04-30 14:28:30 +0300178 skb_key.indev_ifindex = skb->skb_iif;
179 /* skb_flow_dissect() does not set n_proto in case an unknown
180 * protocol, so do it rather here.
181 */
182 skb_key.basic.n_proto = skb->protocol;
183 skb_flow_dissect_tunnel_info(skb, &mask->dissector, &skb_key);
184 skb_flow_dissect(skb, &mask->dissector, &skb_key, 0);
Amir Vadaibc3103f2016-09-08 16:23:47 +0300185
Paul Blakey05cd2712018-04-30 14:28:30 +0300186 fl_set_masked_key(&skb_mkey, &skb_key, mask);
Jiri Pirko77b99002015-05-12 14:56:21 +0200187
Paul Blakey05cd2712018-04-30 14:28:30 +0300188 f = fl_lookup(mask, &skb_mkey);
189 if (f && !tc_skip_sw(f->flags)) {
190 *res = f->res;
191 return tcf_exts_exec(skb, &f->exts, res);
192 }
Jiri Pirko77b99002015-05-12 14:56:21 +0200193 }
194 return -1;
195}
196
197static int fl_init(struct tcf_proto *tp)
198{
199 struct cls_fl_head *head;
200
201 head = kzalloc(sizeof(*head), GFP_KERNEL);
202 if (!head)
203 return -ENOBUFS;
204
Paul Blakey05cd2712018-04-30 14:28:30 +0300205 INIT_LIST_HEAD_RCU(&head->masks);
Jiri Pirko77b99002015-05-12 14:56:21 +0200206 rcu_assign_pointer(tp->root, head);
Chris Mic15ab232017-08-30 02:31:58 -0400207 idr_init(&head->handle_idr);
Jiri Pirko77b99002015-05-12 14:56:21 +0200208
Paul Blakey05cd2712018-04-30 14:28:30 +0300209 return rhashtable_init(&head->ht, &mask_ht_params);
210}
211
212static bool fl_mask_put(struct cls_fl_head *head, struct fl_flow_mask *mask,
213 bool async)
214{
215 if (!list_empty(&mask->filters))
216 return false;
217
218 rhashtable_remove_fast(&head->ht, &mask->ht_node, mask_ht_params);
219 rhashtable_destroy(&mask->ht);
220 list_del_rcu(&mask->list);
221 if (async)
222 kfree_rcu(mask, rcu);
223 else
224 kfree(mask);
225
226 return true;
Jiri Pirko77b99002015-05-12 14:56:21 +0200227}
228
Cong Wang0dadc112017-11-06 13:47:24 -0800229static void __fl_destroy_filter(struct cls_fl_filter *f)
230{
231 tcf_exts_destroy(&f->exts);
232 tcf_exts_put_net(&f->exts);
233 kfree(f);
234}
235
Cong Wang0552c8a2017-10-26 18:24:33 -0700236static void fl_destroy_filter_work(struct work_struct *work)
237{
238 struct cls_fl_filter *f = container_of(work, struct cls_fl_filter, work);
239
240 rtnl_lock();
Cong Wang0dadc112017-11-06 13:47:24 -0800241 __fl_destroy_filter(f);
Cong Wang0552c8a2017-10-26 18:24:33 -0700242 rtnl_unlock();
243}
244
Jiri Pirko77b99002015-05-12 14:56:21 +0200245static void fl_destroy_filter(struct rcu_head *head)
246{
247 struct cls_fl_filter *f = container_of(head, struct cls_fl_filter, rcu);
248
Cong Wang0552c8a2017-10-26 18:24:33 -0700249 INIT_WORK(&f->work, fl_destroy_filter_work);
250 tcf_queue_work(&f->work);
Jiri Pirko77b99002015-05-12 14:56:21 +0200251}
252
Jakub Kicinski1b0f8032018-01-24 12:54:21 -0800253static void fl_hw_destroy_filter(struct tcf_proto *tp, struct cls_fl_filter *f,
254 struct netlink_ext_ack *extack)
Amir Vadai5b33f482016-03-08 12:42:29 +0200255{
Jiri Pirkode4784c2017-08-07 10:15:32 +0200256 struct tc_cls_flower_offload cls_flower = {};
Jiri Pirko208c0f42017-10-19 15:50:32 +0200257 struct tcf_block *block = tp->chain->block;
Amir Vadai5b33f482016-03-08 12:42:29 +0200258
Jakub Kicinski1b0f8032018-01-24 12:54:21 -0800259 tc_cls_common_offload_init(&cls_flower.common, tp, f->flags, extack);
Jiri Pirkode4784c2017-08-07 10:15:32 +0200260 cls_flower.command = TC_CLSFLOWER_DESTROY;
261 cls_flower.cookie = (unsigned long) f;
Amir Vadai5b33f482016-03-08 12:42:29 +0200262
Jiri Pirko208c0f42017-10-19 15:50:32 +0200263 tc_setup_cb_call(block, &f->exts, TC_SETUP_CLSFLOWER,
Jiri Pirko717503b2017-10-11 09:41:09 +0200264 &cls_flower, false);
Jiri Pirkocaa72602018-01-17 11:46:50 +0100265 tcf_block_offload_dec(block, &f->flags);
Amir Vadai5b33f482016-03-08 12:42:29 +0200266}
267
Amir Vadaie8eb36c2016-06-13 12:06:39 +0300268static int fl_hw_replace_filter(struct tcf_proto *tp,
Quentin Monnet41002032018-01-19 17:44:43 -0800269 struct cls_fl_filter *f,
270 struct netlink_ext_ack *extack)
Amir Vadai5b33f482016-03-08 12:42:29 +0200271{
Jiri Pirkode4784c2017-08-07 10:15:32 +0200272 struct tc_cls_flower_offload cls_flower = {};
Jiri Pirko208c0f42017-10-19 15:50:32 +0200273 struct tcf_block *block = tp->chain->block;
Jiri Pirko717503b2017-10-11 09:41:09 +0200274 bool skip_sw = tc_skip_sw(f->flags);
Amir Vadaie8eb36c2016-06-13 12:06:39 +0300275 int err;
Amir Vadai5b33f482016-03-08 12:42:29 +0200276
Jakub Kicinskiea205942018-01-24 12:54:20 -0800277 tc_cls_common_offload_init(&cls_flower.common, tp, f->flags, extack);
Jiri Pirkode4784c2017-08-07 10:15:32 +0200278 cls_flower.command = TC_CLSFLOWER_REPLACE;
279 cls_flower.cookie = (unsigned long) f;
Paul Blakey05cd2712018-04-30 14:28:30 +0300280 cls_flower.dissector = &f->mask->dissector;
281 cls_flower.mask = &f->mask->key;
Jiri Pirkode4784c2017-08-07 10:15:32 +0200282 cls_flower.key = &f->mkey;
283 cls_flower.exts = &f->exts;
Amritha Nambiar384c1812017-10-27 02:35:34 -0700284 cls_flower.classid = f->res.classid;
Amir Vadai5b33f482016-03-08 12:42:29 +0200285
Jiri Pirko208c0f42017-10-19 15:50:32 +0200286 err = tc_setup_cb_call(block, &f->exts, TC_SETUP_CLSFLOWER,
Jiri Pirko717503b2017-10-11 09:41:09 +0200287 &cls_flower, skip_sw);
288 if (err < 0) {
Jakub Kicinski1b0f8032018-01-24 12:54:21 -0800289 fl_hw_destroy_filter(tp, f, NULL);
Amir Vadaie8eb36c2016-06-13 12:06:39 +0300290 return err;
Jiri Pirko717503b2017-10-11 09:41:09 +0200291 } else if (err > 0) {
Jiri Pirkocaa72602018-01-17 11:46:50 +0100292 tcf_block_offload_inc(block, &f->flags);
Jiri Pirko717503b2017-10-11 09:41:09 +0200293 }
294
295 if (skip_sw && !(f->flags & TCA_CLS_FLAGS_IN_HW))
296 return -EINVAL;
297
Amir Vadaie8eb36c2016-06-13 12:06:39 +0300298 return 0;
Amir Vadai5b33f482016-03-08 12:42:29 +0200299}
300
Amir Vadai10cbc682016-05-13 12:55:37 +0000301static void fl_hw_update_stats(struct tcf_proto *tp, struct cls_fl_filter *f)
302{
Jiri Pirkode4784c2017-08-07 10:15:32 +0200303 struct tc_cls_flower_offload cls_flower = {};
Jiri Pirko208c0f42017-10-19 15:50:32 +0200304 struct tcf_block *block = tp->chain->block;
Amir Vadai10cbc682016-05-13 12:55:37 +0000305
Jakub Kicinskiea205942018-01-24 12:54:20 -0800306 tc_cls_common_offload_init(&cls_flower.common, tp, f->flags, NULL);
Jiri Pirkode4784c2017-08-07 10:15:32 +0200307 cls_flower.command = TC_CLSFLOWER_STATS;
308 cls_flower.cookie = (unsigned long) f;
309 cls_flower.exts = &f->exts;
Amritha Nambiar384c1812017-10-27 02:35:34 -0700310 cls_flower.classid = f->res.classid;
Amir Vadai10cbc682016-05-13 12:55:37 +0000311
Jiri Pirko208c0f42017-10-19 15:50:32 +0200312 tc_setup_cb_call(block, &f->exts, TC_SETUP_CLSFLOWER,
Jiri Pirko717503b2017-10-11 09:41:09 +0200313 &cls_flower, false);
Amir Vadai10cbc682016-05-13 12:55:37 +0000314}
315
Paul Blakey05cd2712018-04-30 14:28:30 +0300316static bool __fl_delete(struct tcf_proto *tp, struct cls_fl_filter *f,
Jakub Kicinski1b0f8032018-01-24 12:54:21 -0800317 struct netlink_ext_ack *extack)
Roi Dayan13fa8762016-11-01 16:08:29 +0200318{
Chris Mic15ab232017-08-30 02:31:58 -0400319 struct cls_fl_head *head = rtnl_dereference(tp->root);
Paul Blakey05cd2712018-04-30 14:28:30 +0300320 bool async = tcf_exts_get_net(&f->exts);
321 bool last;
Chris Mic15ab232017-08-30 02:31:58 -0400322
Matthew Wilcox9c160942017-11-28 09:48:43 -0500323 idr_remove(&head->handle_idr, f->handle);
Roi Dayan13fa8762016-11-01 16:08:29 +0200324 list_del_rcu(&f->list);
Paul Blakey05cd2712018-04-30 14:28:30 +0300325 last = fl_mask_put(head, f->mask, async);
Hadar Hen Zion79685212016-12-01 14:06:34 +0200326 if (!tc_skip_hw(f->flags))
Jakub Kicinski1b0f8032018-01-24 12:54:21 -0800327 fl_hw_destroy_filter(tp, f, extack);
Roi Dayan13fa8762016-11-01 16:08:29 +0200328 tcf_unbind_filter(tp, &f->res);
Paul Blakey05cd2712018-04-30 14:28:30 +0300329 if (async)
Cong Wang0dadc112017-11-06 13:47:24 -0800330 call_rcu(&f->rcu, fl_destroy_filter);
331 else
332 __fl_destroy_filter(f);
Paul Blakey05cd2712018-04-30 14:28:30 +0300333
334 return last;
Roi Dayan13fa8762016-11-01 16:08:29 +0200335}
336
Daniel Borkmannd9363772016-11-27 01:18:01 +0100337static void fl_destroy_sleepable(struct work_struct *work)
338{
339 struct cls_fl_head *head = container_of(work, struct cls_fl_head,
340 work);
Daniel Borkmannd9363772016-11-27 01:18:01 +0100341 kfree(head);
342 module_put(THIS_MODULE);
343}
344
345static void fl_destroy_rcu(struct rcu_head *rcu)
346{
347 struct cls_fl_head *head = container_of(rcu, struct cls_fl_head, rcu);
348
349 INIT_WORK(&head->work, fl_destroy_sleepable);
350 schedule_work(&head->work);
351}
352
Jakub Kicinski715df5e2018-01-24 12:54:13 -0800353static void fl_destroy(struct tcf_proto *tp, struct netlink_ext_ack *extack)
Jiri Pirko77b99002015-05-12 14:56:21 +0200354{
355 struct cls_fl_head *head = rtnl_dereference(tp->root);
Paul Blakey05cd2712018-04-30 14:28:30 +0300356 struct fl_flow_mask *mask, *next_mask;
Jiri Pirko77b99002015-05-12 14:56:21 +0200357 struct cls_fl_filter *f, *next;
358
Paul Blakey05cd2712018-04-30 14:28:30 +0300359 list_for_each_entry_safe(mask, next_mask, &head->masks, list) {
360 list_for_each_entry_safe(f, next, &mask->filters, list) {
361 if (__fl_delete(tp, f, extack))
362 break;
363 }
364 }
Chris Mic15ab232017-08-30 02:31:58 -0400365 idr_destroy(&head->handle_idr);
Daniel Borkmannd9363772016-11-27 01:18:01 +0100366
367 __module_get(THIS_MODULE);
368 call_rcu(&head->rcu, fl_destroy_rcu);
Jiri Pirko77b99002015-05-12 14:56:21 +0200369}
370
WANG Cong8113c092017-08-04 21:31:43 -0700371static void *fl_get(struct tcf_proto *tp, u32 handle)
Jiri Pirko77b99002015-05-12 14:56:21 +0200372{
373 struct cls_fl_head *head = rtnl_dereference(tp->root);
Jiri Pirko77b99002015-05-12 14:56:21 +0200374
Matthew Wilcox322d8842017-11-28 10:01:24 -0500375 return idr_find(&head->handle_idr, handle);
Jiri Pirko77b99002015-05-12 14:56:21 +0200376}
377
378static const struct nla_policy fl_policy[TCA_FLOWER_MAX + 1] = {
379 [TCA_FLOWER_UNSPEC] = { .type = NLA_UNSPEC },
380 [TCA_FLOWER_CLASSID] = { .type = NLA_U32 },
381 [TCA_FLOWER_INDEV] = { .type = NLA_STRING,
382 .len = IFNAMSIZ },
383 [TCA_FLOWER_KEY_ETH_DST] = { .len = ETH_ALEN },
384 [TCA_FLOWER_KEY_ETH_DST_MASK] = { .len = ETH_ALEN },
385 [TCA_FLOWER_KEY_ETH_SRC] = { .len = ETH_ALEN },
386 [TCA_FLOWER_KEY_ETH_SRC_MASK] = { .len = ETH_ALEN },
387 [TCA_FLOWER_KEY_ETH_TYPE] = { .type = NLA_U16 },
388 [TCA_FLOWER_KEY_IP_PROTO] = { .type = NLA_U8 },
389 [TCA_FLOWER_KEY_IPV4_SRC] = { .type = NLA_U32 },
390 [TCA_FLOWER_KEY_IPV4_SRC_MASK] = { .type = NLA_U32 },
391 [TCA_FLOWER_KEY_IPV4_DST] = { .type = NLA_U32 },
392 [TCA_FLOWER_KEY_IPV4_DST_MASK] = { .type = NLA_U32 },
393 [TCA_FLOWER_KEY_IPV6_SRC] = { .len = sizeof(struct in6_addr) },
394 [TCA_FLOWER_KEY_IPV6_SRC_MASK] = { .len = sizeof(struct in6_addr) },
395 [TCA_FLOWER_KEY_IPV6_DST] = { .len = sizeof(struct in6_addr) },
396 [TCA_FLOWER_KEY_IPV6_DST_MASK] = { .len = sizeof(struct in6_addr) },
397 [TCA_FLOWER_KEY_TCP_SRC] = { .type = NLA_U16 },
398 [TCA_FLOWER_KEY_TCP_DST] = { .type = NLA_U16 },
Jamal Hadi Salimb175c3a2015-06-25 06:55:27 -0400399 [TCA_FLOWER_KEY_UDP_SRC] = { .type = NLA_U16 },
400 [TCA_FLOWER_KEY_UDP_DST] = { .type = NLA_U16 },
Hadar Hen Zion9399ae92016-08-17 13:36:13 +0300401 [TCA_FLOWER_KEY_VLAN_ID] = { .type = NLA_U16 },
402 [TCA_FLOWER_KEY_VLAN_PRIO] = { .type = NLA_U8 },
403 [TCA_FLOWER_KEY_VLAN_ETH_TYPE] = { .type = NLA_U16 },
Amir Vadaibc3103f2016-09-08 16:23:47 +0300404 [TCA_FLOWER_KEY_ENC_KEY_ID] = { .type = NLA_U32 },
405 [TCA_FLOWER_KEY_ENC_IPV4_SRC] = { .type = NLA_U32 },
406 [TCA_FLOWER_KEY_ENC_IPV4_SRC_MASK] = { .type = NLA_U32 },
407 [TCA_FLOWER_KEY_ENC_IPV4_DST] = { .type = NLA_U32 },
408 [TCA_FLOWER_KEY_ENC_IPV4_DST_MASK] = { .type = NLA_U32 },
409 [TCA_FLOWER_KEY_ENC_IPV6_SRC] = { .len = sizeof(struct in6_addr) },
410 [TCA_FLOWER_KEY_ENC_IPV6_SRC_MASK] = { .len = sizeof(struct in6_addr) },
411 [TCA_FLOWER_KEY_ENC_IPV6_DST] = { .len = sizeof(struct in6_addr) },
412 [TCA_FLOWER_KEY_ENC_IPV6_DST_MASK] = { .len = sizeof(struct in6_addr) },
Or Gerlitzaa72d702016-09-15 15:28:22 +0300413 [TCA_FLOWER_KEY_TCP_SRC_MASK] = { .type = NLA_U16 },
414 [TCA_FLOWER_KEY_TCP_DST_MASK] = { .type = NLA_U16 },
415 [TCA_FLOWER_KEY_UDP_SRC_MASK] = { .type = NLA_U16 },
416 [TCA_FLOWER_KEY_UDP_DST_MASK] = { .type = NLA_U16 },
Simon Horman5976c5f2016-11-03 13:24:21 +0100417 [TCA_FLOWER_KEY_SCTP_SRC_MASK] = { .type = NLA_U16 },
418 [TCA_FLOWER_KEY_SCTP_DST_MASK] = { .type = NLA_U16 },
419 [TCA_FLOWER_KEY_SCTP_SRC] = { .type = NLA_U16 },
420 [TCA_FLOWER_KEY_SCTP_DST] = { .type = NLA_U16 },
Hadar Hen Zionf4d997f2016-11-07 15:14:39 +0200421 [TCA_FLOWER_KEY_ENC_UDP_SRC_PORT] = { .type = NLA_U16 },
422 [TCA_FLOWER_KEY_ENC_UDP_SRC_PORT_MASK] = { .type = NLA_U16 },
423 [TCA_FLOWER_KEY_ENC_UDP_DST_PORT] = { .type = NLA_U16 },
424 [TCA_FLOWER_KEY_ENC_UDP_DST_PORT_MASK] = { .type = NLA_U16 },
Or Gerlitzfaa3ffc2016-12-07 14:03:10 +0200425 [TCA_FLOWER_KEY_FLAGS] = { .type = NLA_U32 },
426 [TCA_FLOWER_KEY_FLAGS_MASK] = { .type = NLA_U32 },
Simon Horman7b684882016-12-07 13:48:28 +0100427 [TCA_FLOWER_KEY_ICMPV4_TYPE] = { .type = NLA_U8 },
428 [TCA_FLOWER_KEY_ICMPV4_TYPE_MASK] = { .type = NLA_U8 },
429 [TCA_FLOWER_KEY_ICMPV4_CODE] = { .type = NLA_U8 },
430 [TCA_FLOWER_KEY_ICMPV4_CODE_MASK] = { .type = NLA_U8 },
431 [TCA_FLOWER_KEY_ICMPV6_TYPE] = { .type = NLA_U8 },
432 [TCA_FLOWER_KEY_ICMPV6_TYPE_MASK] = { .type = NLA_U8 },
433 [TCA_FLOWER_KEY_ICMPV6_CODE] = { .type = NLA_U8 },
434 [TCA_FLOWER_KEY_ICMPV6_CODE_MASK] = { .type = NLA_U8 },
Simon Horman99d31322017-01-11 14:05:43 +0100435 [TCA_FLOWER_KEY_ARP_SIP] = { .type = NLA_U32 },
436 [TCA_FLOWER_KEY_ARP_SIP_MASK] = { .type = NLA_U32 },
437 [TCA_FLOWER_KEY_ARP_TIP] = { .type = NLA_U32 },
438 [TCA_FLOWER_KEY_ARP_TIP_MASK] = { .type = NLA_U32 },
439 [TCA_FLOWER_KEY_ARP_OP] = { .type = NLA_U8 },
440 [TCA_FLOWER_KEY_ARP_OP_MASK] = { .type = NLA_U8 },
441 [TCA_FLOWER_KEY_ARP_SHA] = { .len = ETH_ALEN },
442 [TCA_FLOWER_KEY_ARP_SHA_MASK] = { .len = ETH_ALEN },
443 [TCA_FLOWER_KEY_ARP_THA] = { .len = ETH_ALEN },
444 [TCA_FLOWER_KEY_ARP_THA_MASK] = { .len = ETH_ALEN },
Benjamin LaHaisea577d8f2017-04-22 16:52:47 -0400445 [TCA_FLOWER_KEY_MPLS_TTL] = { .type = NLA_U8 },
446 [TCA_FLOWER_KEY_MPLS_BOS] = { .type = NLA_U8 },
447 [TCA_FLOWER_KEY_MPLS_TC] = { .type = NLA_U8 },
448 [TCA_FLOWER_KEY_MPLS_LABEL] = { .type = NLA_U32 },
Jiri Pirkofdfc7dd2017-05-23 18:40:45 +0200449 [TCA_FLOWER_KEY_TCP_FLAGS] = { .type = NLA_U16 },
450 [TCA_FLOWER_KEY_TCP_FLAGS_MASK] = { .type = NLA_U16 },
Or Gerlitz4d80cc02017-06-01 21:37:38 +0300451 [TCA_FLOWER_KEY_IP_TOS] = { .type = NLA_U8 },
452 [TCA_FLOWER_KEY_IP_TOS_MASK] = { .type = NLA_U8 },
453 [TCA_FLOWER_KEY_IP_TTL] = { .type = NLA_U8 },
454 [TCA_FLOWER_KEY_IP_TTL_MASK] = { .type = NLA_U8 },
Jiri Pirko77b99002015-05-12 14:56:21 +0200455};
456
457static void fl_set_key_val(struct nlattr **tb,
458 void *val, int val_type,
459 void *mask, int mask_type, int len)
460{
461 if (!tb[val_type])
462 return;
463 memcpy(val, nla_data(tb[val_type]), len);
464 if (mask_type == TCA_FLOWER_UNSPEC || !tb[mask_type])
465 memset(mask, 0xff, len);
466 else
467 memcpy(mask, nla_data(tb[mask_type]), len);
468}
469
Benjamin LaHaise1a7fca62017-05-01 09:58:40 -0400470static int fl_set_key_mpls(struct nlattr **tb,
471 struct flow_dissector_key_mpls *key_val,
472 struct flow_dissector_key_mpls *key_mask)
Benjamin LaHaisea577d8f2017-04-22 16:52:47 -0400473{
474 if (tb[TCA_FLOWER_KEY_MPLS_TTL]) {
475 key_val->mpls_ttl = nla_get_u8(tb[TCA_FLOWER_KEY_MPLS_TTL]);
476 key_mask->mpls_ttl = MPLS_TTL_MASK;
477 }
478 if (tb[TCA_FLOWER_KEY_MPLS_BOS]) {
Benjamin LaHaise1a7fca62017-05-01 09:58:40 -0400479 u8 bos = nla_get_u8(tb[TCA_FLOWER_KEY_MPLS_BOS]);
480
481 if (bos & ~MPLS_BOS_MASK)
482 return -EINVAL;
483 key_val->mpls_bos = bos;
Benjamin LaHaisea577d8f2017-04-22 16:52:47 -0400484 key_mask->mpls_bos = MPLS_BOS_MASK;
485 }
486 if (tb[TCA_FLOWER_KEY_MPLS_TC]) {
Benjamin LaHaise1a7fca62017-05-01 09:58:40 -0400487 u8 tc = nla_get_u8(tb[TCA_FLOWER_KEY_MPLS_TC]);
488
489 if (tc & ~MPLS_TC_MASK)
490 return -EINVAL;
491 key_val->mpls_tc = tc;
Benjamin LaHaisea577d8f2017-04-22 16:52:47 -0400492 key_mask->mpls_tc = MPLS_TC_MASK;
493 }
494 if (tb[TCA_FLOWER_KEY_MPLS_LABEL]) {
Benjamin LaHaise1a7fca62017-05-01 09:58:40 -0400495 u32 label = nla_get_u32(tb[TCA_FLOWER_KEY_MPLS_LABEL]);
496
497 if (label & ~MPLS_LABEL_MASK)
498 return -EINVAL;
499 key_val->mpls_label = label;
Benjamin LaHaisea577d8f2017-04-22 16:52:47 -0400500 key_mask->mpls_label = MPLS_LABEL_MASK;
501 }
Benjamin LaHaise1a7fca62017-05-01 09:58:40 -0400502 return 0;
Benjamin LaHaisea577d8f2017-04-22 16:52:47 -0400503}
504
Hadar Hen Zion9399ae92016-08-17 13:36:13 +0300505static void fl_set_key_vlan(struct nlattr **tb,
506 struct flow_dissector_key_vlan *key_val,
507 struct flow_dissector_key_vlan *key_mask)
508{
509#define VLAN_PRIORITY_MASK 0x7
510
511 if (tb[TCA_FLOWER_KEY_VLAN_ID]) {
512 key_val->vlan_id =
513 nla_get_u16(tb[TCA_FLOWER_KEY_VLAN_ID]) & VLAN_VID_MASK;
514 key_mask->vlan_id = VLAN_VID_MASK;
515 }
516 if (tb[TCA_FLOWER_KEY_VLAN_PRIO]) {
517 key_val->vlan_priority =
518 nla_get_u8(tb[TCA_FLOWER_KEY_VLAN_PRIO]) &
519 VLAN_PRIORITY_MASK;
520 key_mask->vlan_priority = VLAN_PRIORITY_MASK;
521 }
522}
523
Or Gerlitzfaa3ffc2016-12-07 14:03:10 +0200524static void fl_set_key_flag(u32 flower_key, u32 flower_mask,
525 u32 *dissector_key, u32 *dissector_mask,
526 u32 flower_flag_bit, u32 dissector_flag_bit)
527{
528 if (flower_mask & flower_flag_bit) {
529 *dissector_mask |= dissector_flag_bit;
530 if (flower_key & flower_flag_bit)
531 *dissector_key |= dissector_flag_bit;
532 }
533}
534
Or Gerlitzd9724772016-12-22 14:28:15 +0200535static int fl_set_key_flags(struct nlattr **tb,
536 u32 *flags_key, u32 *flags_mask)
Or Gerlitzfaa3ffc2016-12-07 14:03:10 +0200537{
538 u32 key, mask;
539
Or Gerlitzd9724772016-12-22 14:28:15 +0200540 /* mask is mandatory for flags */
541 if (!tb[TCA_FLOWER_KEY_FLAGS_MASK])
542 return -EINVAL;
Or Gerlitzfaa3ffc2016-12-07 14:03:10 +0200543
544 key = be32_to_cpu(nla_get_u32(tb[TCA_FLOWER_KEY_FLAGS]));
Or Gerlitzd9724772016-12-22 14:28:15 +0200545 mask = be32_to_cpu(nla_get_u32(tb[TCA_FLOWER_KEY_FLAGS_MASK]));
Or Gerlitzfaa3ffc2016-12-07 14:03:10 +0200546
547 *flags_key = 0;
548 *flags_mask = 0;
549
550 fl_set_key_flag(key, mask, flags_key, flags_mask,
551 TCA_FLOWER_KEY_FLAGS_IS_FRAGMENT, FLOW_DIS_IS_FRAGMENT);
Pieter Jansen van Vuuren459d1532018-03-06 18:11:14 +0100552 fl_set_key_flag(key, mask, flags_key, flags_mask,
553 TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST,
554 FLOW_DIS_FIRST_FRAG);
Or Gerlitzd9724772016-12-22 14:28:15 +0200555
556 return 0;
Or Gerlitzfaa3ffc2016-12-07 14:03:10 +0200557}
558
Or Gerlitz4d80cc02017-06-01 21:37:38 +0300559static void fl_set_key_ip(struct nlattr **tb,
560 struct flow_dissector_key_ip *key,
561 struct flow_dissector_key_ip *mask)
562{
563 fl_set_key_val(tb, &key->tos, TCA_FLOWER_KEY_IP_TOS,
564 &mask->tos, TCA_FLOWER_KEY_IP_TOS_MASK,
565 sizeof(key->tos));
566
567 fl_set_key_val(tb, &key->ttl, TCA_FLOWER_KEY_IP_TTL,
568 &mask->ttl, TCA_FLOWER_KEY_IP_TTL_MASK,
569 sizeof(key->ttl));
570}
571
Jiri Pirko77b99002015-05-12 14:56:21 +0200572static int fl_set_key(struct net *net, struct nlattr **tb,
Alexander Aring1057c552018-01-18 11:20:54 -0500573 struct fl_flow_key *key, struct fl_flow_key *mask,
574 struct netlink_ext_ack *extack)
Jiri Pirko77b99002015-05-12 14:56:21 +0200575{
Hadar Hen Zion9399ae92016-08-17 13:36:13 +0300576 __be16 ethertype;
Or Gerlitzd9724772016-12-22 14:28:15 +0200577 int ret = 0;
Brian Haleydd3aa3b2015-05-14 13:20:15 -0400578#ifdef CONFIG_NET_CLS_IND
Jiri Pirko77b99002015-05-12 14:56:21 +0200579 if (tb[TCA_FLOWER_INDEV]) {
Alexander Aring1057c552018-01-18 11:20:54 -0500580 int err = tcf_change_indev(net, tb[TCA_FLOWER_INDEV], extack);
Jiri Pirko77b99002015-05-12 14:56:21 +0200581 if (err < 0)
582 return err;
583 key->indev_ifindex = err;
584 mask->indev_ifindex = 0xffffffff;
585 }
Brian Haleydd3aa3b2015-05-14 13:20:15 -0400586#endif
Jiri Pirko77b99002015-05-12 14:56:21 +0200587
588 fl_set_key_val(tb, key->eth.dst, TCA_FLOWER_KEY_ETH_DST,
589 mask->eth.dst, TCA_FLOWER_KEY_ETH_DST_MASK,
590 sizeof(key->eth.dst));
591 fl_set_key_val(tb, key->eth.src, TCA_FLOWER_KEY_ETH_SRC,
592 mask->eth.src, TCA_FLOWER_KEY_ETH_SRC_MASK,
593 sizeof(key->eth.src));
Jamal Hadi Salim66530bd2016-01-10 11:47:01 -0500594
Arnd Bergmann0b498a52016-08-26 17:25:45 +0200595 if (tb[TCA_FLOWER_KEY_ETH_TYPE]) {
Hadar Hen Zion9399ae92016-08-17 13:36:13 +0300596 ethertype = nla_get_be16(tb[TCA_FLOWER_KEY_ETH_TYPE]);
597
Arnd Bergmann0b498a52016-08-26 17:25:45 +0200598 if (ethertype == htons(ETH_P_8021Q)) {
599 fl_set_key_vlan(tb, &key->vlan, &mask->vlan);
600 fl_set_key_val(tb, &key->basic.n_proto,
601 TCA_FLOWER_KEY_VLAN_ETH_TYPE,
602 &mask->basic.n_proto, TCA_FLOWER_UNSPEC,
603 sizeof(key->basic.n_proto));
604 } else {
605 key->basic.n_proto = ethertype;
606 mask->basic.n_proto = cpu_to_be16(~0);
607 }
Hadar Hen Zion9399ae92016-08-17 13:36:13 +0300608 }
Jamal Hadi Salim66530bd2016-01-10 11:47:01 -0500609
Jiri Pirko77b99002015-05-12 14:56:21 +0200610 if (key->basic.n_proto == htons(ETH_P_IP) ||
611 key->basic.n_proto == htons(ETH_P_IPV6)) {
612 fl_set_key_val(tb, &key->basic.ip_proto, TCA_FLOWER_KEY_IP_PROTO,
613 &mask->basic.ip_proto, TCA_FLOWER_UNSPEC,
614 sizeof(key->basic.ip_proto));
Or Gerlitz4d80cc02017-06-01 21:37:38 +0300615 fl_set_key_ip(tb, &key->ip, &mask->ip);
Jiri Pirko77b99002015-05-12 14:56:21 +0200616 }
Jamal Hadi Salim66530bd2016-01-10 11:47:01 -0500617
618 if (tb[TCA_FLOWER_KEY_IPV4_SRC] || tb[TCA_FLOWER_KEY_IPV4_DST]) {
619 key->control.addr_type = FLOW_DISSECTOR_KEY_IPV4_ADDRS;
Paul Blakey970bfcd2016-12-14 19:00:57 +0200620 mask->control.addr_type = ~0;
Jiri Pirko77b99002015-05-12 14:56:21 +0200621 fl_set_key_val(tb, &key->ipv4.src, TCA_FLOWER_KEY_IPV4_SRC,
622 &mask->ipv4.src, TCA_FLOWER_KEY_IPV4_SRC_MASK,
623 sizeof(key->ipv4.src));
624 fl_set_key_val(tb, &key->ipv4.dst, TCA_FLOWER_KEY_IPV4_DST,
625 &mask->ipv4.dst, TCA_FLOWER_KEY_IPV4_DST_MASK,
626 sizeof(key->ipv4.dst));
Jamal Hadi Salim66530bd2016-01-10 11:47:01 -0500627 } else if (tb[TCA_FLOWER_KEY_IPV6_SRC] || tb[TCA_FLOWER_KEY_IPV6_DST]) {
628 key->control.addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS;
Paul Blakey970bfcd2016-12-14 19:00:57 +0200629 mask->control.addr_type = ~0;
Jiri Pirko77b99002015-05-12 14:56:21 +0200630 fl_set_key_val(tb, &key->ipv6.src, TCA_FLOWER_KEY_IPV6_SRC,
631 &mask->ipv6.src, TCA_FLOWER_KEY_IPV6_SRC_MASK,
632 sizeof(key->ipv6.src));
633 fl_set_key_val(tb, &key->ipv6.dst, TCA_FLOWER_KEY_IPV6_DST,
634 &mask->ipv6.dst, TCA_FLOWER_KEY_IPV6_DST_MASK,
635 sizeof(key->ipv6.dst));
636 }
Jamal Hadi Salim66530bd2016-01-10 11:47:01 -0500637
Jiri Pirko77b99002015-05-12 14:56:21 +0200638 if (key->basic.ip_proto == IPPROTO_TCP) {
639 fl_set_key_val(tb, &key->tp.src, TCA_FLOWER_KEY_TCP_SRC,
Or Gerlitzaa72d702016-09-15 15:28:22 +0300640 &mask->tp.src, TCA_FLOWER_KEY_TCP_SRC_MASK,
Jiri Pirko77b99002015-05-12 14:56:21 +0200641 sizeof(key->tp.src));
642 fl_set_key_val(tb, &key->tp.dst, TCA_FLOWER_KEY_TCP_DST,
Or Gerlitzaa72d702016-09-15 15:28:22 +0300643 &mask->tp.dst, TCA_FLOWER_KEY_TCP_DST_MASK,
Jiri Pirko77b99002015-05-12 14:56:21 +0200644 sizeof(key->tp.dst));
Jiri Pirkofdfc7dd2017-05-23 18:40:45 +0200645 fl_set_key_val(tb, &key->tcp.flags, TCA_FLOWER_KEY_TCP_FLAGS,
646 &mask->tcp.flags, TCA_FLOWER_KEY_TCP_FLAGS_MASK,
647 sizeof(key->tcp.flags));
Jiri Pirko77b99002015-05-12 14:56:21 +0200648 } else if (key->basic.ip_proto == IPPROTO_UDP) {
649 fl_set_key_val(tb, &key->tp.src, TCA_FLOWER_KEY_UDP_SRC,
Or Gerlitzaa72d702016-09-15 15:28:22 +0300650 &mask->tp.src, TCA_FLOWER_KEY_UDP_SRC_MASK,
Jiri Pirko77b99002015-05-12 14:56:21 +0200651 sizeof(key->tp.src));
652 fl_set_key_val(tb, &key->tp.dst, TCA_FLOWER_KEY_UDP_DST,
Or Gerlitzaa72d702016-09-15 15:28:22 +0300653 &mask->tp.dst, TCA_FLOWER_KEY_UDP_DST_MASK,
Jiri Pirko77b99002015-05-12 14:56:21 +0200654 sizeof(key->tp.dst));
Simon Horman5976c5f2016-11-03 13:24:21 +0100655 } else if (key->basic.ip_proto == IPPROTO_SCTP) {
656 fl_set_key_val(tb, &key->tp.src, TCA_FLOWER_KEY_SCTP_SRC,
657 &mask->tp.src, TCA_FLOWER_KEY_SCTP_SRC_MASK,
658 sizeof(key->tp.src));
659 fl_set_key_val(tb, &key->tp.dst, TCA_FLOWER_KEY_SCTP_DST,
660 &mask->tp.dst, TCA_FLOWER_KEY_SCTP_DST_MASK,
661 sizeof(key->tp.dst));
Simon Horman7b684882016-12-07 13:48:28 +0100662 } else if (key->basic.n_proto == htons(ETH_P_IP) &&
663 key->basic.ip_proto == IPPROTO_ICMP) {
664 fl_set_key_val(tb, &key->icmp.type, TCA_FLOWER_KEY_ICMPV4_TYPE,
665 &mask->icmp.type,
666 TCA_FLOWER_KEY_ICMPV4_TYPE_MASK,
667 sizeof(key->icmp.type));
668 fl_set_key_val(tb, &key->icmp.code, TCA_FLOWER_KEY_ICMPV4_CODE,
669 &mask->icmp.code,
670 TCA_FLOWER_KEY_ICMPV4_CODE_MASK,
671 sizeof(key->icmp.code));
672 } else if (key->basic.n_proto == htons(ETH_P_IPV6) &&
673 key->basic.ip_proto == IPPROTO_ICMPV6) {
674 fl_set_key_val(tb, &key->icmp.type, TCA_FLOWER_KEY_ICMPV6_TYPE,
675 &mask->icmp.type,
676 TCA_FLOWER_KEY_ICMPV6_TYPE_MASK,
677 sizeof(key->icmp.type));
Simon Horman040587a2017-01-30 16:19:02 +0100678 fl_set_key_val(tb, &key->icmp.code, TCA_FLOWER_KEY_ICMPV6_CODE,
Simon Horman7b684882016-12-07 13:48:28 +0100679 &mask->icmp.code,
Simon Horman040587a2017-01-30 16:19:02 +0100680 TCA_FLOWER_KEY_ICMPV6_CODE_MASK,
Simon Horman7b684882016-12-07 13:48:28 +0100681 sizeof(key->icmp.code));
Benjamin LaHaisea577d8f2017-04-22 16:52:47 -0400682 } else if (key->basic.n_proto == htons(ETH_P_MPLS_UC) ||
683 key->basic.n_proto == htons(ETH_P_MPLS_MC)) {
Benjamin LaHaise1a7fca62017-05-01 09:58:40 -0400684 ret = fl_set_key_mpls(tb, &key->mpls, &mask->mpls);
685 if (ret)
686 return ret;
Simon Horman99d31322017-01-11 14:05:43 +0100687 } else if (key->basic.n_proto == htons(ETH_P_ARP) ||
688 key->basic.n_proto == htons(ETH_P_RARP)) {
689 fl_set_key_val(tb, &key->arp.sip, TCA_FLOWER_KEY_ARP_SIP,
690 &mask->arp.sip, TCA_FLOWER_KEY_ARP_SIP_MASK,
691 sizeof(key->arp.sip));
692 fl_set_key_val(tb, &key->arp.tip, TCA_FLOWER_KEY_ARP_TIP,
693 &mask->arp.tip, TCA_FLOWER_KEY_ARP_TIP_MASK,
694 sizeof(key->arp.tip));
695 fl_set_key_val(tb, &key->arp.op, TCA_FLOWER_KEY_ARP_OP,
696 &mask->arp.op, TCA_FLOWER_KEY_ARP_OP_MASK,
697 sizeof(key->arp.op));
698 fl_set_key_val(tb, key->arp.sha, TCA_FLOWER_KEY_ARP_SHA,
699 mask->arp.sha, TCA_FLOWER_KEY_ARP_SHA_MASK,
700 sizeof(key->arp.sha));
701 fl_set_key_val(tb, key->arp.tha, TCA_FLOWER_KEY_ARP_THA,
702 mask->arp.tha, TCA_FLOWER_KEY_ARP_THA_MASK,
703 sizeof(key->arp.tha));
Jiri Pirko77b99002015-05-12 14:56:21 +0200704 }
705
Amir Vadaibc3103f2016-09-08 16:23:47 +0300706 if (tb[TCA_FLOWER_KEY_ENC_IPV4_SRC] ||
707 tb[TCA_FLOWER_KEY_ENC_IPV4_DST]) {
708 key->enc_control.addr_type = FLOW_DISSECTOR_KEY_IPV4_ADDRS;
Paul Blakey970bfcd2016-12-14 19:00:57 +0200709 mask->enc_control.addr_type = ~0;
Amir Vadaibc3103f2016-09-08 16:23:47 +0300710 fl_set_key_val(tb, &key->enc_ipv4.src,
711 TCA_FLOWER_KEY_ENC_IPV4_SRC,
712 &mask->enc_ipv4.src,
713 TCA_FLOWER_KEY_ENC_IPV4_SRC_MASK,
714 sizeof(key->enc_ipv4.src));
715 fl_set_key_val(tb, &key->enc_ipv4.dst,
716 TCA_FLOWER_KEY_ENC_IPV4_DST,
717 &mask->enc_ipv4.dst,
718 TCA_FLOWER_KEY_ENC_IPV4_DST_MASK,
719 sizeof(key->enc_ipv4.dst));
720 }
721
722 if (tb[TCA_FLOWER_KEY_ENC_IPV6_SRC] ||
723 tb[TCA_FLOWER_KEY_ENC_IPV6_DST]) {
724 key->enc_control.addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS;
Paul Blakey970bfcd2016-12-14 19:00:57 +0200725 mask->enc_control.addr_type = ~0;
Amir Vadaibc3103f2016-09-08 16:23:47 +0300726 fl_set_key_val(tb, &key->enc_ipv6.src,
727 TCA_FLOWER_KEY_ENC_IPV6_SRC,
728 &mask->enc_ipv6.src,
729 TCA_FLOWER_KEY_ENC_IPV6_SRC_MASK,
730 sizeof(key->enc_ipv6.src));
731 fl_set_key_val(tb, &key->enc_ipv6.dst,
732 TCA_FLOWER_KEY_ENC_IPV6_DST,
733 &mask->enc_ipv6.dst,
734 TCA_FLOWER_KEY_ENC_IPV6_DST_MASK,
735 sizeof(key->enc_ipv6.dst));
736 }
737
738 fl_set_key_val(tb, &key->enc_key_id.keyid, TCA_FLOWER_KEY_ENC_KEY_ID,
Hadar Hen Zioneb523f42016-09-27 11:21:18 +0300739 &mask->enc_key_id.keyid, TCA_FLOWER_UNSPEC,
Amir Vadaibc3103f2016-09-08 16:23:47 +0300740 sizeof(key->enc_key_id.keyid));
741
Hadar Hen Zionf4d997f2016-11-07 15:14:39 +0200742 fl_set_key_val(tb, &key->enc_tp.src, TCA_FLOWER_KEY_ENC_UDP_SRC_PORT,
743 &mask->enc_tp.src, TCA_FLOWER_KEY_ENC_UDP_SRC_PORT_MASK,
744 sizeof(key->enc_tp.src));
745
746 fl_set_key_val(tb, &key->enc_tp.dst, TCA_FLOWER_KEY_ENC_UDP_DST_PORT,
747 &mask->enc_tp.dst, TCA_FLOWER_KEY_ENC_UDP_DST_PORT_MASK,
748 sizeof(key->enc_tp.dst));
749
Or Gerlitzd9724772016-12-22 14:28:15 +0200750 if (tb[TCA_FLOWER_KEY_FLAGS])
751 ret = fl_set_key_flags(tb, &key->control.flags, &mask->control.flags);
Or Gerlitzfaa3ffc2016-12-07 14:03:10 +0200752
Or Gerlitzd9724772016-12-22 14:28:15 +0200753 return ret;
Jiri Pirko77b99002015-05-12 14:56:21 +0200754}
755
Paul Blakey05cd2712018-04-30 14:28:30 +0300756static void fl_mask_copy(struct fl_flow_mask *dst,
757 struct fl_flow_mask *src)
Jiri Pirko77b99002015-05-12 14:56:21 +0200758{
Paul Blakey05cd2712018-04-30 14:28:30 +0300759 const void *psrc = fl_key_get_start(&src->key, src);
760 void *pdst = fl_key_get_start(&dst->key, src);
Jiri Pirko77b99002015-05-12 14:56:21 +0200761
Paul Blakey05cd2712018-04-30 14:28:30 +0300762 memcpy(pdst, psrc, fl_mask_range(src));
763 dst->range = src->range;
Jiri Pirko77b99002015-05-12 14:56:21 +0200764}
765
766static const struct rhashtable_params fl_ht_params = {
767 .key_offset = offsetof(struct cls_fl_filter, mkey), /* base offset */
768 .head_offset = offsetof(struct cls_fl_filter, ht_node),
769 .automatic_shrinking = true,
770};
771
Paul Blakey05cd2712018-04-30 14:28:30 +0300772static int fl_init_mask_hashtable(struct fl_flow_mask *mask)
Jiri Pirko77b99002015-05-12 14:56:21 +0200773{
Paul Blakey05cd2712018-04-30 14:28:30 +0300774 mask->filter_ht_params = fl_ht_params;
775 mask->filter_ht_params.key_len = fl_mask_range(mask);
776 mask->filter_ht_params.key_offset += mask->range.start;
Jiri Pirko77b99002015-05-12 14:56:21 +0200777
Paul Blakey05cd2712018-04-30 14:28:30 +0300778 return rhashtable_init(&mask->ht, &mask->filter_ht_params);
Jiri Pirko77b99002015-05-12 14:56:21 +0200779}
780
781#define FL_KEY_MEMBER_OFFSET(member) offsetof(struct fl_flow_key, member)
782#define FL_KEY_MEMBER_SIZE(member) (sizeof(((struct fl_flow_key *) 0)->member))
Jiri Pirko77b99002015-05-12 14:56:21 +0200783
Hadar Hen Zion339ba872016-08-17 13:36:12 +0300784#define FL_KEY_IS_MASKED(mask, member) \
785 memchr_inv(((char *)mask) + FL_KEY_MEMBER_OFFSET(member), \
786 0, FL_KEY_MEMBER_SIZE(member)) \
Jiri Pirko77b99002015-05-12 14:56:21 +0200787
788#define FL_KEY_SET(keys, cnt, id, member) \
789 do { \
790 keys[cnt].key_id = id; \
791 keys[cnt].offset = FL_KEY_MEMBER_OFFSET(member); \
792 cnt++; \
793 } while(0);
794
Hadar Hen Zion339ba872016-08-17 13:36:12 +0300795#define FL_KEY_SET_IF_MASKED(mask, keys, cnt, id, member) \
Jiri Pirko77b99002015-05-12 14:56:21 +0200796 do { \
Hadar Hen Zion339ba872016-08-17 13:36:12 +0300797 if (FL_KEY_IS_MASKED(mask, member)) \
Jiri Pirko77b99002015-05-12 14:56:21 +0200798 FL_KEY_SET(keys, cnt, id, member); \
799 } while(0);
800
Paul Blakey05cd2712018-04-30 14:28:30 +0300801static void fl_init_dissector(struct fl_flow_mask *mask)
Jiri Pirko77b99002015-05-12 14:56:21 +0200802{
803 struct flow_dissector_key keys[FLOW_DISSECTOR_KEY_MAX];
804 size_t cnt = 0;
805
Tom Herbert42aecaa2015-06-04 09:16:39 -0700806 FL_KEY_SET(keys, cnt, FLOW_DISSECTOR_KEY_CONTROL, control);
Jiri Pirko77b99002015-05-12 14:56:21 +0200807 FL_KEY_SET(keys, cnt, FLOW_DISSECTOR_KEY_BASIC, basic);
Hadar Hen Zion339ba872016-08-17 13:36:12 +0300808 FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
809 FLOW_DISSECTOR_KEY_ETH_ADDRS, eth);
810 FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
811 FLOW_DISSECTOR_KEY_IPV4_ADDRS, ipv4);
812 FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
813 FLOW_DISSECTOR_KEY_IPV6_ADDRS, ipv6);
814 FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
815 FLOW_DISSECTOR_KEY_PORTS, tp);
Hadar Hen Zion9399ae92016-08-17 13:36:13 +0300816 FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
Or Gerlitz4d80cc02017-06-01 21:37:38 +0300817 FLOW_DISSECTOR_KEY_IP, ip);
818 FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
Jiri Pirkofdfc7dd2017-05-23 18:40:45 +0200819 FLOW_DISSECTOR_KEY_TCP, tcp);
820 FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
Simon Horman7b684882016-12-07 13:48:28 +0100821 FLOW_DISSECTOR_KEY_ICMP, icmp);
822 FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
Simon Horman99d31322017-01-11 14:05:43 +0100823 FLOW_DISSECTOR_KEY_ARP, arp);
824 FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
Benjamin LaHaisea577d8f2017-04-22 16:52:47 -0400825 FLOW_DISSECTOR_KEY_MPLS, mpls);
826 FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
Hadar Hen Zion9399ae92016-08-17 13:36:13 +0300827 FLOW_DISSECTOR_KEY_VLAN, vlan);
Hadar Hen Zion519d1052016-11-07 15:14:38 +0200828 FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
829 FLOW_DISSECTOR_KEY_ENC_KEYID, enc_key_id);
830 FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
831 FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS, enc_ipv4);
832 FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
833 FLOW_DISSECTOR_KEY_ENC_IPV6_ADDRS, enc_ipv6);
834 if (FL_KEY_IS_MASKED(&mask->key, enc_ipv4) ||
835 FL_KEY_IS_MASKED(&mask->key, enc_ipv6))
836 FL_KEY_SET(keys, cnt, FLOW_DISSECTOR_KEY_ENC_CONTROL,
837 enc_control);
Hadar Hen Zionf4d997f2016-11-07 15:14:39 +0200838 FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
839 FLOW_DISSECTOR_KEY_ENC_PORTS, enc_tp);
Jiri Pirko77b99002015-05-12 14:56:21 +0200840
Paul Blakey05cd2712018-04-30 14:28:30 +0300841 skb_flow_dissector_init(&mask->dissector, keys, cnt);
842}
843
844static struct fl_flow_mask *fl_create_new_mask(struct cls_fl_head *head,
845 struct fl_flow_mask *mask)
846{
847 struct fl_flow_mask *newmask;
848 int err;
849
850 newmask = kzalloc(sizeof(*newmask), GFP_KERNEL);
851 if (!newmask)
852 return ERR_PTR(-ENOMEM);
853
854 fl_mask_copy(newmask, mask);
855
856 err = fl_init_mask_hashtable(newmask);
857 if (err)
858 goto errout_free;
859
860 fl_init_dissector(newmask);
861
862 INIT_LIST_HEAD_RCU(&newmask->filters);
863
864 err = rhashtable_insert_fast(&head->ht, &newmask->ht_node,
865 mask_ht_params);
866 if (err)
867 goto errout_destroy;
868
869 list_add_tail_rcu(&newmask->list, &head->masks);
870
871 return newmask;
872
873errout_destroy:
874 rhashtable_destroy(&newmask->ht);
875errout_free:
876 kfree(newmask);
877
878 return ERR_PTR(err);
Jiri Pirko77b99002015-05-12 14:56:21 +0200879}
880
881static int fl_check_assign_mask(struct cls_fl_head *head,
Paul Blakey05cd2712018-04-30 14:28:30 +0300882 struct cls_fl_filter *fnew,
883 struct cls_fl_filter *fold,
Jiri Pirko77b99002015-05-12 14:56:21 +0200884 struct fl_flow_mask *mask)
885{
Paul Blakey05cd2712018-04-30 14:28:30 +0300886 struct fl_flow_mask *newmask;
Jiri Pirko77b99002015-05-12 14:56:21 +0200887
Paul Blakey05cd2712018-04-30 14:28:30 +0300888 fnew->mask = rhashtable_lookup_fast(&head->ht, mask, mask_ht_params);
889 if (!fnew->mask) {
890 if (fold)
Jiri Pirko77b99002015-05-12 14:56:21 +0200891 return -EINVAL;
Paul Blakey05cd2712018-04-30 14:28:30 +0300892
893 newmask = fl_create_new_mask(head, mask);
894 if (IS_ERR(newmask))
895 return PTR_ERR(newmask);
896
897 fnew->mask = newmask;
898 } else if (fold && fold->mask == fnew->mask) {
899 return -EINVAL;
Jiri Pirko77b99002015-05-12 14:56:21 +0200900 }
901
Jiri Pirko77b99002015-05-12 14:56:21 +0200902 return 0;
903}
904
905static int fl_set_parms(struct net *net, struct tcf_proto *tp,
906 struct cls_fl_filter *f, struct fl_flow_mask *mask,
907 unsigned long base, struct nlattr **tb,
Alexander Aring50a56192018-01-18 11:20:52 -0500908 struct nlattr *est, bool ovr,
909 struct netlink_ext_ack *extack)
Jiri Pirko77b99002015-05-12 14:56:21 +0200910{
Jiri Pirko77b99002015-05-12 14:56:21 +0200911 int err;
912
Alexander Aring50a56192018-01-18 11:20:52 -0500913 err = tcf_exts_validate(net, tp, tb, est, &f->exts, ovr, extack);
Jiri Pirko77b99002015-05-12 14:56:21 +0200914 if (err < 0)
915 return err;
916
917 if (tb[TCA_FLOWER_CLASSID]) {
918 f->res.classid = nla_get_u32(tb[TCA_FLOWER_CLASSID]);
919 tcf_bind_filter(tp, &f->res, base);
920 }
921
Alexander Aring1057c552018-01-18 11:20:54 -0500922 err = fl_set_key(net, tb, &f->key, &mask->key, extack);
Jiri Pirko77b99002015-05-12 14:56:21 +0200923 if (err)
Jiri Pirko45507522017-08-04 14:29:06 +0200924 return err;
Jiri Pirko77b99002015-05-12 14:56:21 +0200925
926 fl_mask_update_range(mask);
927 fl_set_masked_key(&f->mkey, &f->key, mask);
928
Jiri Pirko77b99002015-05-12 14:56:21 +0200929 return 0;
Jiri Pirko77b99002015-05-12 14:56:21 +0200930}
931
Jiri Pirko77b99002015-05-12 14:56:21 +0200932static int fl_change(struct net *net, struct sk_buff *in_skb,
933 struct tcf_proto *tp, unsigned long base,
934 u32 handle, struct nlattr **tca,
Alexander Aring7306db32018-01-18 11:20:51 -0500935 void **arg, bool ovr, struct netlink_ext_ack *extack)
Jiri Pirko77b99002015-05-12 14:56:21 +0200936{
937 struct cls_fl_head *head = rtnl_dereference(tp->root);
WANG Cong8113c092017-08-04 21:31:43 -0700938 struct cls_fl_filter *fold = *arg;
Jiri Pirko77b99002015-05-12 14:56:21 +0200939 struct cls_fl_filter *fnew;
Arnd Bergmann39b7b6a2017-01-19 10:45:31 +0100940 struct nlattr **tb;
Jiri Pirko77b99002015-05-12 14:56:21 +0200941 struct fl_flow_mask mask = {};
942 int err;
943
944 if (!tca[TCA_OPTIONS])
945 return -EINVAL;
946
Arnd Bergmann39b7b6a2017-01-19 10:45:31 +0100947 tb = kcalloc(TCA_FLOWER_MAX + 1, sizeof(struct nlattr *), GFP_KERNEL);
948 if (!tb)
949 return -ENOBUFS;
950
Johannes Bergfceb6432017-04-12 14:34:07 +0200951 err = nla_parse_nested(tb, TCA_FLOWER_MAX, tca[TCA_OPTIONS],
952 fl_policy, NULL);
Jiri Pirko77b99002015-05-12 14:56:21 +0200953 if (err < 0)
Arnd Bergmann39b7b6a2017-01-19 10:45:31 +0100954 goto errout_tb;
Jiri Pirko77b99002015-05-12 14:56:21 +0200955
Arnd Bergmann39b7b6a2017-01-19 10:45:31 +0100956 if (fold && handle && fold->handle != handle) {
957 err = -EINVAL;
958 goto errout_tb;
959 }
Jiri Pirko77b99002015-05-12 14:56:21 +0200960
961 fnew = kzalloc(sizeof(*fnew), GFP_KERNEL);
Arnd Bergmann39b7b6a2017-01-19 10:45:31 +0100962 if (!fnew) {
963 err = -ENOBUFS;
964 goto errout_tb;
965 }
Jiri Pirko77b99002015-05-12 14:56:21 +0200966
WANG Congb9a24bb2016-08-19 12:36:54 -0700967 err = tcf_exts_init(&fnew->exts, TCA_FLOWER_ACT, 0);
968 if (err < 0)
969 goto errout;
Jiri Pirko77b99002015-05-12 14:56:21 +0200970
971 if (!handle) {
Matthew Wilcox85bd0432017-11-28 10:53:03 -0500972 handle = 1;
973 err = idr_alloc_u32(&head->handle_idr, fnew, &handle,
974 INT_MAX, GFP_KERNEL);
975 } else if (!fold) {
976 /* user specifies a handle and it doesn't exist */
977 err = idr_alloc_u32(&head->handle_idr, fnew, &handle,
978 handle, GFP_KERNEL);
Jiri Pirko77b99002015-05-12 14:56:21 +0200979 }
Matthew Wilcox85bd0432017-11-28 10:53:03 -0500980 if (err)
981 goto errout;
982 fnew->handle = handle;
Jiri Pirko77b99002015-05-12 14:56:21 +0200983
Amir Vadaie69985c2016-06-05 17:11:18 +0300984 if (tb[TCA_FLOWER_FLAGS]) {
985 fnew->flags = nla_get_u32(tb[TCA_FLOWER_FLAGS]);
986
987 if (!tc_flags_valid(fnew->flags)) {
988 err = -EINVAL;
Cong Wangfe2502e2017-09-20 09:18:45 -0700989 goto errout_idr;
Amir Vadaie69985c2016-06-05 17:11:18 +0300990 }
991 }
Amir Vadai5b33f482016-03-08 12:42:29 +0200992
Alexander Aring50a56192018-01-18 11:20:52 -0500993 err = fl_set_parms(net, tp, fnew, &mask, base, tb, tca[TCA_RATE], ovr,
994 extack);
Jiri Pirko77b99002015-05-12 14:56:21 +0200995 if (err)
Cong Wangfe2502e2017-09-20 09:18:45 -0700996 goto errout_idr;
Jiri Pirko77b99002015-05-12 14:56:21 +0200997
Paul Blakey05cd2712018-04-30 14:28:30 +0300998 err = fl_check_assign_mask(head, fnew, fold, &mask);
Jiri Pirko77b99002015-05-12 14:56:21 +0200999 if (err)
Cong Wangfe2502e2017-09-20 09:18:45 -07001000 goto errout_idr;
Jiri Pirko77b99002015-05-12 14:56:21 +02001001
Amir Vadaie8eb36c2016-06-13 12:06:39 +03001002 if (!tc_skip_sw(fnew->flags)) {
Paul Blakey05cd2712018-04-30 14:28:30 +03001003 if (!fold && fl_lookup(fnew->mask, &fnew->mkey)) {
Paul Blakeya3308d82017-01-16 10:45:13 +02001004 err = -EEXIST;
Paul Blakey05cd2712018-04-30 14:28:30 +03001005 goto errout_mask;
Paul Blakeya3308d82017-01-16 10:45:13 +02001006 }
1007
Paul Blakey05cd2712018-04-30 14:28:30 +03001008 err = rhashtable_insert_fast(&fnew->mask->ht, &fnew->ht_node,
1009 fnew->mask->filter_ht_params);
Amir Vadaie69985c2016-06-05 17:11:18 +03001010 if (err)
Paul Blakey05cd2712018-04-30 14:28:30 +03001011 goto errout_mask;
Amir Vadaie69985c2016-06-05 17:11:18 +03001012 }
Amir Vadai5b33f482016-03-08 12:42:29 +02001013
Hadar Hen Zion79685212016-12-01 14:06:34 +02001014 if (!tc_skip_hw(fnew->flags)) {
Paul Blakey05cd2712018-04-30 14:28:30 +03001015 err = fl_hw_replace_filter(tp, fnew, extack);
Hadar Hen Zion79685212016-12-01 14:06:34 +02001016 if (err)
Paul Blakey05cd2712018-04-30 14:28:30 +03001017 goto errout_mask;
Hadar Hen Zion79685212016-12-01 14:06:34 +02001018 }
Amir Vadai5b33f482016-03-08 12:42:29 +02001019
Or Gerlitz55593962017-02-16 10:31:13 +02001020 if (!tc_in_hw(fnew->flags))
1021 fnew->flags |= TCA_CLS_FLAGS_NOT_IN_HW;
1022
Amir Vadai5b33f482016-03-08 12:42:29 +02001023 if (fold) {
Jiri Pirko725cbb622016-11-28 15:40:13 +01001024 if (!tc_skip_sw(fold->flags))
Paul Blakey05cd2712018-04-30 14:28:30 +03001025 rhashtable_remove_fast(&fold->mask->ht,
1026 &fold->ht_node,
1027 fold->mask->filter_ht_params);
Hadar Hen Zion79685212016-12-01 14:06:34 +02001028 if (!tc_skip_hw(fold->flags))
Jakub Kicinski1b0f8032018-01-24 12:54:21 -08001029 fl_hw_destroy_filter(tp, fold, NULL);
Amir Vadai5b33f482016-03-08 12:42:29 +02001030 }
Jiri Pirko77b99002015-05-12 14:56:21 +02001031
WANG Cong8113c092017-08-04 21:31:43 -07001032 *arg = fnew;
Jiri Pirko77b99002015-05-12 14:56:21 +02001033
1034 if (fold) {
Matthew Wilcox234a4622017-11-28 09:56:36 -05001035 idr_replace(&head->handle_idr, fnew, fnew->handle);
Daniel Borkmannff3532f2015-07-17 22:38:44 +02001036 list_replace_rcu(&fold->list, &fnew->list);
Jiri Pirko77b99002015-05-12 14:56:21 +02001037 tcf_unbind_filter(tp, &fold->res);
Cong Wang0dadc112017-11-06 13:47:24 -08001038 tcf_exts_get_net(&fold->exts);
Jiri Pirko77b99002015-05-12 14:56:21 +02001039 call_rcu(&fold->rcu, fl_destroy_filter);
1040 } else {
Paul Blakey05cd2712018-04-30 14:28:30 +03001041 list_add_tail_rcu(&fnew->list, &fnew->mask->filters);
Jiri Pirko77b99002015-05-12 14:56:21 +02001042 }
1043
Arnd Bergmann39b7b6a2017-01-19 10:45:31 +01001044 kfree(tb);
Jiri Pirko77b99002015-05-12 14:56:21 +02001045 return 0;
1046
Paul Blakey05cd2712018-04-30 14:28:30 +03001047errout_mask:
1048 fl_mask_put(head, fnew->mask, false);
1049
Cong Wangfe2502e2017-09-20 09:18:45 -07001050errout_idr:
1051 if (fnew->handle)
Matthew Wilcox9c160942017-11-28 09:48:43 -05001052 idr_remove(&head->handle_idr, fnew->handle);
Jiri Pirko77b99002015-05-12 14:56:21 +02001053errout:
WANG Congb9a24bb2016-08-19 12:36:54 -07001054 tcf_exts_destroy(&fnew->exts);
Jiri Pirko77b99002015-05-12 14:56:21 +02001055 kfree(fnew);
Arnd Bergmann39b7b6a2017-01-19 10:45:31 +01001056errout_tb:
1057 kfree(tb);
Jiri Pirko77b99002015-05-12 14:56:21 +02001058 return err;
1059}
1060
Alexander Aring571acf22018-01-18 11:20:53 -05001061static int fl_delete(struct tcf_proto *tp, void *arg, bool *last,
1062 struct netlink_ext_ack *extack)
Jiri Pirko77b99002015-05-12 14:56:21 +02001063{
1064 struct cls_fl_head *head = rtnl_dereference(tp->root);
WANG Cong8113c092017-08-04 21:31:43 -07001065 struct cls_fl_filter *f = arg;
Jiri Pirko77b99002015-05-12 14:56:21 +02001066
Jiri Pirko725cbb622016-11-28 15:40:13 +01001067 if (!tc_skip_sw(f->flags))
Paul Blakey05cd2712018-04-30 14:28:30 +03001068 rhashtable_remove_fast(&f->mask->ht, &f->ht_node,
1069 f->mask->filter_ht_params);
Jakub Kicinski1b0f8032018-01-24 12:54:21 -08001070 __fl_delete(tp, f, extack);
Paul Blakey05cd2712018-04-30 14:28:30 +03001071 *last = list_empty(&head->masks);
Jiri Pirko77b99002015-05-12 14:56:21 +02001072 return 0;
1073}
1074
1075static void fl_walk(struct tcf_proto *tp, struct tcf_walker *arg)
1076{
1077 struct cls_fl_head *head = rtnl_dereference(tp->root);
1078 struct cls_fl_filter *f;
Paul Blakey05cd2712018-04-30 14:28:30 +03001079 struct fl_flow_mask *mask;
Jiri Pirko77b99002015-05-12 14:56:21 +02001080
Paul Blakey05cd2712018-04-30 14:28:30 +03001081 list_for_each_entry_rcu(mask, &head->masks, list) {
1082 list_for_each_entry_rcu(f, &mask->filters, list) {
1083 if (arg->count < arg->skip)
1084 goto skip;
1085 if (arg->fn(tp, f, arg) < 0) {
1086 arg->stop = 1;
1087 break;
1088 }
Jiri Pirko77b99002015-05-12 14:56:21 +02001089skip:
Paul Blakey05cd2712018-04-30 14:28:30 +03001090 arg->count++;
1091 }
Jiri Pirko77b99002015-05-12 14:56:21 +02001092 }
1093}
1094
1095static int fl_dump_key_val(struct sk_buff *skb,
1096 void *val, int val_type,
1097 void *mask, int mask_type, int len)
1098{
1099 int err;
1100
1101 if (!memchr_inv(mask, 0, len))
1102 return 0;
1103 err = nla_put(skb, val_type, len, val);
1104 if (err)
1105 return err;
1106 if (mask_type != TCA_FLOWER_UNSPEC) {
1107 err = nla_put(skb, mask_type, len, mask);
1108 if (err)
1109 return err;
1110 }
1111 return 0;
1112}
1113
Benjamin LaHaisea577d8f2017-04-22 16:52:47 -04001114static int fl_dump_key_mpls(struct sk_buff *skb,
1115 struct flow_dissector_key_mpls *mpls_key,
1116 struct flow_dissector_key_mpls *mpls_mask)
1117{
1118 int err;
1119
1120 if (!memchr_inv(mpls_mask, 0, sizeof(*mpls_mask)))
1121 return 0;
1122 if (mpls_mask->mpls_ttl) {
1123 err = nla_put_u8(skb, TCA_FLOWER_KEY_MPLS_TTL,
1124 mpls_key->mpls_ttl);
1125 if (err)
1126 return err;
1127 }
1128 if (mpls_mask->mpls_tc) {
1129 err = nla_put_u8(skb, TCA_FLOWER_KEY_MPLS_TC,
1130 mpls_key->mpls_tc);
1131 if (err)
1132 return err;
1133 }
1134 if (mpls_mask->mpls_label) {
1135 err = nla_put_u32(skb, TCA_FLOWER_KEY_MPLS_LABEL,
1136 mpls_key->mpls_label);
1137 if (err)
1138 return err;
1139 }
1140 if (mpls_mask->mpls_bos) {
1141 err = nla_put_u8(skb, TCA_FLOWER_KEY_MPLS_BOS,
1142 mpls_key->mpls_bos);
1143 if (err)
1144 return err;
1145 }
1146 return 0;
1147}
1148
Or Gerlitz4d80cc02017-06-01 21:37:38 +03001149static int fl_dump_key_ip(struct sk_buff *skb,
1150 struct flow_dissector_key_ip *key,
1151 struct flow_dissector_key_ip *mask)
1152{
1153 if (fl_dump_key_val(skb, &key->tos, TCA_FLOWER_KEY_IP_TOS, &mask->tos,
1154 TCA_FLOWER_KEY_IP_TOS_MASK, sizeof(key->tos)) ||
1155 fl_dump_key_val(skb, &key->ttl, TCA_FLOWER_KEY_IP_TTL, &mask->ttl,
1156 TCA_FLOWER_KEY_IP_TTL_MASK, sizeof(key->ttl)))
1157 return -1;
1158
1159 return 0;
1160}
1161
Hadar Hen Zion9399ae92016-08-17 13:36:13 +03001162static int fl_dump_key_vlan(struct sk_buff *skb,
1163 struct flow_dissector_key_vlan *vlan_key,
1164 struct flow_dissector_key_vlan *vlan_mask)
1165{
1166 int err;
1167
1168 if (!memchr_inv(vlan_mask, 0, sizeof(*vlan_mask)))
1169 return 0;
1170 if (vlan_mask->vlan_id) {
1171 err = nla_put_u16(skb, TCA_FLOWER_KEY_VLAN_ID,
1172 vlan_key->vlan_id);
1173 if (err)
1174 return err;
1175 }
1176 if (vlan_mask->vlan_priority) {
1177 err = nla_put_u8(skb, TCA_FLOWER_KEY_VLAN_PRIO,
1178 vlan_key->vlan_priority);
1179 if (err)
1180 return err;
1181 }
1182 return 0;
1183}
1184
Or Gerlitzfaa3ffc2016-12-07 14:03:10 +02001185static void fl_get_key_flag(u32 dissector_key, u32 dissector_mask,
1186 u32 *flower_key, u32 *flower_mask,
1187 u32 flower_flag_bit, u32 dissector_flag_bit)
1188{
1189 if (dissector_mask & dissector_flag_bit) {
1190 *flower_mask |= flower_flag_bit;
1191 if (dissector_key & dissector_flag_bit)
1192 *flower_key |= flower_flag_bit;
1193 }
1194}
1195
1196static int fl_dump_key_flags(struct sk_buff *skb, u32 flags_key, u32 flags_mask)
1197{
1198 u32 key, mask;
1199 __be32 _key, _mask;
1200 int err;
1201
1202 if (!memchr_inv(&flags_mask, 0, sizeof(flags_mask)))
1203 return 0;
1204
1205 key = 0;
1206 mask = 0;
1207
1208 fl_get_key_flag(flags_key, flags_mask, &key, &mask,
1209 TCA_FLOWER_KEY_FLAGS_IS_FRAGMENT, FLOW_DIS_IS_FRAGMENT);
Pieter Jansen van Vuuren459d1532018-03-06 18:11:14 +01001210 fl_get_key_flag(flags_key, flags_mask, &key, &mask,
1211 TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST,
1212 FLOW_DIS_FIRST_FRAG);
Or Gerlitzfaa3ffc2016-12-07 14:03:10 +02001213
1214 _key = cpu_to_be32(key);
1215 _mask = cpu_to_be32(mask);
1216
1217 err = nla_put(skb, TCA_FLOWER_KEY_FLAGS, 4, &_key);
1218 if (err)
1219 return err;
1220
1221 return nla_put(skb, TCA_FLOWER_KEY_FLAGS_MASK, 4, &_mask);
1222}
1223
WANG Cong8113c092017-08-04 21:31:43 -07001224static int fl_dump(struct net *net, struct tcf_proto *tp, void *fh,
Jiri Pirko77b99002015-05-12 14:56:21 +02001225 struct sk_buff *skb, struct tcmsg *t)
1226{
WANG Cong8113c092017-08-04 21:31:43 -07001227 struct cls_fl_filter *f = fh;
Jiri Pirko77b99002015-05-12 14:56:21 +02001228 struct nlattr *nest;
1229 struct fl_flow_key *key, *mask;
1230
1231 if (!f)
1232 return skb->len;
1233
1234 t->tcm_handle = f->handle;
1235
1236 nest = nla_nest_start(skb, TCA_OPTIONS);
1237 if (!nest)
1238 goto nla_put_failure;
1239
1240 if (f->res.classid &&
1241 nla_put_u32(skb, TCA_FLOWER_CLASSID, f->res.classid))
1242 goto nla_put_failure;
1243
1244 key = &f->key;
Paul Blakey05cd2712018-04-30 14:28:30 +03001245 mask = &f->mask->key;
Jiri Pirko77b99002015-05-12 14:56:21 +02001246
1247 if (mask->indev_ifindex) {
1248 struct net_device *dev;
1249
1250 dev = __dev_get_by_index(net, key->indev_ifindex);
1251 if (dev && nla_put_string(skb, TCA_FLOWER_INDEV, dev->name))
1252 goto nla_put_failure;
1253 }
1254
Hadar Hen Zion79685212016-12-01 14:06:34 +02001255 if (!tc_skip_hw(f->flags))
1256 fl_hw_update_stats(tp, f);
Amir Vadai10cbc682016-05-13 12:55:37 +00001257
Jiri Pirko77b99002015-05-12 14:56:21 +02001258 if (fl_dump_key_val(skb, key->eth.dst, TCA_FLOWER_KEY_ETH_DST,
1259 mask->eth.dst, TCA_FLOWER_KEY_ETH_DST_MASK,
1260 sizeof(key->eth.dst)) ||
1261 fl_dump_key_val(skb, key->eth.src, TCA_FLOWER_KEY_ETH_SRC,
1262 mask->eth.src, TCA_FLOWER_KEY_ETH_SRC_MASK,
1263 sizeof(key->eth.src)) ||
1264 fl_dump_key_val(skb, &key->basic.n_proto, TCA_FLOWER_KEY_ETH_TYPE,
1265 &mask->basic.n_proto, TCA_FLOWER_UNSPEC,
1266 sizeof(key->basic.n_proto)))
1267 goto nla_put_failure;
Hadar Hen Zion9399ae92016-08-17 13:36:13 +03001268
Benjamin LaHaisea577d8f2017-04-22 16:52:47 -04001269 if (fl_dump_key_mpls(skb, &key->mpls, &mask->mpls))
1270 goto nla_put_failure;
1271
Hadar Hen Zion9399ae92016-08-17 13:36:13 +03001272 if (fl_dump_key_vlan(skb, &key->vlan, &mask->vlan))
1273 goto nla_put_failure;
1274
Jiri Pirko77b99002015-05-12 14:56:21 +02001275 if ((key->basic.n_proto == htons(ETH_P_IP) ||
1276 key->basic.n_proto == htons(ETH_P_IPV6)) &&
Or Gerlitz4d80cc02017-06-01 21:37:38 +03001277 (fl_dump_key_val(skb, &key->basic.ip_proto, TCA_FLOWER_KEY_IP_PROTO,
Jiri Pirko77b99002015-05-12 14:56:21 +02001278 &mask->basic.ip_proto, TCA_FLOWER_UNSPEC,
Or Gerlitz4d80cc02017-06-01 21:37:38 +03001279 sizeof(key->basic.ip_proto)) ||
1280 fl_dump_key_ip(skb, &key->ip, &mask->ip)))
Jiri Pirko77b99002015-05-12 14:56:21 +02001281 goto nla_put_failure;
1282
Tom Herbertc3f83242015-06-04 09:16:40 -07001283 if (key->control.addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS &&
Jiri Pirko77b99002015-05-12 14:56:21 +02001284 (fl_dump_key_val(skb, &key->ipv4.src, TCA_FLOWER_KEY_IPV4_SRC,
1285 &mask->ipv4.src, TCA_FLOWER_KEY_IPV4_SRC_MASK,
1286 sizeof(key->ipv4.src)) ||
1287 fl_dump_key_val(skb, &key->ipv4.dst, TCA_FLOWER_KEY_IPV4_DST,
1288 &mask->ipv4.dst, TCA_FLOWER_KEY_IPV4_DST_MASK,
1289 sizeof(key->ipv4.dst))))
1290 goto nla_put_failure;
Tom Herbertc3f83242015-06-04 09:16:40 -07001291 else if (key->control.addr_type == FLOW_DISSECTOR_KEY_IPV6_ADDRS &&
Jiri Pirko77b99002015-05-12 14:56:21 +02001292 (fl_dump_key_val(skb, &key->ipv6.src, TCA_FLOWER_KEY_IPV6_SRC,
1293 &mask->ipv6.src, TCA_FLOWER_KEY_IPV6_SRC_MASK,
1294 sizeof(key->ipv6.src)) ||
1295 fl_dump_key_val(skb, &key->ipv6.dst, TCA_FLOWER_KEY_IPV6_DST,
1296 &mask->ipv6.dst, TCA_FLOWER_KEY_IPV6_DST_MASK,
1297 sizeof(key->ipv6.dst))))
1298 goto nla_put_failure;
1299
1300 if (key->basic.ip_proto == IPPROTO_TCP &&
1301 (fl_dump_key_val(skb, &key->tp.src, TCA_FLOWER_KEY_TCP_SRC,
Or Gerlitzaa72d702016-09-15 15:28:22 +03001302 &mask->tp.src, TCA_FLOWER_KEY_TCP_SRC_MASK,
Jiri Pirko77b99002015-05-12 14:56:21 +02001303 sizeof(key->tp.src)) ||
1304 fl_dump_key_val(skb, &key->tp.dst, TCA_FLOWER_KEY_TCP_DST,
Or Gerlitzaa72d702016-09-15 15:28:22 +03001305 &mask->tp.dst, TCA_FLOWER_KEY_TCP_DST_MASK,
Jiri Pirkofdfc7dd2017-05-23 18:40:45 +02001306 sizeof(key->tp.dst)) ||
1307 fl_dump_key_val(skb, &key->tcp.flags, TCA_FLOWER_KEY_TCP_FLAGS,
1308 &mask->tcp.flags, TCA_FLOWER_KEY_TCP_FLAGS_MASK,
1309 sizeof(key->tcp.flags))))
Jiri Pirko77b99002015-05-12 14:56:21 +02001310 goto nla_put_failure;
1311 else if (key->basic.ip_proto == IPPROTO_UDP &&
1312 (fl_dump_key_val(skb, &key->tp.src, TCA_FLOWER_KEY_UDP_SRC,
Or Gerlitzaa72d702016-09-15 15:28:22 +03001313 &mask->tp.src, TCA_FLOWER_KEY_UDP_SRC_MASK,
Jiri Pirko77b99002015-05-12 14:56:21 +02001314 sizeof(key->tp.src)) ||
1315 fl_dump_key_val(skb, &key->tp.dst, TCA_FLOWER_KEY_UDP_DST,
Or Gerlitzaa72d702016-09-15 15:28:22 +03001316 &mask->tp.dst, TCA_FLOWER_KEY_UDP_DST_MASK,
Jiri Pirko77b99002015-05-12 14:56:21 +02001317 sizeof(key->tp.dst))))
1318 goto nla_put_failure;
Simon Horman5976c5f2016-11-03 13:24:21 +01001319 else if (key->basic.ip_proto == IPPROTO_SCTP &&
1320 (fl_dump_key_val(skb, &key->tp.src, TCA_FLOWER_KEY_SCTP_SRC,
1321 &mask->tp.src, TCA_FLOWER_KEY_SCTP_SRC_MASK,
1322 sizeof(key->tp.src)) ||
1323 fl_dump_key_val(skb, &key->tp.dst, TCA_FLOWER_KEY_SCTP_DST,
1324 &mask->tp.dst, TCA_FLOWER_KEY_SCTP_DST_MASK,
1325 sizeof(key->tp.dst))))
1326 goto nla_put_failure;
Simon Horman7b684882016-12-07 13:48:28 +01001327 else if (key->basic.n_proto == htons(ETH_P_IP) &&
1328 key->basic.ip_proto == IPPROTO_ICMP &&
1329 (fl_dump_key_val(skb, &key->icmp.type,
1330 TCA_FLOWER_KEY_ICMPV4_TYPE, &mask->icmp.type,
1331 TCA_FLOWER_KEY_ICMPV4_TYPE_MASK,
1332 sizeof(key->icmp.type)) ||
1333 fl_dump_key_val(skb, &key->icmp.code,
1334 TCA_FLOWER_KEY_ICMPV4_CODE, &mask->icmp.code,
1335 TCA_FLOWER_KEY_ICMPV4_CODE_MASK,
1336 sizeof(key->icmp.code))))
1337 goto nla_put_failure;
1338 else if (key->basic.n_proto == htons(ETH_P_IPV6) &&
1339 key->basic.ip_proto == IPPROTO_ICMPV6 &&
1340 (fl_dump_key_val(skb, &key->icmp.type,
1341 TCA_FLOWER_KEY_ICMPV6_TYPE, &mask->icmp.type,
1342 TCA_FLOWER_KEY_ICMPV6_TYPE_MASK,
1343 sizeof(key->icmp.type)) ||
1344 fl_dump_key_val(skb, &key->icmp.code,
1345 TCA_FLOWER_KEY_ICMPV6_CODE, &mask->icmp.code,
1346 TCA_FLOWER_KEY_ICMPV6_CODE_MASK,
1347 sizeof(key->icmp.code))))
1348 goto nla_put_failure;
Simon Horman99d31322017-01-11 14:05:43 +01001349 else if ((key->basic.n_proto == htons(ETH_P_ARP) ||
1350 key->basic.n_proto == htons(ETH_P_RARP)) &&
1351 (fl_dump_key_val(skb, &key->arp.sip,
1352 TCA_FLOWER_KEY_ARP_SIP, &mask->arp.sip,
1353 TCA_FLOWER_KEY_ARP_SIP_MASK,
1354 sizeof(key->arp.sip)) ||
1355 fl_dump_key_val(skb, &key->arp.tip,
1356 TCA_FLOWER_KEY_ARP_TIP, &mask->arp.tip,
1357 TCA_FLOWER_KEY_ARP_TIP_MASK,
1358 sizeof(key->arp.tip)) ||
1359 fl_dump_key_val(skb, &key->arp.op,
1360 TCA_FLOWER_KEY_ARP_OP, &mask->arp.op,
1361 TCA_FLOWER_KEY_ARP_OP_MASK,
1362 sizeof(key->arp.op)) ||
1363 fl_dump_key_val(skb, key->arp.sha, TCA_FLOWER_KEY_ARP_SHA,
1364 mask->arp.sha, TCA_FLOWER_KEY_ARP_SHA_MASK,
1365 sizeof(key->arp.sha)) ||
1366 fl_dump_key_val(skb, key->arp.tha, TCA_FLOWER_KEY_ARP_THA,
1367 mask->arp.tha, TCA_FLOWER_KEY_ARP_THA_MASK,
1368 sizeof(key->arp.tha))))
1369 goto nla_put_failure;
Jiri Pirko77b99002015-05-12 14:56:21 +02001370
Amir Vadaibc3103f2016-09-08 16:23:47 +03001371 if (key->enc_control.addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS &&
1372 (fl_dump_key_val(skb, &key->enc_ipv4.src,
1373 TCA_FLOWER_KEY_ENC_IPV4_SRC, &mask->enc_ipv4.src,
1374 TCA_FLOWER_KEY_ENC_IPV4_SRC_MASK,
1375 sizeof(key->enc_ipv4.src)) ||
1376 fl_dump_key_val(skb, &key->enc_ipv4.dst,
1377 TCA_FLOWER_KEY_ENC_IPV4_DST, &mask->enc_ipv4.dst,
1378 TCA_FLOWER_KEY_ENC_IPV4_DST_MASK,
1379 sizeof(key->enc_ipv4.dst))))
1380 goto nla_put_failure;
1381 else if (key->enc_control.addr_type == FLOW_DISSECTOR_KEY_IPV6_ADDRS &&
1382 (fl_dump_key_val(skb, &key->enc_ipv6.src,
1383 TCA_FLOWER_KEY_ENC_IPV6_SRC, &mask->enc_ipv6.src,
1384 TCA_FLOWER_KEY_ENC_IPV6_SRC_MASK,
1385 sizeof(key->enc_ipv6.src)) ||
1386 fl_dump_key_val(skb, &key->enc_ipv6.dst,
1387 TCA_FLOWER_KEY_ENC_IPV6_DST,
1388 &mask->enc_ipv6.dst,
1389 TCA_FLOWER_KEY_ENC_IPV6_DST_MASK,
1390 sizeof(key->enc_ipv6.dst))))
1391 goto nla_put_failure;
1392
1393 if (fl_dump_key_val(skb, &key->enc_key_id, TCA_FLOWER_KEY_ENC_KEY_ID,
Hadar Hen Zioneb523f42016-09-27 11:21:18 +03001394 &mask->enc_key_id, TCA_FLOWER_UNSPEC,
Hadar Hen Zionf4d997f2016-11-07 15:14:39 +02001395 sizeof(key->enc_key_id)) ||
1396 fl_dump_key_val(skb, &key->enc_tp.src,
1397 TCA_FLOWER_KEY_ENC_UDP_SRC_PORT,
1398 &mask->enc_tp.src,
1399 TCA_FLOWER_KEY_ENC_UDP_SRC_PORT_MASK,
1400 sizeof(key->enc_tp.src)) ||
1401 fl_dump_key_val(skb, &key->enc_tp.dst,
1402 TCA_FLOWER_KEY_ENC_UDP_DST_PORT,
1403 &mask->enc_tp.dst,
1404 TCA_FLOWER_KEY_ENC_UDP_DST_PORT_MASK,
1405 sizeof(key->enc_tp.dst)))
Amir Vadaibc3103f2016-09-08 16:23:47 +03001406 goto nla_put_failure;
1407
Or Gerlitzfaa3ffc2016-12-07 14:03:10 +02001408 if (fl_dump_key_flags(skb, key->control.flags, mask->control.flags))
1409 goto nla_put_failure;
1410
Or Gerlitz749e6722017-02-16 10:31:10 +02001411 if (f->flags && nla_put_u32(skb, TCA_FLOWER_FLAGS, f->flags))
1412 goto nla_put_failure;
Amir Vadaie69985c2016-06-05 17:11:18 +03001413
Jiri Pirko77b99002015-05-12 14:56:21 +02001414 if (tcf_exts_dump(skb, &f->exts))
1415 goto nla_put_failure;
1416
1417 nla_nest_end(skb, nest);
1418
1419 if (tcf_exts_dump_stats(skb, &f->exts) < 0)
1420 goto nla_put_failure;
1421
1422 return skb->len;
1423
1424nla_put_failure:
1425 nla_nest_cancel(skb, nest);
1426 return -1;
1427}
1428
Cong Wang07d79fc2017-08-30 14:30:36 -07001429static void fl_bind_class(void *fh, u32 classid, unsigned long cl)
1430{
1431 struct cls_fl_filter *f = fh;
1432
1433 if (f && f->res.classid == classid)
1434 f->res.class = cl;
1435}
1436
Jiri Pirko77b99002015-05-12 14:56:21 +02001437static struct tcf_proto_ops cls_fl_ops __read_mostly = {
1438 .kind = "flower",
1439 .classify = fl_classify,
1440 .init = fl_init,
1441 .destroy = fl_destroy,
1442 .get = fl_get,
1443 .change = fl_change,
1444 .delete = fl_delete,
1445 .walk = fl_walk,
1446 .dump = fl_dump,
Cong Wang07d79fc2017-08-30 14:30:36 -07001447 .bind_class = fl_bind_class,
Jiri Pirko77b99002015-05-12 14:56:21 +02001448 .owner = THIS_MODULE,
1449};
1450
1451static int __init cls_fl_init(void)
1452{
1453 return register_tcf_proto_ops(&cls_fl_ops);
1454}
1455
1456static void __exit cls_fl_exit(void)
1457{
1458 unregister_tcf_proto_ops(&cls_fl_ops);
1459}
1460
1461module_init(cls_fl_init);
1462module_exit(cls_fl_exit);
1463
1464MODULE_AUTHOR("Jiri Pirko <jiri@resnulli.us>");
1465MODULE_DESCRIPTION("Flower classifier");
1466MODULE_LICENSE("GPL v2");