blob: d3068dd80e7fcbf20c4a68240fd0ecc7a206466a [file] [log] [blame]
Ben Menchaca84f36632014-02-28 20:57:38 +00001/*
2 **************************************************************************
Gareth Williamsd5618a82015-05-20 11:13:32 +01003 * Copyright (c) 2014-2015 The Linux Foundation. All rights reserved.
Ben Menchaca84f36632014-02-28 20:57:38 +00004 * Permission to use, copy, modify, and/or distribute this software for
5 * any purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all copies.
7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
13 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14 **************************************************************************
15 */
16
17struct ecm_classifier_instance;
18
19/*
20 * Classifier types.
21 * MUST BE RECORDED IN ASCENDING ORDER OF PRIORITY
22 */
23enum ecm_classifier_types {
24 ECM_CLASSIFIER_TYPE_DEFAULT = 0, /* MUST BE FIRST, Default classifier */
Hai Shalom81f4e202014-06-04 09:30:27 -070025#ifdef ECM_CLASSIFIER_HYFI_ENABLE
Ben Menchaca84f36632014-02-28 20:57:38 +000026 ECM_CLASSIFIER_TYPE_HYFI, /* HyFi classifier */
Hai Shalom81f4e202014-06-04 09:30:27 -070027#endif
Murat Sezginb3731e82014-11-26 12:20:59 -080028#ifdef ECM_CLASSIFIER_DSCP_ENABLE
Gareth Williams8932a912014-06-11 18:06:25 -070029 ECM_CLASSIFIER_TYPE_DSCP, /* Provides DSCP and DSCP remarking support */
Murat Sezginb3731e82014-11-26 12:20:59 -080030#endif
31#ifdef ECM_CLASSIFIER_NL_ENABLE
Ben Menchaca84f36632014-02-28 20:57:38 +000032 ECM_CLASSIFIER_TYPE_NL, /* Provides netlink interface */
Murat Sezginb3731e82014-11-26 12:20:59 -080033#endif
Gareth Williamsdcda9b92015-05-13 10:08:15 +010034#ifdef ECM_CLASSIFIER_PCC_ENABLE
35 ECM_CLASSIFIER_TYPE_PCC, /* Parental control subsystem support classifier */
36#endif
Ben Menchaca84f36632014-02-28 20:57:38 +000037 ECM_CLASSIFIER_TYPES, /* MUST BE LAST */
38};
39typedef enum ecm_classifier_types ecm_classifier_type_t;
40
41/*
42 * enum ecm_classifier_relevances
43 * Whether a classifier is relevant to a connection
44 */
45enum ecm_classifier_relevances {
46 ECM_CLASSIFIER_RELEVANCE_MAYBE = 0, /* Classifier has not yet determined relevance */
47 ECM_CLASSIFIER_RELEVANCE_NO, /* Classifier is not relevant to a connection (classifier will be unassigned from the connection after returning this from a process() call) */
48 ECM_CLASSIFIER_RELEVANCE_YES, /* Classifier is relevant to the connection, process actions will be inspected by the front end when returning this from a process() call */
49};
50typedef enum ecm_classifier_relevances ecm_classifier_relevence_t;
51
52/*
53 * enum ecm_classifier_acceleration_modes
54 * Modes in which a connection may be accelerated
Murat Sezgind701ac52014-08-20 14:02:30 -070055 *
56 * These are used by a classifier to indicate its desire to accelerate.
Ben Menchaca84f36632014-02-28 20:57:38 +000057 */
58enum ecm_classifier_acceleration_modes {
59 ECM_CLASSIFIER_ACCELERATION_MODE_DONT_CARE = 0, /* Classifier does not care if the connection is accelerated */
60 ECM_CLASSIFIER_ACCELERATION_MODE_NO, /* Connection must not be accelerated */
61 ECM_CLASSIFIER_ACCELERATION_MODE_ACCEL, /* Connection can be accelerated whenever */
62};
63typedef enum ecm_classifier_acceleration_modes ecm_classifier_acceleration_mode_t;
64
65/*
66 * Process actions
67 * A process result, that is relevant, may contain zero or more actions for the front end.
68 * Due to the parallel processing nature of classifiers, *usually* the action(s) of the highest priority
69 * classifier will override any lower priority actions. This is up to front end discretion, of course.
70 */
Gareth Williams27c3db12014-06-11 17:37:56 -070071#define ECM_CLASSIFIER_PROCESS_ACTION_DROP 0x00000001 /* Drop */
72#define ECM_CLASSIFIER_PROCESS_ACTION_QOS_TAG 0x00000002 /* Contains flow & return qos tags */
Ben Menchaca84f36632014-02-28 20:57:38 +000073#define ECM_CLASSIFIER_PROCESS_ACTION_ACCEL_MODE 0x00000004 /* Contains an accel mode */
74#define ECM_CLASSIFIER_PROCESS_ACTION_TIMER_GROUP 0x00000008 /* Contains a timer group change */
Murat Sezgin62c92832015-03-06 16:08:31 -080075
76#ifdef ECM_CLASSIFIER_DSCP_ENABLE
Gareth Williamsbd03e232014-06-11 17:55:28 -070077#define ECM_CLASSIFIER_PROCESS_ACTION_DSCP 0x00000010 /* Contains DSCP marking information */
78#define ECM_CLASSIFIER_PROCESS_ACTION_DSCP_DENY 0x00000020 /* Denies any DSCP changes */
Murat Sezgin62c92832015-03-06 16:08:31 -080079#endif
Ben Menchaca84f36632014-02-28 20:57:38 +000080
81/*
82 * struct ecm_classifier_process_response
83 * Response structure returned by a process call
84 */
85struct ecm_classifier_process_response {
86 ecm_classifier_relevence_t relevance; /* Is this classifier relevant to the connection? */
87 uint32_t became_relevant; /* DB time the classifier became relevant or not relevant, if relevance is maybe this field is not relevant! */
88
89 uint32_t process_actions; /* Actions this process response contains */
90
91 /*
92 * The following fields are only to be inspected if this response is relevant AND the process_actions indicates so
93 */
94 bool drop; /* Drop packet at hand */
Gareth Williams27c3db12014-06-11 17:37:56 -070095 uint32_t flow_qos_tag; /* QoS tag to use for the packet */
96 uint32_t return_qos_tag; /* QoS tag to use for the packet */
Murat Sezgin62c92832015-03-06 16:08:31 -080097#ifdef ECM_CLASSIFIER_DSCP_ENABLE
Gareth Williamsbd03e232014-06-11 17:55:28 -070098 uint8_t flow_dscp; /* DSCP mark for flow */
99 uint8_t return_dscp; /* DSCP mark for return */
Murat Sezgin62c92832015-03-06 16:08:31 -0800100#endif
Ben Menchaca84f36632014-02-28 20:57:38 +0000101 ecm_classifier_acceleration_mode_t accel_mode; /* Acceleration needed for this connection */
102 ecm_db_timer_group_t timer_group; /* Timer group the connection should be in */
103};
104
105/*
Murat Sezginb2676062015-06-12 17:05:31 -0700106 * Sync rule structure.
107 * Acceleration engine's sync parameters will be stored
108 * in this data structure to update the classifiers.
109 */
110struct ecm_classifier_rule_sync {
111 uint32_t flow_tx_packet_count;
112 uint32_t return_tx_packet_count;
113 uint32_t reason;
114};
115
116/*
117 * Create rule structure.
118 * Additional create rule parameters from the classifiers
119 * will be copied to this data structure before pushing them to
120 * the underlying accelaration engine.
121 */
122struct ecm_classifier_rule_create {
123
124};
125
126/*
Ben Menchaca84f36632014-02-28 20:57:38 +0000127 * To be implemented by all classifiers
128 */
129typedef void (*ecm_classifier_ref_method_t)(struct ecm_classifier_instance *ci);
130typedef int (*ecm_classifier_deref_callback_t)(struct ecm_classifier_instance *ci);
131typedef void (*ecm_classifier_process_callback_t)(struct ecm_classifier_instance *ci, ecm_tracker_sender_type_t sender, struct ecm_tracker_ip_header *ip_hdr, struct sk_buff *skb, struct ecm_classifier_process_response *process_response);
132 /* Process new data for connection, process_response is populated with the response of processing */
Murat Sezginb2676062015-06-12 17:05:31 -0700133typedef void (*ecm_classifier_sync_from_v4_callback_t)(struct ecm_classifier_instance *ci, struct ecm_classifier_rule_create *ecrc);
134 /* Sync the accel engine state with state from the classifier */
135typedef void (*ecm_classifier_sync_to_v4_callback_t)(struct ecm_classifier_instance *ci, struct ecm_classifier_rule_sync *sync);
136 /* Sync the classifier state with current accel engine state */
137typedef void (*ecm_classifier_sync_from_v6_callback_t)(struct ecm_classifier_instance *ci, struct ecm_classifier_rule_create *ecrc);
138 /* Sync the accel engine state with state from the classifier */
139typedef void (*ecm_classifier_sync_to_v6_callback_t)(struct ecm_classifier_instance *ci, struct ecm_classifier_rule_sync *sync);
140 /* Sync the classifier state with current accel engine state */
Ben Menchaca84f36632014-02-28 20:57:38 +0000141typedef ecm_classifier_type_t (*ecm_classifier_type_get_callback_t)(struct ecm_classifier_instance *ci);
142 /* Get type of classifier this is */
143typedef bool (*ecm_classifier_reclassify_allowed_get_callback_t)(struct ecm_classifier_instance *ci);
144 /* Get whether reclassification is allowed */
145typedef void (*ecm_classifier_reclassify_callback_t)(struct ecm_classifier_instance *ci);
146 /* Reclassify */
147typedef void (*ecm_classifier_last_process_response_get_callback_t)(struct ecm_classifier_instance *ci, struct ecm_classifier_process_response *process_response);
148 /* Get last process response */
Gareth Williamsf98d4192015-03-11 16:55:41 +0000149#ifdef ECM_STATE_OUTPUT_ENABLE
Gareth Williamsd5618a82015-05-20 11:13:32 +0100150typedef int (*ecm_classifier_state_get_callback_t)(struct ecm_classifier_instance *ci, struct ecm_state_file_instance *sfi);
151 /* Get state output. Returns 0 upon success. */
Gareth Williamsf98d4192015-03-11 16:55:41 +0000152#endif
Ben Menchaca84f36632014-02-28 20:57:38 +0000153
154/*
155 * Base class for all types of classifiers
156 */
157struct ecm_classifier_instance {
158 struct ecm_classifier_instance *ca_next; /* DB use only: Connection assignment next pointer */
159 struct ecm_classifier_instance *ca_prev; /* DB use only: Connection assignment prev pointer */
160
161 ecm_classifier_process_callback_t process; /* Process new skb */
162 ecm_classifier_sync_from_v4_callback_t sync_from_v4;
Murat Sezginb2676062015-06-12 17:05:31 -0700163 /* Sync the accel engine with state from the classifier */
164 ecm_classifier_sync_to_v4_callback_t sync_to_v4;/* Sync the classifier with state from the accel engine */
Ben Menchaca84f36632014-02-28 20:57:38 +0000165 ecm_classifier_sync_from_v6_callback_t sync_from_v6;
Murat Sezginb2676062015-06-12 17:05:31 -0700166 /* Sync the accel engine with state from the classifier */
167 ecm_classifier_sync_to_v6_callback_t sync_to_v6;/* Sync the classifier with state from the accel engine */
Ben Menchaca84f36632014-02-28 20:57:38 +0000168 ecm_classifier_type_get_callback_t type_get; /* Get type of classifier */
169 ecm_classifier_reclassify_allowed_get_callback_t reclassify_allowed;
170 /* Get whether reclassification is allowed */
171 ecm_classifier_reclassify_callback_t reclassify;
172 /* Reclassify */
173 ecm_classifier_last_process_response_get_callback_t last_process_response_get;
174 /* Return last process response */
Gareth Williamsf98d4192015-03-11 16:55:41 +0000175#ifdef ECM_STATE_OUTPUT_ENABLE
Gareth Williamsd5618a82015-05-20 11:13:32 +0100176 ecm_classifier_state_get_callback_t state_get;
177 /* Return its state */
Gareth Williamsf98d4192015-03-11 16:55:41 +0000178#endif
Ben Menchaca84f36632014-02-28 20:57:38 +0000179 ecm_classifier_ref_method_t ref;
180 ecm_classifier_deref_callback_t deref;
181};
182
Gareth Williamsf98d4192015-03-11 16:55:41 +0000183#ifdef ECM_STATE_OUTPUT_ENABLE
Ben Menchaca84f36632014-02-28 20:57:38 +0000184/*
Gareth Williamsd5618a82015-05-20 11:13:32 +0100185 * ecm_classifier_process_response_state_get()
186 * Output detail for the process response
Ben Menchaca84f36632014-02-28 20:57:38 +0000187 *
Gareth Williamsd5618a82015-05-20 11:13:32 +0100188 * Returns 0 on success.
Ben Menchaca84f36632014-02-28 20:57:38 +0000189 */
Gareth Williamsd5618a82015-05-20 11:13:32 +0100190static inline int ecm_classifier_process_response_state_get(struct ecm_state_file_instance *sfi, struct ecm_classifier_process_response *pr)
Ben Menchaca84f36632014-02-28 20:57:38 +0000191{
Gareth Williamsd5618a82015-05-20 11:13:32 +0100192 int result;
193
194 if ((result = ecm_state_prefix_add(sfi, "pr"))) {
195 return result;
196 }
Ben Menchaca84f36632014-02-28 20:57:38 +0000197
198 if (pr->relevance == ECM_CLASSIFIER_RELEVANCE_NO) {
Gareth Williamsd5618a82015-05-20 11:13:32 +0100199 return ecm_state_write(sfi, "relevant", "%s", "no");
Ben Menchaca84f36632014-02-28 20:57:38 +0000200 }
201
202 if (pr->process_actions & ECM_CLASSIFIER_PROCESS_ACTION_DROP) {
203 if (pr->drop) {
Gareth Williamsd5618a82015-05-20 11:13:32 +0100204 if ((result = ecm_state_write(sfi, "drop", "yes"))) {
205 return result;
206 }
Ben Menchaca84f36632014-02-28 20:57:38 +0000207 } else {
Gareth Williamsd5618a82015-05-20 11:13:32 +0100208 if ((result = ecm_state_write(sfi, "drop", "no"))) {
209 return result;
210 }
Ben Menchaca84f36632014-02-28 20:57:38 +0000211 }
212 }
213
Ben Menchaca84f36632014-02-28 20:57:38 +0000214 if (pr->relevance == ECM_CLASSIFIER_RELEVANCE_MAYBE) {
Gareth Williamsd5618a82015-05-20 11:13:32 +0100215 if ((result = ecm_state_write(sfi, "accel", "denied"))) {
216 return result;
217 }
218 if ((result = ecm_state_write(sfi, "relevant", "maybe"))) {
219 return result;
220 }
Ben Menchaca84f36632014-02-28 20:57:38 +0000221 } else {
Gareth Williamsd5618a82015-05-20 11:13:32 +0100222 if ((result = ecm_state_write(sfi, "relevant", "yes"))) {
223 return result;
224 }
225 if (pr->process_actions & ECM_CLASSIFIER_PROCESS_ACTION_ACCEL_MODE) {
226 if (pr->accel_mode == ECM_CLASSIFIER_ACCELERATION_MODE_ACCEL) {
227 if ((result = ecm_state_write(sfi, "accel", "wanted"))) {
228 return result;
229 }
230 }
231 else if (pr->accel_mode == ECM_CLASSIFIER_ACCELERATION_MODE_NO) {
232 if ((result = ecm_state_write(sfi, "accel", "denied"))) {
233 return result;
234 }
235 }
236 /* Else don't care */
237 }
Ben Menchaca84f36632014-02-28 20:57:38 +0000238 }
239
Gareth Williamsd5618a82015-05-20 11:13:32 +0100240 if (pr->process_actions & ECM_CLASSIFIER_PROCESS_ACTION_QOS_TAG) {
241 if ((result = ecm_state_write(sfi, "flow_qos_tag", "%u", pr->flow_qos_tag))) {
242 return result;
243 }
244 if ((result = ecm_state_write(sfi, "return_qos_tag", "%u", pr->return_qos_tag))) {
245 return result;
246 }
247 }
248#ifdef ECM_CLASSIFIER_DSCP_ENABLE
249 if (pr->process_actions & ECM_CLASSIFIER_PROCESS_ACTION_DSCP) {
250 if ((result = ecm_state_write(sfi, "flow_dscp", "%u", pr->flow_dscp))) {
251 return result;
252 }
253 if ((result = ecm_state_write(sfi, "return_dscp", "%u", pr->return_dscp))) {
254 return result;
255 }
256 }
257#endif
258 if (pr->process_actions & ECM_CLASSIFIER_PROCESS_ACTION_TIMER_GROUP) {
259 if ((result = ecm_state_write(sfi, "timer_group", "%d", pr->timer_group))) {
260 return result;
261 }
262 }
263
264 return ecm_state_prefix_remove(sfi);
Ben Menchaca84f36632014-02-28 20:57:38 +0000265}
Gareth Williamsf98d4192015-03-11 16:55:41 +0000266#endif
267
Ben Menchaca84f36632014-02-28 20:57:38 +0000268
269