blob: fdda166b35ceeee80b4f413fb4c7c32bad5aedb9 [file] [log] [blame]
Ben Menchaca84f36632014-02-28 20:57:38 +00001/*
2 **************************************************************************
Murat Sezginf4f7ab42018-10-12 17:01:46 -07003 * Copyright (c) 2014-2015, 2018, 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 */
Murat Sezginf4f7ab42018-10-12 17:01:46 -070025#ifdef ECM_CLASSIFIER_MARK_ENABLE
26 ECM_CLASSIFIER_TYPE_MARK, /* Mark classifier */
27#endif
Hai Shalom81f4e202014-06-04 09:30:27 -070028#ifdef ECM_CLASSIFIER_HYFI_ENABLE
Ben Menchaca84f36632014-02-28 20:57:38 +000029 ECM_CLASSIFIER_TYPE_HYFI, /* HyFi classifier */
Hai Shalom81f4e202014-06-04 09:30:27 -070030#endif
Murat Sezginb3731e82014-11-26 12:20:59 -080031#ifdef ECM_CLASSIFIER_DSCP_ENABLE
Gareth Williams8932a912014-06-11 18:06:25 -070032 ECM_CLASSIFIER_TYPE_DSCP, /* Provides DSCP and DSCP remarking support */
Murat Sezginb3731e82014-11-26 12:20:59 -080033#endif
34#ifdef ECM_CLASSIFIER_NL_ENABLE
Ben Menchaca84f36632014-02-28 20:57:38 +000035 ECM_CLASSIFIER_TYPE_NL, /* Provides netlink interface */
Murat Sezginb3731e82014-11-26 12:20:59 -080036#endif
Gareth Williamsdcda9b92015-05-13 10:08:15 +010037#ifdef ECM_CLASSIFIER_PCC_ENABLE
38 ECM_CLASSIFIER_TYPE_PCC, /* Parental control subsystem support classifier */
39#endif
Ben Menchaca84f36632014-02-28 20:57:38 +000040 ECM_CLASSIFIER_TYPES, /* MUST BE LAST */
41};
42typedef enum ecm_classifier_types ecm_classifier_type_t;
43
44/*
45 * enum ecm_classifier_relevances
46 * Whether a classifier is relevant to a connection
47 */
48enum ecm_classifier_relevances {
49 ECM_CLASSIFIER_RELEVANCE_MAYBE = 0, /* Classifier has not yet determined relevance */
50 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) */
51 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 */
52};
53typedef enum ecm_classifier_relevances ecm_classifier_relevence_t;
54
55/*
56 * enum ecm_classifier_acceleration_modes
57 * Modes in which a connection may be accelerated
Murat Sezgind701ac52014-08-20 14:02:30 -070058 *
59 * These are used by a classifier to indicate its desire to accelerate.
Ben Menchaca84f36632014-02-28 20:57:38 +000060 */
61enum ecm_classifier_acceleration_modes {
62 ECM_CLASSIFIER_ACCELERATION_MODE_DONT_CARE = 0, /* Classifier does not care if the connection is accelerated */
63 ECM_CLASSIFIER_ACCELERATION_MODE_NO, /* Connection must not be accelerated */
64 ECM_CLASSIFIER_ACCELERATION_MODE_ACCEL, /* Connection can be accelerated whenever */
65};
66typedef enum ecm_classifier_acceleration_modes ecm_classifier_acceleration_mode_t;
67
68/*
69 * Process actions
70 * A process result, that is relevant, may contain zero or more actions for the front end.
71 * Due to the parallel processing nature of classifiers, *usually* the action(s) of the highest priority
72 * classifier will override any lower priority actions. This is up to front end discretion, of course.
73 */
Gareth Williams27c3db12014-06-11 17:37:56 -070074#define ECM_CLASSIFIER_PROCESS_ACTION_DROP 0x00000001 /* Drop */
75#define ECM_CLASSIFIER_PROCESS_ACTION_QOS_TAG 0x00000002 /* Contains flow & return qos tags */
Ben Menchaca84f36632014-02-28 20:57:38 +000076#define ECM_CLASSIFIER_PROCESS_ACTION_ACCEL_MODE 0x00000004 /* Contains an accel mode */
77#define ECM_CLASSIFIER_PROCESS_ACTION_TIMER_GROUP 0x00000008 /* Contains a timer group change */
Murat Sezgin62c92832015-03-06 16:08:31 -080078
79#ifdef ECM_CLASSIFIER_DSCP_ENABLE
Gareth Williamsbd03e232014-06-11 17:55:28 -070080#define ECM_CLASSIFIER_PROCESS_ACTION_DSCP 0x00000010 /* Contains DSCP marking information */
81#define ECM_CLASSIFIER_PROCESS_ACTION_DSCP_DENY 0x00000020 /* Denies any DSCP changes */
Murat Sezgin62c92832015-03-06 16:08:31 -080082#endif
Ben Menchaca84f36632014-02-28 20:57:38 +000083
84/*
85 * struct ecm_classifier_process_response
86 * Response structure returned by a process call
87 */
88struct ecm_classifier_process_response {
89 ecm_classifier_relevence_t relevance; /* Is this classifier relevant to the connection? */
90 uint32_t became_relevant; /* DB time the classifier became relevant or not relevant, if relevance is maybe this field is not relevant! */
91
92 uint32_t process_actions; /* Actions this process response contains */
93
94 /*
95 * The following fields are only to be inspected if this response is relevant AND the process_actions indicates so
96 */
97 bool drop; /* Drop packet at hand */
Gareth Williams27c3db12014-06-11 17:37:56 -070098 uint32_t flow_qos_tag; /* QoS tag to use for the packet */
99 uint32_t return_qos_tag; /* QoS tag to use for the packet */
Murat Sezgin62c92832015-03-06 16:08:31 -0800100#ifdef ECM_CLASSIFIER_DSCP_ENABLE
Gareth Williamsbd03e232014-06-11 17:55:28 -0700101 uint8_t flow_dscp; /* DSCP mark for flow */
102 uint8_t return_dscp; /* DSCP mark for return */
Murat Sezgin62c92832015-03-06 16:08:31 -0800103#endif
Ben Menchaca84f36632014-02-28 20:57:38 +0000104 ecm_classifier_acceleration_mode_t accel_mode; /* Acceleration needed for this connection */
105 ecm_db_timer_group_t timer_group; /* Timer group the connection should be in */
106};
107
108/*
Murat Sezginb2676062015-06-12 17:05:31 -0700109 * Sync rule structure.
110 * Acceleration engine's sync parameters will be stored
111 * in this data structure to update the classifiers.
112 */
113struct ecm_classifier_rule_sync {
114 uint32_t flow_tx_packet_count;
115 uint32_t return_tx_packet_count;
116 uint32_t reason;
117};
118
119/*
120 * Create rule structure.
121 * Additional create rule parameters from the classifiers
122 * will be copied to this data structure before pushing them to
123 * the underlying accelaration engine.
124 */
125struct ecm_classifier_rule_create {
126
127};
128
129/*
Ben Menchaca84f36632014-02-28 20:57:38 +0000130 * To be implemented by all classifiers
131 */
132typedef void (*ecm_classifier_ref_method_t)(struct ecm_classifier_instance *ci);
133typedef int (*ecm_classifier_deref_callback_t)(struct ecm_classifier_instance *ci);
134typedef 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);
135 /* Process new data for connection, process_response is populated with the response of processing */
Murat Sezginb2676062015-06-12 17:05:31 -0700136typedef void (*ecm_classifier_sync_from_v4_callback_t)(struct ecm_classifier_instance *ci, struct ecm_classifier_rule_create *ecrc);
137 /* Sync the accel engine state with state from the classifier */
138typedef void (*ecm_classifier_sync_to_v4_callback_t)(struct ecm_classifier_instance *ci, struct ecm_classifier_rule_sync *sync);
139 /* Sync the classifier state with current accel engine state */
140typedef void (*ecm_classifier_sync_from_v6_callback_t)(struct ecm_classifier_instance *ci, struct ecm_classifier_rule_create *ecrc);
141 /* Sync the accel engine state with state from the classifier */
142typedef void (*ecm_classifier_sync_to_v6_callback_t)(struct ecm_classifier_instance *ci, struct ecm_classifier_rule_sync *sync);
143 /* Sync the classifier state with current accel engine state */
Ben Menchaca84f36632014-02-28 20:57:38 +0000144typedef ecm_classifier_type_t (*ecm_classifier_type_get_callback_t)(struct ecm_classifier_instance *ci);
145 /* Get type of classifier this is */
146typedef bool (*ecm_classifier_reclassify_allowed_get_callback_t)(struct ecm_classifier_instance *ci);
147 /* Get whether reclassification is allowed */
148typedef void (*ecm_classifier_reclassify_callback_t)(struct ecm_classifier_instance *ci);
149 /* Reclassify */
150typedef void (*ecm_classifier_last_process_response_get_callback_t)(struct ecm_classifier_instance *ci, struct ecm_classifier_process_response *process_response);
151 /* Get last process response */
Gareth Williamsf98d4192015-03-11 16:55:41 +0000152#ifdef ECM_STATE_OUTPUT_ENABLE
Gareth Williamsd5618a82015-05-20 11:13:32 +0100153typedef int (*ecm_classifier_state_get_callback_t)(struct ecm_classifier_instance *ci, struct ecm_state_file_instance *sfi);
154 /* Get state output. Returns 0 upon success. */
Gareth Williamsf98d4192015-03-11 16:55:41 +0000155#endif
Ben Menchaca84f36632014-02-28 20:57:38 +0000156
157/*
Murat Sezgine34b0172015-11-05 21:58:14 -0800158 * Determines if a connection should be kept.
159 */
160typedef bool (*ecm_classifier_should_keep_connection_t)
161 (struct ecm_classifier_instance *ci, uint8_t *mac);
162
163/*
Ben Menchaca84f36632014-02-28 20:57:38 +0000164 * Base class for all types of classifiers
165 */
166struct ecm_classifier_instance {
167 struct ecm_classifier_instance *ca_next; /* DB use only: Connection assignment next pointer */
168 struct ecm_classifier_instance *ca_prev; /* DB use only: Connection assignment prev pointer */
169
170 ecm_classifier_process_callback_t process; /* Process new skb */
171 ecm_classifier_sync_from_v4_callback_t sync_from_v4;
Murat Sezginb2676062015-06-12 17:05:31 -0700172 /* Sync the accel engine with state from the classifier */
173 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 +0000174 ecm_classifier_sync_from_v6_callback_t sync_from_v6;
Murat Sezginb2676062015-06-12 17:05:31 -0700175 /* Sync the accel engine with state from the classifier */
176 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 +0000177 ecm_classifier_type_get_callback_t type_get; /* Get type of classifier */
178 ecm_classifier_reclassify_allowed_get_callback_t reclassify_allowed;
179 /* Get whether reclassification is allowed */
180 ecm_classifier_reclassify_callback_t reclassify;
181 /* Reclassify */
182 ecm_classifier_last_process_response_get_callback_t last_process_response_get;
183 /* Return last process response */
Murat Sezgine34b0172015-11-05 21:58:14 -0800184 ecm_classifier_should_keep_connection_t should_keep_connection;
185 /* Check if connection should be kept when FDB updates */
Gareth Williamsf98d4192015-03-11 16:55:41 +0000186#ifdef ECM_STATE_OUTPUT_ENABLE
Gareth Williamsd5618a82015-05-20 11:13:32 +0100187 ecm_classifier_state_get_callback_t state_get;
188 /* Return its state */
Gareth Williamsf98d4192015-03-11 16:55:41 +0000189#endif
Ben Menchaca84f36632014-02-28 20:57:38 +0000190 ecm_classifier_ref_method_t ref;
191 ecm_classifier_deref_callback_t deref;
192};
193
Gareth Williamsf98d4192015-03-11 16:55:41 +0000194#ifdef ECM_STATE_OUTPUT_ENABLE
Ben Menchaca84f36632014-02-28 20:57:38 +0000195/*
Gareth Williamsd5618a82015-05-20 11:13:32 +0100196 * ecm_classifier_process_response_state_get()
197 * Output detail for the process response
Ben Menchaca84f36632014-02-28 20:57:38 +0000198 *
Gareth Williamsd5618a82015-05-20 11:13:32 +0100199 * Returns 0 on success.
Ben Menchaca84f36632014-02-28 20:57:38 +0000200 */
Gareth Williamsd5618a82015-05-20 11:13:32 +0100201static 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 +0000202{
Gareth Williamsd5618a82015-05-20 11:13:32 +0100203 int result;
204
205 if ((result = ecm_state_prefix_add(sfi, "pr"))) {
206 return result;
207 }
Ben Menchaca84f36632014-02-28 20:57:38 +0000208
209 if (pr->relevance == ECM_CLASSIFIER_RELEVANCE_NO) {
Gareth Williamsd5618a82015-05-20 11:13:32 +0100210 return ecm_state_write(sfi, "relevant", "%s", "no");
Ben Menchaca84f36632014-02-28 20:57:38 +0000211 }
212
213 if (pr->process_actions & ECM_CLASSIFIER_PROCESS_ACTION_DROP) {
214 if (pr->drop) {
Gareth Williamsd5618a82015-05-20 11:13:32 +0100215 if ((result = ecm_state_write(sfi, "drop", "yes"))) {
216 return result;
217 }
Ben Menchaca84f36632014-02-28 20:57:38 +0000218 } else {
Gareth Williamsd5618a82015-05-20 11:13:32 +0100219 if ((result = ecm_state_write(sfi, "drop", "no"))) {
220 return result;
221 }
Ben Menchaca84f36632014-02-28 20:57:38 +0000222 }
223 }
224
Ben Menchaca84f36632014-02-28 20:57:38 +0000225 if (pr->relevance == ECM_CLASSIFIER_RELEVANCE_MAYBE) {
Gareth Williamsd5618a82015-05-20 11:13:32 +0100226 if ((result = ecm_state_write(sfi, "accel", "denied"))) {
227 return result;
228 }
229 if ((result = ecm_state_write(sfi, "relevant", "maybe"))) {
230 return result;
231 }
Ben Menchaca84f36632014-02-28 20:57:38 +0000232 } else {
Gareth Williamsd5618a82015-05-20 11:13:32 +0100233 if ((result = ecm_state_write(sfi, "relevant", "yes"))) {
234 return result;
235 }
236 if (pr->process_actions & ECM_CLASSIFIER_PROCESS_ACTION_ACCEL_MODE) {
237 if (pr->accel_mode == ECM_CLASSIFIER_ACCELERATION_MODE_ACCEL) {
238 if ((result = ecm_state_write(sfi, "accel", "wanted"))) {
239 return result;
240 }
241 }
242 else if (pr->accel_mode == ECM_CLASSIFIER_ACCELERATION_MODE_NO) {
243 if ((result = ecm_state_write(sfi, "accel", "denied"))) {
244 return result;
245 }
246 }
247 /* Else don't care */
248 }
Ben Menchaca84f36632014-02-28 20:57:38 +0000249 }
250
Gareth Williamsd5618a82015-05-20 11:13:32 +0100251 if (pr->process_actions & ECM_CLASSIFIER_PROCESS_ACTION_QOS_TAG) {
252 if ((result = ecm_state_write(sfi, "flow_qos_tag", "%u", pr->flow_qos_tag))) {
253 return result;
254 }
255 if ((result = ecm_state_write(sfi, "return_qos_tag", "%u", pr->return_qos_tag))) {
256 return result;
257 }
258 }
259#ifdef ECM_CLASSIFIER_DSCP_ENABLE
260 if (pr->process_actions & ECM_CLASSIFIER_PROCESS_ACTION_DSCP) {
261 if ((result = ecm_state_write(sfi, "flow_dscp", "%u", pr->flow_dscp))) {
262 return result;
263 }
264 if ((result = ecm_state_write(sfi, "return_dscp", "%u", pr->return_dscp))) {
265 return result;
266 }
267 }
268#endif
269 if (pr->process_actions & ECM_CLASSIFIER_PROCESS_ACTION_TIMER_GROUP) {
270 if ((result = ecm_state_write(sfi, "timer_group", "%d", pr->timer_group))) {
271 return result;
272 }
273 }
274
275 return ecm_state_prefix_remove(sfi);
Ben Menchaca84f36632014-02-28 20:57:38 +0000276}
Gareth Williamsf98d4192015-03-11 16:55:41 +0000277#endif
278
Murat Sezginc725ad82016-04-13 17:12:50 -0700279extern struct ecm_classifier_instance *ecm_classifier_assign_classifier(struct ecm_db_connection_instance *ci, ecm_classifier_type_t type);
280extern bool ecm_classifier_reclassify(struct ecm_db_connection_instance *ci, int assignment_count, struct ecm_classifier_instance *assignments[]);
Ben Menchaca84f36632014-02-28 20:57:38 +0000281