| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (c) 2016, Amir Vadai <amir@vadai.me> |
|---|
| 3 | 4 | * 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 | 5 | */ |
|---|
| 10 | 6 | |
|---|
| 11 | 7 | #ifndef __NET_TC_TUNNEL_KEY_H |
|---|
| .. | .. |
|---|
| 32 | 28 | { |
|---|
| 33 | 29 | #ifdef CONFIG_NET_CLS_ACT |
|---|
| 34 | 30 | struct tcf_tunnel_key *t = to_tunnel_key(a); |
|---|
| 35 | | - struct tcf_tunnel_key_params *params = rtnl_dereference(t->params); |
|---|
| 31 | + struct tcf_tunnel_key_params *params; |
|---|
| 36 | 32 | |
|---|
| 37 | | - if (a->ops && a->ops->type == TCA_ACT_TUNNEL_KEY) |
|---|
| 33 | + params = rcu_dereference_protected(t->params, |
|---|
| 34 | + lockdep_is_held(&a->tcfa_lock)); |
|---|
| 35 | + if (a->ops && a->ops->id == TCA_ID_TUNNEL_KEY) |
|---|
| 38 | 36 | return params->tcft_action == TCA_TUNNEL_KEY_ACT_SET; |
|---|
| 39 | 37 | #endif |
|---|
| 40 | 38 | return false; |
|---|
| .. | .. |
|---|
| 44 | 42 | { |
|---|
| 45 | 43 | #ifdef CONFIG_NET_CLS_ACT |
|---|
| 46 | 44 | struct tcf_tunnel_key *t = to_tunnel_key(a); |
|---|
| 47 | | - struct tcf_tunnel_key_params *params = rtnl_dereference(t->params); |
|---|
| 45 | + struct tcf_tunnel_key_params *params; |
|---|
| 48 | 46 | |
|---|
| 49 | | - if (a->ops && a->ops->type == TCA_ACT_TUNNEL_KEY) |
|---|
| 47 | + params = rcu_dereference_protected(t->params, |
|---|
| 48 | + lockdep_is_held(&a->tcfa_lock)); |
|---|
| 49 | + if (a->ops && a->ops->id == TCA_ID_TUNNEL_KEY) |
|---|
| 50 | 50 | return params->tcft_action == TCA_TUNNEL_KEY_ACT_RELEASE; |
|---|
| 51 | 51 | #endif |
|---|
| 52 | 52 | return false; |
|---|
| .. | .. |
|---|
| 56 | 56 | { |
|---|
| 57 | 57 | #ifdef CONFIG_NET_CLS_ACT |
|---|
| 58 | 58 | struct tcf_tunnel_key *t = to_tunnel_key(a); |
|---|
| 59 | | - struct tcf_tunnel_key_params *params = rtnl_dereference(t->params); |
|---|
| 59 | + struct tcf_tunnel_key_params *params; |
|---|
| 60 | + |
|---|
| 61 | + params = rcu_dereference_protected(t->params, |
|---|
| 62 | + lockdep_is_held(&a->tcfa_lock)); |
|---|
| 60 | 63 | |
|---|
| 61 | 64 | return ¶ms->tcft_enc_metadata->u.tun_info; |
|---|
| 62 | 65 | #else |
|---|
| 63 | 66 | return NULL; |
|---|
| 64 | 67 | #endif |
|---|
| 65 | 68 | } |
|---|
| 69 | + |
|---|
| 70 | +static inline struct ip_tunnel_info * |
|---|
| 71 | +tcf_tunnel_info_copy(const struct tc_action *a) |
|---|
| 72 | +{ |
|---|
| 73 | +#ifdef CONFIG_NET_CLS_ACT |
|---|
| 74 | + struct ip_tunnel_info *tun = tcf_tunnel_info(a); |
|---|
| 75 | + |
|---|
| 76 | + if (tun) { |
|---|
| 77 | + size_t tun_size = sizeof(*tun) + tun->options_len; |
|---|
| 78 | + struct ip_tunnel_info *tun_copy = kmemdup(tun, tun_size, |
|---|
| 79 | + GFP_ATOMIC); |
|---|
| 80 | + |
|---|
| 81 | + return tun_copy; |
|---|
| 82 | + } |
|---|
| 83 | +#endif |
|---|
| 84 | + return NULL; |
|---|
| 85 | +} |
|---|
| 66 | 86 | #endif /* __NET_TC_TUNNEL_KEY_H */ |
|---|