0001
0002
0003
0004
0005
0006
0007 #ifndef __NET_TC_TUNNEL_KEY_H
0008 #define __NET_TC_TUNNEL_KEY_H
0009
0010 #include <net/act_api.h>
0011 #include <linux/tc_act/tc_tunnel_key.h>
0012 #include <net/dst_metadata.h>
0013
0014 struct tcf_tunnel_key_params {
0015 struct rcu_head rcu;
0016 int tcft_action;
0017 struct metadata_dst *tcft_enc_metadata;
0018 };
0019
0020 struct tcf_tunnel_key {
0021 struct tc_action common;
0022 struct tcf_tunnel_key_params __rcu *params;
0023 };
0024
0025 #define to_tunnel_key(a) ((struct tcf_tunnel_key *)a)
0026
0027 static inline bool is_tcf_tunnel_set(const struct tc_action *a)
0028 {
0029 #ifdef CONFIG_NET_CLS_ACT
0030 struct tcf_tunnel_key *t = to_tunnel_key(a);
0031 struct tcf_tunnel_key_params *params;
0032
0033 params = rcu_dereference_protected(t->params,
0034 lockdep_is_held(&a->tcfa_lock));
0035 if (a->ops && a->ops->id == TCA_ID_TUNNEL_KEY)
0036 return params->tcft_action == TCA_TUNNEL_KEY_ACT_SET;
0037 #endif
0038 return false;
0039 }
0040
0041 static inline bool is_tcf_tunnel_release(const struct tc_action *a)
0042 {
0043 #ifdef CONFIG_NET_CLS_ACT
0044 struct tcf_tunnel_key *t = to_tunnel_key(a);
0045 struct tcf_tunnel_key_params *params;
0046
0047 params = rcu_dereference_protected(t->params,
0048 lockdep_is_held(&a->tcfa_lock));
0049 if (a->ops && a->ops->id == TCA_ID_TUNNEL_KEY)
0050 return params->tcft_action == TCA_TUNNEL_KEY_ACT_RELEASE;
0051 #endif
0052 return false;
0053 }
0054
0055 static inline struct ip_tunnel_info *tcf_tunnel_info(const struct tc_action *a)
0056 {
0057 #ifdef CONFIG_NET_CLS_ACT
0058 struct tcf_tunnel_key *t = to_tunnel_key(a);
0059 struct tcf_tunnel_key_params *params;
0060
0061 params = rcu_dereference_protected(t->params,
0062 lockdep_is_held(&a->tcfa_lock));
0063
0064 return ¶ms->tcft_enc_metadata->u.tun_info;
0065 #else
0066 return NULL;
0067 #endif
0068 }
0069
0070 static inline struct ip_tunnel_info *
0071 tcf_tunnel_info_copy(const struct tc_action *a)
0072 {
0073 #ifdef CONFIG_NET_CLS_ACT
0074 struct ip_tunnel_info *tun = tcf_tunnel_info(a);
0075
0076 if (tun) {
0077 size_t tun_size = sizeof(*tun) + tun->options_len;
0078 struct ip_tunnel_info *tun_copy = kmemdup(tun, tun_size,
0079 GFP_ATOMIC);
0080
0081 return tun_copy;
0082 }
0083 #endif
0084 return NULL;
0085 }
0086 #endif