Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2016, Amir Vadai <amir@vadai.me> |
| 4 | * Copyright (c) 2016, Mellanox Technologies. All rights reserved. |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <linux/module.h> |
| 8 | #include <linux/init.h> |
| 9 | #include <linux/kernel.h> |
| 10 | #include <linux/skbuff.h> |
| 11 | #include <linux/rtnetlink.h> |
Simon Horman | 0ed5269 | 2018-06-26 21:39:37 -0700 | [diff] [blame] | 12 | #include <net/geneve.h> |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 13 | #include <net/netlink.h> |
| 14 | #include <net/pkt_sched.h> |
| 15 | #include <net/dst.h> |
Davide Caratti | e5fdaba | 2019-03-20 15:00:13 +0100 | [diff] [blame] | 16 | #include <net/pkt_cls.h> |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 17 | |
| 18 | #include <linux/tc_act/tc_tunnel_key.h> |
| 19 | #include <net/tc_act/tc_tunnel_key.h> |
| 20 | |
Alexey Dobriyan | c7d03a0 | 2016-11-17 04:58:21 +0300 | [diff] [blame] | 21 | static unsigned int tunnel_key_net_id; |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 22 | static struct tc_action_ops act_tunnel_key_ops; |
| 23 | |
| 24 | static int tunnel_key_act(struct sk_buff *skb, const struct tc_action *a, |
| 25 | struct tcf_result *res) |
| 26 | { |
| 27 | struct tcf_tunnel_key *t = to_tunnel_key(a); |
| 28 | struct tcf_tunnel_key_params *params; |
| 29 | int action; |
| 30 | |
Paolo Abeni | 7fd4b28 | 2018-07-30 14:30:43 +0200 | [diff] [blame] | 31 | params = rcu_dereference_bh(t->params); |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 32 | |
| 33 | tcf_lastuse_update(&t->tcf_tm); |
| 34 | bstats_cpu_update(this_cpu_ptr(t->common.cpu_bstats), skb); |
Davide Caratti | 38230a3 | 2018-07-06 21:01:06 +0200 | [diff] [blame] | 35 | action = READ_ONCE(t->tcf_action); |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 36 | |
| 37 | switch (params->tcft_action) { |
| 38 | case TCA_TUNNEL_KEY_ACT_RELEASE: |
| 39 | skb_dst_drop(skb); |
| 40 | break; |
| 41 | case TCA_TUNNEL_KEY_ACT_SET: |
| 42 | skb_dst_drop(skb); |
| 43 | skb_dst_set(skb, dst_clone(¶ms->tcft_enc_metadata->dst)); |
| 44 | break; |
| 45 | default: |
| 46 | WARN_ONCE(1, "Bad tunnel_key action %d.\n", |
| 47 | params->tcft_action); |
| 48 | break; |
| 49 | } |
| 50 | |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 51 | return action; |
| 52 | } |
| 53 | |
Simon Horman | 0ed5269 | 2018-06-26 21:39:37 -0700 | [diff] [blame] | 54 | static const struct nla_policy |
| 55 | enc_opts_policy[TCA_TUNNEL_KEY_ENC_OPTS_MAX + 1] = { |
| 56 | [TCA_TUNNEL_KEY_ENC_OPTS_GENEVE] = { .type = NLA_NESTED }, |
| 57 | }; |
| 58 | |
| 59 | static const struct nla_policy |
| 60 | geneve_opt_policy[TCA_TUNNEL_KEY_ENC_OPT_GENEVE_MAX + 1] = { |
| 61 | [TCA_TUNNEL_KEY_ENC_OPT_GENEVE_CLASS] = { .type = NLA_U16 }, |
| 62 | [TCA_TUNNEL_KEY_ENC_OPT_GENEVE_TYPE] = { .type = NLA_U8 }, |
| 63 | [TCA_TUNNEL_KEY_ENC_OPT_GENEVE_DATA] = { .type = NLA_BINARY, |
| 64 | .len = 128 }, |
| 65 | }; |
| 66 | |
| 67 | static int |
| 68 | tunnel_key_copy_geneve_opt(const struct nlattr *nla, void *dst, int dst_len, |
| 69 | struct netlink_ext_ack *extack) |
| 70 | { |
| 71 | struct nlattr *tb[TCA_TUNNEL_KEY_ENC_OPT_GENEVE_MAX + 1]; |
| 72 | int err, data_len, opt_len; |
| 73 | u8 *data; |
| 74 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 75 | err = nla_parse_nested_deprecated(tb, |
| 76 | TCA_TUNNEL_KEY_ENC_OPT_GENEVE_MAX, |
| 77 | nla, geneve_opt_policy, extack); |
Simon Horman | 0ed5269 | 2018-06-26 21:39:37 -0700 | [diff] [blame] | 78 | if (err < 0) |
| 79 | return err; |
| 80 | |
| 81 | if (!tb[TCA_TUNNEL_KEY_ENC_OPT_GENEVE_CLASS] || |
| 82 | !tb[TCA_TUNNEL_KEY_ENC_OPT_GENEVE_TYPE] || |
| 83 | !tb[TCA_TUNNEL_KEY_ENC_OPT_GENEVE_DATA]) { |
| 84 | NL_SET_ERR_MSG(extack, "Missing tunnel key geneve option class, type or data"); |
| 85 | return -EINVAL; |
| 86 | } |
| 87 | |
| 88 | data = nla_data(tb[TCA_TUNNEL_KEY_ENC_OPT_GENEVE_DATA]); |
| 89 | data_len = nla_len(tb[TCA_TUNNEL_KEY_ENC_OPT_GENEVE_DATA]); |
| 90 | if (data_len < 4) { |
| 91 | NL_SET_ERR_MSG(extack, "Tunnel key geneve option data is less than 4 bytes long"); |
| 92 | return -ERANGE; |
| 93 | } |
| 94 | if (data_len % 4) { |
| 95 | NL_SET_ERR_MSG(extack, "Tunnel key geneve option data is not a multiple of 4 bytes long"); |
| 96 | return -ERANGE; |
| 97 | } |
| 98 | |
| 99 | opt_len = sizeof(struct geneve_opt) + data_len; |
| 100 | if (dst) { |
| 101 | struct geneve_opt *opt = dst; |
| 102 | |
| 103 | WARN_ON(dst_len < opt_len); |
| 104 | |
| 105 | opt->opt_class = |
| 106 | nla_get_be16(tb[TCA_TUNNEL_KEY_ENC_OPT_GENEVE_CLASS]); |
| 107 | opt->type = nla_get_u8(tb[TCA_TUNNEL_KEY_ENC_OPT_GENEVE_TYPE]); |
| 108 | opt->length = data_len / 4; /* length is in units of 4 bytes */ |
| 109 | opt->r1 = 0; |
| 110 | opt->r2 = 0; |
| 111 | opt->r3 = 0; |
| 112 | |
| 113 | memcpy(opt + 1, data, data_len); |
| 114 | } |
| 115 | |
| 116 | return opt_len; |
| 117 | } |
| 118 | |
| 119 | static int tunnel_key_copy_opts(const struct nlattr *nla, u8 *dst, |
| 120 | int dst_len, struct netlink_ext_ack *extack) |
| 121 | { |
| 122 | int err, rem, opt_len, len = nla_len(nla), opts_len = 0; |
| 123 | const struct nlattr *attr, *head = nla_data(nla); |
| 124 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 125 | err = nla_validate_deprecated(head, len, TCA_TUNNEL_KEY_ENC_OPTS_MAX, |
| 126 | enc_opts_policy, extack); |
Simon Horman | 0ed5269 | 2018-06-26 21:39:37 -0700 | [diff] [blame] | 127 | if (err) |
| 128 | return err; |
| 129 | |
| 130 | nla_for_each_attr(attr, head, len, rem) { |
| 131 | switch (nla_type(attr)) { |
| 132 | case TCA_TUNNEL_KEY_ENC_OPTS_GENEVE: |
| 133 | opt_len = tunnel_key_copy_geneve_opt(attr, dst, |
| 134 | dst_len, extack); |
| 135 | if (opt_len < 0) |
| 136 | return opt_len; |
| 137 | opts_len += opt_len; |
| 138 | if (dst) { |
| 139 | dst_len -= opt_len; |
| 140 | dst += opt_len; |
| 141 | } |
| 142 | break; |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | if (!opts_len) { |
| 147 | NL_SET_ERR_MSG(extack, "Empty list of tunnel options"); |
| 148 | return -EINVAL; |
| 149 | } |
| 150 | |
| 151 | if (rem > 0) { |
| 152 | NL_SET_ERR_MSG(extack, "Trailing data after parsing tunnel key options attributes"); |
| 153 | return -EINVAL; |
| 154 | } |
| 155 | |
| 156 | return opts_len; |
| 157 | } |
| 158 | |
| 159 | static int tunnel_key_get_opts_len(struct nlattr *nla, |
| 160 | struct netlink_ext_ack *extack) |
| 161 | { |
| 162 | return tunnel_key_copy_opts(nla, NULL, 0, extack); |
| 163 | } |
| 164 | |
| 165 | static int tunnel_key_opts_set(struct nlattr *nla, struct ip_tunnel_info *info, |
| 166 | int opts_len, struct netlink_ext_ack *extack) |
| 167 | { |
| 168 | info->options_len = opts_len; |
| 169 | switch (nla_type(nla_data(nla))) { |
| 170 | case TCA_TUNNEL_KEY_ENC_OPTS_GENEVE: |
| 171 | #if IS_ENABLED(CONFIG_INET) |
| 172 | info->key.tun_flags |= TUNNEL_GENEVE_OPT; |
| 173 | return tunnel_key_copy_opts(nla, ip_tunnel_info_opts(info), |
| 174 | opts_len, extack); |
| 175 | #else |
| 176 | return -EAFNOSUPPORT; |
| 177 | #endif |
| 178 | default: |
| 179 | NL_SET_ERR_MSG(extack, "Cannot set tunnel options for unknown tunnel type"); |
| 180 | return -EINVAL; |
| 181 | } |
| 182 | } |
| 183 | |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 184 | static const struct nla_policy tunnel_key_policy[TCA_TUNNEL_KEY_MAX + 1] = { |
| 185 | [TCA_TUNNEL_KEY_PARMS] = { .len = sizeof(struct tc_tunnel_key) }, |
| 186 | [TCA_TUNNEL_KEY_ENC_IPV4_SRC] = { .type = NLA_U32 }, |
| 187 | [TCA_TUNNEL_KEY_ENC_IPV4_DST] = { .type = NLA_U32 }, |
| 188 | [TCA_TUNNEL_KEY_ENC_IPV6_SRC] = { .len = sizeof(struct in6_addr) }, |
| 189 | [TCA_TUNNEL_KEY_ENC_IPV6_DST] = { .len = sizeof(struct in6_addr) }, |
| 190 | [TCA_TUNNEL_KEY_ENC_KEY_ID] = { .type = NLA_U32 }, |
Hadar Hen Zion | 75bfbca | 2016-11-07 15:14:41 +0200 | [diff] [blame] | 191 | [TCA_TUNNEL_KEY_ENC_DST_PORT] = {.type = NLA_U16}, |
Jiri Benc | 86087e1 | 2017-06-14 21:19:31 +0200 | [diff] [blame] | 192 | [TCA_TUNNEL_KEY_NO_CSUM] = { .type = NLA_U8 }, |
Simon Horman | 0ed5269 | 2018-06-26 21:39:37 -0700 | [diff] [blame] | 193 | [TCA_TUNNEL_KEY_ENC_OPTS] = { .type = NLA_NESTED }, |
Or Gerlitz | 07a557f | 2018-07-17 19:27:16 +0300 | [diff] [blame] | 194 | [TCA_TUNNEL_KEY_ENC_TOS] = { .type = NLA_U8 }, |
| 195 | [TCA_TUNNEL_KEY_ENC_TTL] = { .type = NLA_U8 }, |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 196 | }; |
| 197 | |
Davide Caratti | 9174c3d | 2019-01-10 20:21:02 +0100 | [diff] [blame] | 198 | static void tunnel_key_release_params(struct tcf_tunnel_key_params *p) |
| 199 | { |
| 200 | if (!p) |
| 201 | return; |
wenxu | 4177c5d | 2019-03-05 08:29:28 +0800 | [diff] [blame] | 202 | if (p->tcft_action == TCA_TUNNEL_KEY_ACT_SET) |
Davide Caratti | 9174c3d | 2019-01-10 20:21:02 +0100 | [diff] [blame] | 203 | dst_release(&p->tcft_enc_metadata->dst); |
wenxu | 4177c5d | 2019-03-05 08:29:28 +0800 | [diff] [blame] | 204 | |
Davide Caratti | 9174c3d | 2019-01-10 20:21:02 +0100 | [diff] [blame] | 205 | kfree_rcu(p, rcu); |
| 206 | } |
| 207 | |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 208 | static int tunnel_key_init(struct net *net, struct nlattr *nla, |
| 209 | struct nlattr *est, struct tc_action **a, |
Vlad Buslov | 789871b | 2018-07-05 17:24:25 +0300 | [diff] [blame] | 210 | int ovr, int bind, bool rtnl_held, |
Davide Caratti | 85d0966 | 2019-03-20 14:59:59 +0100 | [diff] [blame] | 211 | struct tcf_proto *tp, |
Vlad Buslov | 789871b | 2018-07-05 17:24:25 +0300 | [diff] [blame] | 212 | struct netlink_ext_ack *extack) |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 213 | { |
| 214 | struct tc_action_net *tn = net_generic(net, tunnel_key_net_id); |
| 215 | struct nlattr *tb[TCA_TUNNEL_KEY_MAX + 1]; |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 216 | struct tcf_tunnel_key_params *params_new; |
| 217 | struct metadata_dst *metadata = NULL; |
Davide Caratti | e5fdaba | 2019-03-20 15:00:13 +0100 | [diff] [blame] | 218 | struct tcf_chain *goto_ch = NULL; |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 219 | struct tc_tunnel_key *parm; |
| 220 | struct tcf_tunnel_key *t; |
| 221 | bool exists = false; |
Hadar Hen Zion | 75bfbca | 2016-11-07 15:14:41 +0200 | [diff] [blame] | 222 | __be16 dst_port = 0; |
Adi Nissim | 80ef0f2 | 2018-12-02 14:55:20 +0200 | [diff] [blame] | 223 | __be64 key_id = 0; |
Simon Horman | 0ed5269 | 2018-06-26 21:39:37 -0700 | [diff] [blame] | 224 | int opts_len = 0; |
Adi Nissim | 80ef0f2 | 2018-12-02 14:55:20 +0200 | [diff] [blame] | 225 | __be16 flags = 0; |
Or Gerlitz | 07a557f | 2018-07-17 19:27:16 +0300 | [diff] [blame] | 226 | u8 tos, ttl; |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 227 | int ret = 0; |
Dmytro Linkin | 7be8ef2 | 2019-08-01 13:02:51 +0000 | [diff] [blame] | 228 | u32 index; |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 229 | int err; |
| 230 | |
Simon Horman | 9d7298c | 2018-06-26 21:39:35 -0700 | [diff] [blame] | 231 | if (!nla) { |
| 232 | NL_SET_ERR_MSG(extack, "Tunnel requires attributes to be passed"); |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 233 | return -EINVAL; |
Simon Horman | 9d7298c | 2018-06-26 21:39:35 -0700 | [diff] [blame] | 234 | } |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 235 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 236 | err = nla_parse_nested_deprecated(tb, TCA_TUNNEL_KEY_MAX, nla, |
| 237 | tunnel_key_policy, extack); |
Simon Horman | 9d7298c | 2018-06-26 21:39:35 -0700 | [diff] [blame] | 238 | if (err < 0) { |
| 239 | NL_SET_ERR_MSG(extack, "Failed to parse nested tunnel key attributes"); |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 240 | return err; |
Simon Horman | 9d7298c | 2018-06-26 21:39:35 -0700 | [diff] [blame] | 241 | } |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 242 | |
Simon Horman | 9d7298c | 2018-06-26 21:39:35 -0700 | [diff] [blame] | 243 | if (!tb[TCA_TUNNEL_KEY_PARMS]) { |
| 244 | NL_SET_ERR_MSG(extack, "Missing tunnel key parameters"); |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 245 | return -EINVAL; |
Simon Horman | 9d7298c | 2018-06-26 21:39:35 -0700 | [diff] [blame] | 246 | } |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 247 | |
| 248 | parm = nla_data(tb[TCA_TUNNEL_KEY_PARMS]); |
Dmytro Linkin | 7be8ef2 | 2019-08-01 13:02:51 +0000 | [diff] [blame] | 249 | index = parm->index; |
| 250 | err = tcf_idr_check_alloc(tn, &index, a, bind); |
Vlad Buslov | 0190c1d | 2018-07-05 17:24:32 +0300 | [diff] [blame] | 251 | if (err < 0) |
| 252 | return err; |
| 253 | exists = err; |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 254 | if (exists && bind) |
| 255 | return 0; |
| 256 | |
| 257 | switch (parm->t_action) { |
| 258 | case TCA_TUNNEL_KEY_ACT_RELEASE: |
| 259 | break; |
| 260 | case TCA_TUNNEL_KEY_ACT_SET: |
Adi Nissim | 80ef0f2 | 2018-12-02 14:55:20 +0200 | [diff] [blame] | 261 | if (tb[TCA_TUNNEL_KEY_ENC_KEY_ID]) { |
| 262 | __be32 key32; |
| 263 | |
| 264 | key32 = nla_get_be32(tb[TCA_TUNNEL_KEY_ENC_KEY_ID]); |
| 265 | key_id = key32_to_tunnel_id(key32); |
| 266 | flags = TUNNEL_KEY; |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 267 | } |
| 268 | |
Adi Nissim | 80ef0f2 | 2018-12-02 14:55:20 +0200 | [diff] [blame] | 269 | flags |= TUNNEL_CSUM; |
Jiri Benc | 86087e1 | 2017-06-14 21:19:31 +0200 | [diff] [blame] | 270 | if (tb[TCA_TUNNEL_KEY_NO_CSUM] && |
| 271 | nla_get_u8(tb[TCA_TUNNEL_KEY_NO_CSUM])) |
| 272 | flags &= ~TUNNEL_CSUM; |
| 273 | |
Hadar Hen Zion | 75bfbca | 2016-11-07 15:14:41 +0200 | [diff] [blame] | 274 | if (tb[TCA_TUNNEL_KEY_ENC_DST_PORT]) |
| 275 | dst_port = nla_get_be16(tb[TCA_TUNNEL_KEY_ENC_DST_PORT]); |
| 276 | |
Simon Horman | 0ed5269 | 2018-06-26 21:39:37 -0700 | [diff] [blame] | 277 | if (tb[TCA_TUNNEL_KEY_ENC_OPTS]) { |
| 278 | opts_len = tunnel_key_get_opts_len(tb[TCA_TUNNEL_KEY_ENC_OPTS], |
| 279 | extack); |
| 280 | if (opts_len < 0) { |
| 281 | ret = opts_len; |
| 282 | goto err_out; |
| 283 | } |
| 284 | } |
| 285 | |
Or Gerlitz | 07a557f | 2018-07-17 19:27:16 +0300 | [diff] [blame] | 286 | tos = 0; |
| 287 | if (tb[TCA_TUNNEL_KEY_ENC_TOS]) |
| 288 | tos = nla_get_u8(tb[TCA_TUNNEL_KEY_ENC_TOS]); |
| 289 | ttl = 0; |
| 290 | if (tb[TCA_TUNNEL_KEY_ENC_TTL]) |
| 291 | ttl = nla_get_u8(tb[TCA_TUNNEL_KEY_ENC_TTL]); |
| 292 | |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 293 | if (tb[TCA_TUNNEL_KEY_ENC_IPV4_SRC] && |
| 294 | tb[TCA_TUNNEL_KEY_ENC_IPV4_DST]) { |
| 295 | __be32 saddr; |
| 296 | __be32 daddr; |
| 297 | |
| 298 | saddr = nla_get_in_addr(tb[TCA_TUNNEL_KEY_ENC_IPV4_SRC]); |
| 299 | daddr = nla_get_in_addr(tb[TCA_TUNNEL_KEY_ENC_IPV4_DST]); |
| 300 | |
Or Gerlitz | 07a557f | 2018-07-17 19:27:16 +0300 | [diff] [blame] | 301 | metadata = __ip_tun_set_dst(saddr, daddr, tos, ttl, |
Jiri Benc | 86087e1 | 2017-06-14 21:19:31 +0200 | [diff] [blame] | 302 | dst_port, flags, |
Simon Horman | 0ed5269 | 2018-06-26 21:39:37 -0700 | [diff] [blame] | 303 | key_id, opts_len); |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 304 | } else if (tb[TCA_TUNNEL_KEY_ENC_IPV6_SRC] && |
| 305 | tb[TCA_TUNNEL_KEY_ENC_IPV6_DST]) { |
| 306 | struct in6_addr saddr; |
| 307 | struct in6_addr daddr; |
| 308 | |
| 309 | saddr = nla_get_in6_addr(tb[TCA_TUNNEL_KEY_ENC_IPV6_SRC]); |
| 310 | daddr = nla_get_in6_addr(tb[TCA_TUNNEL_KEY_ENC_IPV6_DST]); |
| 311 | |
Or Gerlitz | 07a557f | 2018-07-17 19:27:16 +0300 | [diff] [blame] | 312 | metadata = __ipv6_tun_set_dst(&saddr, &daddr, tos, ttl, dst_port, |
Jiri Benc | 86087e1 | 2017-06-14 21:19:31 +0200 | [diff] [blame] | 313 | 0, flags, |
Hadar Hen Zion | 75bfbca | 2016-11-07 15:14:41 +0200 | [diff] [blame] | 314 | key_id, 0); |
Simon Horman | a1165b5 | 2018-06-26 21:39:34 -0700 | [diff] [blame] | 315 | } else { |
Simon Horman | 9d7298c | 2018-06-26 21:39:35 -0700 | [diff] [blame] | 316 | NL_SET_ERR_MSG(extack, "Missing either ipv4 or ipv6 src and dst"); |
Simon Horman | a1165b5 | 2018-06-26 21:39:34 -0700 | [diff] [blame] | 317 | ret = -EINVAL; |
| 318 | goto err_out; |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | if (!metadata) { |
Simon Horman | 9d7298c | 2018-06-26 21:39:35 -0700 | [diff] [blame] | 322 | NL_SET_ERR_MSG(extack, "Cannot allocate tunnel metadata dst"); |
Simon Horman | a1165b5 | 2018-06-26 21:39:34 -0700 | [diff] [blame] | 323 | ret = -ENOMEM; |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 324 | goto err_out; |
| 325 | } |
| 326 | |
wenxu | 41411e2 | 2019-02-22 15:58:12 +0800 | [diff] [blame] | 327 | #ifdef CONFIG_DST_CACHE |
| 328 | ret = dst_cache_init(&metadata->u.tun_info.dst_cache, GFP_KERNEL); |
| 329 | if (ret) |
| 330 | goto release_tun_meta; |
| 331 | #endif |
| 332 | |
Simon Horman | 0ed5269 | 2018-06-26 21:39:37 -0700 | [diff] [blame] | 333 | if (opts_len) { |
| 334 | ret = tunnel_key_opts_set(tb[TCA_TUNNEL_KEY_ENC_OPTS], |
| 335 | &metadata->u.tun_info, |
| 336 | opts_len, extack); |
| 337 | if (ret < 0) |
wenxu | 4177c5d | 2019-03-05 08:29:28 +0800 | [diff] [blame] | 338 | goto release_tun_meta; |
Simon Horman | 0ed5269 | 2018-06-26 21:39:37 -0700 | [diff] [blame] | 339 | } |
| 340 | |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 341 | metadata->u.tun_info.mode |= IP_TUNNEL_INFO_TX; |
| 342 | break; |
| 343 | default: |
Simon Horman | 9d7298c | 2018-06-26 21:39:35 -0700 | [diff] [blame] | 344 | NL_SET_ERR_MSG(extack, "Unknown tunnel key action"); |
Roman Mashak | 51d4740 | 2018-03-12 16:20:58 -0400 | [diff] [blame] | 345 | ret = -EINVAL; |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 346 | goto err_out; |
| 347 | } |
| 348 | |
| 349 | if (!exists) { |
Dmytro Linkin | 7be8ef2 | 2019-08-01 13:02:51 +0000 | [diff] [blame] | 350 | ret = tcf_idr_create(tn, index, est, a, |
Chris Mi | 65a206c | 2017-08-30 02:31:59 -0400 | [diff] [blame] | 351 | &act_tunnel_key_ops, bind, true); |
Simon Horman | 9d7298c | 2018-06-26 21:39:35 -0700 | [diff] [blame] | 352 | if (ret) { |
| 353 | NL_SET_ERR_MSG(extack, "Cannot create TC IDR"); |
wenxu | 4177c5d | 2019-03-05 08:29:28 +0800 | [diff] [blame] | 354 | goto release_tun_meta; |
Simon Horman | 9d7298c | 2018-06-26 21:39:35 -0700 | [diff] [blame] | 355 | } |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 356 | |
| 357 | ret = ACT_P_CREATED; |
Vlad Buslov | 4e8ddd7 | 2018-07-05 17:24:30 +0300 | [diff] [blame] | 358 | } else if (!ovr) { |
Vlad Buslov | 4e8ddd7 | 2018-07-05 17:24:30 +0300 | [diff] [blame] | 359 | NL_SET_ERR_MSG(extack, "TC IDR already exists"); |
Davide Caratti | ee28bb5 | 2018-09-04 19:00:19 +0200 | [diff] [blame] | 360 | ret = -EEXIST; |
wenxu | 4177c5d | 2019-03-05 08:29:28 +0800 | [diff] [blame] | 361 | goto release_tun_meta; |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 362 | } |
| 363 | |
Davide Caratti | e5fdaba | 2019-03-20 15:00:13 +0100 | [diff] [blame] | 364 | err = tcf_action_check_ctrlact(parm->action, tp, &goto_ch, extack); |
| 365 | if (err < 0) { |
| 366 | ret = err; |
| 367 | exists = true; |
| 368 | goto release_tun_meta; |
| 369 | } |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 370 | t = to_tunnel_key(*a); |
| 371 | |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 372 | params_new = kzalloc(sizeof(*params_new), GFP_KERNEL); |
| 373 | if (unlikely(!params_new)) { |
Simon Horman | 9d7298c | 2018-06-26 21:39:35 -0700 | [diff] [blame] | 374 | NL_SET_ERR_MSG(extack, "Cannot allocate tunnel key parameters"); |
Davide Caratti | ee28bb5 | 2018-09-04 19:00:19 +0200 | [diff] [blame] | 375 | ret = -ENOMEM; |
| 376 | exists = true; |
Davide Caratti | e5fdaba | 2019-03-20 15:00:13 +0100 | [diff] [blame] | 377 | goto put_chain; |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 378 | } |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 379 | params_new->tcft_action = parm->t_action; |
| 380 | params_new->tcft_enc_metadata = metadata; |
| 381 | |
Vlad Buslov | 653cd28 | 2018-08-14 21:46:16 +0300 | [diff] [blame] | 382 | spin_lock_bh(&t->tcf_lock); |
Davide Caratti | e5fdaba | 2019-03-20 15:00:13 +0100 | [diff] [blame] | 383 | goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch); |
Vlad Buslov | 729e012 | 2018-08-10 20:51:50 +0300 | [diff] [blame] | 384 | rcu_swap_protected(t->params, params_new, |
| 385 | lockdep_is_held(&t->tcf_lock)); |
Vlad Buslov | 653cd28 | 2018-08-14 21:46:16 +0300 | [diff] [blame] | 386 | spin_unlock_bh(&t->tcf_lock); |
Davide Caratti | 9174c3d | 2019-01-10 20:21:02 +0100 | [diff] [blame] | 387 | tunnel_key_release_params(params_new); |
Davide Caratti | e5fdaba | 2019-03-20 15:00:13 +0100 | [diff] [blame] | 388 | if (goto_ch) |
| 389 | tcf_chain_put_by_act(goto_ch); |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 390 | |
| 391 | if (ret == ACT_P_CREATED) |
Chris Mi | 65a206c | 2017-08-30 02:31:59 -0400 | [diff] [blame] | 392 | tcf_idr_insert(tn, *a); |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 393 | |
| 394 | return ret; |
| 395 | |
Davide Caratti | e5fdaba | 2019-03-20 15:00:13 +0100 | [diff] [blame] | 396 | put_chain: |
| 397 | if (goto_ch) |
| 398 | tcf_chain_put_by_act(goto_ch); |
| 399 | |
Davide Caratti | ee28bb5 | 2018-09-04 19:00:19 +0200 | [diff] [blame] | 400 | release_tun_meta: |
Vlad Buslov | a3df633 | 2019-02-25 17:28:27 +0200 | [diff] [blame] | 401 | if (metadata) |
| 402 | dst_release(&metadata->dst); |
Davide Caratti | ee28bb5 | 2018-09-04 19:00:19 +0200 | [diff] [blame] | 403 | |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 404 | err_out: |
| 405 | if (exists) |
Chris Mi | 65a206c | 2017-08-30 02:31:59 -0400 | [diff] [blame] | 406 | tcf_idr_release(*a, bind); |
Vlad Buslov | 0190c1d | 2018-07-05 17:24:32 +0300 | [diff] [blame] | 407 | else |
Dmytro Linkin | 7be8ef2 | 2019-08-01 13:02:51 +0000 | [diff] [blame] | 408 | tcf_idr_cleanup(tn, index); |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 409 | return ret; |
| 410 | } |
| 411 | |
Cong Wang | 9a63b25 | 2017-12-05 12:53:07 -0800 | [diff] [blame] | 412 | static void tunnel_key_release(struct tc_action *a) |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 413 | { |
| 414 | struct tcf_tunnel_key *t = to_tunnel_key(a); |
| 415 | struct tcf_tunnel_key_params *params; |
| 416 | |
Hadar Hen Zion | 07c0f09 | 2016-09-12 15:19:21 +0300 | [diff] [blame] | 417 | params = rcu_dereference_protected(t->params, 1); |
Davide Caratti | 9174c3d | 2019-01-10 20:21:02 +0100 | [diff] [blame] | 418 | tunnel_key_release_params(params); |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 419 | } |
| 420 | |
Simon Horman | 0ed5269 | 2018-06-26 21:39:37 -0700 | [diff] [blame] | 421 | static int tunnel_key_geneve_opts_dump(struct sk_buff *skb, |
| 422 | const struct ip_tunnel_info *info) |
| 423 | { |
| 424 | int len = info->options_len; |
| 425 | u8 *src = (u8 *)(info + 1); |
| 426 | struct nlattr *start; |
| 427 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 428 | start = nla_nest_start_noflag(skb, TCA_TUNNEL_KEY_ENC_OPTS_GENEVE); |
Simon Horman | 0ed5269 | 2018-06-26 21:39:37 -0700 | [diff] [blame] | 429 | if (!start) |
| 430 | return -EMSGSIZE; |
| 431 | |
| 432 | while (len > 0) { |
| 433 | struct geneve_opt *opt = (struct geneve_opt *)src; |
| 434 | |
| 435 | if (nla_put_be16(skb, TCA_TUNNEL_KEY_ENC_OPT_GENEVE_CLASS, |
| 436 | opt->opt_class) || |
| 437 | nla_put_u8(skb, TCA_TUNNEL_KEY_ENC_OPT_GENEVE_TYPE, |
| 438 | opt->type) || |
| 439 | nla_put(skb, TCA_TUNNEL_KEY_ENC_OPT_GENEVE_DATA, |
Cong Wang | a162c35 | 2018-09-06 14:50:16 -0700 | [diff] [blame] | 440 | opt->length * 4, opt + 1)) { |
| 441 | nla_nest_cancel(skb, start); |
Simon Horman | 0ed5269 | 2018-06-26 21:39:37 -0700 | [diff] [blame] | 442 | return -EMSGSIZE; |
Cong Wang | a162c35 | 2018-09-06 14:50:16 -0700 | [diff] [blame] | 443 | } |
Simon Horman | 0ed5269 | 2018-06-26 21:39:37 -0700 | [diff] [blame] | 444 | |
| 445 | len -= sizeof(struct geneve_opt) + opt->length * 4; |
| 446 | src += sizeof(struct geneve_opt) + opt->length * 4; |
| 447 | } |
| 448 | |
| 449 | nla_nest_end(skb, start); |
| 450 | return 0; |
| 451 | } |
| 452 | |
| 453 | static int tunnel_key_opts_dump(struct sk_buff *skb, |
| 454 | const struct ip_tunnel_info *info) |
| 455 | { |
| 456 | struct nlattr *start; |
Cong Wang | a162c35 | 2018-09-06 14:50:16 -0700 | [diff] [blame] | 457 | int err = -EINVAL; |
Simon Horman | 0ed5269 | 2018-06-26 21:39:37 -0700 | [diff] [blame] | 458 | |
| 459 | if (!info->options_len) |
| 460 | return 0; |
| 461 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 462 | start = nla_nest_start_noflag(skb, TCA_TUNNEL_KEY_ENC_OPTS); |
Simon Horman | 0ed5269 | 2018-06-26 21:39:37 -0700 | [diff] [blame] | 463 | if (!start) |
| 464 | return -EMSGSIZE; |
| 465 | |
| 466 | if (info->key.tun_flags & TUNNEL_GENEVE_OPT) { |
| 467 | err = tunnel_key_geneve_opts_dump(skb, info); |
| 468 | if (err) |
Cong Wang | a162c35 | 2018-09-06 14:50:16 -0700 | [diff] [blame] | 469 | goto err_out; |
Simon Horman | 0ed5269 | 2018-06-26 21:39:37 -0700 | [diff] [blame] | 470 | } else { |
Cong Wang | a162c35 | 2018-09-06 14:50:16 -0700 | [diff] [blame] | 471 | err_out: |
| 472 | nla_nest_cancel(skb, start); |
| 473 | return err; |
Simon Horman | 0ed5269 | 2018-06-26 21:39:37 -0700 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | nla_nest_end(skb, start); |
| 477 | return 0; |
| 478 | } |
| 479 | |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 480 | static int tunnel_key_dump_addresses(struct sk_buff *skb, |
| 481 | const struct ip_tunnel_info *info) |
| 482 | { |
| 483 | unsigned short family = ip_tunnel_info_af(info); |
| 484 | |
| 485 | if (family == AF_INET) { |
| 486 | __be32 saddr = info->key.u.ipv4.src; |
| 487 | __be32 daddr = info->key.u.ipv4.dst; |
| 488 | |
| 489 | if (!nla_put_in_addr(skb, TCA_TUNNEL_KEY_ENC_IPV4_SRC, saddr) && |
| 490 | !nla_put_in_addr(skb, TCA_TUNNEL_KEY_ENC_IPV4_DST, daddr)) |
| 491 | return 0; |
| 492 | } |
| 493 | |
| 494 | if (family == AF_INET6) { |
| 495 | const struct in6_addr *saddr6 = &info->key.u.ipv6.src; |
| 496 | const struct in6_addr *daddr6 = &info->key.u.ipv6.dst; |
| 497 | |
| 498 | if (!nla_put_in6_addr(skb, |
| 499 | TCA_TUNNEL_KEY_ENC_IPV6_SRC, saddr6) && |
| 500 | !nla_put_in6_addr(skb, |
| 501 | TCA_TUNNEL_KEY_ENC_IPV6_DST, daddr6)) |
| 502 | return 0; |
| 503 | } |
| 504 | |
| 505 | return -EINVAL; |
| 506 | } |
| 507 | |
| 508 | static int tunnel_key_dump(struct sk_buff *skb, struct tc_action *a, |
| 509 | int bind, int ref) |
| 510 | { |
| 511 | unsigned char *b = skb_tail_pointer(skb); |
| 512 | struct tcf_tunnel_key *t = to_tunnel_key(a); |
| 513 | struct tcf_tunnel_key_params *params; |
| 514 | struct tc_tunnel_key opt = { |
| 515 | .index = t->tcf_index, |
Vlad Buslov | 036bb44 | 2018-07-05 17:24:24 +0300 | [diff] [blame] | 516 | .refcnt = refcount_read(&t->tcf_refcnt) - ref, |
| 517 | .bindcnt = atomic_read(&t->tcf_bindcnt) - bind, |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 518 | }; |
| 519 | struct tcf_t tm; |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 520 | |
Vlad Buslov | 653cd28 | 2018-08-14 21:46:16 +0300 | [diff] [blame] | 521 | spin_lock_bh(&t->tcf_lock); |
Vlad Buslov | 729e012 | 2018-08-10 20:51:50 +0300 | [diff] [blame] | 522 | params = rcu_dereference_protected(t->params, |
| 523 | lockdep_is_held(&t->tcf_lock)); |
| 524 | opt.action = t->tcf_action; |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 525 | opt.t_action = params->tcft_action; |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 526 | |
| 527 | if (nla_put(skb, TCA_TUNNEL_KEY_PARMS, sizeof(opt), &opt)) |
| 528 | goto nla_put_failure; |
| 529 | |
| 530 | if (params->tcft_action == TCA_TUNNEL_KEY_ACT_SET) { |
Simon Horman | 0ed5269 | 2018-06-26 21:39:37 -0700 | [diff] [blame] | 531 | struct ip_tunnel_info *info = |
| 532 | ¶ms->tcft_enc_metadata->u.tun_info; |
| 533 | struct ip_tunnel_key *key = &info->key; |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 534 | __be32 key_id = tunnel_id_to_key32(key->tun_id); |
| 535 | |
Adi Nissim | 80ef0f2 | 2018-12-02 14:55:20 +0200 | [diff] [blame] | 536 | if (((key->tun_flags & TUNNEL_KEY) && |
| 537 | nla_put_be32(skb, TCA_TUNNEL_KEY_ENC_KEY_ID, key_id)) || |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 538 | tunnel_key_dump_addresses(skb, |
Hadar Hen Zion | 75bfbca | 2016-11-07 15:14:41 +0200 | [diff] [blame] | 539 | ¶ms->tcft_enc_metadata->u.tun_info) || |
Adi Nissim | 1c25324 | 2018-12-02 14:55:21 +0200 | [diff] [blame] | 540 | (key->tp_dst && |
| 541 | nla_put_be16(skb, TCA_TUNNEL_KEY_ENC_DST_PORT, |
| 542 | key->tp_dst)) || |
Jiri Benc | 86087e1 | 2017-06-14 21:19:31 +0200 | [diff] [blame] | 543 | nla_put_u8(skb, TCA_TUNNEL_KEY_NO_CSUM, |
Simon Horman | 0ed5269 | 2018-06-26 21:39:37 -0700 | [diff] [blame] | 544 | !(key->tun_flags & TUNNEL_CSUM)) || |
| 545 | tunnel_key_opts_dump(skb, info)) |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 546 | goto nla_put_failure; |
Or Gerlitz | 07a557f | 2018-07-17 19:27:16 +0300 | [diff] [blame] | 547 | |
| 548 | if (key->tos && nla_put_u8(skb, TCA_TUNNEL_KEY_ENC_TOS, key->tos)) |
| 549 | goto nla_put_failure; |
| 550 | |
| 551 | if (key->ttl && nla_put_u8(skb, TCA_TUNNEL_KEY_ENC_TTL, key->ttl)) |
| 552 | goto nla_put_failure; |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | tcf_tm_dump(&tm, &t->tcf_tm); |
| 556 | if (nla_put_64bit(skb, TCA_TUNNEL_KEY_TM, sizeof(tm), |
| 557 | &tm, TCA_TUNNEL_KEY_PAD)) |
| 558 | goto nla_put_failure; |
Vlad Buslov | 653cd28 | 2018-08-14 21:46:16 +0300 | [diff] [blame] | 559 | spin_unlock_bh(&t->tcf_lock); |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 560 | |
Hadar Hen Zion | 07c0f09 | 2016-09-12 15:19:21 +0300 | [diff] [blame] | 561 | return skb->len; |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 562 | |
| 563 | nla_put_failure: |
Vlad Buslov | 653cd28 | 2018-08-14 21:46:16 +0300 | [diff] [blame] | 564 | spin_unlock_bh(&t->tcf_lock); |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 565 | nlmsg_trim(skb, b); |
Hadar Hen Zion | 07c0f09 | 2016-09-12 15:19:21 +0300 | [diff] [blame] | 566 | return -1; |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | static int tunnel_key_walker(struct net *net, struct sk_buff *skb, |
| 570 | struct netlink_callback *cb, int type, |
Alexander Aring | 4178010 | 2018-02-15 10:54:58 -0500 | [diff] [blame] | 571 | const struct tc_action_ops *ops, |
| 572 | struct netlink_ext_ack *extack) |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 573 | { |
| 574 | struct tc_action_net *tn = net_generic(net, tunnel_key_net_id); |
| 575 | |
Alexander Aring | b362014 | 2018-02-15 10:54:59 -0500 | [diff] [blame] | 576 | return tcf_generic_walker(tn, skb, cb, type, ops, extack); |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 577 | } |
| 578 | |
Cong Wang | f061b48 | 2018-08-29 10:15:35 -0700 | [diff] [blame] | 579 | static int tunnel_key_search(struct net *net, struct tc_action **a, u32 index) |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 580 | { |
| 581 | struct tc_action_net *tn = net_generic(net, tunnel_key_net_id); |
| 582 | |
Chris Mi | 65a206c | 2017-08-30 02:31:59 -0400 | [diff] [blame] | 583 | return tcf_idr_search(tn, a, index); |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | static struct tc_action_ops act_tunnel_key_ops = { |
| 587 | .kind = "tunnel_key", |
Eli Cohen | eddd2cf | 2019-02-10 14:25:00 +0200 | [diff] [blame] | 588 | .id = TCA_ID_TUNNEL_KEY, |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 589 | .owner = THIS_MODULE, |
| 590 | .act = tunnel_key_act, |
| 591 | .dump = tunnel_key_dump, |
| 592 | .init = tunnel_key_init, |
| 593 | .cleanup = tunnel_key_release, |
| 594 | .walk = tunnel_key_walker, |
| 595 | .lookup = tunnel_key_search, |
| 596 | .size = sizeof(struct tcf_tunnel_key), |
| 597 | }; |
| 598 | |
| 599 | static __net_init int tunnel_key_init_net(struct net *net) |
| 600 | { |
| 601 | struct tc_action_net *tn = net_generic(net, tunnel_key_net_id); |
| 602 | |
Cong Wang | 981471b | 2019-08-25 10:01:32 -0700 | [diff] [blame] | 603 | return tc_action_net_init(net, tn, &act_tunnel_key_ops); |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 604 | } |
| 605 | |
Cong Wang | 039af9c | 2017-12-11 15:35:03 -0800 | [diff] [blame] | 606 | static void __net_exit tunnel_key_exit_net(struct list_head *net_list) |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 607 | { |
Cong Wang | 039af9c | 2017-12-11 15:35:03 -0800 | [diff] [blame] | 608 | tc_action_net_exit(net_list, tunnel_key_net_id); |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | static struct pernet_operations tunnel_key_net_ops = { |
| 612 | .init = tunnel_key_init_net, |
Cong Wang | 039af9c | 2017-12-11 15:35:03 -0800 | [diff] [blame] | 613 | .exit_batch = tunnel_key_exit_net, |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 614 | .id = &tunnel_key_net_id, |
| 615 | .size = sizeof(struct tc_action_net), |
Amir Vadai | d0f6dd8 | 2016-09-08 16:23:48 +0300 | [diff] [blame] | 616 | }; |
| 617 | |
| 618 | static int __init tunnel_key_init_module(void) |
| 619 | { |
| 620 | return tcf_register_action(&act_tunnel_key_ops, &tunnel_key_net_ops); |
| 621 | } |
| 622 | |
| 623 | static void __exit tunnel_key_cleanup_module(void) |
| 624 | { |
| 625 | tcf_unregister_action(&act_tunnel_key_ops, &tunnel_key_net_ops); |
| 626 | } |
| 627 | |
| 628 | module_init(tunnel_key_init_module); |
| 629 | module_exit(tunnel_key_cleanup_module); |
| 630 | |
| 631 | MODULE_AUTHOR("Amir Vadai <amir@vadai.me>"); |
| 632 | MODULE_DESCRIPTION("ip tunnel manipulation actions"); |
| 633 | MODULE_LICENSE("GPL v2"); |