0001
0002
0003
0004 #ifndef __NET_TC_GATE_H
0005 #define __NET_TC_GATE_H
0006
0007 #include <net/act_api.h>
0008 #include <linux/tc_act/tc_gate.h>
0009
0010 struct action_gate_entry {
0011 u8 gate_state;
0012 u32 interval;
0013 s32 ipv;
0014 s32 maxoctets;
0015 };
0016
0017 struct tcfg_gate_entry {
0018 int index;
0019 u8 gate_state;
0020 u32 interval;
0021 s32 ipv;
0022 s32 maxoctets;
0023 struct list_head list;
0024 };
0025
0026 struct tcf_gate_params {
0027 s32 tcfg_priority;
0028 u64 tcfg_basetime;
0029 u64 tcfg_cycletime;
0030 u64 tcfg_cycletime_ext;
0031 u32 tcfg_flags;
0032 s32 tcfg_clockid;
0033 size_t num_entries;
0034 struct list_head entries;
0035 };
0036
0037 #define GATE_ACT_GATE_OPEN BIT(0)
0038 #define GATE_ACT_PENDING BIT(1)
0039
0040 struct tcf_gate {
0041 struct tc_action common;
0042 struct tcf_gate_params param;
0043 u8 current_gate_status;
0044 ktime_t current_close_time;
0045 u32 current_entry_octets;
0046 s32 current_max_octets;
0047 struct tcfg_gate_entry *next_entry;
0048 struct hrtimer hitimer;
0049 enum tk_offsets tk_offset;
0050 };
0051
0052 #define to_gate(a) ((struct tcf_gate *)a)
0053
0054 static inline bool is_tcf_gate(const struct tc_action *a)
0055 {
0056 #ifdef CONFIG_NET_CLS_ACT
0057 if (a->ops && a->ops->id == TCA_ID_GATE)
0058 return true;
0059 #endif
0060 return false;
0061 }
0062
0063 static inline s32 tcf_gate_prio(const struct tc_action *a)
0064 {
0065 s32 tcfg_prio;
0066
0067 tcfg_prio = to_gate(a)->param.tcfg_priority;
0068
0069 return tcfg_prio;
0070 }
0071
0072 static inline u64 tcf_gate_basetime(const struct tc_action *a)
0073 {
0074 u64 tcfg_basetime;
0075
0076 tcfg_basetime = to_gate(a)->param.tcfg_basetime;
0077
0078 return tcfg_basetime;
0079 }
0080
0081 static inline u64 tcf_gate_cycletime(const struct tc_action *a)
0082 {
0083 u64 tcfg_cycletime;
0084
0085 tcfg_cycletime = to_gate(a)->param.tcfg_cycletime;
0086
0087 return tcfg_cycletime;
0088 }
0089
0090 static inline u64 tcf_gate_cycletimeext(const struct tc_action *a)
0091 {
0092 u64 tcfg_cycletimeext;
0093
0094 tcfg_cycletimeext = to_gate(a)->param.tcfg_cycletime_ext;
0095
0096 return tcfg_cycletimeext;
0097 }
0098
0099 static inline u32 tcf_gate_num_entries(const struct tc_action *a)
0100 {
0101 u32 num_entries;
0102
0103 num_entries = to_gate(a)->param.num_entries;
0104
0105 return num_entries;
0106 }
0107
0108 static inline struct action_gate_entry
0109 *tcf_gate_get_list(const struct tc_action *a)
0110 {
0111 struct action_gate_entry *oe;
0112 struct tcf_gate_params *p;
0113 struct tcfg_gate_entry *entry;
0114 u32 num_entries;
0115 int i = 0;
0116
0117 p = &to_gate(a)->param;
0118 num_entries = p->num_entries;
0119
0120 list_for_each_entry(entry, &p->entries, list)
0121 i++;
0122
0123 if (i != num_entries)
0124 return NULL;
0125
0126 oe = kcalloc(num_entries, sizeof(*oe), GFP_ATOMIC);
0127 if (!oe)
0128 return NULL;
0129
0130 i = 0;
0131 list_for_each_entry(entry, &p->entries, list) {
0132 oe[i].gate_state = entry->gate_state;
0133 oe[i].interval = entry->interval;
0134 oe[i].ipv = entry->ipv;
0135 oe[i].maxoctets = entry->maxoctets;
0136 i++;
0137 }
0138
0139 return oe;
0140 }
0141 #endif