blob: b3dffe893003501c5cf1fc46ea598a24cfb3659d [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/*
Murat Sezgine34b0172015-11-05 21:58:14 -0800155 * Determines if a connection should be kept.
156 */
157typedef bool (*ecm_classifier_should_keep_connection_t)
158 (struct ecm_classifier_instance *ci, uint8_t *mac);
159
160/*
Ben Menchaca84f36632014-02-28 20:57:38 +0000161 * Base class for all types of classifiers
162 */
163struct ecm_classifier_instance {
164 struct ecm_classifier_instance *ca_next; /* DB use only: Connection assignment next pointer */
165 struct ecm_classifier_instance *ca_prev; /* DB use only: Connection assignment prev pointer */
166
167 ecm_classifier_process_callback_t process; /* Process new skb */
168 ecm_classifier_sync_from_v4_callback_t sync_from_v4;
Murat Sezginb2676062015-06-12 17:05:31 -0700169 /* Sync the accel engine with state from the classifier */
170 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 +0000171 ecm_classifier_sync_from_v6_callback_t sync_from_v6;
Murat Sezginb2676062015-06-12 17:05:31 -0700172 /* Sync the accel engine with state from the classifier */
173 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 +0000174 ecm_classifier_type_get_callback_t type_get; /* Get type of classifier */
175 ecm_classifier_reclassify_allowed_get_callback_t reclassify_allowed;
176 /* Get whether reclassification is allowed */
177 ecm_classifier_reclassify_callback_t reclassify;
178 /* Reclassify */
179 ecm_classifier_last_process_response_get_callback_t last_process_response_get;
180 /* Return last process response */
Murat Sezgine34b0172015-11-05 21:58:14 -0800181 ecm_classifier_should_keep_connection_t should_keep_connection;
182 /* Check if connection should be kept when FDB updates */
Gareth Williamsf98d4192015-03-11 16:55:41 +0000183#ifdef ECM_STATE_OUTPUT_ENABLE
Gareth Williamsd5618a82015-05-20 11:13:32 +0100184 ecm_classifier_state_get_callback_t state_get;
185 /* Return its state */
Gareth Williamsf98d4192015-03-11 16:55:41 +0000186#endif
Ben Menchaca84f36632014-02-28 20:57:38 +0000187 ecm_classifier_ref_method_t ref;
188 ecm_classifier_deref_callback_t deref;
189};
190
Gareth Williamsf98d4192015-03-11 16:55:41 +0000191#ifdef ECM_STATE_OUTPUT_ENABLE
Ben Menchaca84f36632014-02-28 20:57:38 +0000192/*
Gareth Williamsd5618a82015-05-20 11:13:32 +0100193 * ecm_classifier_process_response_state_get()
194 * Output detail for the process response
Ben Menchaca84f36632014-02-28 20:57:38 +0000195 *
Gareth Williamsd5618a82015-05-20 11:13:32 +0100196 * Returns 0 on success.
Ben Menchaca84f36632014-02-28 20:57:38 +0000197 */
Gareth Williamsd5618a82015-05-20 11:13:32 +0100198static 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 +0000199{
Gareth Williamsd5618a82015-05-20 11:13:32 +0100200 int result;
201
202 if ((result = ecm_state_prefix_add(sfi, "pr"))) {
203 return result;
204 }
Ben Menchaca84f36632014-02-28 20:57:38 +0000205
206 if (pr->relevance == ECM_CLASSIFIER_RELEVANCE_NO) {
Gareth Williamsd5618a82015-05-20 11:13:32 +0100207 return ecm_state_write(sfi, "relevant", "%s", "no");
Ben Menchaca84f36632014-02-28 20:57:38 +0000208 }
209
210 if (pr->process_actions & ECM_CLASSIFIER_PROCESS_ACTION_DROP) {
211 if (pr->drop) {
Gareth Williamsd5618a82015-05-20 11:13:32 +0100212 if ((result = ecm_state_write(sfi, "drop", "yes"))) {
213 return result;
214 }
Ben Menchaca84f36632014-02-28 20:57:38 +0000215 } else {
Gareth Williamsd5618a82015-05-20 11:13:32 +0100216 if ((result = ecm_state_write(sfi, "drop", "no"))) {
217 return result;
218 }
Ben Menchaca84f36632014-02-28 20:57:38 +0000219 }
220 }
221
Ben Menchaca84f36632014-02-28 20:57:38 +0000222 if (pr->relevance == ECM_CLASSIFIER_RELEVANCE_MAYBE) {
Gareth Williamsd5618a82015-05-20 11:13:32 +0100223 if ((result = ecm_state_write(sfi, "accel", "denied"))) {
224 return result;
225 }
226 if ((result = ecm_state_write(sfi, "relevant", "maybe"))) {
227 return result;
228 }
Ben Menchaca84f36632014-02-28 20:57:38 +0000229 } else {
Gareth Williamsd5618a82015-05-20 11:13:32 +0100230 if ((result = ecm_state_write(sfi, "relevant", "yes"))) {
231 return result;
232 }
233 if (pr->process_actions & ECM_CLASSIFIER_PROCESS_ACTION_ACCEL_MODE) {
234 if (pr->accel_mode == ECM_CLASSIFIER_ACCELERATION_MODE_ACCEL) {
235 if ((result = ecm_state_write(sfi, "accel", "wanted"))) {
236 return result;
237 }
238 }
239 else if (pr->accel_mode == ECM_CLASSIFIER_ACCELERATION_MODE_NO) {
240 if ((result = ecm_state_write(sfi, "accel", "denied"))) {
241 return result;
242 }
243 }
244 /* Else don't care */
245 }
Ben Menchaca84f36632014-02-28 20:57:38 +0000246 }
247
Gareth Williamsd5618a82015-05-20 11:13:32 +0100248 if (pr->process_actions & ECM_CLASSIFIER_PROCESS_ACTION_QOS_TAG) {
249 if ((result = ecm_state_write(sfi, "flow_qos_tag", "%u", pr->flow_qos_tag))) {
250 return result;
251 }
252 if ((result = ecm_state_write(sfi, "return_qos_tag", "%u", pr->return_qos_tag))) {
253 return result;
254 }
255 }
256#ifdef ECM_CLASSIFIER_DSCP_ENABLE
257 if (pr->process_actions & ECM_CLASSIFIER_PROCESS_ACTION_DSCP) {
258 if ((result = ecm_state_write(sfi, "flow_dscp", "%u", pr->flow_dscp))) {
259 return result;
260 }
261 if ((result = ecm_state_write(sfi, "return_dscp", "%u", pr->return_dscp))) {
262 return result;
263 }
264 }
265#endif
266 if (pr->process_actions & ECM_CLASSIFIER_PROCESS_ACTION_TIMER_GROUP) {
267 if ((result = ecm_state_write(sfi, "timer_group", "%d", pr->timer_group))) {
268 return result;
269 }
270 }
271
272 return ecm_state_prefix_remove(sfi);
Ben Menchaca84f36632014-02-28 20:57:38 +0000273}
Gareth Williamsf98d4192015-03-11 16:55:41 +0000274#endif
275
Murat Sezginc725ad82016-04-13 17:12:50 -0700276extern struct ecm_classifier_instance *ecm_classifier_assign_classifier(struct ecm_db_connection_instance *ci, ecm_classifier_type_t type);
277extern 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 +0000278