Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [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 | #include <linux/module.h> |
Murat Sezgin | f2b9453 | 2014-12-05 14:53:53 -0800 | [diff] [blame] | 17 | #include <linux/of.h> |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 18 | |
| 19 | extern int ecm_tracker_init(void); |
| 20 | extern void ecm_tracker_exit(void); |
| 21 | |
| 22 | extern int ecm_db_init(void); |
| 23 | extern void ecm_db_connection_defunct_all(void); |
| 24 | extern void ecm_db_exit(void); |
| 25 | |
| 26 | extern int ecm_tracker_tcp_module_init(void); |
| 27 | extern void ecm_tracker_tcp_module_exit(void); |
| 28 | |
| 29 | extern int ecm_tracker_udp_module_init(void); |
| 30 | extern void ecm_tracker_udp_module_exit(void); |
| 31 | |
| 32 | extern int ecm_tracker_datagram_module_init(void); |
| 33 | extern void ecm_tracker_datagram_module_exit(void); |
| 34 | |
| 35 | extern int ecm_classifier_default_init(void); |
| 36 | extern void ecm_classifier_default_exit(void); |
| 37 | |
Murat Sezgin | aaaafb4 | 2014-11-24 17:02:05 -0800 | [diff] [blame] | 38 | #ifdef ECM_CLASSIFIER_NL_ENABLE |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 39 | extern int ecm_classifier_nl_rules_init(void); |
| 40 | extern void ecm_classifier_nl_rules_exit(void); |
Murat Sezgin | aaaafb4 | 2014-11-24 17:02:05 -0800 | [diff] [blame] | 41 | #endif |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 42 | |
Hai Shalom | 81f4e20 | 2014-06-04 09:30:27 -0700 | [diff] [blame] | 43 | #ifdef ECM_CLASSIFIER_HYFI_ENABLE |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 44 | extern int ecm_classifier_hyfi_rules_init(void); |
| 45 | extern void ecm_classifier_hyfi_rules_exit(void); |
Hai Shalom | 81f4e20 | 2014-06-04 09:30:27 -0700 | [diff] [blame] | 46 | #endif |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 47 | |
| 48 | extern int ecm_interface_init(void); |
| 49 | extern void ecm_interface_stop(int); |
| 50 | extern void ecm_interface_exit(void); |
| 51 | |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 52 | #ifdef ECM_INTERFACE_BOND_ENABLE |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 53 | extern int ecm_bond_notifier_init(void); |
| 54 | extern void ecm_bond_notifier_stop(int); |
| 55 | extern void ecm_bond_notifier_exit(void); |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 56 | #endif |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 57 | |
| 58 | extern int ecm_front_end_ipv4_init(void); |
| 59 | extern void ecm_front_end_ipv4_stop(int); |
| 60 | extern void ecm_front_end_ipv4_exit(void); |
| 61 | |
Murat Sezgin | 49465a4 | 2014-11-24 15:37:48 -0800 | [diff] [blame] | 62 | #ifdef ECM_FRONT_END_IPV6_ENABLE |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 63 | extern int ecm_front_end_ipv6_init(void); |
| 64 | extern void ecm_front_end_ipv6_stop(int); |
| 65 | extern void ecm_front_end_ipv6_exit(void); |
Murat Sezgin | 49465a4 | 2014-11-24 15:37:48 -0800 | [diff] [blame] | 66 | #endif |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 67 | |
| 68 | extern int ecm_conntrack_notifier_init(void); |
| 69 | extern void ecm_conntrack_notifier_stop(int); |
| 70 | extern void ecm_conntrack_notifier_exit(void); |
| 71 | |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 72 | #ifdef ECM_CLASSIFIER_DSCP_ENABLE |
Gareth Williams | 4a02c9b | 2014-10-10 14:50:33 +0100 | [diff] [blame] | 73 | extern int ecm_classifier_dscp_init(void); |
| 74 | extern void ecm_classifier_dscp_exit(void); |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 75 | #endif |
Gareth Williams | 4a02c9b | 2014-10-10 14:50:33 +0100 | [diff] [blame] | 76 | |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 77 | /* |
| 78 | * ecm_init() |
| 79 | */ |
| 80 | static int __init ecm_init(void) |
| 81 | { |
| 82 | int ret; |
Murat Sezgin | f2b9453 | 2014-12-05 14:53:53 -0800 | [diff] [blame] | 83 | |
| 84 | /* |
| 85 | * Run only for IPQ8064 platform, if the device tree is used. |
| 86 | */ |
| 87 | #ifdef CONFIG_OF |
| 88 | if (!of_machine_is_compatible("qcom,ipq8064")) { |
| 89 | printk(KERN_WARNING "Not compatible platform for ECM\n"); |
| 90 | return 0; |
| 91 | } |
| 92 | #endif |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 93 | printk(KERN_INFO "ECM init\n"); |
| 94 | |
| 95 | ret = ecm_tracker_init(); |
| 96 | if (0 != ret) { |
| 97 | return ret; |
| 98 | } |
| 99 | |
| 100 | ret = ecm_db_init(); |
| 101 | if (0 != ret) { |
| 102 | goto err_db; |
| 103 | } |
| 104 | |
| 105 | ret = ecm_tracker_tcp_module_init(); |
| 106 | if (0 != ret) { |
| 107 | goto err_tr_tcp; |
| 108 | } |
| 109 | |
| 110 | ret = ecm_tracker_udp_module_init(); |
| 111 | if (0 != ret) { |
| 112 | goto err_tr_udp; |
| 113 | } |
| 114 | |
| 115 | ret = ecm_tracker_datagram_module_init(); |
| 116 | if (0 != ret) { |
| 117 | goto err_tr_datagram; |
| 118 | } |
| 119 | |
| 120 | ret = ecm_classifier_default_init(); |
| 121 | if (0 != ret) { |
| 122 | goto err_cls_default; |
| 123 | } |
| 124 | |
Murat Sezgin | aaaafb4 | 2014-11-24 17:02:05 -0800 | [diff] [blame] | 125 | #ifdef ECM_CLASSIFIER_NL_ENABLE |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 126 | ret = ecm_classifier_nl_rules_init(); |
| 127 | if (0 != ret) { |
| 128 | goto err_cls_nl; |
| 129 | } |
Murat Sezgin | aaaafb4 | 2014-11-24 17:02:05 -0800 | [diff] [blame] | 130 | #endif |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 131 | |
Hai Shalom | 81f4e20 | 2014-06-04 09:30:27 -0700 | [diff] [blame] | 132 | #ifdef ECM_CLASSIFIER_HYFI_ENABLE |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 133 | ret = ecm_classifier_hyfi_rules_init(); |
| 134 | if (0 != ret) { |
| 135 | goto err_cls_hyfi; |
| 136 | } |
Hai Shalom | 81f4e20 | 2014-06-04 09:30:27 -0700 | [diff] [blame] | 137 | #endif |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 138 | |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 139 | #ifdef ECM_CLASSIFIER_DSCP_ENABLE |
Gareth Williams | 4a02c9b | 2014-10-10 14:50:33 +0100 | [diff] [blame] | 140 | ret = ecm_classifier_dscp_init(); |
| 141 | if (0 != ret) { |
| 142 | goto err_cls_dscp; |
| 143 | } |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 144 | #endif |
Gareth Williams | 4a02c9b | 2014-10-10 14:50:33 +0100 | [diff] [blame] | 145 | |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 146 | ret = ecm_interface_init(); |
| 147 | if (0 != ret) { |
| 148 | goto err_iface; |
| 149 | } |
| 150 | |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 151 | #ifdef ECM_INTERFACE_BOND_ENABLE |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 152 | ret = ecm_bond_notifier_init(); |
| 153 | if (0 != ret) { |
| 154 | goto err_bond; |
| 155 | } |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 156 | #endif |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 157 | |
| 158 | ret = ecm_front_end_ipv4_init(); |
| 159 | if (0 != ret) { |
| 160 | goto err_fe_ipv4; |
| 161 | } |
| 162 | |
Murat Sezgin | 49465a4 | 2014-11-24 15:37:48 -0800 | [diff] [blame] | 163 | #ifdef ECM_FRONT_END_IPV6_ENABLE |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 164 | ret = ecm_front_end_ipv6_init(); |
| 165 | if (0 != ret) { |
| 166 | goto err_fe_ipv6; |
| 167 | } |
Murat Sezgin | 49465a4 | 2014-11-24 15:37:48 -0800 | [diff] [blame] | 168 | #endif |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 169 | |
| 170 | ret = ecm_conntrack_notifier_init(); |
| 171 | if (0 != ret) { |
| 172 | goto err_ct; |
| 173 | } |
| 174 | |
| 175 | printk(KERN_INFO "ECM init complete\n"); |
| 176 | return 0; |
| 177 | |
| 178 | err_ct: |
Murat Sezgin | 49465a4 | 2014-11-24 15:37:48 -0800 | [diff] [blame] | 179 | #ifdef ECM_FRONT_END_IPV6_ENABLE |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 180 | ecm_front_end_ipv6_exit(); |
| 181 | err_fe_ipv6: |
Murat Sezgin | 49465a4 | 2014-11-24 15:37:48 -0800 | [diff] [blame] | 182 | #endif |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 183 | ecm_front_end_ipv4_exit(); |
| 184 | err_fe_ipv4: |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 185 | #ifdef ECM_INTERFACE_BOND_ENABLE |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 186 | ecm_bond_notifier_exit(); |
| 187 | err_bond: |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 188 | #endif |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 189 | ecm_interface_exit(); |
| 190 | err_iface: |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 191 | #ifdef ECM_CLASSIFIER_DSCP_ENABLE |
Gareth Williams | 4a02c9b | 2014-10-10 14:50:33 +0100 | [diff] [blame] | 192 | ecm_classifier_dscp_exit(); |
| 193 | err_cls_dscp: |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 194 | #endif |
Hai Shalom | 81f4e20 | 2014-06-04 09:30:27 -0700 | [diff] [blame] | 195 | #ifdef ECM_CLASSIFIER_HYFI_ENABLE |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 196 | ecm_classifier_hyfi_rules_exit(); |
| 197 | err_cls_hyfi: |
Hai Shalom | 81f4e20 | 2014-06-04 09:30:27 -0700 | [diff] [blame] | 198 | #endif |
Murat Sezgin | aaaafb4 | 2014-11-24 17:02:05 -0800 | [diff] [blame] | 199 | #ifdef ECM_CLASSIFIER_NL_ENABLE |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 200 | ecm_classifier_nl_rules_exit(); |
| 201 | err_cls_nl: |
Murat Sezgin | aaaafb4 | 2014-11-24 17:02:05 -0800 | [diff] [blame] | 202 | #endif |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 203 | ecm_classifier_default_exit(); |
| 204 | err_cls_default: |
| 205 | ecm_tracker_datagram_module_exit(); |
| 206 | err_tr_datagram: |
| 207 | ecm_tracker_udp_module_exit(); |
| 208 | err_tr_udp: |
| 209 | ecm_tracker_tcp_module_exit(); |
| 210 | err_tr_tcp: |
| 211 | ecm_db_exit(); |
| 212 | err_db: |
| 213 | ecm_tracker_exit(); |
| 214 | |
| 215 | printk(KERN_INFO "ECM init failed: %d\n", ret); |
| 216 | return ret; |
| 217 | } |
| 218 | |
| 219 | /* |
| 220 | * ecm_exit() |
| 221 | */ |
| 222 | static void __exit ecm_exit(void) |
| 223 | { |
| 224 | printk(KERN_INFO "ECM exit\n"); |
| 225 | |
Murat Sezgin | f2b9453 | 2014-12-05 14:53:53 -0800 | [diff] [blame] | 226 | /* |
| 227 | * If the platform is not IPQ8064 and device tree is enabled, |
| 228 | * this means ECM started but none of the features are used. |
| 229 | * So, just return here. |
| 230 | */ |
| 231 | #ifdef CONFIG_OF |
| 232 | if (!of_machine_is_compatible("qcom,ipq8064")) { |
| 233 | return; |
| 234 | } |
| 235 | #endif |
| 236 | |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 237 | /* call stop on anything that requires a prepare-to-exit signal */ |
| 238 | printk(KERN_INFO "stop conntrack notifier\n"); |
| 239 | ecm_conntrack_notifier_stop(1); |
| 240 | printk(KERN_INFO "stop front_end_ipv4\n"); |
| 241 | ecm_front_end_ipv4_stop(1); |
Murat Sezgin | 49465a4 | 2014-11-24 15:37:48 -0800 | [diff] [blame] | 242 | #ifdef ECM_FRONT_END_IPV6_ENABLE |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 243 | printk(KERN_INFO "stop front_end_ipv6\n"); |
| 244 | ecm_front_end_ipv6_stop(1); |
Murat Sezgin | 49465a4 | 2014-11-24 15:37:48 -0800 | [diff] [blame] | 245 | #endif |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 246 | printk(KERN_INFO "stop interface\n"); |
| 247 | ecm_interface_stop(1); |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 248 | #ifdef ECM_INTERFACE_BOND_ENABLE |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 249 | printk(KERN_INFO "stop bond notifier\n"); |
| 250 | ecm_bond_notifier_stop(1); |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 251 | #endif |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 252 | printk(KERN_INFO "defunct all db connections\n"); |
| 253 | ecm_db_connection_defunct_all(); |
| 254 | |
| 255 | /* now call exit on each module */ |
| 256 | printk(KERN_INFO "exit conntrack notifier\n"); |
| 257 | ecm_conntrack_notifier_exit(); |
| 258 | printk(KERN_INFO "exit front_end_ipv4\n"); |
| 259 | ecm_front_end_ipv4_exit(); |
Murat Sezgin | 49465a4 | 2014-11-24 15:37:48 -0800 | [diff] [blame] | 260 | #ifdef ECM_FRONT_END_IPV6_ENABLE |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 261 | printk(KERN_INFO "exit front_end_ipv6\n"); |
| 262 | ecm_front_end_ipv6_exit(); |
Murat Sezgin | 49465a4 | 2014-11-24 15:37:48 -0800 | [diff] [blame] | 263 | #endif |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 264 | #ifdef ECM_INTERFACE_BOND_ENABLE |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 265 | printk(KERN_INFO "exit bond notifier\n"); |
| 266 | ecm_bond_notifier_exit(); |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 267 | #endif |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 268 | printk(KERN_INFO "exit interface\n"); |
| 269 | ecm_interface_exit(); |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 270 | #ifdef ECM_CLASSIFIER_DSCP_ENABLE |
Gareth Williams | 4a02c9b | 2014-10-10 14:50:33 +0100 | [diff] [blame] | 271 | printk(KERN_INFO "exit dscp classifier\n"); |
| 272 | ecm_classifier_dscp_exit(); |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 273 | #endif |
Hai Shalom | 81f4e20 | 2014-06-04 09:30:27 -0700 | [diff] [blame] | 274 | #ifdef ECM_CLASSIFIER_HYFI_ENABLE |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 275 | printk(KERN_INFO "exit hyfi classifier\n"); |
| 276 | ecm_classifier_hyfi_rules_exit(); |
Hai Shalom | 81f4e20 | 2014-06-04 09:30:27 -0700 | [diff] [blame] | 277 | #endif |
Murat Sezgin | aaaafb4 | 2014-11-24 17:02:05 -0800 | [diff] [blame] | 278 | #ifdef ECM_CLASSIFIER_NL_ENABLE |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 279 | printk(KERN_INFO "exit nl classifier\n"); |
| 280 | ecm_classifier_nl_rules_exit(); |
Murat Sezgin | aaaafb4 | 2014-11-24 17:02:05 -0800 | [diff] [blame] | 281 | #endif |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 282 | printk(KERN_INFO "exit default classifier\n"); |
| 283 | ecm_classifier_default_exit(); |
| 284 | printk(KERN_INFO "exit datagram tracker\n"); |
| 285 | ecm_tracker_datagram_module_exit(); |
| 286 | printk(KERN_INFO "exit udp tracker\n"); |
| 287 | ecm_tracker_udp_module_exit(); |
| 288 | printk(KERN_INFO "exit tcp tracker\n"); |
| 289 | ecm_tracker_tcp_module_exit(); |
| 290 | printk(KERN_INFO "exit db\n"); |
| 291 | ecm_db_exit(); |
| 292 | printk(KERN_INFO "exit tracker\n"); |
| 293 | ecm_tracker_exit(); |
| 294 | |
| 295 | printk(KERN_INFO "ECM exit complete\n"); |
| 296 | } |
| 297 | |
| 298 | module_init(ecm_init) |
| 299 | module_exit(ecm_exit) |
| 300 | |
| 301 | MODULE_AUTHOR("Qualcomm Atheros, Inc."); |
| 302 | MODULE_DESCRIPTION("ECM Core"); |
| 303 | #ifdef MODULE_LICENSE |
| 304 | MODULE_LICENSE("Dual BSD/GPL"); |
| 305 | #endif |
| 306 | |