Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * Copyright (c) 2014 Jiri Pirko <jiri@resnulli.us>
0004  */
0005 
0006 #ifndef __NET_TC_VLAN_H
0007 #define __NET_TC_VLAN_H
0008 
0009 #include <net/act_api.h>
0010 #include <linux/tc_act/tc_vlan.h>
0011 
0012 struct tcf_vlan_params {
0013     int               tcfv_action;
0014     unsigned char     tcfv_push_dst[ETH_ALEN];
0015     unsigned char     tcfv_push_src[ETH_ALEN];
0016     u16               tcfv_push_vid;
0017     __be16            tcfv_push_proto;
0018     u8                tcfv_push_prio;
0019     bool              tcfv_push_prio_exists;
0020     struct rcu_head   rcu;
0021 };
0022 
0023 struct tcf_vlan {
0024     struct tc_action    common;
0025     struct tcf_vlan_params __rcu *vlan_p;
0026 };
0027 #define to_vlan(a) ((struct tcf_vlan *)a)
0028 
0029 static inline bool is_tcf_vlan(const struct tc_action *a)
0030 {
0031 #ifdef CONFIG_NET_CLS_ACT
0032     if (a->ops && a->ops->id == TCA_ID_VLAN)
0033         return true;
0034 #endif
0035     return false;
0036 }
0037 
0038 static inline u32 tcf_vlan_action(const struct tc_action *a)
0039 {
0040     u32 tcfv_action;
0041 
0042     rcu_read_lock();
0043     tcfv_action = rcu_dereference(to_vlan(a)->vlan_p)->tcfv_action;
0044     rcu_read_unlock();
0045 
0046     return tcfv_action;
0047 }
0048 
0049 static inline u16 tcf_vlan_push_vid(const struct tc_action *a)
0050 {
0051     u16 tcfv_push_vid;
0052 
0053     rcu_read_lock();
0054     tcfv_push_vid = rcu_dereference(to_vlan(a)->vlan_p)->tcfv_push_vid;
0055     rcu_read_unlock();
0056 
0057     return tcfv_push_vid;
0058 }
0059 
0060 static inline __be16 tcf_vlan_push_proto(const struct tc_action *a)
0061 {
0062     __be16 tcfv_push_proto;
0063 
0064     rcu_read_lock();
0065     tcfv_push_proto = rcu_dereference(to_vlan(a)->vlan_p)->tcfv_push_proto;
0066     rcu_read_unlock();
0067 
0068     return tcfv_push_proto;
0069 }
0070 
0071 static inline u8 tcf_vlan_push_prio(const struct tc_action *a)
0072 {
0073     u8 tcfv_push_prio;
0074 
0075     rcu_read_lock();
0076     tcfv_push_prio = rcu_dereference(to_vlan(a)->vlan_p)->tcfv_push_prio;
0077     rcu_read_unlock();
0078 
0079     return tcfv_push_prio;
0080 }
0081 
0082 static inline void tcf_vlan_push_eth(unsigned char *src, unsigned char *dest,
0083                      const struct tc_action *a)
0084 {
0085     rcu_read_lock();
0086     memcpy(dest, rcu_dereference(to_vlan(a)->vlan_p)->tcfv_push_dst, ETH_ALEN);
0087     memcpy(src, rcu_dereference(to_vlan(a)->vlan_p)->tcfv_push_src, ETH_ALEN);
0088     rcu_read_unlock();
0089 }
0090 
0091 #endif /* __NET_TC_VLAN_H */