19952f691SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 2ca9b0e27SAlexander Duyck /* 3ca9b0e27SAlexander Duyck * Copyright (c) 2008, Intel Corporation. 4ca9b0e27SAlexander Duyck * 5ca9b0e27SAlexander Duyck * Author: Alexander Duyck <alexander.h.duyck@intel.com> 6ca9b0e27SAlexander Duyck */ 7ca9b0e27SAlexander Duyck 8ca9b0e27SAlexander Duyck #ifndef __NET_TC_SKBEDIT_H 9ca9b0e27SAlexander Duyck #define __NET_TC_SKBEDIT_H 10ca9b0e27SAlexander Duyck 11ca9b0e27SAlexander Duyck #include <net/act_api.h> 12519afb18SAmir Vadai #include <linux/tc_act/tc_skbedit.h> 13ca9b0e27SAlexander Duyck 14c749cddaSDavide Caratti struct tcf_skbedit_params { 15ca9b0e27SAlexander Duyck u32 flags; 16ca9b0e27SAlexander Duyck u32 priority; 171c55d62eSjamal u32 mark; 184fe77d82SAntonio Quartulli u32 mask; 19ca9b0e27SAlexander Duyck u16 queue_mapping; 2038a6f086STonghao Zhang u16 mapping_mod; 21ff202ee1SJamal Hadi Salim u16 ptype; 22c749cddaSDavide Caratti struct rcu_head rcu; 23c749cddaSDavide Caratti }; 24c749cddaSDavide Caratti 25c749cddaSDavide Caratti struct tcf_skbedit { 26c749cddaSDavide Caratti struct tc_action common; 27c749cddaSDavide Caratti struct tcf_skbedit_params __rcu *params; 28ca9b0e27SAlexander Duyck }; 29a85a970aSWANG Cong #define to_skbedit(a) ((struct tcf_skbedit *)a) 30ca9b0e27SAlexander Duyck 31fe93f0b2SPetr Machata /* Return true iff action is the one identified by FLAG. */ is_tcf_skbedit_with_flag(const struct tc_action * a,u32 flag)32fe93f0b2SPetr Machatastatic inline bool is_tcf_skbedit_with_flag(const struct tc_action *a, u32 flag) 33519afb18SAmir Vadai { 34519afb18SAmir Vadai #ifdef CONFIG_NET_CLS_ACT 35c749cddaSDavide Caratti u32 flags; 36c749cddaSDavide Caratti 37eddd2cf1SEli Cohen if (a->ops && a->ops->id == TCA_ID_SKBEDIT) { 38c749cddaSDavide Caratti rcu_read_lock(); 39c749cddaSDavide Caratti flags = rcu_dereference(to_skbedit(a)->params)->flags; 40c749cddaSDavide Caratti rcu_read_unlock(); 41fe93f0b2SPetr Machata return flags == flag; 42c749cddaSDavide Caratti } 43519afb18SAmir Vadai #endif 44519afb18SAmir Vadai return false; 45519afb18SAmir Vadai } 46519afb18SAmir Vadai 47fe93f0b2SPetr Machata /* Return true iff action is mark */ is_tcf_skbedit_mark(const struct tc_action * a)48fe93f0b2SPetr Machatastatic inline bool is_tcf_skbedit_mark(const struct tc_action *a) 49fe93f0b2SPetr Machata { 50fe93f0b2SPetr Machata return is_tcf_skbedit_with_flag(a, SKBEDIT_F_MARK); 51fe93f0b2SPetr Machata } 52fe93f0b2SPetr Machata tcf_skbedit_mark(const struct tc_action * a)53519afb18SAmir Vadaistatic inline u32 tcf_skbedit_mark(const struct tc_action *a) 54519afb18SAmir Vadai { 55c749cddaSDavide Caratti u32 mark; 56c749cddaSDavide Caratti 57c749cddaSDavide Caratti rcu_read_lock(); 58c749cddaSDavide Caratti mark = rcu_dereference(to_skbedit(a)->params)->mark; 59c749cddaSDavide Caratti rcu_read_unlock(); 60c749cddaSDavide Caratti 61c749cddaSDavide Caratti return mark; 62519afb18SAmir Vadai } 63519afb18SAmir Vadai 6477feb4eeSJohn Hurley /* Return true iff action is ptype */ is_tcf_skbedit_ptype(const struct tc_action * a)6577feb4eeSJohn Hurleystatic inline bool is_tcf_skbedit_ptype(const struct tc_action *a) 6677feb4eeSJohn Hurley { 67fe93f0b2SPetr Machata return is_tcf_skbedit_with_flag(a, SKBEDIT_F_PTYPE); 6877feb4eeSJohn Hurley } 6977feb4eeSJohn Hurley tcf_skbedit_ptype(const struct tc_action * a)7077feb4eeSJohn Hurleystatic inline u32 tcf_skbedit_ptype(const struct tc_action *a) 7177feb4eeSJohn Hurley { 7277feb4eeSJohn Hurley u16 ptype; 7377feb4eeSJohn Hurley 7477feb4eeSJohn Hurley rcu_read_lock(); 7577feb4eeSJohn Hurley ptype = rcu_dereference(to_skbedit(a)->params)->ptype; 7677feb4eeSJohn Hurley rcu_read_unlock(); 7777feb4eeSJohn Hurley 7877feb4eeSJohn Hurley return ptype; 7977feb4eeSJohn Hurley } 8077feb4eeSJohn Hurley 812ce12410SPetr Machata /* Return true iff action is priority */ is_tcf_skbedit_priority(const struct tc_action * a)822ce12410SPetr Machatastatic inline bool is_tcf_skbedit_priority(const struct tc_action *a) 832ce12410SPetr Machata { 842ce12410SPetr Machata return is_tcf_skbedit_with_flag(a, SKBEDIT_F_PRIORITY); 852ce12410SPetr Machata } 862ce12410SPetr Machata tcf_skbedit_priority(const struct tc_action * a)872ce12410SPetr Machatastatic inline u32 tcf_skbedit_priority(const struct tc_action *a) 882ce12410SPetr Machata { 892ce12410SPetr Machata u32 priority; 902ce12410SPetr Machata 912ce12410SPetr Machata rcu_read_lock(); 922ce12410SPetr Machata priority = rcu_dereference(to_skbedit(a)->params)->priority; 932ce12410SPetr Machata rcu_read_unlock(); 942ce12410SPetr Machata 952ce12410SPetr Machata return priority; 962ce12410SPetr Machata } 972ce12410SPetr Machata tcf_skbedit_rx_queue_mapping(const struct tc_action * a)98*4a6a676fSAmritha Nambiarstatic inline u16 tcf_skbedit_rx_queue_mapping(const struct tc_action *a) 99*4a6a676fSAmritha Nambiar { 100*4a6a676fSAmritha Nambiar u16 rx_queue; 101*4a6a676fSAmritha Nambiar 102*4a6a676fSAmritha Nambiar rcu_read_lock(); 103*4a6a676fSAmritha Nambiar rx_queue = rcu_dereference(to_skbedit(a)->params)->queue_mapping; 104*4a6a676fSAmritha Nambiar rcu_read_unlock(); 105*4a6a676fSAmritha Nambiar 106*4a6a676fSAmritha Nambiar return rx_queue; 107*4a6a676fSAmritha Nambiar } 108*4a6a676fSAmritha Nambiar 109a9c64939SIdo Schimmel /* Return true iff action is queue_mapping */ is_tcf_skbedit_queue_mapping(const struct tc_action * a)110a9c64939SIdo Schimmelstatic inline bool is_tcf_skbedit_queue_mapping(const struct tc_action *a) 111a9c64939SIdo Schimmel { 112a9c64939SIdo Schimmel return is_tcf_skbedit_with_flag(a, SKBEDIT_F_QUEUE_MAPPING); 113a9c64939SIdo Schimmel } 114a9c64939SIdo Schimmel 115*4a6a676fSAmritha Nambiar /* Return true if action is on ingress traffic */ is_tcf_skbedit_ingress(u32 flags)116*4a6a676fSAmritha Nambiarstatic inline bool is_tcf_skbedit_ingress(u32 flags) 117*4a6a676fSAmritha Nambiar { 118*4a6a676fSAmritha Nambiar return flags & TCA_ACT_FLAGS_AT_INGRESS; 119*4a6a676fSAmritha Nambiar } 120*4a6a676fSAmritha Nambiar is_tcf_skbedit_tx_queue_mapping(const struct tc_action * a)121*4a6a676fSAmritha Nambiarstatic inline bool is_tcf_skbedit_tx_queue_mapping(const struct tc_action *a) 122*4a6a676fSAmritha Nambiar { 123*4a6a676fSAmritha Nambiar return is_tcf_skbedit_queue_mapping(a) && 124*4a6a676fSAmritha Nambiar !is_tcf_skbedit_ingress(a->tcfa_flags); 125*4a6a676fSAmritha Nambiar } 126*4a6a676fSAmritha Nambiar is_tcf_skbedit_rx_queue_mapping(const struct tc_action * a)127*4a6a676fSAmritha Nambiarstatic inline bool is_tcf_skbedit_rx_queue_mapping(const struct tc_action *a) 128*4a6a676fSAmritha Nambiar { 129*4a6a676fSAmritha Nambiar return is_tcf_skbedit_queue_mapping(a) && 130*4a6a676fSAmritha Nambiar is_tcf_skbedit_ingress(a->tcfa_flags); 131*4a6a676fSAmritha Nambiar } 132*4a6a676fSAmritha Nambiar 133a9c64939SIdo Schimmel /* Return true iff action is inheritdsfield */ is_tcf_skbedit_inheritdsfield(const struct tc_action * a)134a9c64939SIdo Schimmelstatic inline bool is_tcf_skbedit_inheritdsfield(const struct tc_action *a) 135a9c64939SIdo Schimmel { 136a9c64939SIdo Schimmel return is_tcf_skbedit_with_flag(a, SKBEDIT_F_INHERITDSFIELD); 137a9c64939SIdo Schimmel } 138a9c64939SIdo Schimmel 139ca9b0e27SAlexander Duyck #endif /* __NET_TC_SKBEDIT_H */ 140