xref: /linux/include/net/tc_act/tc_vlan.h (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
2c7e2b968SJiri Pirko /*
3c7e2b968SJiri Pirko  * Copyright (c) 2014 Jiri Pirko <jiri@resnulli.us>
4c7e2b968SJiri Pirko  */
5c7e2b968SJiri Pirko 
6c7e2b968SJiri Pirko #ifndef __NET_TC_VLAN_H
7c7e2b968SJiri Pirko #define __NET_TC_VLAN_H
8c7e2b968SJiri Pirko 
9c7e2b968SJiri Pirko #include <net/act_api.h>
1053e89941SOr Gerlitz #include <linux/tc_act/tc_vlan.h>
11c7e2b968SJiri Pirko 
124c5b9d96SManish Kurup struct tcf_vlan_params {
13c7e2b968SJiri Pirko 	int               tcfv_action;
1419fbcb36SGuillaume Nault 	unsigned char     tcfv_push_dst[ETH_ALEN];
1519fbcb36SGuillaume Nault 	unsigned char     tcfv_push_src[ETH_ALEN];
1608dcf9fdSJiri Pirko 	u16               tcfv_push_vid;
17c7e2b968SJiri Pirko 	__be16            tcfv_push_proto;
18956af371SHadar Hen Zion 	u8                tcfv_push_prio;
199c5eee0aSBoris Sukholitko 	bool              tcfv_push_prio_exists;
204c5b9d96SManish Kurup 	struct rcu_head   rcu;
214c5b9d96SManish Kurup };
224c5b9d96SManish Kurup 
234c5b9d96SManish Kurup struct tcf_vlan {
244c5b9d96SManish Kurup 	struct tc_action	common;
254c5b9d96SManish Kurup 	struct tcf_vlan_params __rcu *vlan_p;
26c7e2b968SJiri Pirko };
27a85a970aSWANG Cong #define to_vlan(a) ((struct tcf_vlan *)a)
28c7e2b968SJiri Pirko 
is_tcf_vlan(const struct tc_action * a)2953e89941SOr Gerlitz static inline bool is_tcf_vlan(const struct tc_action *a)
3053e89941SOr Gerlitz {
3153e89941SOr Gerlitz #ifdef CONFIG_NET_CLS_ACT
32eddd2cf1SEli Cohen 	if (a->ops && a->ops->id == TCA_ID_VLAN)
3353e89941SOr Gerlitz 		return true;
3453e89941SOr Gerlitz #endif
3553e89941SOr Gerlitz 	return false;
3653e89941SOr Gerlitz }
3753e89941SOr Gerlitz 
tcf_vlan_action(const struct tc_action * a)3853e89941SOr Gerlitz static inline u32 tcf_vlan_action(const struct tc_action *a)
3953e89941SOr Gerlitz {
404c5b9d96SManish Kurup 	u32 tcfv_action;
414c5b9d96SManish Kurup 
424c5b9d96SManish Kurup 	rcu_read_lock();
434c5b9d96SManish Kurup 	tcfv_action = rcu_dereference(to_vlan(a)->vlan_p)->tcfv_action;
444c5b9d96SManish Kurup 	rcu_read_unlock();
454c5b9d96SManish Kurup 
464c5b9d96SManish Kurup 	return tcfv_action;
4753e89941SOr Gerlitz }
4853e89941SOr Gerlitz 
tcf_vlan_push_vid(const struct tc_action * a)4953e89941SOr Gerlitz static inline u16 tcf_vlan_push_vid(const struct tc_action *a)
5053e89941SOr Gerlitz {
514c5b9d96SManish Kurup 	u16 tcfv_push_vid;
524c5b9d96SManish Kurup 
534c5b9d96SManish Kurup 	rcu_read_lock();
544c5b9d96SManish Kurup 	tcfv_push_vid = rcu_dereference(to_vlan(a)->vlan_p)->tcfv_push_vid;
554c5b9d96SManish Kurup 	rcu_read_unlock();
564c5b9d96SManish Kurup 
574c5b9d96SManish Kurup 	return tcfv_push_vid;
5853e89941SOr Gerlitz }
5953e89941SOr Gerlitz 
tcf_vlan_push_proto(const struct tc_action * a)6053e89941SOr Gerlitz static inline __be16 tcf_vlan_push_proto(const struct tc_action *a)
6153e89941SOr Gerlitz {
624c5b9d96SManish Kurup 	__be16 tcfv_push_proto;
634c5b9d96SManish Kurup 
644c5b9d96SManish Kurup 	rcu_read_lock();
654c5b9d96SManish Kurup 	tcfv_push_proto = rcu_dereference(to_vlan(a)->vlan_p)->tcfv_push_proto;
664c5b9d96SManish Kurup 	rcu_read_unlock();
674c5b9d96SManish Kurup 
684c5b9d96SManish Kurup 	return tcfv_push_proto;
6953e89941SOr Gerlitz }
7053e89941SOr Gerlitz 
tcf_vlan_push_prio(const struct tc_action * a)71a150201aSPetr Machata static inline u8 tcf_vlan_push_prio(const struct tc_action *a)
72a150201aSPetr Machata {
734c5b9d96SManish Kurup 	u8 tcfv_push_prio;
74a150201aSPetr Machata 
754c5b9d96SManish Kurup 	rcu_read_lock();
764c5b9d96SManish Kurup 	tcfv_push_prio = rcu_dereference(to_vlan(a)->vlan_p)->tcfv_push_prio;
774c5b9d96SManish Kurup 	rcu_read_unlock();
784c5b9d96SManish Kurup 
794c5b9d96SManish Kurup 	return tcfv_push_prio;
804c5b9d96SManish Kurup }
81ab95465cSMaor Dickman 
tcf_vlan_push_eth(unsigned char * src,unsigned char * dest,const struct tc_action * a)82ab95465cSMaor Dickman static inline void tcf_vlan_push_eth(unsigned char *src, unsigned char *dest,
83ab95465cSMaor Dickman 				     const struct tc_action *a)
84ab95465cSMaor Dickman {
85ab95465cSMaor Dickman 	rcu_read_lock();
86ab95465cSMaor Dickman 	memcpy(dest, rcu_dereference(to_vlan(a)->vlan_p)->tcfv_push_dst, ETH_ALEN);
87*054d5575SLouis Peens 	memcpy(src, rcu_dereference(to_vlan(a)->vlan_p)->tcfv_push_src, ETH_ALEN);
88ab95465cSMaor Dickman 	rcu_read_unlock();
89ab95465cSMaor Dickman }
90ab95465cSMaor Dickman 
91c7e2b968SJiri Pirko #endif /* __NET_TC_VLAN_H */
92