tc_tunnel_key.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. #ifndef __NET_TC_TUNNEL_KEY_H
  11. #define __NET_TC_TUNNEL_KEY_H
  12. #include <net/act_api.h>
  13. #include <linux/tc_act/tc_tunnel_key.h>
  14. #include <net/dst_metadata.h>
  15. struct tcf_tunnel_key_params {
  16. struct rcu_head rcu;
  17. int tcft_action;
  18. int action;
  19. struct metadata_dst *tcft_enc_metadata;
  20. };
  21. struct tcf_tunnel_key {
  22. struct tc_action common;
  23. struct tcf_tunnel_key_params __rcu *params;
  24. };
  25. #define to_tunnel_key(a) ((struct tcf_tunnel_key *)a)
  26. static inline bool is_tcf_tunnel_set(const struct tc_action *a)
  27. {
  28. #ifdef CONFIG_NET_CLS_ACT
  29. struct tcf_tunnel_key *t = to_tunnel_key(a);
  30. struct tcf_tunnel_key_params *params = rtnl_dereference(t->params);
  31. if (a->ops && a->ops->type == TCA_ACT_TUNNEL_KEY)
  32. return params->tcft_action == TCA_TUNNEL_KEY_ACT_SET;
  33. #endif
  34. return false;
  35. }
  36. static inline bool is_tcf_tunnel_release(const struct tc_action *a)
  37. {
  38. #ifdef CONFIG_NET_CLS_ACT
  39. struct tcf_tunnel_key *t = to_tunnel_key(a);
  40. struct tcf_tunnel_key_params *params = rtnl_dereference(t->params);
  41. if (a->ops && a->ops->type == TCA_ACT_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 = rtnl_dereference(t->params);
  51. return &params->tcft_enc_metadata->u.tun_info;
  52. #else
  53. return NULL;
  54. #endif
  55. }
  56. #endif /* __NET_TC_TUNNEL_KEY_H */