blob: 08f02241bfb71f97e8fab05d029cda00f412b903 [file] [log] [blame]
Ben Menchaca84f36632014-02-28 20:57:38 +00001/*
2 **************************************************************************
3 * Copyright (c) 2014, The Linux Foundation. All rights reserved.
4 * 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
Gareth Williams8932a912014-06-11 18:06:25 -070028 ECM_CLASSIFIER_TYPE_DSCP, /* Provides DSCP and DSCP remarking support */
Ben Menchaca84f36632014-02-28 20:57:38 +000029 ECM_CLASSIFIER_TYPE_NL, /* Provides netlink interface */
30 ECM_CLASSIFIER_TYPES, /* MUST BE LAST */
31};
32typedef enum ecm_classifier_types ecm_classifier_type_t;
33
34/*
35 * enum ecm_classifier_relevances
36 * Whether a classifier is relevant to a connection
37 */
38enum ecm_classifier_relevances {
39 ECM_CLASSIFIER_RELEVANCE_MAYBE = 0, /* Classifier has not yet determined relevance */
40 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) */
41 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 */
42};
43typedef enum ecm_classifier_relevances ecm_classifier_relevence_t;
44
45/*
46 * enum ecm_classifier_acceleration_modes
47 * Modes in which a connection may be accelerated
48 */
49enum ecm_classifier_acceleration_modes {
50 ECM_CLASSIFIER_ACCELERATION_MODE_DONT_CARE = 0, /* Classifier does not care if the connection is accelerated */
51 ECM_CLASSIFIER_ACCELERATION_MODE_NO, /* Connection must not be accelerated */
52 ECM_CLASSIFIER_ACCELERATION_MODE_ACCEL, /* Connection can be accelerated whenever */
53};
54typedef enum ecm_classifier_acceleration_modes ecm_classifier_acceleration_mode_t;
55
56/*
57 * Process actions
58 * A process result, that is relevant, may contain zero or more actions for the front end.
59 * Due to the parallel processing nature of classifiers, *usually* the action(s) of the highest priority
60 * classifier will override any lower priority actions. This is up to front end discretion, of course.
61 */
Gareth Williams27c3db12014-06-11 17:37:56 -070062#define ECM_CLASSIFIER_PROCESS_ACTION_DROP 0x00000001 /* Drop */
63#define ECM_CLASSIFIER_PROCESS_ACTION_QOS_TAG 0x00000002 /* Contains flow & return qos tags */
Ben Menchaca84f36632014-02-28 20:57:38 +000064#define ECM_CLASSIFIER_PROCESS_ACTION_ACCEL_MODE 0x00000004 /* Contains an accel mode */
65#define ECM_CLASSIFIER_PROCESS_ACTION_TIMER_GROUP 0x00000008 /* Contains a timer group change */
Gareth Williamsbd03e232014-06-11 17:55:28 -070066#define ECM_CLASSIFIER_PROCESS_ACTION_DSCP 0x00000010 /* Contains DSCP marking information */
67#define ECM_CLASSIFIER_PROCESS_ACTION_DSCP_DENY 0x00000020 /* Denies any DSCP changes */
Ben Menchaca84f36632014-02-28 20:57:38 +000068
69/*
70 * struct ecm_classifier_process_response
71 * Response structure returned by a process call
72 */
73struct ecm_classifier_process_response {
74 ecm_classifier_relevence_t relevance; /* Is this classifier relevant to the connection? */
75 uint32_t became_relevant; /* DB time the classifier became relevant or not relevant, if relevance is maybe this field is not relevant! */
76
77 uint32_t process_actions; /* Actions this process response contains */
78
79 /*
80 * The following fields are only to be inspected if this response is relevant AND the process_actions indicates so
81 */
82 bool drop; /* Drop packet at hand */
Gareth Williams27c3db12014-06-11 17:37:56 -070083 uint32_t flow_qos_tag; /* QoS tag to use for the packet */
84 uint32_t return_qos_tag; /* QoS tag to use for the packet */
Gareth Williamsbd03e232014-06-11 17:55:28 -070085 uint8_t flow_dscp; /* DSCP mark for flow */
86 uint8_t return_dscp; /* DSCP mark for return */
Ben Menchaca84f36632014-02-28 20:57:38 +000087 ecm_classifier_acceleration_mode_t accel_mode; /* Acceleration needed for this connection */
88 ecm_db_timer_group_t timer_group; /* Timer group the connection should be in */
89};
90
91/*
92 * To be implemented by all classifiers
93 */
94typedef void (*ecm_classifier_ref_method_t)(struct ecm_classifier_instance *ci);
95typedef int (*ecm_classifier_deref_callback_t)(struct ecm_classifier_instance *ci);
96typedef 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);
97 /* Process new data for connection, process_response is populated with the response of processing */
98typedef void (*ecm_classifier_sync_from_v4_callback_t)(struct ecm_classifier_instance *ci, struct nss_ipv4_create *params);
99 /* Sync the NSS state with state from the classifier */
100typedef void (*ecm_classifier_sync_to_v4_callback_t)(struct ecm_classifier_instance *ci, struct nss_ipv4_cb_params *params);
101 /* Sync the classifier state with current NSS state */
102typedef void (*ecm_classifier_sync_from_v6_callback_t)(struct ecm_classifier_instance *ci, struct nss_ipv6_create *params);
103 /* Sync the NSS state with state from the classifier */
104typedef void (*ecm_classifier_sync_to_v6_callback_t)(struct ecm_classifier_instance *ci, struct nss_ipv6_cb_params *params);
105 /* Sync the classifier state with current NSS state */
106typedef ecm_classifier_type_t (*ecm_classifier_type_get_callback_t)(struct ecm_classifier_instance *ci);
107 /* Get type of classifier this is */
108typedef bool (*ecm_classifier_reclassify_allowed_get_callback_t)(struct ecm_classifier_instance *ci);
109 /* Get whether reclassification is allowed */
110typedef void (*ecm_classifier_reclassify_callback_t)(struct ecm_classifier_instance *ci);
111 /* Reclassify */
112typedef void (*ecm_classifier_last_process_response_get_callback_t)(struct ecm_classifier_instance *ci, struct ecm_classifier_process_response *process_response);
113 /* Get last process response */
114typedef int (*ecm_classifier_xml_state_get_callback_t)(struct ecm_classifier_instance *ci, char *buf, int buf_sz);
115 /* Get XML state output, buf has buf_sz bytes available. Returns number of bytes written.
116 * Function has failed if the return is (<= 0) || (return value == buf_sz).
117 * The return code is compatible with snprintf().
118 */
119
120/*
121 * Base class for all types of classifiers
122 */
123struct ecm_classifier_instance {
124 struct ecm_classifier_instance *ca_next; /* DB use only: Connection assignment next pointer */
125 struct ecm_classifier_instance *ca_prev; /* DB use only: Connection assignment prev pointer */
126
127 ecm_classifier_process_callback_t process; /* Process new skb */
128 ecm_classifier_sync_from_v4_callback_t sync_from_v4;
129 /* Sync the NSS with state from the classifier */
130 ecm_classifier_sync_to_v4_callback_t sync_to_v4;/* Sync the classifier with state from the NSS */
131 ecm_classifier_sync_from_v6_callback_t sync_from_v6;
132 /* Sync the NSS with state from the classifier */
133 ecm_classifier_sync_to_v6_callback_t sync_to_v6;/* Sync the classifier with state from the NSS */
134 ecm_classifier_type_get_callback_t type_get; /* Get type of classifier */
135 ecm_classifier_reclassify_allowed_get_callback_t reclassify_allowed;
136 /* Get whether reclassification is allowed */
137 ecm_classifier_reclassify_callback_t reclassify;
138 /* Reclassify */
139 ecm_classifier_last_process_response_get_callback_t last_process_response_get;
140 /* Return last process response */
141 ecm_classifier_xml_state_get_callback_t xml_state_get;
142 /* Return an XML element containing its state */
143 ecm_classifier_ref_method_t ref;
144 ecm_classifier_deref_callback_t deref;
145};
146
147/*
148 * ecm_classifier_process_response_xml_state_get()
149 * Output an XML block for the process response
150 *
151 * This function writes an XML element into the given buffer.
152 * It will write no more than buf_sz, even if that truncates the output.
153 * It will return <= 0 or buf_sz (truncation) if there is a failure.
154 * The return code is compatible with snprintf()
155 */
156static inline int ecm_classifier_process_response_xml_state_get(char *buf, int buf_sz, struct ecm_classifier_process_response *pr)
157{
158 char *drop_str = "";
159 char *accel_mode_str = "";
160 char timer_group_str[50] = "";
Gareth Williams67ee8cf2014-06-13 15:07:44 -0700161 char qos_tag_str[60] = "";
Gareth Williamsbd03e232014-06-11 17:55:28 -0700162 char dscp_str[50] = "";
Ben Menchaca84f36632014-02-28 20:57:38 +0000163 char *relevance_str = "";
164
165 if (pr->relevance == ECM_CLASSIFIER_RELEVANCE_NO) {
166 return snprintf(buf, buf_sz, "<pr relevant=\"no\"/>\n");
167 }
168
169 if (pr->process_actions & ECM_CLASSIFIER_PROCESS_ACTION_DROP) {
170 if (pr->drop) {
171 drop_str = " drop=\"yes\"";
172 } else {
173 drop_str = " drop=\"no\"";
174 }
175 }
176
177 if (pr->process_actions & ECM_CLASSIFIER_PROCESS_ACTION_ACCEL_MODE) {
178 if (pr->accel_mode == ECM_CLASSIFIER_ACCELERATION_MODE_ACCEL) {
179 accel_mode_str = " accel=\"wanted\"";
180 }
181 else if (pr->accel_mode == ECM_CLASSIFIER_ACCELERATION_MODE_NO) {
182 accel_mode_str = " accel=\"denied\"";
183 }
184 /* Else don't care */
185 }
186
187 if (pr->process_actions & ECM_CLASSIFIER_PROCESS_ACTION_QOS_TAG) {
Gareth Williams27c3db12014-06-11 17:37:56 -0700188 snprintf(qos_tag_str, sizeof(qos_tag_str), " flow_qos_tag=\"%u\" return_qos_tag=\"%u\"",
189 pr->flow_qos_tag, pr->return_qos_tag);
Ben Menchaca84f36632014-02-28 20:57:38 +0000190 }
191
Gareth Williamsbd03e232014-06-11 17:55:28 -0700192 if (pr->process_actions & ECM_CLASSIFIER_PROCESS_ACTION_DSCP) {
193 snprintf(dscp_str, sizeof(dscp_str), " flow_dscp=\"%u\" return_dscp=\"%u\"",
194 pr->flow_dscp, pr->return_dscp);
195 }
196
Ben Menchaca84f36632014-02-28 20:57:38 +0000197 if (pr->process_actions & ECM_CLASSIFIER_PROCESS_ACTION_TIMER_GROUP) {
198 snprintf(timer_group_str, sizeof(timer_group_str), " timer_group=\"%d\"", pr->timer_group);
199 }
200
201 if (pr->relevance == ECM_CLASSIFIER_RELEVANCE_MAYBE) {
202 accel_mode_str = " accel=\"denied\"";
203 relevance_str = " relevant=\"maybe\"";
204 } else {
205 relevance_str = " relevant=\"yes\"";
206 }
207
Gareth Williamsbd03e232014-06-11 17:55:28 -0700208 return snprintf(buf, buf_sz, "<pr %s became_relevant=\"%u\"%s%s%s%s%s/>\n",
Ben Menchaca84f36632014-02-28 20:57:38 +0000209 relevance_str,
210 pr->became_relevant,
211 drop_str,
212 qos_tag_str,
213 timer_group_str,
Gareth Williamsbd03e232014-06-11 17:55:28 -0700214 accel_mode_str,
215 dscp_str);
Ben Menchaca84f36632014-02-28 20:57:38 +0000216}
217
218