Linux Audio

Check our new training course

Loading...
v4.17
 
 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#ifndef __NET_TC_TUNNEL_KEY_H
12#define __NET_TC_TUNNEL_KEY_H
13
14#include <net/act_api.h>
15#include <linux/tc_act/tc_tunnel_key.h>
16#include <net/dst_metadata.h>
17
18struct tcf_tunnel_key_params {
19	struct rcu_head		rcu;
20	int			tcft_action;
21	int			action;
22	struct metadata_dst     *tcft_enc_metadata;
23};
24
25struct tcf_tunnel_key {
26	struct tc_action	      common;
27	struct tcf_tunnel_key_params __rcu *params;
28};
29
30#define to_tunnel_key(a) ((struct tcf_tunnel_key *)a)
31
32static inline bool is_tcf_tunnel_set(const struct tc_action *a)
33{
34#ifdef CONFIG_NET_CLS_ACT
35	struct tcf_tunnel_key *t = to_tunnel_key(a);
36	struct tcf_tunnel_key_params *params = rtnl_dereference(t->params);
37
38	if (a->ops && a->ops->type == TCA_ACT_TUNNEL_KEY)
 
 
39		return params->tcft_action == TCA_TUNNEL_KEY_ACT_SET;
40#endif
41	return false;
42}
43
44static inline bool is_tcf_tunnel_release(const struct tc_action *a)
45{
46#ifdef CONFIG_NET_CLS_ACT
47	struct tcf_tunnel_key *t = to_tunnel_key(a);
48	struct tcf_tunnel_key_params *params = rtnl_dereference(t->params);
49
50	if (a->ops && a->ops->type == TCA_ACT_TUNNEL_KEY)
 
 
51		return params->tcft_action == TCA_TUNNEL_KEY_ACT_RELEASE;
52#endif
53	return false;
54}
55
56static inline struct ip_tunnel_info *tcf_tunnel_info(const struct tc_action *a)
57{
58#ifdef CONFIG_NET_CLS_ACT
59	struct tcf_tunnel_key *t = to_tunnel_key(a);
60	struct tcf_tunnel_key_params *params = rtnl_dereference(t->params);
 
 
 
61
62	return &params->tcft_enc_metadata->u.tun_info;
63#else
64	return NULL;
65#endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66}
67#endif /* __NET_TC_TUNNEL_KEY_H */
v6.8
 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
 7#ifndef __NET_TC_TUNNEL_KEY_H
 8#define __NET_TC_TUNNEL_KEY_H
 9
10#include <net/act_api.h>
11#include <linux/tc_act/tc_tunnel_key.h>
12#include <net/dst_metadata.h>
13
14struct tcf_tunnel_key_params {
15	struct rcu_head		rcu;
16	int			tcft_action;
 
17	struct metadata_dst     *tcft_enc_metadata;
18};
19
20struct tcf_tunnel_key {
21	struct tc_action	      common;
22	struct tcf_tunnel_key_params __rcu *params;
23};
24
25#define to_tunnel_key(a) ((struct tcf_tunnel_key *)a)
26
27static inline bool is_tcf_tunnel_set(const struct tc_action *a)
28{
29#ifdef CONFIG_NET_CLS_ACT
30	struct tcf_tunnel_key *t = to_tunnel_key(a);
31	struct tcf_tunnel_key_params *params;
32
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)
36		return params->tcft_action == TCA_TUNNEL_KEY_ACT_SET;
37#endif
38	return false;
39}
40
41static inline bool is_tcf_tunnel_release(const struct tc_action *a)
42{
43#ifdef CONFIG_NET_CLS_ACT
44	struct tcf_tunnel_key *t = to_tunnel_key(a);
45	struct tcf_tunnel_key_params *params;
46
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		return params->tcft_action == TCA_TUNNEL_KEY_ACT_RELEASE;
51#endif
52	return false;
53}
54
55static inline struct ip_tunnel_info *tcf_tunnel_info(const struct tc_action *a)
56{
57#ifdef CONFIG_NET_CLS_ACT
58	struct tcf_tunnel_key *t = to_tunnel_key(a);
59	struct tcf_tunnel_key_params *params;
60
61	params = rcu_dereference_protected(t->params,
62					   lockdep_is_held(&a->tcfa_lock));
63
64	return &params->tcft_enc_metadata->u.tun_info;
65#else
66	return NULL;
67#endif
68}
69
70static inline struct ip_tunnel_info *
71tcf_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}
86#endif /* __NET_TC_TUNNEL_KEY_H */