tc_tunnel_key.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright (c) 2016, Amir Vadai <amir@vadai.me>
  4. * Copyright (c) 2016, Mellanox Technologies. All rights reserved.
  5. */
  6. #ifndef __NET_TC_TUNNEL_KEY_H
  7. #define __NET_TC_TUNNEL_KEY_H
  8. #include <net/act_api.h>
  9. #include <linux/tc_act/tc_tunnel_key.h>
  10. #include <net/dst_metadata.h>
  11. struct tcf_tunnel_key_params {
  12. struct rcu_head rcu;
  13. int tcft_action;
  14. int action;
  15. struct metadata_dst *tcft_enc_metadata;
  16. };
  17. struct tcf_tunnel_key {
  18. struct tc_action common;
  19. struct tcf_tunnel_key_params __rcu *params;
  20. };
  21. #define to_tunnel_key(a) ((struct tcf_tunnel_key *)a)
  22. static inline bool is_tcf_tunnel_set(const struct tc_action *a)
  23. {
  24. #ifdef CONFIG_NET_CLS_ACT
  25. struct tcf_tunnel_key *t = to_tunnel_key(a);
  26. struct tcf_tunnel_key_params *params;
  27. params = rcu_dereference_protected(t->params,
  28. lockdep_is_held(&a->tcfa_lock));
  29. if (a->ops && a->ops->id == TCA_ID_TUNNEL_KEY)
  30. return params->tcft_action == TCA_TUNNEL_KEY_ACT_SET;
  31. #endif
  32. return false;
  33. }
  34. static inline bool is_tcf_tunnel_release(const struct tc_action *a)
  35. {
  36. #ifdef CONFIG_NET_CLS_ACT
  37. struct tcf_tunnel_key *t = to_tunnel_key(a);
  38. struct tcf_tunnel_key_params *params;
  39. params = rcu_dereference_protected(t->params,
  40. lockdep_is_held(&a->tcfa_lock));
  41. if (a->ops && a->ops->id == TCA_ID_TUNNEL_KEY)
  42. return params->tcft_action == TCA_TUNNEL_KEY_ACT_RELEASE;
  43. #endif
  44. return false;
  45. }
  46. static inline struct ip_tunnel_info *tcf_tunnel_info(const struct tc_action *a)
  47. {
  48. #ifdef CONFIG_NET_CLS_ACT
  49. struct tcf_tunnel_key *t = to_tunnel_key(a);
  50. struct tcf_tunnel_key_params *params;
  51. params = rcu_dereference_protected(t->params,
  52. lockdep_is_held(&a->tcfa_lock));
  53. return &params->tcft_enc_metadata->u.tun_info;
  54. #else
  55. return NULL;
  56. #endif
  57. }
  58. static inline struct ip_tunnel_info *
  59. tcf_tunnel_info_copy(const struct tc_action *a)
  60. {
  61. #ifdef CONFIG_NET_CLS_ACT
  62. struct ip_tunnel_info *tun = tcf_tunnel_info(a);
  63. if (tun) {
  64. size_t tun_size = sizeof(*tun) + tun->options_len;
  65. struct ip_tunnel_info *tun_copy = kmemdup(tun, tun_size,
  66. GFP_ATOMIC);
  67. return tun_copy;
  68. }
  69. #endif
  70. return NULL;
  71. }
  72. #endif /* __NET_TC_TUNNEL_KEY_H */