| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * net/sched/cls_api.c Packet classifier API. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; either version |
| 7 | * 2 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> |
| 10 | * |
| 11 | * Changes: |
| 12 | * |
| 13 | * Eduardo J. Blanco <ejbs@netlabs.com.uy> :990222: kmod support |
| 14 | * |
| 15 | */ |
| 16 | |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/module.h> |
| 18 | #include <linux/types.h> |
| 19 | #include <linux/kernel.h> |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/string.h> |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/errno.h> |
| Jiri Pirko | 33a4892 | 2017-02-09 14:38:57 +0100 | [diff] [blame] | 22 | #include <linux/err.h> |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/skbuff.h> |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/init.h> |
| 25 | #include <linux/kmod.h> |
| Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 26 | #include <linux/slab.h> |
| Jiri Pirko | 4861738 | 2018-01-17 11:46:46 +0100 | [diff] [blame] | 27 | #include <linux/idr.h> |
| Denis V. Lunev | b854272 | 2007-12-01 00:21:31 +1100 | [diff] [blame] | 28 | #include <net/net_namespace.h> |
| 29 | #include <net/sock.h> |
| Arnaldo Carvalho de Melo | dc5fc57 | 2007-03-25 23:06:12 -0700 | [diff] [blame] | 30 | #include <net/netlink.h> |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <net/pkt_sched.h> |
| 32 | #include <net/pkt_cls.h> |
| 33 | |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | /* The list of all installed classifier types */ |
| WANG Cong | 3627287 | 2013-12-15 20:15:11 -0800 | [diff] [blame] | 35 | static LIST_HEAD(tcf_proto_base); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | /* Protects list of registered TC modules. It is pure SMP lock. */ |
| 38 | static DEFINE_RWLOCK(cls_mod_lock); |
| 39 | |
| 40 | /* Find classifier type by string name */ |
| 41 | |
| Jiri Pirko | f34e8bf | 2018-07-23 09:23:04 +0200 | [diff] [blame] | 42 | static const struct tcf_proto_ops *__tcf_proto_lookup_ops(const char *kind) |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | { |
| Eric Dumazet | dcd7608 | 2013-12-20 10:04:18 -0800 | [diff] [blame] | 44 | const struct tcf_proto_ops *t, *res = NULL; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
| 46 | if (kind) { |
| 47 | read_lock(&cls_mod_lock); |
| WANG Cong | 3627287 | 2013-12-15 20:15:11 -0800 | [diff] [blame] | 48 | list_for_each_entry(t, &tcf_proto_base, head) { |
| Jiri Pirko | 33a4892 | 2017-02-09 14:38:57 +0100 | [diff] [blame] | 49 | if (strcmp(kind, t->kind) == 0) { |
| Eric Dumazet | dcd7608 | 2013-12-20 10:04:18 -0800 | [diff] [blame] | 50 | if (try_module_get(t->owner)) |
| 51 | res = t; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | break; |
| 53 | } |
| 54 | } |
| 55 | read_unlock(&cls_mod_lock); |
| 56 | } |
| Eric Dumazet | dcd7608 | 2013-12-20 10:04:18 -0800 | [diff] [blame] | 57 | return res; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| Jiri Pirko | f34e8bf | 2018-07-23 09:23:04 +0200 | [diff] [blame] | 60 | static const struct tcf_proto_ops * |
| 61 | tcf_proto_lookup_ops(const char *kind, struct netlink_ext_ack *extack) |
| 62 | { |
| 63 | const struct tcf_proto_ops *ops; |
| 64 | |
| 65 | ops = __tcf_proto_lookup_ops(kind); |
| 66 | if (ops) |
| 67 | return ops; |
| 68 | #ifdef CONFIG_MODULES |
| 69 | rtnl_unlock(); |
| 70 | request_module("cls_%s", kind); |
| 71 | rtnl_lock(); |
| 72 | ops = __tcf_proto_lookup_ops(kind); |
| 73 | /* We dropped the RTNL semaphore in order to perform |
| 74 | * the module load. So, even if we succeeded in loading |
| 75 | * the module we have to replay the request. We indicate |
| 76 | * this using -EAGAIN. |
| 77 | */ |
| 78 | if (ops) { |
| 79 | module_put(ops->owner); |
| 80 | return ERR_PTR(-EAGAIN); |
| 81 | } |
| 82 | #endif |
| 83 | NL_SET_ERR_MSG(extack, "TC classifier not found"); |
| 84 | return ERR_PTR(-ENOENT); |
| 85 | } |
| 86 | |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | /* Register(unregister) new classifier type */ |
| 88 | |
| 89 | int register_tcf_proto_ops(struct tcf_proto_ops *ops) |
| 90 | { |
| WANG Cong | 3627287 | 2013-12-15 20:15:11 -0800 | [diff] [blame] | 91 | struct tcf_proto_ops *t; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | int rc = -EEXIST; |
| 93 | |
| 94 | write_lock(&cls_mod_lock); |
| WANG Cong | 3627287 | 2013-12-15 20:15:11 -0800 | [diff] [blame] | 95 | list_for_each_entry(t, &tcf_proto_base, head) |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | if (!strcmp(ops->kind, t->kind)) |
| 97 | goto out; |
| 98 | |
| WANG Cong | 3627287 | 2013-12-15 20:15:11 -0800 | [diff] [blame] | 99 | list_add_tail(&ops->head, &tcf_proto_base); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | rc = 0; |
| 101 | out: |
| 102 | write_unlock(&cls_mod_lock); |
| 103 | return rc; |
| 104 | } |
| Stephen Hemminger | aa767bf | 2008-01-21 02:26:41 -0800 | [diff] [blame] | 105 | EXPORT_SYMBOL(register_tcf_proto_ops); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
| Cong Wang | 7aa0045 | 2017-10-26 18:24:28 -0700 | [diff] [blame] | 107 | static struct workqueue_struct *tc_filter_wq; |
| 108 | |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | int unregister_tcf_proto_ops(struct tcf_proto_ops *ops) |
| 110 | { |
| WANG Cong | 3627287 | 2013-12-15 20:15:11 -0800 | [diff] [blame] | 111 | struct tcf_proto_ops *t; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | int rc = -ENOENT; |
| 113 | |
| Daniel Borkmann | c78e174 | 2015-05-20 17:13:33 +0200 | [diff] [blame] | 114 | /* Wait for outstanding call_rcu()s, if any, from a |
| 115 | * tcf_proto_ops's destroy() handler. |
| 116 | */ |
| 117 | rcu_barrier(); |
| Cong Wang | 7aa0045 | 2017-10-26 18:24:28 -0700 | [diff] [blame] | 118 | flush_workqueue(tc_filter_wq); |
| Daniel Borkmann | c78e174 | 2015-05-20 17:13:33 +0200 | [diff] [blame] | 119 | |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | write_lock(&cls_mod_lock); |
| Eric Dumazet | dcd7608 | 2013-12-20 10:04:18 -0800 | [diff] [blame] | 121 | list_for_each_entry(t, &tcf_proto_base, head) { |
| 122 | if (t == ops) { |
| 123 | list_del(&t->head); |
| 124 | rc = 0; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | break; |
| Eric Dumazet | dcd7608 | 2013-12-20 10:04:18 -0800 | [diff] [blame] | 126 | } |
| 127 | } |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | write_unlock(&cls_mod_lock); |
| 129 | return rc; |
| 130 | } |
| Stephen Hemminger | aa767bf | 2008-01-21 02:26:41 -0800 | [diff] [blame] | 131 | EXPORT_SYMBOL(unregister_tcf_proto_ops); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
| Cong Wang | aaa908f | 2018-05-23 15:26:53 -0700 | [diff] [blame] | 133 | bool tcf_queue_work(struct rcu_work *rwork, work_func_t func) |
| Cong Wang | 7aa0045 | 2017-10-26 18:24:28 -0700 | [diff] [blame] | 134 | { |
| Cong Wang | aaa908f | 2018-05-23 15:26:53 -0700 | [diff] [blame] | 135 | INIT_RCU_WORK(rwork, func); |
| 136 | return queue_rcu_work(tc_filter_wq, rwork); |
| Cong Wang | 7aa0045 | 2017-10-26 18:24:28 -0700 | [diff] [blame] | 137 | } |
| 138 | EXPORT_SYMBOL(tcf_queue_work); |
| 139 | |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | /* Select new prio value from the range, managed by kernel. */ |
| 141 | |
| Stephen Hemminger | aa767bf | 2008-01-21 02:26:41 -0800 | [diff] [blame] | 142 | static inline u32 tcf_auto_prio(struct tcf_proto *tp) |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | { |
| Stephen Hemminger | aa767bf | 2008-01-21 02:26:41 -0800 | [diff] [blame] | 144 | u32 first = TC_H_MAKE(0xC0000000U, 0U); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
| 146 | if (tp) |
| Eric Dumazet | cc7ec45 | 2011-01-19 19:26:56 +0000 | [diff] [blame] | 147 | first = tp->prio - 1; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | |
| Jiri Pirko | 7961973 | 2017-05-17 11:07:58 +0200 | [diff] [blame] | 149 | return TC_H_MAJ(first); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | } |
| 151 | |
| Jiri Pirko | 33a4892 | 2017-02-09 14:38:57 +0100 | [diff] [blame] | 152 | static struct tcf_proto *tcf_proto_create(const char *kind, u32 protocol, |
| Alexander Aring | c35a4ac | 2018-01-18 11:20:50 -0500 | [diff] [blame] | 153 | u32 prio, struct tcf_chain *chain, |
| 154 | struct netlink_ext_ack *extack) |
| Jiri Pirko | 33a4892 | 2017-02-09 14:38:57 +0100 | [diff] [blame] | 155 | { |
| 156 | struct tcf_proto *tp; |
| 157 | int err; |
| 158 | |
| 159 | tp = kzalloc(sizeof(*tp), GFP_KERNEL); |
| 160 | if (!tp) |
| 161 | return ERR_PTR(-ENOBUFS); |
| 162 | |
| Jiri Pirko | f34e8bf | 2018-07-23 09:23:04 +0200 | [diff] [blame] | 163 | tp->ops = tcf_proto_lookup_ops(kind, extack); |
| 164 | if (IS_ERR(tp->ops)) { |
| 165 | err = PTR_ERR(tp->ops); |
| Jiri Pirko | d68d75f | 2018-05-11 17:45:32 +0200 | [diff] [blame] | 166 | goto errout; |
| Jiri Pirko | 33a4892 | 2017-02-09 14:38:57 +0100 | [diff] [blame] | 167 | } |
| 168 | tp->classify = tp->ops->classify; |
| 169 | tp->protocol = protocol; |
| 170 | tp->prio = prio; |
| Jiri Pirko | 5bc1701 | 2017-05-17 11:08:01 +0200 | [diff] [blame] | 171 | tp->chain = chain; |
| Jiri Pirko | 33a4892 | 2017-02-09 14:38:57 +0100 | [diff] [blame] | 172 | |
| 173 | err = tp->ops->init(tp); |
| 174 | if (err) { |
| 175 | module_put(tp->ops->owner); |
| 176 | goto errout; |
| 177 | } |
| 178 | return tp; |
| 179 | |
| 180 | errout: |
| 181 | kfree(tp); |
| 182 | return ERR_PTR(err); |
| 183 | } |
| 184 | |
| Jakub Kicinski | 715df5e | 2018-01-24 12:54:13 -0800 | [diff] [blame] | 185 | static void tcf_proto_destroy(struct tcf_proto *tp, |
| 186 | struct netlink_ext_ack *extack) |
| Jiri Pirko | cf1facd | 2017-02-09 14:38:56 +0100 | [diff] [blame] | 187 | { |
| Jakub Kicinski | 715df5e | 2018-01-24 12:54:13 -0800 | [diff] [blame] | 188 | tp->ops->destroy(tp, extack); |
| WANG Cong | 763dbf6 | 2017-04-19 14:21:21 -0700 | [diff] [blame] | 189 | module_put(tp->ops->owner); |
| 190 | kfree_rcu(tp, rcu); |
| Jiri Pirko | cf1facd | 2017-02-09 14:38:56 +0100 | [diff] [blame] | 191 | } |
| 192 | |
| Jiri Pirko | a9b1944 | 2018-01-17 11:46:45 +0100 | [diff] [blame] | 193 | struct tcf_filter_chain_list_item { |
| 194 | struct list_head list; |
| 195 | tcf_chain_head_change_t *chain_head_change; |
| 196 | void *chain_head_change_priv; |
| 197 | }; |
| 198 | |
| Jiri Pirko | 5bc1701 | 2017-05-17 11:08:01 +0200 | [diff] [blame] | 199 | static struct tcf_chain *tcf_chain_create(struct tcf_block *block, |
| 200 | u32 chain_index) |
| Jiri Pirko | 2190d1d | 2017-05-17 11:07:59 +0200 | [diff] [blame] | 201 | { |
| Jiri Pirko | 5bc1701 | 2017-05-17 11:08:01 +0200 | [diff] [blame] | 202 | struct tcf_chain *chain; |
| 203 | |
| 204 | chain = kzalloc(sizeof(*chain), GFP_KERNEL); |
| 205 | if (!chain) |
| 206 | return NULL; |
| 207 | list_add_tail(&chain->list, &block->chain_list); |
| 208 | chain->block = block; |
| 209 | chain->index = chain_index; |
| Cong Wang | e2ef754 | 2017-09-11 16:33:31 -0700 | [diff] [blame] | 210 | chain->refcnt = 1; |
| Jiri Pirko | f71e0ca4 | 2018-07-23 09:23:05 +0200 | [diff] [blame^] | 211 | if (!chain->index) |
| 212 | block->chain0.chain = chain; |
| Jiri Pirko | 5bc1701 | 2017-05-17 11:08:01 +0200 | [diff] [blame] | 213 | return chain; |
| Jiri Pirko | 2190d1d | 2017-05-17 11:07:59 +0200 | [diff] [blame] | 214 | } |
| 215 | |
| Jiri Pirko | a9b1944 | 2018-01-17 11:46:45 +0100 | [diff] [blame] | 216 | static void tcf_chain_head_change_item(struct tcf_filter_chain_list_item *item, |
| 217 | struct tcf_proto *tp_head) |
| 218 | { |
| 219 | if (item->chain_head_change) |
| 220 | item->chain_head_change(tp_head, item->chain_head_change_priv); |
| 221 | } |
| Jiri Pirko | f71e0ca4 | 2018-07-23 09:23:05 +0200 | [diff] [blame^] | 222 | |
| 223 | static void tcf_chain0_head_change(struct tcf_chain *chain, |
| 224 | struct tcf_proto *tp_head) |
| Jiri Pirko | c7eb7d7 | 2017-11-03 11:46:24 +0100 | [diff] [blame] | 225 | { |
| Jiri Pirko | a9b1944 | 2018-01-17 11:46:45 +0100 | [diff] [blame] | 226 | struct tcf_filter_chain_list_item *item; |
| Jiri Pirko | f71e0ca4 | 2018-07-23 09:23:05 +0200 | [diff] [blame^] | 227 | struct tcf_block *block = chain->block; |
| Jiri Pirko | a9b1944 | 2018-01-17 11:46:45 +0100 | [diff] [blame] | 228 | |
| Jiri Pirko | f71e0ca4 | 2018-07-23 09:23:05 +0200 | [diff] [blame^] | 229 | if (chain->index) |
| 230 | return; |
| 231 | list_for_each_entry(item, &block->chain0.filter_chain_list, list) |
| Jiri Pirko | a9b1944 | 2018-01-17 11:46:45 +0100 | [diff] [blame] | 232 | tcf_chain_head_change_item(item, tp_head); |
| Jiri Pirko | c7eb7d7 | 2017-11-03 11:46:24 +0100 | [diff] [blame] | 233 | } |
| 234 | |
| Jiri Pirko | f93e1cd | 2017-05-20 15:01:32 +0200 | [diff] [blame] | 235 | static void tcf_chain_flush(struct tcf_chain *chain) |
| Jiri Pirko | cf1facd | 2017-02-09 14:38:56 +0100 | [diff] [blame] | 236 | { |
| Roman Kapl | d7aa04a | 2017-11-20 22:21:13 +0100 | [diff] [blame] | 237 | struct tcf_proto *tp = rtnl_dereference(chain->filter_chain); |
| Jiri Pirko | cf1facd | 2017-02-09 14:38:56 +0100 | [diff] [blame] | 238 | |
| Jiri Pirko | f71e0ca4 | 2018-07-23 09:23:05 +0200 | [diff] [blame^] | 239 | tcf_chain0_head_change(chain, NULL); |
| Roman Kapl | d7aa04a | 2017-11-20 22:21:13 +0100 | [diff] [blame] | 240 | while (tp) { |
| Jiri Pirko | 2190d1d | 2017-05-17 11:07:59 +0200 | [diff] [blame] | 241 | RCU_INIT_POINTER(chain->filter_chain, tp->next); |
| Jakub Kicinski | 715df5e | 2018-01-24 12:54:13 -0800 | [diff] [blame] | 242 | tcf_proto_destroy(tp, NULL); |
| Roman Kapl | d7aa04a | 2017-11-20 22:21:13 +0100 | [diff] [blame] | 243 | tp = rtnl_dereference(chain->filter_chain); |
| 244 | tcf_chain_put(chain); |
| Jiri Pirko | cf1facd | 2017-02-09 14:38:56 +0100 | [diff] [blame] | 245 | } |
| Jiri Pirko | f93e1cd | 2017-05-20 15:01:32 +0200 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | static void tcf_chain_destroy(struct tcf_chain *chain) |
| 249 | { |
| Cong Wang | efbf789 | 2017-12-04 10:48:18 -0800 | [diff] [blame] | 250 | struct tcf_block *block = chain->block; |
| 251 | |
| Cong Wang | e2ef754 | 2017-09-11 16:33:31 -0700 | [diff] [blame] | 252 | list_del(&chain->list); |
| Jiri Pirko | f71e0ca4 | 2018-07-23 09:23:05 +0200 | [diff] [blame^] | 253 | if (!chain->index) |
| 254 | block->chain0.chain = NULL; |
| Cong Wang | e2ef754 | 2017-09-11 16:33:31 -0700 | [diff] [blame] | 255 | kfree(chain); |
| Jiri Pirko | f71e0ca4 | 2018-07-23 09:23:05 +0200 | [diff] [blame^] | 256 | if (list_empty(&block->chain_list) && block->refcnt == 0) |
| Cong Wang | efbf789 | 2017-12-04 10:48:18 -0800 | [diff] [blame] | 257 | kfree(block); |
| Cong Wang | e2ef754 | 2017-09-11 16:33:31 -0700 | [diff] [blame] | 258 | } |
| Jiri Pirko | 744a4cf | 2017-08-22 22:46:49 +0200 | [diff] [blame] | 259 | |
| Cong Wang | e2ef754 | 2017-09-11 16:33:31 -0700 | [diff] [blame] | 260 | static void tcf_chain_hold(struct tcf_chain *chain) |
| 261 | { |
| 262 | ++chain->refcnt; |
| Jiri Pirko | 2190d1d | 2017-05-17 11:07:59 +0200 | [diff] [blame] | 263 | } |
| 264 | |
| WANG Cong | 367a8ce | 2017-05-23 09:42:37 -0700 | [diff] [blame] | 265 | struct tcf_chain *tcf_chain_get(struct tcf_block *block, u32 chain_index, |
| 266 | bool create) |
| Jiri Pirko | 5bc1701 | 2017-05-17 11:08:01 +0200 | [diff] [blame] | 267 | { |
| 268 | struct tcf_chain *chain; |
| 269 | |
| 270 | list_for_each_entry(chain, &block->chain_list, list) { |
| Cong Wang | e2ef754 | 2017-09-11 16:33:31 -0700 | [diff] [blame] | 271 | if (chain->index == chain_index) { |
| 272 | tcf_chain_hold(chain); |
| 273 | return chain; |
| 274 | } |
| Jiri Pirko | 5bc1701 | 2017-05-17 11:08:01 +0200 | [diff] [blame] | 275 | } |
| Jiri Pirko | 8053238 | 2017-09-06 13:14:19 +0200 | [diff] [blame] | 276 | |
| Cong Wang | e2ef754 | 2017-09-11 16:33:31 -0700 | [diff] [blame] | 277 | return create ? tcf_chain_create(block, chain_index) : NULL; |
| Jiri Pirko | 5bc1701 | 2017-05-17 11:08:01 +0200 | [diff] [blame] | 278 | } |
| 279 | EXPORT_SYMBOL(tcf_chain_get); |
| 280 | |
| 281 | void tcf_chain_put(struct tcf_chain *chain) |
| 282 | { |
| Cong Wang | e2ef754 | 2017-09-11 16:33:31 -0700 | [diff] [blame] | 283 | if (--chain->refcnt == 0) |
| Jiri Pirko | 5bc1701 | 2017-05-17 11:08:01 +0200 | [diff] [blame] | 284 | tcf_chain_destroy(chain); |
| 285 | } |
| 286 | EXPORT_SYMBOL(tcf_chain_put); |
| 287 | |
| Jiri Pirko | caa7260 | 2018-01-17 11:46:50 +0100 | [diff] [blame] | 288 | static bool tcf_block_offload_in_use(struct tcf_block *block) |
| Jiri Pirko | 8c4083b | 2017-10-19 15:50:29 +0200 | [diff] [blame] | 289 | { |
| Jiri Pirko | caa7260 | 2018-01-17 11:46:50 +0100 | [diff] [blame] | 290 | return block->offloadcnt; |
| 291 | } |
| 292 | |
| 293 | static int tcf_block_offload_cmd(struct tcf_block *block, |
| 294 | struct net_device *dev, |
| 295 | struct tcf_block_ext_info *ei, |
| John Hurley | 60513bd | 2018-06-25 14:30:04 -0700 | [diff] [blame] | 296 | enum tc_block_command command, |
| 297 | struct netlink_ext_ack *extack) |
| Jiri Pirko | caa7260 | 2018-01-17 11:46:50 +0100 | [diff] [blame] | 298 | { |
| Jiri Pirko | 8c4083b | 2017-10-19 15:50:29 +0200 | [diff] [blame] | 299 | struct tc_block_offload bo = {}; |
| 300 | |
| Jiri Pirko | 8c4083b | 2017-10-19 15:50:29 +0200 | [diff] [blame] | 301 | bo.command = command; |
| 302 | bo.binder_type = ei->binder_type; |
| 303 | bo.block = block; |
| John Hurley | 60513bd | 2018-06-25 14:30:04 -0700 | [diff] [blame] | 304 | bo.extack = extack; |
| Jiri Pirko | caa7260 | 2018-01-17 11:46:50 +0100 | [diff] [blame] | 305 | return dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_BLOCK, &bo); |
| Jiri Pirko | 8c4083b | 2017-10-19 15:50:29 +0200 | [diff] [blame] | 306 | } |
| 307 | |
| Jiri Pirko | caa7260 | 2018-01-17 11:46:50 +0100 | [diff] [blame] | 308 | static int tcf_block_offload_bind(struct tcf_block *block, struct Qdisc *q, |
| John Hurley | 60513bd | 2018-06-25 14:30:04 -0700 | [diff] [blame] | 309 | struct tcf_block_ext_info *ei, |
| 310 | struct netlink_ext_ack *extack) |
| Jiri Pirko | 8c4083b | 2017-10-19 15:50:29 +0200 | [diff] [blame] | 311 | { |
| Jiri Pirko | caa7260 | 2018-01-17 11:46:50 +0100 | [diff] [blame] | 312 | struct net_device *dev = q->dev_queue->dev; |
| 313 | int err; |
| 314 | |
| 315 | if (!dev->netdev_ops->ndo_setup_tc) |
| 316 | goto no_offload_dev_inc; |
| 317 | |
| 318 | /* If tc offload feature is disabled and the block we try to bind |
| 319 | * to already has some offloaded filters, forbid to bind. |
| 320 | */ |
| John Hurley | 60513bd | 2018-06-25 14:30:04 -0700 | [diff] [blame] | 321 | if (!tc_can_offload(dev) && tcf_block_offload_in_use(block)) { |
| 322 | NL_SET_ERR_MSG(extack, "Bind to offloaded block failed as dev has offload disabled"); |
| Jiri Pirko | caa7260 | 2018-01-17 11:46:50 +0100 | [diff] [blame] | 323 | return -EOPNOTSUPP; |
| John Hurley | 60513bd | 2018-06-25 14:30:04 -0700 | [diff] [blame] | 324 | } |
| Jiri Pirko | caa7260 | 2018-01-17 11:46:50 +0100 | [diff] [blame] | 325 | |
| John Hurley | 60513bd | 2018-06-25 14:30:04 -0700 | [diff] [blame] | 326 | err = tcf_block_offload_cmd(block, dev, ei, TC_BLOCK_BIND, extack); |
| Jiri Pirko | caa7260 | 2018-01-17 11:46:50 +0100 | [diff] [blame] | 327 | if (err == -EOPNOTSUPP) |
| 328 | goto no_offload_dev_inc; |
| 329 | return err; |
| 330 | |
| 331 | no_offload_dev_inc: |
| 332 | if (tcf_block_offload_in_use(block)) |
| 333 | return -EOPNOTSUPP; |
| 334 | block->nooffloaddevcnt++; |
| 335 | return 0; |
| Jiri Pirko | 8c4083b | 2017-10-19 15:50:29 +0200 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | static void tcf_block_offload_unbind(struct tcf_block *block, struct Qdisc *q, |
| 339 | struct tcf_block_ext_info *ei) |
| 340 | { |
| Jiri Pirko | caa7260 | 2018-01-17 11:46:50 +0100 | [diff] [blame] | 341 | struct net_device *dev = q->dev_queue->dev; |
| 342 | int err; |
| 343 | |
| 344 | if (!dev->netdev_ops->ndo_setup_tc) |
| 345 | goto no_offload_dev_dec; |
| John Hurley | 60513bd | 2018-06-25 14:30:04 -0700 | [diff] [blame] | 346 | err = tcf_block_offload_cmd(block, dev, ei, TC_BLOCK_UNBIND, NULL); |
| Jiri Pirko | caa7260 | 2018-01-17 11:46:50 +0100 | [diff] [blame] | 347 | if (err == -EOPNOTSUPP) |
| 348 | goto no_offload_dev_dec; |
| 349 | return; |
| 350 | |
| 351 | no_offload_dev_dec: |
| 352 | WARN_ON(block->nooffloaddevcnt-- == 0); |
| Jiri Pirko | 8c4083b | 2017-10-19 15:50:29 +0200 | [diff] [blame] | 353 | } |
| 354 | |
| Jiri Pirko | a9b1944 | 2018-01-17 11:46:45 +0100 | [diff] [blame] | 355 | static int |
| Jiri Pirko | f71e0ca4 | 2018-07-23 09:23:05 +0200 | [diff] [blame^] | 356 | tcf_chain0_head_change_cb_add(struct tcf_block *block, |
| 357 | struct tcf_block_ext_info *ei, |
| 358 | struct netlink_ext_ack *extack) |
| Jiri Pirko | a9b1944 | 2018-01-17 11:46:45 +0100 | [diff] [blame] | 359 | { |
| Jiri Pirko | f71e0ca4 | 2018-07-23 09:23:05 +0200 | [diff] [blame^] | 360 | struct tcf_chain *chain0 = block->chain0.chain; |
| Jiri Pirko | a9b1944 | 2018-01-17 11:46:45 +0100 | [diff] [blame] | 361 | struct tcf_filter_chain_list_item *item; |
| 362 | |
| 363 | item = kmalloc(sizeof(*item), GFP_KERNEL); |
| 364 | if (!item) { |
| 365 | NL_SET_ERR_MSG(extack, "Memory allocation for head change callback item failed"); |
| 366 | return -ENOMEM; |
| 367 | } |
| 368 | item->chain_head_change = ei->chain_head_change; |
| 369 | item->chain_head_change_priv = ei->chain_head_change_priv; |
| Jiri Pirko | f71e0ca4 | 2018-07-23 09:23:05 +0200 | [diff] [blame^] | 370 | if (chain0 && chain0->filter_chain) |
| 371 | tcf_chain_head_change_item(item, chain0->filter_chain); |
| 372 | list_add(&item->list, &block->chain0.filter_chain_list); |
| Jiri Pirko | a9b1944 | 2018-01-17 11:46:45 +0100 | [diff] [blame] | 373 | return 0; |
| 374 | } |
| 375 | |
| 376 | static void |
| Jiri Pirko | f71e0ca4 | 2018-07-23 09:23:05 +0200 | [diff] [blame^] | 377 | tcf_chain0_head_change_cb_del(struct tcf_block *block, |
| 378 | struct tcf_block_ext_info *ei) |
| Jiri Pirko | a9b1944 | 2018-01-17 11:46:45 +0100 | [diff] [blame] | 379 | { |
| Jiri Pirko | f71e0ca4 | 2018-07-23 09:23:05 +0200 | [diff] [blame^] | 380 | struct tcf_chain *chain0 = block->chain0.chain; |
| Jiri Pirko | a9b1944 | 2018-01-17 11:46:45 +0100 | [diff] [blame] | 381 | struct tcf_filter_chain_list_item *item; |
| 382 | |
| Jiri Pirko | f71e0ca4 | 2018-07-23 09:23:05 +0200 | [diff] [blame^] | 383 | list_for_each_entry(item, &block->chain0.filter_chain_list, list) { |
| Jiri Pirko | a9b1944 | 2018-01-17 11:46:45 +0100 | [diff] [blame] | 384 | if ((!ei->chain_head_change && !ei->chain_head_change_priv) || |
| 385 | (item->chain_head_change == ei->chain_head_change && |
| 386 | item->chain_head_change_priv == ei->chain_head_change_priv)) { |
| Jiri Pirko | f71e0ca4 | 2018-07-23 09:23:05 +0200 | [diff] [blame^] | 387 | if (chain0) |
| 388 | tcf_chain_head_change_item(item, NULL); |
| Jiri Pirko | a9b1944 | 2018-01-17 11:46:45 +0100 | [diff] [blame] | 389 | list_del(&item->list); |
| 390 | kfree(item); |
| 391 | return; |
| 392 | } |
| 393 | } |
| 394 | WARN_ON(1); |
| 395 | } |
| 396 | |
| Jiri Pirko | 4861738 | 2018-01-17 11:46:46 +0100 | [diff] [blame] | 397 | struct tcf_net { |
| 398 | struct idr idr; |
| 399 | }; |
| 400 | |
| 401 | static unsigned int tcf_net_id; |
| 402 | |
| 403 | static int tcf_block_insert(struct tcf_block *block, struct net *net, |
| Jiri Pirko | bb047dd | 2018-02-13 12:00:16 +0100 | [diff] [blame] | 404 | struct netlink_ext_ack *extack) |
| Jiri Pirko | a9b1944 | 2018-01-17 11:46:45 +0100 | [diff] [blame] | 405 | { |
| Jiri Pirko | 4861738 | 2018-01-17 11:46:46 +0100 | [diff] [blame] | 406 | struct tcf_net *tn = net_generic(net, tcf_net_id); |
| Jiri Pirko | 4861738 | 2018-01-17 11:46:46 +0100 | [diff] [blame] | 407 | |
| Jiri Pirko | bb047dd | 2018-02-13 12:00:16 +0100 | [diff] [blame] | 408 | return idr_alloc_u32(&tn->idr, block, &block->index, block->index, |
| 409 | GFP_KERNEL); |
| Jiri Pirko | a9b1944 | 2018-01-17 11:46:45 +0100 | [diff] [blame] | 410 | } |
| 411 | |
| Jiri Pirko | 4861738 | 2018-01-17 11:46:46 +0100 | [diff] [blame] | 412 | static void tcf_block_remove(struct tcf_block *block, struct net *net) |
| Jiri Pirko | 6529eab | 2017-05-17 11:07:55 +0200 | [diff] [blame] | 413 | { |
| Jiri Pirko | 4861738 | 2018-01-17 11:46:46 +0100 | [diff] [blame] | 414 | struct tcf_net *tn = net_generic(net, tcf_net_id); |
| 415 | |
| Matthew Wilcox | 9c16094 | 2017-11-28 09:48:43 -0500 | [diff] [blame] | 416 | idr_remove(&tn->idr, block->index); |
| Jiri Pirko | 4861738 | 2018-01-17 11:46:46 +0100 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | static struct tcf_block *tcf_block_create(struct net *net, struct Qdisc *q, |
| Jiri Pirko | bb047dd | 2018-02-13 12:00:16 +0100 | [diff] [blame] | 420 | u32 block_index, |
| Jiri Pirko | 4861738 | 2018-01-17 11:46:46 +0100 | [diff] [blame] | 421 | struct netlink_ext_ack *extack) |
| 422 | { |
| 423 | struct tcf_block *block; |
| Jiri Pirko | 6529eab | 2017-05-17 11:07:55 +0200 | [diff] [blame] | 424 | |
| Jiri Pirko | 4861738 | 2018-01-17 11:46:46 +0100 | [diff] [blame] | 425 | block = kzalloc(sizeof(*block), GFP_KERNEL); |
| Alexander Aring | 8d1a77f | 2017-12-20 12:35:19 -0500 | [diff] [blame] | 426 | if (!block) { |
| 427 | NL_SET_ERR_MSG(extack, "Memory allocation for block failed"); |
| Jiri Pirko | 4861738 | 2018-01-17 11:46:46 +0100 | [diff] [blame] | 428 | return ERR_PTR(-ENOMEM); |
| Alexander Aring | 8d1a77f | 2017-12-20 12:35:19 -0500 | [diff] [blame] | 429 | } |
| Jiri Pirko | 5bc1701 | 2017-05-17 11:08:01 +0200 | [diff] [blame] | 430 | INIT_LIST_HEAD(&block->chain_list); |
| Jiri Pirko | acb6744 | 2017-10-19 15:50:31 +0200 | [diff] [blame] | 431 | INIT_LIST_HEAD(&block->cb_list); |
| Jiri Pirko | f36fe1c | 2018-01-17 11:46:48 +0100 | [diff] [blame] | 432 | INIT_LIST_HEAD(&block->owner_list); |
| Jiri Pirko | f71e0ca4 | 2018-07-23 09:23:05 +0200 | [diff] [blame^] | 433 | INIT_LIST_HEAD(&block->chain0.filter_chain_list); |
| Jiri Pirko | acb6744 | 2017-10-19 15:50:31 +0200 | [diff] [blame] | 434 | |
| Jiri Pirko | 4861738 | 2018-01-17 11:46:46 +0100 | [diff] [blame] | 435 | block->refcnt = 1; |
| 436 | block->net = net; |
| Jiri Pirko | bb047dd | 2018-02-13 12:00:16 +0100 | [diff] [blame] | 437 | block->index = block_index; |
| 438 | |
| 439 | /* Don't store q pointer for blocks which are shared */ |
| 440 | if (!tcf_block_shared(block)) |
| 441 | block->q = q; |
| Jiri Pirko | 4861738 | 2018-01-17 11:46:46 +0100 | [diff] [blame] | 442 | return block; |
| Jiri Pirko | 4861738 | 2018-01-17 11:46:46 +0100 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | static struct tcf_block *tcf_block_lookup(struct net *net, u32 block_index) |
| 446 | { |
| 447 | struct tcf_net *tn = net_generic(net, tcf_net_id); |
| 448 | |
| Matthew Wilcox | 322d884 | 2017-11-28 10:01:24 -0500 | [diff] [blame] | 449 | return idr_find(&tn->idr, block_index); |
| Jiri Pirko | 4861738 | 2018-01-17 11:46:46 +0100 | [diff] [blame] | 450 | } |
| 451 | |
| Vlad Buslov | c431f89 | 2018-05-31 09:52:53 +0300 | [diff] [blame] | 452 | /* Find tcf block. |
| 453 | * Set q, parent, cl when appropriate. |
| 454 | */ |
| 455 | |
| 456 | static struct tcf_block *tcf_block_find(struct net *net, struct Qdisc **q, |
| 457 | u32 *parent, unsigned long *cl, |
| 458 | int ifindex, u32 block_index, |
| 459 | struct netlink_ext_ack *extack) |
| 460 | { |
| 461 | struct tcf_block *block; |
| 462 | |
| 463 | if (ifindex == TCM_IFINDEX_MAGIC_BLOCK) { |
| 464 | block = tcf_block_lookup(net, block_index); |
| 465 | if (!block) { |
| 466 | NL_SET_ERR_MSG(extack, "Block of given index was not found"); |
| 467 | return ERR_PTR(-EINVAL); |
| 468 | } |
| 469 | } else { |
| 470 | const struct Qdisc_class_ops *cops; |
| 471 | struct net_device *dev; |
| 472 | |
| 473 | /* Find link */ |
| 474 | dev = __dev_get_by_index(net, ifindex); |
| 475 | if (!dev) |
| 476 | return ERR_PTR(-ENODEV); |
| 477 | |
| 478 | /* Find qdisc */ |
| 479 | if (!*parent) { |
| 480 | *q = dev->qdisc; |
| 481 | *parent = (*q)->handle; |
| 482 | } else { |
| 483 | *q = qdisc_lookup(dev, TC_H_MAJ(*parent)); |
| 484 | if (!*q) { |
| 485 | NL_SET_ERR_MSG(extack, "Parent Qdisc doesn't exists"); |
| 486 | return ERR_PTR(-EINVAL); |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | /* Is it classful? */ |
| 491 | cops = (*q)->ops->cl_ops; |
| 492 | if (!cops) { |
| 493 | NL_SET_ERR_MSG(extack, "Qdisc not classful"); |
| 494 | return ERR_PTR(-EINVAL); |
| 495 | } |
| 496 | |
| 497 | if (!cops->tcf_block) { |
| 498 | NL_SET_ERR_MSG(extack, "Class doesn't support blocks"); |
| 499 | return ERR_PTR(-EOPNOTSUPP); |
| 500 | } |
| 501 | |
| 502 | /* Do we search for filter, attached to class? */ |
| 503 | if (TC_H_MIN(*parent)) { |
| 504 | *cl = cops->find(*q, *parent); |
| 505 | if (*cl == 0) { |
| 506 | NL_SET_ERR_MSG(extack, "Specified class doesn't exist"); |
| 507 | return ERR_PTR(-ENOENT); |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | /* And the last stroke */ |
| 512 | block = cops->tcf_block(*q, *cl, extack); |
| 513 | if (!block) |
| 514 | return ERR_PTR(-EINVAL); |
| 515 | if (tcf_block_shared(block)) { |
| 516 | NL_SET_ERR_MSG(extack, "This filter block is shared. Please use the block index to manipulate the filters"); |
| 517 | return ERR_PTR(-EOPNOTSUPP); |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | return block; |
| 522 | } |
| 523 | |
| Jiri Pirko | f36fe1c | 2018-01-17 11:46:48 +0100 | [diff] [blame] | 524 | struct tcf_block_owner_item { |
| 525 | struct list_head list; |
| 526 | struct Qdisc *q; |
| 527 | enum tcf_block_binder_type binder_type; |
| 528 | }; |
| 529 | |
| 530 | static void |
| 531 | tcf_block_owner_netif_keep_dst(struct tcf_block *block, |
| 532 | struct Qdisc *q, |
| 533 | enum tcf_block_binder_type binder_type) |
| 534 | { |
| 535 | if (block->keep_dst && |
| 536 | binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS && |
| 537 | binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_EGRESS) |
| 538 | netif_keep_dst(qdisc_dev(q)); |
| 539 | } |
| 540 | |
| 541 | void tcf_block_netif_keep_dst(struct tcf_block *block) |
| 542 | { |
| 543 | struct tcf_block_owner_item *item; |
| 544 | |
| 545 | block->keep_dst = true; |
| 546 | list_for_each_entry(item, &block->owner_list, list) |
| 547 | tcf_block_owner_netif_keep_dst(block, item->q, |
| 548 | item->binder_type); |
| 549 | } |
| 550 | EXPORT_SYMBOL(tcf_block_netif_keep_dst); |
| 551 | |
| 552 | static int tcf_block_owner_add(struct tcf_block *block, |
| 553 | struct Qdisc *q, |
| 554 | enum tcf_block_binder_type binder_type) |
| 555 | { |
| 556 | struct tcf_block_owner_item *item; |
| 557 | |
| 558 | item = kmalloc(sizeof(*item), GFP_KERNEL); |
| 559 | if (!item) |
| 560 | return -ENOMEM; |
| 561 | item->q = q; |
| 562 | item->binder_type = binder_type; |
| 563 | list_add(&item->list, &block->owner_list); |
| 564 | return 0; |
| 565 | } |
| 566 | |
| 567 | static void tcf_block_owner_del(struct tcf_block *block, |
| 568 | struct Qdisc *q, |
| 569 | enum tcf_block_binder_type binder_type) |
| 570 | { |
| 571 | struct tcf_block_owner_item *item; |
| 572 | |
| 573 | list_for_each_entry(item, &block->owner_list, list) { |
| 574 | if (item->q == q && item->binder_type == binder_type) { |
| 575 | list_del(&item->list); |
| 576 | kfree(item); |
| 577 | return; |
| 578 | } |
| 579 | } |
| 580 | WARN_ON(1); |
| 581 | } |
| 582 | |
| Jiri Pirko | 4861738 | 2018-01-17 11:46:46 +0100 | [diff] [blame] | 583 | int tcf_block_get_ext(struct tcf_block **p_block, struct Qdisc *q, |
| 584 | struct tcf_block_ext_info *ei, |
| 585 | struct netlink_ext_ack *extack) |
| 586 | { |
| 587 | struct net *net = qdisc_net(q); |
| 588 | struct tcf_block *block = NULL; |
| 589 | bool created = false; |
| 590 | int err; |
| 591 | |
| 592 | if (ei->block_index) { |
| 593 | /* block_index not 0 means the shared block is requested */ |
| 594 | block = tcf_block_lookup(net, ei->block_index); |
| 595 | if (block) |
| 596 | block->refcnt++; |
| 597 | } |
| 598 | |
| 599 | if (!block) { |
| Jiri Pirko | bb047dd | 2018-02-13 12:00:16 +0100 | [diff] [blame] | 600 | block = tcf_block_create(net, q, ei->block_index, extack); |
| Jiri Pirko | 4861738 | 2018-01-17 11:46:46 +0100 | [diff] [blame] | 601 | if (IS_ERR(block)) |
| 602 | return PTR_ERR(block); |
| 603 | created = true; |
| Jiri Pirko | bb047dd | 2018-02-13 12:00:16 +0100 | [diff] [blame] | 604 | if (tcf_block_shared(block)) { |
| 605 | err = tcf_block_insert(block, net, extack); |
| Jiri Pirko | 4861738 | 2018-01-17 11:46:46 +0100 | [diff] [blame] | 606 | if (err) |
| 607 | goto err_block_insert; |
| 608 | } |
| 609 | } |
| 610 | |
| Jiri Pirko | f36fe1c | 2018-01-17 11:46:48 +0100 | [diff] [blame] | 611 | err = tcf_block_owner_add(block, q, ei->binder_type); |
| 612 | if (err) |
| 613 | goto err_block_owner_add; |
| 614 | |
| 615 | tcf_block_owner_netif_keep_dst(block, q, ei->binder_type); |
| 616 | |
| Jiri Pirko | f71e0ca4 | 2018-07-23 09:23:05 +0200 | [diff] [blame^] | 617 | err = tcf_chain0_head_change_cb_add(block, ei, extack); |
| Jiri Pirko | a9b1944 | 2018-01-17 11:46:45 +0100 | [diff] [blame] | 618 | if (err) |
| Jiri Pirko | f71e0ca4 | 2018-07-23 09:23:05 +0200 | [diff] [blame^] | 619 | goto err_chain0_head_change_cb_add; |
| Jiri Pirko | caa7260 | 2018-01-17 11:46:50 +0100 | [diff] [blame] | 620 | |
| John Hurley | 60513bd | 2018-06-25 14:30:04 -0700 | [diff] [blame] | 621 | err = tcf_block_offload_bind(block, q, ei, extack); |
| Jiri Pirko | caa7260 | 2018-01-17 11:46:50 +0100 | [diff] [blame] | 622 | if (err) |
| 623 | goto err_block_offload_bind; |
| 624 | |
| Jiri Pirko | 6529eab | 2017-05-17 11:07:55 +0200 | [diff] [blame] | 625 | *p_block = block; |
| 626 | return 0; |
| Jiri Pirko | 2190d1d | 2017-05-17 11:07:59 +0200 | [diff] [blame] | 627 | |
| Jiri Pirko | caa7260 | 2018-01-17 11:46:50 +0100 | [diff] [blame] | 628 | err_block_offload_bind: |
| Jiri Pirko | f71e0ca4 | 2018-07-23 09:23:05 +0200 | [diff] [blame^] | 629 | tcf_chain0_head_change_cb_del(block, ei); |
| 630 | err_chain0_head_change_cb_add: |
| Jiri Pirko | f36fe1c | 2018-01-17 11:46:48 +0100 | [diff] [blame] | 631 | tcf_block_owner_del(block, q, ei->binder_type); |
| 632 | err_block_owner_add: |
| Jiri Pirko | 4861738 | 2018-01-17 11:46:46 +0100 | [diff] [blame] | 633 | if (created) { |
| 634 | if (tcf_block_shared(block)) |
| 635 | tcf_block_remove(block, net); |
| 636 | err_block_insert: |
| Jiri Pirko | 4861738 | 2018-01-17 11:46:46 +0100 | [diff] [blame] | 637 | kfree(block); |
| 638 | } else { |
| 639 | block->refcnt--; |
| 640 | } |
| Jiri Pirko | 2190d1d | 2017-05-17 11:07:59 +0200 | [diff] [blame] | 641 | return err; |
| Jiri Pirko | 6529eab | 2017-05-17 11:07:55 +0200 | [diff] [blame] | 642 | } |
| Jiri Pirko | 8c4083b | 2017-10-19 15:50:29 +0200 | [diff] [blame] | 643 | EXPORT_SYMBOL(tcf_block_get_ext); |
| 644 | |
| Jiri Pirko | c7eb7d7 | 2017-11-03 11:46:24 +0100 | [diff] [blame] | 645 | static void tcf_chain_head_change_dflt(struct tcf_proto *tp_head, void *priv) |
| 646 | { |
| 647 | struct tcf_proto __rcu **p_filter_chain = priv; |
| 648 | |
| 649 | rcu_assign_pointer(*p_filter_chain, tp_head); |
| 650 | } |
| 651 | |
| Jiri Pirko | 8c4083b | 2017-10-19 15:50:29 +0200 | [diff] [blame] | 652 | int tcf_block_get(struct tcf_block **p_block, |
| Alexander Aring | 8d1a77f | 2017-12-20 12:35:19 -0500 | [diff] [blame] | 653 | struct tcf_proto __rcu **p_filter_chain, struct Qdisc *q, |
| 654 | struct netlink_ext_ack *extack) |
| Jiri Pirko | 8c4083b | 2017-10-19 15:50:29 +0200 | [diff] [blame] | 655 | { |
| Jiri Pirko | c7eb7d7 | 2017-11-03 11:46:24 +0100 | [diff] [blame] | 656 | struct tcf_block_ext_info ei = { |
| 657 | .chain_head_change = tcf_chain_head_change_dflt, |
| 658 | .chain_head_change_priv = p_filter_chain, |
| 659 | }; |
| Jiri Pirko | 8c4083b | 2017-10-19 15:50:29 +0200 | [diff] [blame] | 660 | |
| Jiri Pirko | c7eb7d7 | 2017-11-03 11:46:24 +0100 | [diff] [blame] | 661 | WARN_ON(!p_filter_chain); |
| Alexander Aring | 8d1a77f | 2017-12-20 12:35:19 -0500 | [diff] [blame] | 662 | return tcf_block_get_ext(p_block, q, &ei, extack); |
| Jiri Pirko | 8c4083b | 2017-10-19 15:50:29 +0200 | [diff] [blame] | 663 | } |
| Jiri Pirko | 6529eab | 2017-05-17 11:07:55 +0200 | [diff] [blame] | 664 | EXPORT_SYMBOL(tcf_block_get); |
| 665 | |
| Cong Wang | 7aa0045 | 2017-10-26 18:24:28 -0700 | [diff] [blame] | 666 | /* XXX: Standalone actions are not allowed to jump to any chain, and bound |
| Roman Kapl | a60b3f5 | 2017-11-24 12:27:58 +0100 | [diff] [blame] | 667 | * actions should be all removed after flushing. |
| Cong Wang | 7aa0045 | 2017-10-26 18:24:28 -0700 | [diff] [blame] | 668 | */ |
| Jiri Pirko | c7eb7d7 | 2017-11-03 11:46:24 +0100 | [diff] [blame] | 669 | void tcf_block_put_ext(struct tcf_block *block, struct Qdisc *q, |
| David S. Miller | e1ea2f9 | 2017-10-30 14:10:01 +0900 | [diff] [blame] | 670 | struct tcf_block_ext_info *ei) |
| Cong Wang | 7aa0045 | 2017-10-26 18:24:28 -0700 | [diff] [blame] | 671 | { |
| Cong Wang | efbf789 | 2017-12-04 10:48:18 -0800 | [diff] [blame] | 672 | struct tcf_chain *chain, *tmp; |
| Cong Wang | 1697c4b | 2017-09-11 16:33:32 -0700 | [diff] [blame] | 673 | |
| David S. Miller | c30abd5 | 2017-12-16 22:11:55 -0500 | [diff] [blame] | 674 | if (!block) |
| 675 | return; |
| Jiri Pirko | f71e0ca4 | 2018-07-23 09:23:05 +0200 | [diff] [blame^] | 676 | tcf_chain0_head_change_cb_del(block, ei); |
| Jiri Pirko | f36fe1c | 2018-01-17 11:46:48 +0100 | [diff] [blame] | 677 | tcf_block_owner_del(block, q, ei->binder_type); |
| Roman Kapl | a60b3f5 | 2017-11-24 12:27:58 +0100 | [diff] [blame] | 678 | |
| Jiri Pirko | f71e0ca4 | 2018-07-23 09:23:05 +0200 | [diff] [blame^] | 679 | if (block->refcnt == 1) { |
| Jiri Pirko | 4861738 | 2018-01-17 11:46:46 +0100 | [diff] [blame] | 680 | if (tcf_block_shared(block)) |
| 681 | tcf_block_remove(block, block->net); |
| 682 | |
| 683 | /* Hold a refcnt for all chains, so that they don't disappear |
| 684 | * while we are iterating. |
| 685 | */ |
| 686 | list_for_each_entry(chain, &block->chain_list, list) |
| 687 | tcf_chain_hold(chain); |
| 688 | |
| 689 | list_for_each_entry(chain, &block->chain_list, list) |
| 690 | tcf_chain_flush(chain); |
| 691 | } |
| Cong Wang | 1697c4b | 2017-09-11 16:33:32 -0700 | [diff] [blame] | 692 | |
| Jiri Pirko | 4bb1b11 | 2017-11-02 15:07:01 +0100 | [diff] [blame] | 693 | tcf_block_offload_unbind(block, q, ei); |
| 694 | |
| Jiri Pirko | f71e0ca4 | 2018-07-23 09:23:05 +0200 | [diff] [blame^] | 695 | if (block->refcnt == 1) { |
| Jiri Pirko | 4861738 | 2018-01-17 11:46:46 +0100 | [diff] [blame] | 696 | /* At this point, all the chains should have refcnt >= 1. */ |
| 697 | list_for_each_entry_safe(chain, tmp, &block->chain_list, list) |
| 698 | tcf_chain_put(chain); |
| Jiri Pirko | df45bf8 | 2017-12-08 19:27:27 +0100 | [diff] [blame] | 699 | |
| Jiri Pirko | f71e0ca4 | 2018-07-23 09:23:05 +0200 | [diff] [blame^] | 700 | block->refcnt--; |
| 701 | if (list_empty(&block->chain_list)) |
| 702 | kfree(block); |
| Jiri Pirko | 4861738 | 2018-01-17 11:46:46 +0100 | [diff] [blame] | 703 | } |
| Jiri Pirko | 6529eab | 2017-05-17 11:07:55 +0200 | [diff] [blame] | 704 | } |
| Jiri Pirko | 8c4083b | 2017-10-19 15:50:29 +0200 | [diff] [blame] | 705 | EXPORT_SYMBOL(tcf_block_put_ext); |
| 706 | |
| 707 | void tcf_block_put(struct tcf_block *block) |
| 708 | { |
| 709 | struct tcf_block_ext_info ei = {0, }; |
| 710 | |
| Jiri Pirko | 4853f12 | 2017-12-21 13:13:59 +0100 | [diff] [blame] | 711 | if (!block) |
| 712 | return; |
| Jiri Pirko | c7eb7d7 | 2017-11-03 11:46:24 +0100 | [diff] [blame] | 713 | tcf_block_put_ext(block, block->q, &ei); |
| Jiri Pirko | 8c4083b | 2017-10-19 15:50:29 +0200 | [diff] [blame] | 714 | } |
| David S. Miller | e1ea2f9 | 2017-10-30 14:10:01 +0900 | [diff] [blame] | 715 | |
| Jiri Pirko | 6529eab | 2017-05-17 11:07:55 +0200 | [diff] [blame] | 716 | EXPORT_SYMBOL(tcf_block_put); |
| Jiri Pirko | cf1facd | 2017-02-09 14:38:56 +0100 | [diff] [blame] | 717 | |
| Jiri Pirko | acb6744 | 2017-10-19 15:50:31 +0200 | [diff] [blame] | 718 | struct tcf_block_cb { |
| 719 | struct list_head list; |
| 720 | tc_setup_cb_t *cb; |
| 721 | void *cb_ident; |
| 722 | void *cb_priv; |
| 723 | unsigned int refcnt; |
| 724 | }; |
| 725 | |
| 726 | void *tcf_block_cb_priv(struct tcf_block_cb *block_cb) |
| 727 | { |
| 728 | return block_cb->cb_priv; |
| 729 | } |
| 730 | EXPORT_SYMBOL(tcf_block_cb_priv); |
| 731 | |
| 732 | struct tcf_block_cb *tcf_block_cb_lookup(struct tcf_block *block, |
| 733 | tc_setup_cb_t *cb, void *cb_ident) |
| 734 | { struct tcf_block_cb *block_cb; |
| 735 | |
| 736 | list_for_each_entry(block_cb, &block->cb_list, list) |
| 737 | if (block_cb->cb == cb && block_cb->cb_ident == cb_ident) |
| 738 | return block_cb; |
| 739 | return NULL; |
| 740 | } |
| 741 | EXPORT_SYMBOL(tcf_block_cb_lookup); |
| 742 | |
| 743 | void tcf_block_cb_incref(struct tcf_block_cb *block_cb) |
| 744 | { |
| 745 | block_cb->refcnt++; |
| 746 | } |
| 747 | EXPORT_SYMBOL(tcf_block_cb_incref); |
| 748 | |
| 749 | unsigned int tcf_block_cb_decref(struct tcf_block_cb *block_cb) |
| 750 | { |
| 751 | return --block_cb->refcnt; |
| 752 | } |
| 753 | EXPORT_SYMBOL(tcf_block_cb_decref); |
| 754 | |
| John Hurley | 3263674 | 2018-06-25 14:30:10 -0700 | [diff] [blame] | 755 | static int |
| 756 | tcf_block_playback_offloads(struct tcf_block *block, tc_setup_cb_t *cb, |
| 757 | void *cb_priv, bool add, bool offload_in_use, |
| 758 | struct netlink_ext_ack *extack) |
| 759 | { |
| 760 | struct tcf_chain *chain; |
| 761 | struct tcf_proto *tp; |
| 762 | int err; |
| 763 | |
| 764 | list_for_each_entry(chain, &block->chain_list, list) { |
| 765 | for (tp = rtnl_dereference(chain->filter_chain); tp; |
| 766 | tp = rtnl_dereference(tp->next)) { |
| 767 | if (tp->ops->reoffload) { |
| 768 | err = tp->ops->reoffload(tp, add, cb, cb_priv, |
| 769 | extack); |
| 770 | if (err && add) |
| 771 | goto err_playback_remove; |
| 772 | } else if (add && offload_in_use) { |
| 773 | err = -EOPNOTSUPP; |
| 774 | NL_SET_ERR_MSG(extack, "Filter HW offload failed - classifier without re-offloading support"); |
| 775 | goto err_playback_remove; |
| 776 | } |
| 777 | } |
| 778 | } |
| 779 | |
| 780 | return 0; |
| 781 | |
| 782 | err_playback_remove: |
| 783 | tcf_block_playback_offloads(block, cb, cb_priv, false, offload_in_use, |
| 784 | extack); |
| 785 | return err; |
| 786 | } |
| 787 | |
| Jiri Pirko | acb6744 | 2017-10-19 15:50:31 +0200 | [diff] [blame] | 788 | struct tcf_block_cb *__tcf_block_cb_register(struct tcf_block *block, |
| 789 | tc_setup_cb_t *cb, void *cb_ident, |
| John Hurley | 60513bd | 2018-06-25 14:30:04 -0700 | [diff] [blame] | 790 | void *cb_priv, |
| 791 | struct netlink_ext_ack *extack) |
| Jiri Pirko | acb6744 | 2017-10-19 15:50:31 +0200 | [diff] [blame] | 792 | { |
| 793 | struct tcf_block_cb *block_cb; |
| John Hurley | 3263674 | 2018-06-25 14:30:10 -0700 | [diff] [blame] | 794 | int err; |
| Jiri Pirko | acb6744 | 2017-10-19 15:50:31 +0200 | [diff] [blame] | 795 | |
| John Hurley | 3263674 | 2018-06-25 14:30:10 -0700 | [diff] [blame] | 796 | /* Replay any already present rules */ |
| 797 | err = tcf_block_playback_offloads(block, cb, cb_priv, true, |
| 798 | tcf_block_offload_in_use(block), |
| 799 | extack); |
| 800 | if (err) |
| 801 | return ERR_PTR(err); |
| Jiri Pirko | caa7260 | 2018-01-17 11:46:50 +0100 | [diff] [blame] | 802 | |
| Jiri Pirko | acb6744 | 2017-10-19 15:50:31 +0200 | [diff] [blame] | 803 | block_cb = kzalloc(sizeof(*block_cb), GFP_KERNEL); |
| 804 | if (!block_cb) |
| Jiri Pirko | caa7260 | 2018-01-17 11:46:50 +0100 | [diff] [blame] | 805 | return ERR_PTR(-ENOMEM); |
| Jiri Pirko | acb6744 | 2017-10-19 15:50:31 +0200 | [diff] [blame] | 806 | block_cb->cb = cb; |
| 807 | block_cb->cb_ident = cb_ident; |
| 808 | block_cb->cb_priv = cb_priv; |
| 809 | list_add(&block_cb->list, &block->cb_list); |
| 810 | return block_cb; |
| 811 | } |
| 812 | EXPORT_SYMBOL(__tcf_block_cb_register); |
| 813 | |
| 814 | int tcf_block_cb_register(struct tcf_block *block, |
| 815 | tc_setup_cb_t *cb, void *cb_ident, |
| John Hurley | 60513bd | 2018-06-25 14:30:04 -0700 | [diff] [blame] | 816 | void *cb_priv, struct netlink_ext_ack *extack) |
| Jiri Pirko | acb6744 | 2017-10-19 15:50:31 +0200 | [diff] [blame] | 817 | { |
| 818 | struct tcf_block_cb *block_cb; |
| 819 | |
| John Hurley | 60513bd | 2018-06-25 14:30:04 -0700 | [diff] [blame] | 820 | block_cb = __tcf_block_cb_register(block, cb, cb_ident, cb_priv, |
| 821 | extack); |
| Gustavo A. R. Silva | baa2d2b | 2018-07-18 23:14:17 -0500 | [diff] [blame] | 822 | return PTR_ERR_OR_ZERO(block_cb); |
| Jiri Pirko | acb6744 | 2017-10-19 15:50:31 +0200 | [diff] [blame] | 823 | } |
| 824 | EXPORT_SYMBOL(tcf_block_cb_register); |
| 825 | |
| John Hurley | 3263674 | 2018-06-25 14:30:10 -0700 | [diff] [blame] | 826 | void __tcf_block_cb_unregister(struct tcf_block *block, |
| 827 | struct tcf_block_cb *block_cb) |
| Jiri Pirko | acb6744 | 2017-10-19 15:50:31 +0200 | [diff] [blame] | 828 | { |
| John Hurley | 3263674 | 2018-06-25 14:30:10 -0700 | [diff] [blame] | 829 | tcf_block_playback_offloads(block, block_cb->cb, block_cb->cb_priv, |
| 830 | false, tcf_block_offload_in_use(block), |
| 831 | NULL); |
| Jiri Pirko | acb6744 | 2017-10-19 15:50:31 +0200 | [diff] [blame] | 832 | list_del(&block_cb->list); |
| 833 | kfree(block_cb); |
| 834 | } |
| 835 | EXPORT_SYMBOL(__tcf_block_cb_unregister); |
| 836 | |
| 837 | void tcf_block_cb_unregister(struct tcf_block *block, |
| 838 | tc_setup_cb_t *cb, void *cb_ident) |
| 839 | { |
| 840 | struct tcf_block_cb *block_cb; |
| 841 | |
| 842 | block_cb = tcf_block_cb_lookup(block, cb, cb_ident); |
| 843 | if (!block_cb) |
| 844 | return; |
| John Hurley | 3263674 | 2018-06-25 14:30:10 -0700 | [diff] [blame] | 845 | __tcf_block_cb_unregister(block, block_cb); |
| Jiri Pirko | acb6744 | 2017-10-19 15:50:31 +0200 | [diff] [blame] | 846 | } |
| 847 | EXPORT_SYMBOL(tcf_block_cb_unregister); |
| 848 | |
| 849 | static int tcf_block_cb_call(struct tcf_block *block, enum tc_setup_type type, |
| 850 | void *type_data, bool err_stop) |
| 851 | { |
| 852 | struct tcf_block_cb *block_cb; |
| 853 | int ok_count = 0; |
| 854 | int err; |
| 855 | |
| David S. Miller | 9a99dc1 | 2018-06-06 13:55:47 -0400 | [diff] [blame] | 856 | /* Make sure all netdevs sharing this block are offload-capable. */ |
| 857 | if (block->nooffloaddevcnt && err_stop) |
| 858 | return -EOPNOTSUPP; |
| 859 | |
| Jiri Pirko | acb6744 | 2017-10-19 15:50:31 +0200 | [diff] [blame] | 860 | list_for_each_entry(block_cb, &block->cb_list, list) { |
| 861 | err = block_cb->cb(type, type_data, block_cb->cb_priv); |
| 862 | if (err) { |
| 863 | if (err_stop) |
| 864 | return err; |
| 865 | } else { |
| 866 | ok_count++; |
| 867 | } |
| 868 | } |
| 869 | return ok_count; |
| 870 | } |
| 871 | |
| Jiri Pirko | 87d8309 | 2017-05-17 11:07:54 +0200 | [diff] [blame] | 872 | /* Main classifier routine: scans classifier chain attached |
| 873 | * to this qdisc, (optionally) tests for protocol and asks |
| 874 | * specific classifiers. |
| 875 | */ |
| 876 | int tcf_classify(struct sk_buff *skb, const struct tcf_proto *tp, |
| 877 | struct tcf_result *res, bool compat_mode) |
| 878 | { |
| 879 | __be16 protocol = tc_skb_protocol(skb); |
| 880 | #ifdef CONFIG_NET_CLS_ACT |
| 881 | const int max_reclassify_loop = 4; |
| Jiri Pirko | ee538dc | 2017-05-23 09:11:59 +0200 | [diff] [blame] | 882 | const struct tcf_proto *orig_tp = tp; |
| 883 | const struct tcf_proto *first_tp; |
| Jiri Pirko | 87d8309 | 2017-05-17 11:07:54 +0200 | [diff] [blame] | 884 | int limit = 0; |
| 885 | |
| 886 | reclassify: |
| 887 | #endif |
| 888 | for (; tp; tp = rcu_dereference_bh(tp->next)) { |
| 889 | int err; |
| 890 | |
| 891 | if (tp->protocol != protocol && |
| 892 | tp->protocol != htons(ETH_P_ALL)) |
| 893 | continue; |
| 894 | |
| 895 | err = tp->classify(skb, tp, res); |
| 896 | #ifdef CONFIG_NET_CLS_ACT |
| Jiri Pirko | db50514 | 2017-05-17 11:08:03 +0200 | [diff] [blame] | 897 | if (unlikely(err == TC_ACT_RECLASSIFY && !compat_mode)) { |
| Jiri Pirko | ee538dc | 2017-05-23 09:11:59 +0200 | [diff] [blame] | 898 | first_tp = orig_tp; |
| Jiri Pirko | 87d8309 | 2017-05-17 11:07:54 +0200 | [diff] [blame] | 899 | goto reset; |
| Jiri Pirko | db50514 | 2017-05-17 11:08:03 +0200 | [diff] [blame] | 900 | } else if (unlikely(TC_ACT_EXT_CMP(err, TC_ACT_GOTO_CHAIN))) { |
| Jiri Pirko | ee538dc | 2017-05-23 09:11:59 +0200 | [diff] [blame] | 901 | first_tp = res->goto_tp; |
| Jiri Pirko | db50514 | 2017-05-17 11:08:03 +0200 | [diff] [blame] | 902 | goto reset; |
| 903 | } |
| Jiri Pirko | 87d8309 | 2017-05-17 11:07:54 +0200 | [diff] [blame] | 904 | #endif |
| 905 | if (err >= 0) |
| 906 | return err; |
| 907 | } |
| 908 | |
| 909 | return TC_ACT_UNSPEC; /* signal: continue lookup */ |
| 910 | #ifdef CONFIG_NET_CLS_ACT |
| 911 | reset: |
| 912 | if (unlikely(limit++ >= max_reclassify_loop)) { |
| Jiri Pirko | 9d3aaff | 2018-01-17 11:46:47 +0100 | [diff] [blame] | 913 | net_notice_ratelimited("%u: reclassify loop, rule prio %u, protocol %02x\n", |
| 914 | tp->chain->block->index, |
| 915 | tp->prio & 0xffff, |
| Jiri Pirko | 87d8309 | 2017-05-17 11:07:54 +0200 | [diff] [blame] | 916 | ntohs(tp->protocol)); |
| 917 | return TC_ACT_SHOT; |
| 918 | } |
| 919 | |
| Jiri Pirko | ee538dc | 2017-05-23 09:11:59 +0200 | [diff] [blame] | 920 | tp = first_tp; |
| Jiri Pirko | 87d8309 | 2017-05-17 11:07:54 +0200 | [diff] [blame] | 921 | protocol = tc_skb_protocol(skb); |
| 922 | goto reclassify; |
| 923 | #endif |
| 924 | } |
| 925 | EXPORT_SYMBOL(tcf_classify); |
| 926 | |
| Jiri Pirko | 2190d1d | 2017-05-17 11:07:59 +0200 | [diff] [blame] | 927 | struct tcf_chain_info { |
| 928 | struct tcf_proto __rcu **pprev; |
| 929 | struct tcf_proto __rcu *next; |
| 930 | }; |
| 931 | |
| 932 | static struct tcf_proto *tcf_chain_tp_prev(struct tcf_chain_info *chain_info) |
| 933 | { |
| 934 | return rtnl_dereference(*chain_info->pprev); |
| 935 | } |
| 936 | |
| 937 | static void tcf_chain_tp_insert(struct tcf_chain *chain, |
| 938 | struct tcf_chain_info *chain_info, |
| 939 | struct tcf_proto *tp) |
| 940 | { |
| Jiri Pirko | c7eb7d7 | 2017-11-03 11:46:24 +0100 | [diff] [blame] | 941 | if (*chain_info->pprev == chain->filter_chain) |
| Jiri Pirko | f71e0ca4 | 2018-07-23 09:23:05 +0200 | [diff] [blame^] | 942 | tcf_chain0_head_change(chain, tp); |
| Jiri Pirko | 2190d1d | 2017-05-17 11:07:59 +0200 | [diff] [blame] | 943 | RCU_INIT_POINTER(tp->next, tcf_chain_tp_prev(chain_info)); |
| 944 | rcu_assign_pointer(*chain_info->pprev, tp); |
| Cong Wang | e2ef754 | 2017-09-11 16:33:31 -0700 | [diff] [blame] | 945 | tcf_chain_hold(chain); |
| Jiri Pirko | 2190d1d | 2017-05-17 11:07:59 +0200 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | static void tcf_chain_tp_remove(struct tcf_chain *chain, |
| 949 | struct tcf_chain_info *chain_info, |
| 950 | struct tcf_proto *tp) |
| 951 | { |
| 952 | struct tcf_proto *next = rtnl_dereference(chain_info->next); |
| 953 | |
| Jiri Pirko | c7eb7d7 | 2017-11-03 11:46:24 +0100 | [diff] [blame] | 954 | if (tp == chain->filter_chain) |
| Jiri Pirko | f71e0ca4 | 2018-07-23 09:23:05 +0200 | [diff] [blame^] | 955 | tcf_chain0_head_change(chain, next); |
| Jiri Pirko | 2190d1d | 2017-05-17 11:07:59 +0200 | [diff] [blame] | 956 | RCU_INIT_POINTER(*chain_info->pprev, next); |
| Cong Wang | e2ef754 | 2017-09-11 16:33:31 -0700 | [diff] [blame] | 957 | tcf_chain_put(chain); |
| Jiri Pirko | 2190d1d | 2017-05-17 11:07:59 +0200 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | static struct tcf_proto *tcf_chain_tp_find(struct tcf_chain *chain, |
| 961 | struct tcf_chain_info *chain_info, |
| 962 | u32 protocol, u32 prio, |
| 963 | bool prio_allocate) |
| 964 | { |
| 965 | struct tcf_proto **pprev; |
| 966 | struct tcf_proto *tp; |
| 967 | |
| 968 | /* Check the chain for existence of proto-tcf with this priority */ |
| 969 | for (pprev = &chain->filter_chain; |
| 970 | (tp = rtnl_dereference(*pprev)); pprev = &tp->next) { |
| 971 | if (tp->prio >= prio) { |
| 972 | if (tp->prio == prio) { |
| 973 | if (prio_allocate || |
| 974 | (tp->protocol != protocol && protocol)) |
| 975 | return ERR_PTR(-EINVAL); |
| 976 | } else { |
| 977 | tp = NULL; |
| 978 | } |
| 979 | break; |
| 980 | } |
| 981 | } |
| 982 | chain_info->pprev = pprev; |
| 983 | chain_info->next = tp ? tp->next : NULL; |
| 984 | return tp; |
| 985 | } |
| 986 | |
| WANG Cong | 7120371 | 2017-08-07 15:26:50 -0700 | [diff] [blame] | 987 | static int tcf_fill_node(struct net *net, struct sk_buff *skb, |
| Jiri Pirko | 7960d1d | 2018-01-17 11:46:51 +0100 | [diff] [blame] | 988 | struct tcf_proto *tp, struct tcf_block *block, |
| 989 | struct Qdisc *q, u32 parent, void *fh, |
| 990 | u32 portid, u32 seq, u16 flags, int event) |
| WANG Cong | 7120371 | 2017-08-07 15:26:50 -0700 | [diff] [blame] | 991 | { |
| 992 | struct tcmsg *tcm; |
| 993 | struct nlmsghdr *nlh; |
| 994 | unsigned char *b = skb_tail_pointer(skb); |
| 995 | |
| 996 | nlh = nlmsg_put(skb, portid, seq, event, sizeof(*tcm), flags); |
| 997 | if (!nlh) |
| 998 | goto out_nlmsg_trim; |
| 999 | tcm = nlmsg_data(nlh); |
| 1000 | tcm->tcm_family = AF_UNSPEC; |
| 1001 | tcm->tcm__pad1 = 0; |
| 1002 | tcm->tcm__pad2 = 0; |
| Jiri Pirko | 7960d1d | 2018-01-17 11:46:51 +0100 | [diff] [blame] | 1003 | if (q) { |
| 1004 | tcm->tcm_ifindex = qdisc_dev(q)->ifindex; |
| 1005 | tcm->tcm_parent = parent; |
| 1006 | } else { |
| 1007 | tcm->tcm_ifindex = TCM_IFINDEX_MAGIC_BLOCK; |
| 1008 | tcm->tcm_block_index = block->index; |
| 1009 | } |
| WANG Cong | 7120371 | 2017-08-07 15:26:50 -0700 | [diff] [blame] | 1010 | tcm->tcm_info = TC_H_MAKE(tp->prio, tp->protocol); |
| 1011 | if (nla_put_string(skb, TCA_KIND, tp->ops->kind)) |
| 1012 | goto nla_put_failure; |
| 1013 | if (nla_put_u32(skb, TCA_CHAIN, tp->chain->index)) |
| 1014 | goto nla_put_failure; |
| 1015 | if (!fh) { |
| 1016 | tcm->tcm_handle = 0; |
| 1017 | } else { |
| 1018 | if (tp->ops->dump && tp->ops->dump(net, tp, fh, skb, tcm) < 0) |
| 1019 | goto nla_put_failure; |
| 1020 | } |
| 1021 | nlh->nlmsg_len = skb_tail_pointer(skb) - b; |
| 1022 | return skb->len; |
| 1023 | |
| 1024 | out_nlmsg_trim: |
| 1025 | nla_put_failure: |
| 1026 | nlmsg_trim(skb, b); |
| 1027 | return -1; |
| 1028 | } |
| 1029 | |
| 1030 | static int tfilter_notify(struct net *net, struct sk_buff *oskb, |
| 1031 | struct nlmsghdr *n, struct tcf_proto *tp, |
| Jiri Pirko | 7960d1d | 2018-01-17 11:46:51 +0100 | [diff] [blame] | 1032 | struct tcf_block *block, struct Qdisc *q, |
| 1033 | u32 parent, void *fh, int event, bool unicast) |
| WANG Cong | 7120371 | 2017-08-07 15:26:50 -0700 | [diff] [blame] | 1034 | { |
| 1035 | struct sk_buff *skb; |
| 1036 | u32 portid = oskb ? NETLINK_CB(oskb).portid : 0; |
| 1037 | |
| 1038 | skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL); |
| 1039 | if (!skb) |
| 1040 | return -ENOBUFS; |
| 1041 | |
| Jiri Pirko | 7960d1d | 2018-01-17 11:46:51 +0100 | [diff] [blame] | 1042 | if (tcf_fill_node(net, skb, tp, block, q, parent, fh, portid, |
| 1043 | n->nlmsg_seq, n->nlmsg_flags, event) <= 0) { |
| WANG Cong | 7120371 | 2017-08-07 15:26:50 -0700 | [diff] [blame] | 1044 | kfree_skb(skb); |
| 1045 | return -EINVAL; |
| 1046 | } |
| 1047 | |
| 1048 | if (unicast) |
| 1049 | return netlink_unicast(net->rtnl, skb, portid, MSG_DONTWAIT); |
| 1050 | |
| 1051 | return rtnetlink_send(skb, net, portid, RTNLGRP_TC, |
| 1052 | n->nlmsg_flags & NLM_F_ECHO); |
| 1053 | } |
| 1054 | |
| 1055 | static int tfilter_del_notify(struct net *net, struct sk_buff *oskb, |
| 1056 | struct nlmsghdr *n, struct tcf_proto *tp, |
| Jiri Pirko | 7960d1d | 2018-01-17 11:46:51 +0100 | [diff] [blame] | 1057 | struct tcf_block *block, struct Qdisc *q, |
| Alexander Aring | c35a4ac | 2018-01-18 11:20:50 -0500 | [diff] [blame] | 1058 | u32 parent, void *fh, bool unicast, bool *last, |
| 1059 | struct netlink_ext_ack *extack) |
| WANG Cong | 7120371 | 2017-08-07 15:26:50 -0700 | [diff] [blame] | 1060 | { |
| 1061 | struct sk_buff *skb; |
| 1062 | u32 portid = oskb ? NETLINK_CB(oskb).portid : 0; |
| 1063 | int err; |
| 1064 | |
| 1065 | skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL); |
| 1066 | if (!skb) |
| 1067 | return -ENOBUFS; |
| 1068 | |
| Jiri Pirko | 7960d1d | 2018-01-17 11:46:51 +0100 | [diff] [blame] | 1069 | if (tcf_fill_node(net, skb, tp, block, q, parent, fh, portid, |
| 1070 | n->nlmsg_seq, n->nlmsg_flags, RTM_DELTFILTER) <= 0) { |
| Alexander Aring | c35a4ac | 2018-01-18 11:20:50 -0500 | [diff] [blame] | 1071 | NL_SET_ERR_MSG(extack, "Failed to build del event notification"); |
| WANG Cong | 7120371 | 2017-08-07 15:26:50 -0700 | [diff] [blame] | 1072 | kfree_skb(skb); |
| 1073 | return -EINVAL; |
| 1074 | } |
| 1075 | |
| Alexander Aring | 571acf2 | 2018-01-18 11:20:53 -0500 | [diff] [blame] | 1076 | err = tp->ops->delete(tp, fh, last, extack); |
| WANG Cong | 7120371 | 2017-08-07 15:26:50 -0700 | [diff] [blame] | 1077 | if (err) { |
| 1078 | kfree_skb(skb); |
| 1079 | return err; |
| 1080 | } |
| 1081 | |
| 1082 | if (unicast) |
| 1083 | return netlink_unicast(net->rtnl, skb, portid, MSG_DONTWAIT); |
| 1084 | |
| Alexander Aring | c35a4ac | 2018-01-18 11:20:50 -0500 | [diff] [blame] | 1085 | err = rtnetlink_send(skb, net, portid, RTNLGRP_TC, |
| 1086 | n->nlmsg_flags & NLM_F_ECHO); |
| 1087 | if (err < 0) |
| 1088 | NL_SET_ERR_MSG(extack, "Failed to send filter delete notification"); |
| 1089 | return err; |
| WANG Cong | 7120371 | 2017-08-07 15:26:50 -0700 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | static void tfilter_notify_chain(struct net *net, struct sk_buff *oskb, |
| Jiri Pirko | 7960d1d | 2018-01-17 11:46:51 +0100 | [diff] [blame] | 1093 | struct tcf_block *block, struct Qdisc *q, |
| 1094 | u32 parent, struct nlmsghdr *n, |
| WANG Cong | 7120371 | 2017-08-07 15:26:50 -0700 | [diff] [blame] | 1095 | struct tcf_chain *chain, int event) |
| 1096 | { |
| 1097 | struct tcf_proto *tp; |
| 1098 | |
| 1099 | for (tp = rtnl_dereference(chain->filter_chain); |
| 1100 | tp; tp = rtnl_dereference(tp->next)) |
| Jiri Pirko | 7960d1d | 2018-01-17 11:46:51 +0100 | [diff] [blame] | 1101 | tfilter_notify(net, oskb, n, tp, block, |
| YueHaibing | 5318918 | 2018-07-17 20:58:14 +0800 | [diff] [blame] | 1102 | q, parent, NULL, event, false); |
| WANG Cong | 7120371 | 2017-08-07 15:26:50 -0700 | [diff] [blame] | 1103 | } |
| 1104 | |
| Vlad Buslov | c431f89 | 2018-05-31 09:52:53 +0300 | [diff] [blame] | 1105 | static int tc_new_tfilter(struct sk_buff *skb, struct nlmsghdr *n, |
| David Ahern | c21ef3e | 2017-04-16 09:48:24 -0700 | [diff] [blame] | 1106 | struct netlink_ext_ack *extack) |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | { |
| YOSHIFUJI Hideaki | 3b1e0a6 | 2008-03-26 02:26:21 +0900 | [diff] [blame] | 1108 | struct net *net = sock_net(skb->sk); |
| Patrick McHardy | add93b6 | 2008-01-22 22:11:33 -0800 | [diff] [blame] | 1109 | struct nlattr *tca[TCA_MAX + 1]; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | struct tcmsg *t; |
| 1111 | u32 protocol; |
| 1112 | u32 prio; |
| Jiri Pirko | 9d36d9e | 2017-05-17 11:07:57 +0200 | [diff] [blame] | 1113 | bool prio_allocate; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | u32 parent; |
| Jiri Pirko | 5bc1701 | 2017-05-17 11:08:01 +0200 | [diff] [blame] | 1115 | u32 chain_index; |
| Jiri Pirko | 7960d1d | 2018-01-17 11:46:51 +0100 | [diff] [blame] | 1116 | struct Qdisc *q = NULL; |
| Jiri Pirko | 2190d1d | 2017-05-17 11:07:59 +0200 | [diff] [blame] | 1117 | struct tcf_chain_info chain_info; |
| Jiri Pirko | 5bc1701 | 2017-05-17 11:08:01 +0200 | [diff] [blame] | 1118 | struct tcf_chain *chain = NULL; |
| Jiri Pirko | 6529eab | 2017-05-17 11:07:55 +0200 | [diff] [blame] | 1119 | struct tcf_block *block; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | struct tcf_proto *tp; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | unsigned long cl; |
| WANG Cong | 8113c09 | 2017-08-04 21:31:43 -0700 | [diff] [blame] | 1122 | void *fh; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | int err; |
| Daniel Borkmann | 628185c | 2016-12-21 18:04:11 +0100 | [diff] [blame] | 1124 | int tp_created; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | |
| Vlad Buslov | c431f89 | 2018-05-31 09:52:53 +0300 | [diff] [blame] | 1126 | if (!netlink_ns_capable(skb, net->user_ns, CAP_NET_ADMIN)) |
| Eric W. Biederman | dfc47ef | 2012-11-16 03:03:00 +0000 | [diff] [blame] | 1127 | return -EPERM; |
| Hong zhi guo | de179c8 | 2013-03-25 17:36:33 +0000 | [diff] [blame] | 1128 | |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | replay: |
| Daniel Borkmann | 628185c | 2016-12-21 18:04:11 +0100 | [diff] [blame] | 1130 | tp_created = 0; |
| 1131 | |
| David Ahern | c21ef3e | 2017-04-16 09:48:24 -0700 | [diff] [blame] | 1132 | err = nlmsg_parse(n, sizeof(*t), tca, TCA_MAX, NULL, extack); |
| Hong zhi guo | de179c8 | 2013-03-25 17:36:33 +0000 | [diff] [blame] | 1133 | if (err < 0) |
| 1134 | return err; |
| 1135 | |
| David S. Miller | 942b816 | 2012-06-26 21:48:50 -0700 | [diff] [blame] | 1136 | t = nlmsg_data(n); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | protocol = TC_H_MIN(t->tcm_info); |
| 1138 | prio = TC_H_MAJ(t->tcm_info); |
| Jiri Pirko | 9d36d9e | 2017-05-17 11:07:57 +0200 | [diff] [blame] | 1139 | prio_allocate = false; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | parent = t->tcm_parent; |
| 1141 | cl = 0; |
| 1142 | |
| 1143 | if (prio == 0) { |
| Vlad Buslov | c431f89 | 2018-05-31 09:52:53 +0300 | [diff] [blame] | 1144 | /* If no priority is provided by the user, |
| 1145 | * we allocate one. |
| 1146 | */ |
| 1147 | if (n->nlmsg_flags & NLM_F_CREATE) { |
| 1148 | prio = TC_H_MAKE(0x80000000U, 0U); |
| 1149 | prio_allocate = true; |
| 1150 | } else { |
| Alexander Aring | c35a4ac | 2018-01-18 11:20:50 -0500 | [diff] [blame] | 1151 | NL_SET_ERR_MSG(extack, "Invalid filter command with priority of zero"); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | return -ENOENT; |
| Daniel Borkmann | ea7f827 | 2016-06-10 23:10:22 +0200 | [diff] [blame] | 1153 | } |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | /* Find head of filter chain. */ |
| 1157 | |
| Vlad Buslov | c431f89 | 2018-05-31 09:52:53 +0300 | [diff] [blame] | 1158 | block = tcf_block_find(net, &q, &parent, &cl, |
| 1159 | t->tcm_ifindex, t->tcm_block_index, extack); |
| 1160 | if (IS_ERR(block)) { |
| 1161 | err = PTR_ERR(block); |
| 1162 | goto errout; |
| Jiri Pirko | 6bb16e7 | 2017-02-09 14:38:58 +0100 | [diff] [blame] | 1163 | } |
| Jiri Pirko | 5bc1701 | 2017-05-17 11:08:01 +0200 | [diff] [blame] | 1164 | |
| 1165 | chain_index = tca[TCA_CHAIN] ? nla_get_u32(tca[TCA_CHAIN]) : 0; |
| 1166 | if (chain_index > TC_ACT_EXT_VAL_MASK) { |
| Alexander Aring | c35a4ac | 2018-01-18 11:20:50 -0500 | [diff] [blame] | 1167 | NL_SET_ERR_MSG(extack, "Specified chain index exceeds upper limit"); |
| Jiri Pirko | 5bc1701 | 2017-05-17 11:08:01 +0200 | [diff] [blame] | 1168 | err = -EINVAL; |
| 1169 | goto errout; |
| 1170 | } |
| Vlad Buslov | c431f89 | 2018-05-31 09:52:53 +0300 | [diff] [blame] | 1171 | chain = tcf_chain_get(block, chain_index, true); |
| Jiri Pirko | 5bc1701 | 2017-05-17 11:08:01 +0200 | [diff] [blame] | 1172 | if (!chain) { |
| Alexander Aring | c35a4ac | 2018-01-18 11:20:50 -0500 | [diff] [blame] | 1173 | NL_SET_ERR_MSG(extack, "Cannot find specified filter chain"); |
| Vlad Buslov | c431f89 | 2018-05-31 09:52:53 +0300 | [diff] [blame] | 1174 | err = -ENOMEM; |
| Daniel Borkmann | ea7f827 | 2016-06-10 23:10:22 +0200 | [diff] [blame] | 1175 | goto errout; |
| 1176 | } |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | |
| Jiri Pirko | 2190d1d | 2017-05-17 11:07:59 +0200 | [diff] [blame] | 1178 | tp = tcf_chain_tp_find(chain, &chain_info, protocol, |
| 1179 | prio, prio_allocate); |
| 1180 | if (IS_ERR(tp)) { |
| Alexander Aring | c35a4ac | 2018-01-18 11:20:50 -0500 | [diff] [blame] | 1181 | NL_SET_ERR_MSG(extack, "Filter with specified priority/protocol not found"); |
| Jiri Pirko | 2190d1d | 2017-05-17 11:07:59 +0200 | [diff] [blame] | 1182 | err = PTR_ERR(tp); |
| 1183 | goto errout; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | if (tp == NULL) { |
| 1187 | /* Proto-tcf does not exist, create new one */ |
| 1188 | |
| Jiri Pirko | 6bb16e7 | 2017-02-09 14:38:58 +0100 | [diff] [blame] | 1189 | if (tca[TCA_KIND] == NULL || !protocol) { |
| Alexander Aring | c35a4ac | 2018-01-18 11:20:50 -0500 | [diff] [blame] | 1190 | NL_SET_ERR_MSG(extack, "Filter kind and protocol must be specified"); |
| Jiri Pirko | 6bb16e7 | 2017-02-09 14:38:58 +0100 | [diff] [blame] | 1191 | err = -EINVAL; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1192 | goto errout; |
| Jiri Pirko | 6bb16e7 | 2017-02-09 14:38:58 +0100 | [diff] [blame] | 1193 | } |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | |
| Vlad Buslov | c431f89 | 2018-05-31 09:52:53 +0300 | [diff] [blame] | 1195 | if (!(n->nlmsg_flags & NLM_F_CREATE)) { |
| Alexander Aring | c35a4ac | 2018-01-18 11:20:50 -0500 | [diff] [blame] | 1196 | NL_SET_ERR_MSG(extack, "Need both RTM_NEWTFILTER and NLM_F_CREATE to create a new filter"); |
| Jiri Pirko | 6bb16e7 | 2017-02-09 14:38:58 +0100 | [diff] [blame] | 1197 | err = -ENOENT; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | goto errout; |
| Jiri Pirko | 6bb16e7 | 2017-02-09 14:38:58 +0100 | [diff] [blame] | 1199 | } |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | |
| Jiri Pirko | 9d36d9e | 2017-05-17 11:07:57 +0200 | [diff] [blame] | 1201 | if (prio_allocate) |
| Jiri Pirko | 2190d1d | 2017-05-17 11:07:59 +0200 | [diff] [blame] | 1202 | prio = tcf_auto_prio(tcf_chain_tp_prev(&chain_info)); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | |
| Jiri Pirko | 33a4892 | 2017-02-09 14:38:57 +0100 | [diff] [blame] | 1204 | tp = tcf_proto_create(nla_data(tca[TCA_KIND]), |
| Alexander Aring | c35a4ac | 2018-01-18 11:20:50 -0500 | [diff] [blame] | 1205 | protocol, prio, chain, extack); |
| Jiri Pirko | 33a4892 | 2017-02-09 14:38:57 +0100 | [diff] [blame] | 1206 | if (IS_ERR(tp)) { |
| 1207 | err = PTR_ERR(tp); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | goto errout; |
| 1209 | } |
| Minoru Usui | 12186be | 2009-06-02 02:17:34 -0700 | [diff] [blame] | 1210 | tp_created = 1; |
| Jiri Pirko | 6bb16e7 | 2017-02-09 14:38:58 +0100 | [diff] [blame] | 1211 | } else if (tca[TCA_KIND] && nla_strcmp(tca[TCA_KIND], tp->ops->kind)) { |
| Alexander Aring | c35a4ac | 2018-01-18 11:20:50 -0500 | [diff] [blame] | 1212 | NL_SET_ERR_MSG(extack, "Specified filter kind does not match existing one"); |
| Jiri Pirko | 6bb16e7 | 2017-02-09 14:38:58 +0100 | [diff] [blame] | 1213 | err = -EINVAL; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | goto errout; |
| Jiri Pirko | 6bb16e7 | 2017-02-09 14:38:58 +0100 | [diff] [blame] | 1215 | } |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | |
| 1217 | fh = tp->ops->get(tp, t->tcm_handle); |
| 1218 | |
| WANG Cong | 8113c09 | 2017-08-04 21:31:43 -0700 | [diff] [blame] | 1219 | if (!fh) { |
| Vlad Buslov | c431f89 | 2018-05-31 09:52:53 +0300 | [diff] [blame] | 1220 | if (!(n->nlmsg_flags & NLM_F_CREATE)) { |
| Alexander Aring | c35a4ac | 2018-01-18 11:20:50 -0500 | [diff] [blame] | 1221 | NL_SET_ERR_MSG(extack, "Need both RTM_NEWTFILTER and NLM_F_CREATE to create a new filter"); |
| Jiri Pirko | 6bb16e7 | 2017-02-09 14:38:58 +0100 | [diff] [blame] | 1222 | err = -ENOENT; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | goto errout; |
| Jiri Pirko | 6bb16e7 | 2017-02-09 14:38:58 +0100 | [diff] [blame] | 1224 | } |
| Vlad Buslov | c431f89 | 2018-05-31 09:52:53 +0300 | [diff] [blame] | 1225 | } else if (n->nlmsg_flags & NLM_F_EXCL) { |
| 1226 | NL_SET_ERR_MSG(extack, "Filter already exists"); |
| 1227 | err = -EEXIST; |
| 1228 | goto errout; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 | } |
| 1230 | |
| Cong Wang | 2f7ef2f | 2014-04-25 13:54:06 -0700 | [diff] [blame] | 1231 | err = tp->ops->change(net, skb, tp, cl, t->tcm_handle, tca, &fh, |
| Alexander Aring | 7306db3 | 2018-01-18 11:20:51 -0500 | [diff] [blame] | 1232 | n->nlmsg_flags & NLM_F_CREATE ? TCA_ACT_NOREPLACE : TCA_ACT_REPLACE, |
| 1233 | extack); |
| Minoru Usui | 12186be | 2009-06-02 02:17:34 -0700 | [diff] [blame] | 1234 | if (err == 0) { |
| Jiri Pirko | 2190d1d | 2017-05-17 11:07:59 +0200 | [diff] [blame] | 1235 | if (tp_created) |
| 1236 | tcf_chain_tp_insert(chain, &chain_info, tp); |
| Jiri Pirko | 7960d1d | 2018-01-17 11:46:51 +0100 | [diff] [blame] | 1237 | tfilter_notify(net, skb, n, tp, block, q, parent, fh, |
| Jiri Pirko | a10fa20 | 2017-10-13 14:01:05 +0200 | [diff] [blame] | 1238 | RTM_NEWTFILTER, false); |
| Minoru Usui | 12186be | 2009-06-02 02:17:34 -0700 | [diff] [blame] | 1239 | } else { |
| 1240 | if (tp_created) |
| Jakub Kicinski | 715df5e | 2018-01-24 12:54:13 -0800 | [diff] [blame] | 1241 | tcf_proto_destroy(tp, NULL); |
| Minoru Usui | 12186be | 2009-06-02 02:17:34 -0700 | [diff] [blame] | 1242 | } |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | |
| 1244 | errout: |
| Jiri Pirko | 5bc1701 | 2017-05-17 11:08:01 +0200 | [diff] [blame] | 1245 | if (chain) |
| 1246 | tcf_chain_put(chain); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | if (err == -EAGAIN) |
| 1248 | /* Replay the request. */ |
| 1249 | goto replay; |
| 1250 | return err; |
| 1251 | } |
| 1252 | |
| Vlad Buslov | c431f89 | 2018-05-31 09:52:53 +0300 | [diff] [blame] | 1253 | static int tc_del_tfilter(struct sk_buff *skb, struct nlmsghdr *n, |
| 1254 | struct netlink_ext_ack *extack) |
| 1255 | { |
| 1256 | struct net *net = sock_net(skb->sk); |
| 1257 | struct nlattr *tca[TCA_MAX + 1]; |
| 1258 | struct tcmsg *t; |
| 1259 | u32 protocol; |
| 1260 | u32 prio; |
| 1261 | u32 parent; |
| 1262 | u32 chain_index; |
| 1263 | struct Qdisc *q = NULL; |
| 1264 | struct tcf_chain_info chain_info; |
| 1265 | struct tcf_chain *chain = NULL; |
| 1266 | struct tcf_block *block; |
| 1267 | struct tcf_proto *tp = NULL; |
| 1268 | unsigned long cl = 0; |
| 1269 | void *fh = NULL; |
| 1270 | int err; |
| 1271 | |
| 1272 | if (!netlink_ns_capable(skb, net->user_ns, CAP_NET_ADMIN)) |
| 1273 | return -EPERM; |
| 1274 | |
| 1275 | err = nlmsg_parse(n, sizeof(*t), tca, TCA_MAX, NULL, extack); |
| 1276 | if (err < 0) |
| 1277 | return err; |
| 1278 | |
| 1279 | t = nlmsg_data(n); |
| 1280 | protocol = TC_H_MIN(t->tcm_info); |
| 1281 | prio = TC_H_MAJ(t->tcm_info); |
| 1282 | parent = t->tcm_parent; |
| 1283 | |
| 1284 | if (prio == 0 && (protocol || t->tcm_handle || tca[TCA_KIND])) { |
| 1285 | NL_SET_ERR_MSG(extack, "Cannot flush filters with protocol, handle or kind set"); |
| 1286 | return -ENOENT; |
| 1287 | } |
| 1288 | |
| 1289 | /* Find head of filter chain. */ |
| 1290 | |
| 1291 | block = tcf_block_find(net, &q, &parent, &cl, |
| 1292 | t->tcm_ifindex, t->tcm_block_index, extack); |
| 1293 | if (IS_ERR(block)) { |
| 1294 | err = PTR_ERR(block); |
| 1295 | goto errout; |
| 1296 | } |
| 1297 | |
| 1298 | chain_index = tca[TCA_CHAIN] ? nla_get_u32(tca[TCA_CHAIN]) : 0; |
| 1299 | if (chain_index > TC_ACT_EXT_VAL_MASK) { |
| 1300 | NL_SET_ERR_MSG(extack, "Specified chain index exceeds upper limit"); |
| 1301 | err = -EINVAL; |
| 1302 | goto errout; |
| 1303 | } |
| 1304 | chain = tcf_chain_get(block, chain_index, false); |
| 1305 | if (!chain) { |
| 1306 | NL_SET_ERR_MSG(extack, "Cannot find specified filter chain"); |
| 1307 | err = -EINVAL; |
| 1308 | goto errout; |
| 1309 | } |
| 1310 | |
| 1311 | if (prio == 0) { |
| 1312 | tfilter_notify_chain(net, skb, block, q, parent, n, |
| 1313 | chain, RTM_DELTFILTER); |
| 1314 | tcf_chain_flush(chain); |
| 1315 | err = 0; |
| 1316 | goto errout; |
| 1317 | } |
| 1318 | |
| 1319 | tp = tcf_chain_tp_find(chain, &chain_info, protocol, |
| 1320 | prio, false); |
| 1321 | if (!tp || IS_ERR(tp)) { |
| 1322 | NL_SET_ERR_MSG(extack, "Filter with specified priority/protocol not found"); |
| Vlad Buslov | 0e39903 | 2018-06-04 18:32:23 +0300 | [diff] [blame] | 1323 | err = tp ? PTR_ERR(tp) : -ENOENT; |
| Vlad Buslov | c431f89 | 2018-05-31 09:52:53 +0300 | [diff] [blame] | 1324 | goto errout; |
| 1325 | } else if (tca[TCA_KIND] && nla_strcmp(tca[TCA_KIND], tp->ops->kind)) { |
| 1326 | NL_SET_ERR_MSG(extack, "Specified filter kind does not match existing one"); |
| 1327 | err = -EINVAL; |
| 1328 | goto errout; |
| 1329 | } |
| 1330 | |
| 1331 | fh = tp->ops->get(tp, t->tcm_handle); |
| 1332 | |
| 1333 | if (!fh) { |
| 1334 | if (t->tcm_handle == 0) { |
| 1335 | tcf_chain_tp_remove(chain, &chain_info, tp); |
| 1336 | tfilter_notify(net, skb, n, tp, block, q, parent, fh, |
| 1337 | RTM_DELTFILTER, false); |
| 1338 | tcf_proto_destroy(tp, extack); |
| 1339 | err = 0; |
| 1340 | } else { |
| 1341 | NL_SET_ERR_MSG(extack, "Specified filter handle not found"); |
| 1342 | err = -ENOENT; |
| 1343 | } |
| 1344 | } else { |
| 1345 | bool last; |
| 1346 | |
| 1347 | err = tfilter_del_notify(net, skb, n, tp, block, |
| 1348 | q, parent, fh, false, &last, |
| 1349 | extack); |
| 1350 | if (err) |
| 1351 | goto errout; |
| 1352 | if (last) { |
| 1353 | tcf_chain_tp_remove(chain, &chain_info, tp); |
| 1354 | tcf_proto_destroy(tp, extack); |
| 1355 | } |
| 1356 | } |
| 1357 | |
| 1358 | errout: |
| 1359 | if (chain) |
| 1360 | tcf_chain_put(chain); |
| 1361 | return err; |
| 1362 | } |
| 1363 | |
| 1364 | static int tc_get_tfilter(struct sk_buff *skb, struct nlmsghdr *n, |
| 1365 | struct netlink_ext_ack *extack) |
| 1366 | { |
| 1367 | struct net *net = sock_net(skb->sk); |
| 1368 | struct nlattr *tca[TCA_MAX + 1]; |
| 1369 | struct tcmsg *t; |
| 1370 | u32 protocol; |
| 1371 | u32 prio; |
| 1372 | u32 parent; |
| 1373 | u32 chain_index; |
| 1374 | struct Qdisc *q = NULL; |
| 1375 | struct tcf_chain_info chain_info; |
| 1376 | struct tcf_chain *chain = NULL; |
| 1377 | struct tcf_block *block; |
| 1378 | struct tcf_proto *tp = NULL; |
| 1379 | unsigned long cl = 0; |
| 1380 | void *fh = NULL; |
| 1381 | int err; |
| 1382 | |
| 1383 | err = nlmsg_parse(n, sizeof(*t), tca, TCA_MAX, NULL, extack); |
| 1384 | if (err < 0) |
| 1385 | return err; |
| 1386 | |
| 1387 | t = nlmsg_data(n); |
| 1388 | protocol = TC_H_MIN(t->tcm_info); |
| 1389 | prio = TC_H_MAJ(t->tcm_info); |
| 1390 | parent = t->tcm_parent; |
| 1391 | |
| 1392 | if (prio == 0) { |
| 1393 | NL_SET_ERR_MSG(extack, "Invalid filter command with priority of zero"); |
| 1394 | return -ENOENT; |
| 1395 | } |
| 1396 | |
| 1397 | /* Find head of filter chain. */ |
| 1398 | |
| 1399 | block = tcf_block_find(net, &q, &parent, &cl, |
| 1400 | t->tcm_ifindex, t->tcm_block_index, extack); |
| 1401 | if (IS_ERR(block)) { |
| 1402 | err = PTR_ERR(block); |
| 1403 | goto errout; |
| 1404 | } |
| 1405 | |
| 1406 | chain_index = tca[TCA_CHAIN] ? nla_get_u32(tca[TCA_CHAIN]) : 0; |
| 1407 | if (chain_index > TC_ACT_EXT_VAL_MASK) { |
| 1408 | NL_SET_ERR_MSG(extack, "Specified chain index exceeds upper limit"); |
| 1409 | err = -EINVAL; |
| 1410 | goto errout; |
| 1411 | } |
| 1412 | chain = tcf_chain_get(block, chain_index, false); |
| 1413 | if (!chain) { |
| 1414 | NL_SET_ERR_MSG(extack, "Cannot find specified filter chain"); |
| 1415 | err = -EINVAL; |
| 1416 | goto errout; |
| 1417 | } |
| 1418 | |
| 1419 | tp = tcf_chain_tp_find(chain, &chain_info, protocol, |
| 1420 | prio, false); |
| 1421 | if (!tp || IS_ERR(tp)) { |
| 1422 | NL_SET_ERR_MSG(extack, "Filter with specified priority/protocol not found"); |
| Vlad Buslov | 0e39903 | 2018-06-04 18:32:23 +0300 | [diff] [blame] | 1423 | err = tp ? PTR_ERR(tp) : -ENOENT; |
| Vlad Buslov | c431f89 | 2018-05-31 09:52:53 +0300 | [diff] [blame] | 1424 | goto errout; |
| 1425 | } else if (tca[TCA_KIND] && nla_strcmp(tca[TCA_KIND], tp->ops->kind)) { |
| 1426 | NL_SET_ERR_MSG(extack, "Specified filter kind does not match existing one"); |
| 1427 | err = -EINVAL; |
| 1428 | goto errout; |
| 1429 | } |
| 1430 | |
| 1431 | fh = tp->ops->get(tp, t->tcm_handle); |
| 1432 | |
| 1433 | if (!fh) { |
| 1434 | NL_SET_ERR_MSG(extack, "Specified filter handle not found"); |
| 1435 | err = -ENOENT; |
| 1436 | } else { |
| 1437 | err = tfilter_notify(net, skb, n, tp, block, q, parent, |
| 1438 | fh, RTM_NEWTFILTER, true); |
| 1439 | if (err < 0) |
| 1440 | NL_SET_ERR_MSG(extack, "Failed to send filter notify message"); |
| 1441 | } |
| 1442 | |
| 1443 | errout: |
| 1444 | if (chain) |
| 1445 | tcf_chain_put(chain); |
| 1446 | return err; |
| 1447 | } |
| 1448 | |
| Stephen Hemminger | aa767bf | 2008-01-21 02:26:41 -0800 | [diff] [blame] | 1449 | struct tcf_dump_args { |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1450 | struct tcf_walker w; |
| 1451 | struct sk_buff *skb; |
| 1452 | struct netlink_callback *cb; |
| Jiri Pirko | 7960d1d | 2018-01-17 11:46:51 +0100 | [diff] [blame] | 1453 | struct tcf_block *block; |
| Jiri Pirko | a10fa20 | 2017-10-13 14:01:05 +0200 | [diff] [blame] | 1454 | struct Qdisc *q; |
| 1455 | u32 parent; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | }; |
| 1457 | |
| WANG Cong | 8113c09 | 2017-08-04 21:31:43 -0700 | [diff] [blame] | 1458 | static int tcf_node_dump(struct tcf_proto *tp, void *n, struct tcf_walker *arg) |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1459 | { |
| Stephen Hemminger | aa767bf | 2008-01-21 02:26:41 -0800 | [diff] [blame] | 1460 | struct tcf_dump_args *a = (void *)arg; |
| WANG Cong | 832d1d5 | 2014-01-09 16:14:01 -0800 | [diff] [blame] | 1461 | struct net *net = sock_net(a->skb->sk); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1462 | |
| Jiri Pirko | 7960d1d | 2018-01-17 11:46:51 +0100 | [diff] [blame] | 1463 | return tcf_fill_node(net, a->skb, tp, a->block, a->q, a->parent, |
| Jiri Pirko | a10fa20 | 2017-10-13 14:01:05 +0200 | [diff] [blame] | 1464 | n, NETLINK_CB(a->cb->skb).portid, |
| Jamal Hadi Salim | 5a7a555 | 2016-09-18 08:45:33 -0400 | [diff] [blame] | 1465 | a->cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 1466 | RTM_NEWTFILTER); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | } |
| 1468 | |
| Jiri Pirko | a10fa20 | 2017-10-13 14:01:05 +0200 | [diff] [blame] | 1469 | static bool tcf_chain_dump(struct tcf_chain *chain, struct Qdisc *q, u32 parent, |
| 1470 | struct sk_buff *skb, struct netlink_callback *cb, |
| Jiri Pirko | acb31fa | 2017-05-17 11:08:00 +0200 | [diff] [blame] | 1471 | long index_start, long *p_index) |
| 1472 | { |
| 1473 | struct net *net = sock_net(skb->sk); |
| Jiri Pirko | 7960d1d | 2018-01-17 11:46:51 +0100 | [diff] [blame] | 1474 | struct tcf_block *block = chain->block; |
| Jiri Pirko | acb31fa | 2017-05-17 11:08:00 +0200 | [diff] [blame] | 1475 | struct tcmsg *tcm = nlmsg_data(cb->nlh); |
| 1476 | struct tcf_dump_args arg; |
| 1477 | struct tcf_proto *tp; |
| 1478 | |
| 1479 | for (tp = rtnl_dereference(chain->filter_chain); |
| 1480 | tp; tp = rtnl_dereference(tp->next), (*p_index)++) { |
| 1481 | if (*p_index < index_start) |
| 1482 | continue; |
| 1483 | if (TC_H_MAJ(tcm->tcm_info) && |
| 1484 | TC_H_MAJ(tcm->tcm_info) != tp->prio) |
| 1485 | continue; |
| 1486 | if (TC_H_MIN(tcm->tcm_info) && |
| 1487 | TC_H_MIN(tcm->tcm_info) != tp->protocol) |
| 1488 | continue; |
| 1489 | if (*p_index > index_start) |
| 1490 | memset(&cb->args[1], 0, |
| 1491 | sizeof(cb->args) - sizeof(cb->args[0])); |
| 1492 | if (cb->args[1] == 0) { |
| YueHaibing | 5318918 | 2018-07-17 20:58:14 +0800 | [diff] [blame] | 1493 | if (tcf_fill_node(net, skb, tp, block, q, parent, NULL, |
| Jiri Pirko | acb31fa | 2017-05-17 11:08:00 +0200 | [diff] [blame] | 1494 | NETLINK_CB(cb->skb).portid, |
| 1495 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 1496 | RTM_NEWTFILTER) <= 0) |
| Jiri Pirko | 5bc1701 | 2017-05-17 11:08:01 +0200 | [diff] [blame] | 1497 | return false; |
| Jiri Pirko | acb31fa | 2017-05-17 11:08:00 +0200 | [diff] [blame] | 1498 | |
| 1499 | cb->args[1] = 1; |
| 1500 | } |
| 1501 | if (!tp->ops->walk) |
| 1502 | continue; |
| 1503 | arg.w.fn = tcf_node_dump; |
| 1504 | arg.skb = skb; |
| 1505 | arg.cb = cb; |
| Jiri Pirko | 7960d1d | 2018-01-17 11:46:51 +0100 | [diff] [blame] | 1506 | arg.block = block; |
| Jiri Pirko | a10fa20 | 2017-10-13 14:01:05 +0200 | [diff] [blame] | 1507 | arg.q = q; |
| 1508 | arg.parent = parent; |
| Jiri Pirko | acb31fa | 2017-05-17 11:08:00 +0200 | [diff] [blame] | 1509 | arg.w.stop = 0; |
| 1510 | arg.w.skip = cb->args[1] - 1; |
| 1511 | arg.w.count = 0; |
| Vlad Buslov | 01683a1 | 2018-07-09 13:29:11 +0300 | [diff] [blame] | 1512 | arg.w.cookie = cb->args[2]; |
| Jiri Pirko | acb31fa | 2017-05-17 11:08:00 +0200 | [diff] [blame] | 1513 | tp->ops->walk(tp, &arg.w); |
| Vlad Buslov | 01683a1 | 2018-07-09 13:29:11 +0300 | [diff] [blame] | 1514 | cb->args[2] = arg.w.cookie; |
| Jiri Pirko | acb31fa | 2017-05-17 11:08:00 +0200 | [diff] [blame] | 1515 | cb->args[1] = arg.w.count + 1; |
| 1516 | if (arg.w.stop) |
| Jiri Pirko | 5bc1701 | 2017-05-17 11:08:01 +0200 | [diff] [blame] | 1517 | return false; |
| Jiri Pirko | acb31fa | 2017-05-17 11:08:00 +0200 | [diff] [blame] | 1518 | } |
| Jiri Pirko | 5bc1701 | 2017-05-17 11:08:01 +0200 | [diff] [blame] | 1519 | return true; |
| Jiri Pirko | acb31fa | 2017-05-17 11:08:00 +0200 | [diff] [blame] | 1520 | } |
| 1521 | |
| Eric Dumazet | bd27a87 | 2009-11-05 20:57:26 -0800 | [diff] [blame] | 1522 | /* called with RTNL */ |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1523 | static int tc_dump_tfilter(struct sk_buff *skb, struct netlink_callback *cb) |
| 1524 | { |
| YOSHIFUJI Hideaki | 3b1e0a6 | 2008-03-26 02:26:21 +0900 | [diff] [blame] | 1525 | struct net *net = sock_net(skb->sk); |
| Jiri Pirko | 5bc1701 | 2017-05-17 11:08:01 +0200 | [diff] [blame] | 1526 | struct nlattr *tca[TCA_MAX + 1]; |
| Jiri Pirko | 7960d1d | 2018-01-17 11:46:51 +0100 | [diff] [blame] | 1527 | struct Qdisc *q = NULL; |
| Jiri Pirko | 6529eab | 2017-05-17 11:07:55 +0200 | [diff] [blame] | 1528 | struct tcf_block *block; |
| Jiri Pirko | 2190d1d | 2017-05-17 11:07:59 +0200 | [diff] [blame] | 1529 | struct tcf_chain *chain; |
| David S. Miller | 942b816 | 2012-06-26 21:48:50 -0700 | [diff] [blame] | 1530 | struct tcmsg *tcm = nlmsg_data(cb->nlh); |
| Jiri Pirko | acb31fa | 2017-05-17 11:08:00 +0200 | [diff] [blame] | 1531 | long index_start; |
| 1532 | long index; |
| Jiri Pirko | a10fa20 | 2017-10-13 14:01:05 +0200 | [diff] [blame] | 1533 | u32 parent; |
| Jiri Pirko | 5bc1701 | 2017-05-17 11:08:01 +0200 | [diff] [blame] | 1534 | int err; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1535 | |
| Hong zhi guo | 573ce26 | 2013-03-27 06:47:04 +0000 | [diff] [blame] | 1536 | if (nlmsg_len(cb->nlh) < sizeof(*tcm)) |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1537 | return skb->len; |
| Jiri Pirko | 5bc1701 | 2017-05-17 11:08:01 +0200 | [diff] [blame] | 1538 | |
| 1539 | err = nlmsg_parse(cb->nlh, sizeof(*tcm), tca, TCA_MAX, NULL, NULL); |
| 1540 | if (err) |
| 1541 | return err; |
| 1542 | |
| Jiri Pirko | 7960d1d | 2018-01-17 11:46:51 +0100 | [diff] [blame] | 1543 | if (tcm->tcm_ifindex == TCM_IFINDEX_MAGIC_BLOCK) { |
| 1544 | block = tcf_block_lookup(net, tcm->tcm_block_index); |
| 1545 | if (!block) |
| WANG Cong | 143976c | 2017-08-24 16:51:29 -0700 | [diff] [blame] | 1546 | goto out; |
| Jiri Pirko | d680b35 | 2018-01-18 16:14:49 +0100 | [diff] [blame] | 1547 | /* If we work with block index, q is NULL and parent value |
| 1548 | * will never be used in the following code. The check |
| 1549 | * in tcf_fill_node prevents it. However, compiler does not |
| 1550 | * see that far, so set parent to zero to silence the warning |
| 1551 | * about parent being uninitialized. |
| 1552 | */ |
| 1553 | parent = 0; |
| Jiri Pirko | 7960d1d | 2018-01-17 11:46:51 +0100 | [diff] [blame] | 1554 | } else { |
| 1555 | const struct Qdisc_class_ops *cops; |
| 1556 | struct net_device *dev; |
| 1557 | unsigned long cl = 0; |
| 1558 | |
| 1559 | dev = __dev_get_by_index(net, tcm->tcm_ifindex); |
| 1560 | if (!dev) |
| 1561 | return skb->len; |
| 1562 | |
| 1563 | parent = tcm->tcm_parent; |
| 1564 | if (!parent) { |
| 1565 | q = dev->qdisc; |
| 1566 | parent = q->handle; |
| 1567 | } else { |
| 1568 | q = qdisc_lookup(dev, TC_H_MAJ(tcm->tcm_parent)); |
| 1569 | } |
| 1570 | if (!q) |
| 1571 | goto out; |
| 1572 | cops = q->ops->cl_ops; |
| 1573 | if (!cops) |
| 1574 | goto out; |
| 1575 | if (!cops->tcf_block) |
| 1576 | goto out; |
| 1577 | if (TC_H_MIN(tcm->tcm_parent)) { |
| 1578 | cl = cops->find(q, tcm->tcm_parent); |
| 1579 | if (cl == 0) |
| 1580 | goto out; |
| 1581 | } |
| 1582 | block = cops->tcf_block(q, cl, NULL); |
| 1583 | if (!block) |
| 1584 | goto out; |
| 1585 | if (tcf_block_shared(block)) |
| 1586 | q = NULL; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | } |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | |
| Jiri Pirko | acb31fa | 2017-05-17 11:08:00 +0200 | [diff] [blame] | 1589 | index_start = cb->args[0]; |
| 1590 | index = 0; |
| Jiri Pirko | 5bc1701 | 2017-05-17 11:08:01 +0200 | [diff] [blame] | 1591 | |
| 1592 | list_for_each_entry(chain, &block->chain_list, list) { |
| 1593 | if (tca[TCA_CHAIN] && |
| 1594 | nla_get_u32(tca[TCA_CHAIN]) != chain->index) |
| 1595 | continue; |
| Jiri Pirko | a10fa20 | 2017-10-13 14:01:05 +0200 | [diff] [blame] | 1596 | if (!tcf_chain_dump(chain, q, parent, skb, cb, |
| Roman Kapl | 5ae437a | 2018-02-19 21:32:51 +0100 | [diff] [blame] | 1597 | index_start, &index)) { |
| 1598 | err = -EMSGSIZE; |
| Jiri Pirko | 5bc1701 | 2017-05-17 11:08:01 +0200 | [diff] [blame] | 1599 | break; |
| Roman Kapl | 5ae437a | 2018-02-19 21:32:51 +0100 | [diff] [blame] | 1600 | } |
| Jiri Pirko | 5bc1701 | 2017-05-17 11:08:01 +0200 | [diff] [blame] | 1601 | } |
| 1602 | |
| Jiri Pirko | acb31fa | 2017-05-17 11:08:00 +0200 | [diff] [blame] | 1603 | cb->args[0] = index; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1604 | |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 | out: |
| Roman Kapl | 5ae437a | 2018-02-19 21:32:51 +0100 | [diff] [blame] | 1606 | /* If we did no progress, the error (EMSGSIZE) is real */ |
| 1607 | if (skb->len == 0 && err) |
| 1608 | return err; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 | return skb->len; |
| 1610 | } |
| 1611 | |
| WANG Cong | 18d0264 | 2014-09-25 10:26:37 -0700 | [diff] [blame] | 1612 | void tcf_exts_destroy(struct tcf_exts *exts) |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1613 | { |
| 1614 | #ifdef CONFIG_NET_CLS_ACT |
| Vlad Buslov | 90b73b7 | 2018-07-05 17:24:33 +0300 | [diff] [blame] | 1615 | tcf_action_destroy(exts->actions, TCA_ACT_UNBIND); |
| WANG Cong | 22dc13c | 2016-08-13 22:35:00 -0700 | [diff] [blame] | 1616 | kfree(exts->actions); |
| 1617 | exts->nr_actions = 0; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1618 | #endif |
| 1619 | } |
| Stephen Hemminger | aa767bf | 2008-01-21 02:26:41 -0800 | [diff] [blame] | 1620 | EXPORT_SYMBOL(tcf_exts_destroy); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1621 | |
| Benjamin LaHaise | c1b5273 | 2013-01-14 05:15:39 +0000 | [diff] [blame] | 1622 | int tcf_exts_validate(struct net *net, struct tcf_proto *tp, struct nlattr **tb, |
| Alexander Aring | 50a5619 | 2018-01-18 11:20:52 -0500 | [diff] [blame] | 1623 | struct nlattr *rate_tlv, struct tcf_exts *exts, bool ovr, |
| 1624 | struct netlink_ext_ack *extack) |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1625 | { |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1626 | #ifdef CONFIG_NET_CLS_ACT |
| 1627 | { |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | struct tc_action *act; |
| Roman Mashak | d04e699 | 2018-03-08 16:59:17 -0500 | [diff] [blame] | 1629 | size_t attr_size = 0; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1630 | |
| WANG Cong | 5da57f4 | 2013-12-15 20:15:07 -0800 | [diff] [blame] | 1631 | if (exts->police && tb[exts->police]) { |
| Jiri Pirko | 9fb9f25 | 2017-05-17 11:08:02 +0200 | [diff] [blame] | 1632 | act = tcf_action_init_1(net, tp, tb[exts->police], |
| 1633 | rate_tlv, "police", ovr, |
| Vlad Buslov | 789871b | 2018-07-05 17:24:25 +0300 | [diff] [blame] | 1634 | TCA_ACT_BIND, true, extack); |
| Patrick McHardy | ab27cfb | 2008-01-23 20:33:13 -0800 | [diff] [blame] | 1635 | if (IS_ERR(act)) |
| 1636 | return PTR_ERR(act); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1637 | |
| WANG Cong | 33be627 | 2013-12-15 20:15:05 -0800 | [diff] [blame] | 1638 | act->type = exts->type = TCA_OLD_COMPAT; |
| WANG Cong | 22dc13c | 2016-08-13 22:35:00 -0700 | [diff] [blame] | 1639 | exts->actions[0] = act; |
| 1640 | exts->nr_actions = 1; |
| WANG Cong | 5da57f4 | 2013-12-15 20:15:07 -0800 | [diff] [blame] | 1641 | } else if (exts->action && tb[exts->action]) { |
| Vlad Buslov | 90b73b7 | 2018-07-05 17:24:33 +0300 | [diff] [blame] | 1642 | int err; |
| WANG Cong | 22dc13c | 2016-08-13 22:35:00 -0700 | [diff] [blame] | 1643 | |
| Jiri Pirko | 9fb9f25 | 2017-05-17 11:08:02 +0200 | [diff] [blame] | 1644 | err = tcf_action_init(net, tp, tb[exts->action], |
| 1645 | rate_tlv, NULL, ovr, TCA_ACT_BIND, |
| Vlad Buslov | 90b73b7 | 2018-07-05 17:24:33 +0300 | [diff] [blame] | 1646 | exts->actions, &attr_size, true, |
| Vlad Buslov | 789871b | 2018-07-05 17:24:25 +0300 | [diff] [blame] | 1647 | extack); |
| Vlad Buslov | 90b73b7 | 2018-07-05 17:24:33 +0300 | [diff] [blame] | 1648 | if (err < 0) |
| WANG Cong | 33be627 | 2013-12-15 20:15:05 -0800 | [diff] [blame] | 1649 | return err; |
| Vlad Buslov | 90b73b7 | 2018-07-05 17:24:33 +0300 | [diff] [blame] | 1650 | exts->nr_actions = err; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1651 | } |
| Cong Wang | e4b95c4 | 2017-11-06 13:47:19 -0800 | [diff] [blame] | 1652 | exts->net = net; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1653 | } |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1654 | #else |
| WANG Cong | 5da57f4 | 2013-12-15 20:15:07 -0800 | [diff] [blame] | 1655 | if ((exts->action && tb[exts->action]) || |
| Alexander Aring | 50a5619 | 2018-01-18 11:20:52 -0500 | [diff] [blame] | 1656 | (exts->police && tb[exts->police])) { |
| 1657 | NL_SET_ERR_MSG(extack, "Classifier actions are not supported per compile options (CONFIG_NET_CLS_ACT)"); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | return -EOPNOTSUPP; |
| Alexander Aring | 50a5619 | 2018-01-18 11:20:52 -0500 | [diff] [blame] | 1659 | } |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1660 | #endif |
| 1661 | |
| 1662 | return 0; |
| 1663 | } |
| Stephen Hemminger | aa767bf | 2008-01-21 02:26:41 -0800 | [diff] [blame] | 1664 | EXPORT_SYMBOL(tcf_exts_validate); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1665 | |
| Jiri Pirko | 9b0d444 | 2017-08-04 14:29:15 +0200 | [diff] [blame] | 1666 | void tcf_exts_change(struct tcf_exts *dst, struct tcf_exts *src) |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1667 | { |
| 1668 | #ifdef CONFIG_NET_CLS_ACT |
| WANG Cong | 22dc13c | 2016-08-13 22:35:00 -0700 | [diff] [blame] | 1669 | struct tcf_exts old = *dst; |
| 1670 | |
| Jiri Pirko | 9b0d444 | 2017-08-04 14:29:15 +0200 | [diff] [blame] | 1671 | *dst = *src; |
| WANG Cong | 22dc13c | 2016-08-13 22:35:00 -0700 | [diff] [blame] | 1672 | tcf_exts_destroy(&old); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1673 | #endif |
| 1674 | } |
| Stephen Hemminger | aa767bf | 2008-01-21 02:26:41 -0800 | [diff] [blame] | 1675 | EXPORT_SYMBOL(tcf_exts_change); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1676 | |
| WANG Cong | 22dc13c | 2016-08-13 22:35:00 -0700 | [diff] [blame] | 1677 | #ifdef CONFIG_NET_CLS_ACT |
| 1678 | static struct tc_action *tcf_exts_first_act(struct tcf_exts *exts) |
| 1679 | { |
| 1680 | if (exts->nr_actions == 0) |
| 1681 | return NULL; |
| 1682 | else |
| 1683 | return exts->actions[0]; |
| 1684 | } |
| 1685 | #endif |
| WANG Cong | 33be627 | 2013-12-15 20:15:05 -0800 | [diff] [blame] | 1686 | |
| WANG Cong | 5da57f4 | 2013-12-15 20:15:07 -0800 | [diff] [blame] | 1687 | int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts) |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1688 | { |
| 1689 | #ifdef CONFIG_NET_CLS_ACT |
| Cong Wang | 9cc63db | 2014-07-16 14:25:30 -0700 | [diff] [blame] | 1690 | struct nlattr *nest; |
| 1691 | |
| Jiri Pirko | 978dfd8 | 2017-08-04 14:29:03 +0200 | [diff] [blame] | 1692 | if (exts->action && tcf_exts_has_actions(exts)) { |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1693 | /* |
| 1694 | * again for backward compatible mode - we want |
| 1695 | * to work with both old and new modes of entering |
| 1696 | * tc data even if iproute2 was newer - jhs |
| 1697 | */ |
| WANG Cong | 33be627 | 2013-12-15 20:15:05 -0800 | [diff] [blame] | 1698 | if (exts->type != TCA_OLD_COMPAT) { |
| WANG Cong | 5da57f4 | 2013-12-15 20:15:07 -0800 | [diff] [blame] | 1699 | nest = nla_nest_start(skb, exts->action); |
| Patrick McHardy | 4b3550ef | 2008-01-23 20:34:11 -0800 | [diff] [blame] | 1700 | if (nest == NULL) |
| 1701 | goto nla_put_failure; |
| WANG Cong | 22dc13c | 2016-08-13 22:35:00 -0700 | [diff] [blame] | 1702 | |
| Vlad Buslov | 90b73b7 | 2018-07-05 17:24:33 +0300 | [diff] [blame] | 1703 | if (tcf_action_dump(skb, exts->actions, 0, 0) < 0) |
| Patrick McHardy | add93b6 | 2008-01-22 22:11:33 -0800 | [diff] [blame] | 1704 | goto nla_put_failure; |
| Patrick McHardy | 4b3550ef | 2008-01-23 20:34:11 -0800 | [diff] [blame] | 1705 | nla_nest_end(skb, nest); |
| WANG Cong | 5da57f4 | 2013-12-15 20:15:07 -0800 | [diff] [blame] | 1706 | } else if (exts->police) { |
| WANG Cong | 33be627 | 2013-12-15 20:15:05 -0800 | [diff] [blame] | 1707 | struct tc_action *act = tcf_exts_first_act(exts); |
| WANG Cong | 5da57f4 | 2013-12-15 20:15:07 -0800 | [diff] [blame] | 1708 | nest = nla_nest_start(skb, exts->police); |
| Jamal Hadi Salim | 63acd68 | 2013-12-23 08:02:12 -0500 | [diff] [blame] | 1709 | if (nest == NULL || !act) |
| Patrick McHardy | 4b3550ef | 2008-01-23 20:34:11 -0800 | [diff] [blame] | 1710 | goto nla_put_failure; |
| WANG Cong | 33be627 | 2013-12-15 20:15:05 -0800 | [diff] [blame] | 1711 | if (tcf_action_dump_old(skb, act, 0, 0) < 0) |
| Patrick McHardy | add93b6 | 2008-01-22 22:11:33 -0800 | [diff] [blame] | 1712 | goto nla_put_failure; |
| Patrick McHardy | 4b3550ef | 2008-01-23 20:34:11 -0800 | [diff] [blame] | 1713 | nla_nest_end(skb, nest); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1714 | } |
| 1715 | } |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1716 | return 0; |
| Cong Wang | 9cc63db | 2014-07-16 14:25:30 -0700 | [diff] [blame] | 1717 | |
| 1718 | nla_put_failure: |
| 1719 | nla_nest_cancel(skb, nest); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1720 | return -1; |
| Cong Wang | 9cc63db | 2014-07-16 14:25:30 -0700 | [diff] [blame] | 1721 | #else |
| 1722 | return 0; |
| 1723 | #endif |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1724 | } |
| Stephen Hemminger | aa767bf | 2008-01-21 02:26:41 -0800 | [diff] [blame] | 1725 | EXPORT_SYMBOL(tcf_exts_dump); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1726 | |
| Stephen Hemminger | aa767bf | 2008-01-21 02:26:41 -0800 | [diff] [blame] | 1727 | |
| WANG Cong | 5da57f4 | 2013-12-15 20:15:07 -0800 | [diff] [blame] | 1728 | int tcf_exts_dump_stats(struct sk_buff *skb, struct tcf_exts *exts) |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 | { |
| 1730 | #ifdef CONFIG_NET_CLS_ACT |
| WANG Cong | 33be627 | 2013-12-15 20:15:05 -0800 | [diff] [blame] | 1731 | struct tc_action *a = tcf_exts_first_act(exts); |
| Ignacy Gawędzki | b057df2 | 2015-02-03 19:05:18 +0100 | [diff] [blame] | 1732 | if (a != NULL && tcf_action_copy_stats(skb, a, 1) < 0) |
| WANG Cong | 33be627 | 2013-12-15 20:15:05 -0800 | [diff] [blame] | 1733 | return -1; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1734 | #endif |
| 1735 | return 0; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1736 | } |
| Stephen Hemminger | aa767bf | 2008-01-21 02:26:41 -0800 | [diff] [blame] | 1737 | EXPORT_SYMBOL(tcf_exts_dump_stats); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1738 | |
| Jiri Pirko | 717503b | 2017-10-11 09:41:09 +0200 | [diff] [blame] | 1739 | static int tc_exts_setup_cb_egdev_call(struct tcf_exts *exts, |
| 1740 | enum tc_setup_type type, |
| 1741 | void *type_data, bool err_stop) |
| Jiri Pirko | b3f55bd | 2017-10-11 09:41:08 +0200 | [diff] [blame] | 1742 | { |
| 1743 | int ok_count = 0; |
| 1744 | #ifdef CONFIG_NET_CLS_ACT |
| 1745 | const struct tc_action *a; |
| 1746 | struct net_device *dev; |
| Or Gerlitz | 9d452ce | 2017-10-24 08:58:02 +0300 | [diff] [blame] | 1747 | int i, ret; |
| Jiri Pirko | b3f55bd | 2017-10-11 09:41:08 +0200 | [diff] [blame] | 1748 | |
| 1749 | if (!tcf_exts_has_actions(exts)) |
| 1750 | return 0; |
| 1751 | |
| Or Gerlitz | 9d452ce | 2017-10-24 08:58:02 +0300 | [diff] [blame] | 1752 | for (i = 0; i < exts->nr_actions; i++) { |
| 1753 | a = exts->actions[i]; |
| Jiri Pirko | b3f55bd | 2017-10-11 09:41:08 +0200 | [diff] [blame] | 1754 | if (!a->ops->get_dev) |
| 1755 | continue; |
| 1756 | dev = a->ops->get_dev(a); |
| Jiri Pirko | 7612fb0 | 2017-11-01 11:47:40 +0100 | [diff] [blame] | 1757 | if (!dev) |
| Jiri Pirko | b3f55bd | 2017-10-11 09:41:08 +0200 | [diff] [blame] | 1758 | continue; |
| 1759 | ret = tc_setup_cb_egdev_call(dev, type, type_data, err_stop); |
| 1760 | if (ret < 0) |
| 1761 | return ret; |
| 1762 | ok_count += ret; |
| 1763 | } |
| 1764 | #endif |
| 1765 | return ok_count; |
| 1766 | } |
| Jiri Pirko | 717503b | 2017-10-11 09:41:09 +0200 | [diff] [blame] | 1767 | |
| Jiri Pirko | 208c0f4 | 2017-10-19 15:50:32 +0200 | [diff] [blame] | 1768 | int tc_setup_cb_call(struct tcf_block *block, struct tcf_exts *exts, |
| 1769 | enum tc_setup_type type, void *type_data, bool err_stop) |
| Jiri Pirko | 717503b | 2017-10-11 09:41:09 +0200 | [diff] [blame] | 1770 | { |
| David S. Miller | 9a99dc1 | 2018-06-06 13:55:47 -0400 | [diff] [blame] | 1771 | int ok_count; |
| Jiri Pirko | 208c0f4 | 2017-10-19 15:50:32 +0200 | [diff] [blame] | 1772 | int ret; |
| 1773 | |
| David S. Miller | 9a99dc1 | 2018-06-06 13:55:47 -0400 | [diff] [blame] | 1774 | ret = tcf_block_cb_call(block, type, type_data, err_stop); |
| 1775 | if (ret < 0) |
| 1776 | return ret; |
| 1777 | ok_count = ret; |
| Jiri Pirko | 208c0f4 | 2017-10-19 15:50:32 +0200 | [diff] [blame] | 1778 | |
| Or Gerlitz | f8f4bef | 2018-05-23 19:24:48 +0300 | [diff] [blame] | 1779 | if (!exts || ok_count) |
| David S. Miller | 9a99dc1 | 2018-06-06 13:55:47 -0400 | [diff] [blame] | 1780 | return ok_count; |
| Jiri Pirko | 208c0f4 | 2017-10-19 15:50:32 +0200 | [diff] [blame] | 1781 | ret = tc_exts_setup_cb_egdev_call(exts, type, type_data, err_stop); |
| 1782 | if (ret < 0) |
| 1783 | return ret; |
| 1784 | ok_count += ret; |
| 1785 | |
| 1786 | return ok_count; |
| Jiri Pirko | 717503b | 2017-10-11 09:41:09 +0200 | [diff] [blame] | 1787 | } |
| 1788 | EXPORT_SYMBOL(tc_setup_cb_call); |
| Jiri Pirko | b3f55bd | 2017-10-11 09:41:08 +0200 | [diff] [blame] | 1789 | |
| Jiri Pirko | 4861738 | 2018-01-17 11:46:46 +0100 | [diff] [blame] | 1790 | static __net_init int tcf_net_init(struct net *net) |
| 1791 | { |
| 1792 | struct tcf_net *tn = net_generic(net, tcf_net_id); |
| 1793 | |
| 1794 | idr_init(&tn->idr); |
| 1795 | return 0; |
| 1796 | } |
| 1797 | |
| 1798 | static void __net_exit tcf_net_exit(struct net *net) |
| 1799 | { |
| 1800 | struct tcf_net *tn = net_generic(net, tcf_net_id); |
| 1801 | |
| 1802 | idr_destroy(&tn->idr); |
| 1803 | } |
| 1804 | |
| 1805 | static struct pernet_operations tcf_net_ops = { |
| 1806 | .init = tcf_net_init, |
| 1807 | .exit = tcf_net_exit, |
| 1808 | .id = &tcf_net_id, |
| 1809 | .size = sizeof(struct tcf_net), |
| 1810 | }; |
| 1811 | |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | static int __init tc_filter_init(void) |
| 1813 | { |
| Jiri Pirko | 4861738 | 2018-01-17 11:46:46 +0100 | [diff] [blame] | 1814 | int err; |
| 1815 | |
| Cong Wang | 7aa0045 | 2017-10-26 18:24:28 -0700 | [diff] [blame] | 1816 | tc_filter_wq = alloc_ordered_workqueue("tc_filter_workqueue", 0); |
| 1817 | if (!tc_filter_wq) |
| 1818 | return -ENOMEM; |
| 1819 | |
| Jiri Pirko | 4861738 | 2018-01-17 11:46:46 +0100 | [diff] [blame] | 1820 | err = register_pernet_subsys(&tcf_net_ops); |
| 1821 | if (err) |
| 1822 | goto err_register_pernet_subsys; |
| 1823 | |
| Vlad Buslov | c431f89 | 2018-05-31 09:52:53 +0300 | [diff] [blame] | 1824 | rtnl_register(PF_UNSPEC, RTM_NEWTFILTER, tc_new_tfilter, NULL, 0); |
| 1825 | rtnl_register(PF_UNSPEC, RTM_DELTFILTER, tc_del_tfilter, NULL, 0); |
| 1826 | rtnl_register(PF_UNSPEC, RTM_GETTFILTER, tc_get_tfilter, |
| Florian Westphal | b97bac6 | 2017-08-09 20:41:48 +0200 | [diff] [blame] | 1827 | tc_dump_tfilter, 0); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1829 | return 0; |
| Jiri Pirko | 4861738 | 2018-01-17 11:46:46 +0100 | [diff] [blame] | 1830 | |
| 1831 | err_register_pernet_subsys: |
| 1832 | destroy_workqueue(tc_filter_wq); |
| 1833 | return err; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | } |
| 1835 | |
| 1836 | subsys_initcall(tc_filter_init); |