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