Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | struct ecm_classifier_instance; |
| 18 | |
| 19 | /* |
| 20 | * Classifier types. |
| 21 | * MUST BE RECORDED IN ASCENDING ORDER OF PRIORITY |
| 22 | */ |
| 23 | enum ecm_classifier_types { |
| 24 | ECM_CLASSIFIER_TYPE_DEFAULT = 0, /* MUST BE FIRST, Default classifier */ |
Hai Shalom | 81f4e20 | 2014-06-04 09:30:27 -0700 | [diff] [blame] | 25 | #ifdef ECM_CLASSIFIER_HYFI_ENABLE |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 26 | ECM_CLASSIFIER_TYPE_HYFI, /* HyFi classifier */ |
Hai Shalom | 81f4e20 | 2014-06-04 09:30:27 -0700 | [diff] [blame] | 27 | #endif |
Gareth Williams | 8932a91 | 2014-06-11 18:06:25 -0700 | [diff] [blame] | 28 | ECM_CLASSIFIER_TYPE_DSCP, /* Provides DSCP and DSCP remarking support */ |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 29 | ECM_CLASSIFIER_TYPE_NL, /* Provides netlink interface */ |
| 30 | ECM_CLASSIFIER_TYPES, /* MUST BE LAST */ |
| 31 | }; |
| 32 | typedef 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 | */ |
| 38 | enum 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 | }; |
| 43 | typedef 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 |
Murat Sezgin | d701ac5 | 2014-08-20 14:02:30 -0700 | [diff] [blame] | 48 | * |
| 49 | * These are used by a classifier to indicate its desire to accelerate. |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 50 | */ |
| 51 | enum ecm_classifier_acceleration_modes { |
| 52 | ECM_CLASSIFIER_ACCELERATION_MODE_DONT_CARE = 0, /* Classifier does not care if the connection is accelerated */ |
| 53 | ECM_CLASSIFIER_ACCELERATION_MODE_NO, /* Connection must not be accelerated */ |
| 54 | ECM_CLASSIFIER_ACCELERATION_MODE_ACCEL, /* Connection can be accelerated whenever */ |
| 55 | }; |
| 56 | typedef enum ecm_classifier_acceleration_modes ecm_classifier_acceleration_mode_t; |
| 57 | |
| 58 | /* |
| 59 | * Process actions |
| 60 | * A process result, that is relevant, may contain zero or more actions for the front end. |
| 61 | * Due to the parallel processing nature of classifiers, *usually* the action(s) of the highest priority |
| 62 | * classifier will override any lower priority actions. This is up to front end discretion, of course. |
| 63 | */ |
Gareth Williams | 27c3db1 | 2014-06-11 17:37:56 -0700 | [diff] [blame] | 64 | #define ECM_CLASSIFIER_PROCESS_ACTION_DROP 0x00000001 /* Drop */ |
| 65 | #define ECM_CLASSIFIER_PROCESS_ACTION_QOS_TAG 0x00000002 /* Contains flow & return qos tags */ |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 66 | #define ECM_CLASSIFIER_PROCESS_ACTION_ACCEL_MODE 0x00000004 /* Contains an accel mode */ |
| 67 | #define ECM_CLASSIFIER_PROCESS_ACTION_TIMER_GROUP 0x00000008 /* Contains a timer group change */ |
Gareth Williams | bd03e23 | 2014-06-11 17:55:28 -0700 | [diff] [blame] | 68 | #define ECM_CLASSIFIER_PROCESS_ACTION_DSCP 0x00000010 /* Contains DSCP marking information */ |
| 69 | #define ECM_CLASSIFIER_PROCESS_ACTION_DSCP_DENY 0x00000020 /* Denies any DSCP changes */ |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 70 | |
| 71 | /* |
| 72 | * struct ecm_classifier_process_response |
| 73 | * Response structure returned by a process call |
| 74 | */ |
| 75 | struct ecm_classifier_process_response { |
| 76 | ecm_classifier_relevence_t relevance; /* Is this classifier relevant to the connection? */ |
| 77 | uint32_t became_relevant; /* DB time the classifier became relevant or not relevant, if relevance is maybe this field is not relevant! */ |
| 78 | |
| 79 | uint32_t process_actions; /* Actions this process response contains */ |
| 80 | |
| 81 | /* |
| 82 | * The following fields are only to be inspected if this response is relevant AND the process_actions indicates so |
| 83 | */ |
| 84 | bool drop; /* Drop packet at hand */ |
Gareth Williams | 27c3db1 | 2014-06-11 17:37:56 -0700 | [diff] [blame] | 85 | uint32_t flow_qos_tag; /* QoS tag to use for the packet */ |
| 86 | uint32_t return_qos_tag; /* QoS tag to use for the packet */ |
Gareth Williams | bd03e23 | 2014-06-11 17:55:28 -0700 | [diff] [blame] | 87 | uint8_t flow_dscp; /* DSCP mark for flow */ |
| 88 | uint8_t return_dscp; /* DSCP mark for return */ |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 89 | ecm_classifier_acceleration_mode_t accel_mode; /* Acceleration needed for this connection */ |
| 90 | ecm_db_timer_group_t timer_group; /* Timer group the connection should be in */ |
| 91 | }; |
| 92 | |
| 93 | /* |
| 94 | * To be implemented by all classifiers |
| 95 | */ |
| 96 | typedef void (*ecm_classifier_ref_method_t)(struct ecm_classifier_instance *ci); |
| 97 | typedef int (*ecm_classifier_deref_callback_t)(struct ecm_classifier_instance *ci); |
| 98 | typedef 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); |
| 99 | /* Process new data for connection, process_response is populated with the response of processing */ |
Murat Sezgin | 6a06db8 | 2014-08-20 16:34:45 -0700 | [diff] [blame^] | 100 | typedef void (*ecm_classifier_sync_from_v4_callback_t)(struct ecm_classifier_instance *ci, struct nss_ipv4_rule_create_msg *nircm); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 101 | /* Sync the NSS state with state from the classifier */ |
Murat Sezgin | 6a06db8 | 2014-08-20 16:34:45 -0700 | [diff] [blame^] | 102 | typedef void (*ecm_classifier_sync_to_v4_callback_t)(struct ecm_classifier_instance *ci, struct nss_ipv4_conn_sync *sync); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 103 | /* Sync the classifier state with current NSS state */ |
| 104 | typedef void (*ecm_classifier_sync_from_v6_callback_t)(struct ecm_classifier_instance *ci, struct nss_ipv6_create *params); |
| 105 | /* Sync the NSS state with state from the classifier */ |
| 106 | typedef void (*ecm_classifier_sync_to_v6_callback_t)(struct ecm_classifier_instance *ci, struct nss_ipv6_cb_params *params); |
| 107 | /* Sync the classifier state with current NSS state */ |
| 108 | typedef ecm_classifier_type_t (*ecm_classifier_type_get_callback_t)(struct ecm_classifier_instance *ci); |
| 109 | /* Get type of classifier this is */ |
| 110 | typedef bool (*ecm_classifier_reclassify_allowed_get_callback_t)(struct ecm_classifier_instance *ci); |
| 111 | /* Get whether reclassification is allowed */ |
| 112 | typedef void (*ecm_classifier_reclassify_callback_t)(struct ecm_classifier_instance *ci); |
| 113 | /* Reclassify */ |
| 114 | typedef void (*ecm_classifier_last_process_response_get_callback_t)(struct ecm_classifier_instance *ci, struct ecm_classifier_process_response *process_response); |
| 115 | /* Get last process response */ |
| 116 | typedef int (*ecm_classifier_xml_state_get_callback_t)(struct ecm_classifier_instance *ci, char *buf, int buf_sz); |
| 117 | /* Get XML state output, buf has buf_sz bytes available. Returns number of bytes written. |
| 118 | * Function has failed if the return is (<= 0) || (return value == buf_sz). |
| 119 | * The return code is compatible with snprintf(). |
| 120 | */ |
| 121 | |
| 122 | /* |
| 123 | * Base class for all types of classifiers |
| 124 | */ |
| 125 | struct ecm_classifier_instance { |
| 126 | struct ecm_classifier_instance *ca_next; /* DB use only: Connection assignment next pointer */ |
| 127 | struct ecm_classifier_instance *ca_prev; /* DB use only: Connection assignment prev pointer */ |
| 128 | |
| 129 | ecm_classifier_process_callback_t process; /* Process new skb */ |
| 130 | ecm_classifier_sync_from_v4_callback_t sync_from_v4; |
| 131 | /* Sync the NSS with state from the classifier */ |
| 132 | ecm_classifier_sync_to_v4_callback_t sync_to_v4;/* Sync the classifier with state from the NSS */ |
| 133 | ecm_classifier_sync_from_v6_callback_t sync_from_v6; |
| 134 | /* Sync the NSS with state from the classifier */ |
| 135 | ecm_classifier_sync_to_v6_callback_t sync_to_v6;/* Sync the classifier with state from the NSS */ |
| 136 | ecm_classifier_type_get_callback_t type_get; /* Get type of classifier */ |
| 137 | ecm_classifier_reclassify_allowed_get_callback_t reclassify_allowed; |
| 138 | /* Get whether reclassification is allowed */ |
| 139 | ecm_classifier_reclassify_callback_t reclassify; |
| 140 | /* Reclassify */ |
| 141 | ecm_classifier_last_process_response_get_callback_t last_process_response_get; |
| 142 | /* Return last process response */ |
| 143 | ecm_classifier_xml_state_get_callback_t xml_state_get; |
| 144 | /* Return an XML element containing its state */ |
| 145 | ecm_classifier_ref_method_t ref; |
| 146 | ecm_classifier_deref_callback_t deref; |
| 147 | }; |
| 148 | |
| 149 | /* |
| 150 | * ecm_classifier_process_response_xml_state_get() |
| 151 | * Output an XML block for the process response |
| 152 | * |
| 153 | * This function writes an XML element into the given buffer. |
| 154 | * It will write no more than buf_sz, even if that truncates the output. |
| 155 | * It will return <= 0 or buf_sz (truncation) if there is a failure. |
| 156 | * The return code is compatible with snprintf() |
| 157 | */ |
| 158 | static inline int ecm_classifier_process_response_xml_state_get(char *buf, int buf_sz, struct ecm_classifier_process_response *pr) |
| 159 | { |
| 160 | char *drop_str = ""; |
| 161 | char *accel_mode_str = ""; |
| 162 | char timer_group_str[50] = ""; |
Gareth Williams | 67ee8cf | 2014-06-13 15:07:44 -0700 | [diff] [blame] | 163 | char qos_tag_str[60] = ""; |
Gareth Williams | bd03e23 | 2014-06-11 17:55:28 -0700 | [diff] [blame] | 164 | char dscp_str[50] = ""; |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 165 | char *relevance_str = ""; |
| 166 | |
| 167 | if (pr->relevance == ECM_CLASSIFIER_RELEVANCE_NO) { |
| 168 | return snprintf(buf, buf_sz, "<pr relevant=\"no\"/>\n"); |
| 169 | } |
| 170 | |
| 171 | if (pr->process_actions & ECM_CLASSIFIER_PROCESS_ACTION_DROP) { |
| 172 | if (pr->drop) { |
| 173 | drop_str = " drop=\"yes\""; |
| 174 | } else { |
| 175 | drop_str = " drop=\"no\""; |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | if (pr->process_actions & ECM_CLASSIFIER_PROCESS_ACTION_ACCEL_MODE) { |
| 180 | if (pr->accel_mode == ECM_CLASSIFIER_ACCELERATION_MODE_ACCEL) { |
| 181 | accel_mode_str = " accel=\"wanted\""; |
| 182 | } |
| 183 | else if (pr->accel_mode == ECM_CLASSIFIER_ACCELERATION_MODE_NO) { |
| 184 | accel_mode_str = " accel=\"denied\""; |
| 185 | } |
| 186 | /* Else don't care */ |
| 187 | } |
| 188 | |
| 189 | if (pr->process_actions & ECM_CLASSIFIER_PROCESS_ACTION_QOS_TAG) { |
Gareth Williams | 27c3db1 | 2014-06-11 17:37:56 -0700 | [diff] [blame] | 190 | snprintf(qos_tag_str, sizeof(qos_tag_str), " flow_qos_tag=\"%u\" return_qos_tag=\"%u\"", |
| 191 | pr->flow_qos_tag, pr->return_qos_tag); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 192 | } |
| 193 | |
Gareth Williams | bd03e23 | 2014-06-11 17:55:28 -0700 | [diff] [blame] | 194 | if (pr->process_actions & ECM_CLASSIFIER_PROCESS_ACTION_DSCP) { |
| 195 | snprintf(dscp_str, sizeof(dscp_str), " flow_dscp=\"%u\" return_dscp=\"%u\"", |
| 196 | pr->flow_dscp, pr->return_dscp); |
| 197 | } |
| 198 | |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 199 | if (pr->process_actions & ECM_CLASSIFIER_PROCESS_ACTION_TIMER_GROUP) { |
| 200 | snprintf(timer_group_str, sizeof(timer_group_str), " timer_group=\"%d\"", pr->timer_group); |
| 201 | } |
| 202 | |
| 203 | if (pr->relevance == ECM_CLASSIFIER_RELEVANCE_MAYBE) { |
| 204 | accel_mode_str = " accel=\"denied\""; |
| 205 | relevance_str = " relevant=\"maybe\""; |
| 206 | } else { |
| 207 | relevance_str = " relevant=\"yes\""; |
| 208 | } |
| 209 | |
Gareth Williams | bd03e23 | 2014-06-11 17:55:28 -0700 | [diff] [blame] | 210 | return snprintf(buf, buf_sz, "<pr %s became_relevant=\"%u\"%s%s%s%s%s/>\n", |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 211 | relevance_str, |
| 212 | pr->became_relevant, |
| 213 | drop_str, |
| 214 | qos_tag_str, |
| 215 | timer_group_str, |
Gareth Williams | bd03e23 | 2014-06-11 17:55:28 -0700 | [diff] [blame] | 216 | accel_mode_str, |
| 217 | dscp_str); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | |