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> |
| 17 | |
| 18 | extern int ecm_tracker_init(void); |
| 19 | extern void ecm_tracker_exit(void); |
| 20 | |
| 21 | extern int ecm_db_init(void); |
| 22 | extern void ecm_db_connection_defunct_all(void); |
| 23 | extern void ecm_db_exit(void); |
| 24 | |
| 25 | extern int ecm_tracker_tcp_module_init(void); |
| 26 | extern void ecm_tracker_tcp_module_exit(void); |
| 27 | |
| 28 | extern int ecm_tracker_udp_module_init(void); |
| 29 | extern void ecm_tracker_udp_module_exit(void); |
| 30 | |
| 31 | extern int ecm_tracker_datagram_module_init(void); |
| 32 | extern void ecm_tracker_datagram_module_exit(void); |
| 33 | |
| 34 | extern int ecm_classifier_default_init(void); |
| 35 | extern void ecm_classifier_default_exit(void); |
| 36 | |
| 37 | extern int ecm_classifier_nl_rules_init(void); |
| 38 | extern void ecm_classifier_nl_rules_exit(void); |
| 39 | |
Hai Shalom | 81f4e20 | 2014-06-04 09:30:27 -0700 | [diff] [blame] | 40 | #ifdef ECM_CLASSIFIER_HYFI_ENABLE |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 41 | extern int ecm_classifier_hyfi_rules_init(void); |
| 42 | extern void ecm_classifier_hyfi_rules_exit(void); |
Hai Shalom | 81f4e20 | 2014-06-04 09:30:27 -0700 | [diff] [blame] | 43 | #endif |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 44 | |
| 45 | extern int ecm_interface_init(void); |
| 46 | extern void ecm_interface_stop(int); |
| 47 | extern void ecm_interface_exit(void); |
| 48 | |
| 49 | extern int ecm_bond_notifier_init(void); |
| 50 | extern void ecm_bond_notifier_stop(int); |
| 51 | extern void ecm_bond_notifier_exit(void); |
| 52 | |
| 53 | extern int ecm_front_end_ipv4_init(void); |
| 54 | extern void ecm_front_end_ipv4_stop(int); |
| 55 | extern void ecm_front_end_ipv4_exit(void); |
| 56 | |
| 57 | extern int ecm_front_end_ipv6_init(void); |
| 58 | extern void ecm_front_end_ipv6_stop(int); |
| 59 | extern void ecm_front_end_ipv6_exit(void); |
| 60 | |
| 61 | extern int ecm_conntrack_notifier_init(void); |
| 62 | extern void ecm_conntrack_notifier_stop(int); |
| 63 | extern void ecm_conntrack_notifier_exit(void); |
| 64 | |
| 65 | /* |
| 66 | * ecm_init() |
| 67 | */ |
| 68 | static int __init ecm_init(void) |
| 69 | { |
| 70 | int ret; |
| 71 | printk(KERN_INFO "ECM init\n"); |
| 72 | |
| 73 | ret = ecm_tracker_init(); |
| 74 | if (0 != ret) { |
| 75 | return ret; |
| 76 | } |
| 77 | |
| 78 | ret = ecm_db_init(); |
| 79 | if (0 != ret) { |
| 80 | goto err_db; |
| 81 | } |
| 82 | |
| 83 | ret = ecm_tracker_tcp_module_init(); |
| 84 | if (0 != ret) { |
| 85 | goto err_tr_tcp; |
| 86 | } |
| 87 | |
| 88 | ret = ecm_tracker_udp_module_init(); |
| 89 | if (0 != ret) { |
| 90 | goto err_tr_udp; |
| 91 | } |
| 92 | |
| 93 | ret = ecm_tracker_datagram_module_init(); |
| 94 | if (0 != ret) { |
| 95 | goto err_tr_datagram; |
| 96 | } |
| 97 | |
| 98 | ret = ecm_classifier_default_init(); |
| 99 | if (0 != ret) { |
| 100 | goto err_cls_default; |
| 101 | } |
| 102 | |
| 103 | ret = ecm_classifier_nl_rules_init(); |
| 104 | if (0 != ret) { |
| 105 | goto err_cls_nl; |
| 106 | } |
| 107 | |
Hai Shalom | 81f4e20 | 2014-06-04 09:30:27 -0700 | [diff] [blame] | 108 | #ifdef ECM_CLASSIFIER_HYFI_ENABLE |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 109 | ret = ecm_classifier_hyfi_rules_init(); |
| 110 | if (0 != ret) { |
| 111 | goto err_cls_hyfi; |
| 112 | } |
Hai Shalom | 81f4e20 | 2014-06-04 09:30:27 -0700 | [diff] [blame] | 113 | #endif |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 114 | |
| 115 | ret = ecm_interface_init(); |
| 116 | if (0 != ret) { |
| 117 | goto err_iface; |
| 118 | } |
| 119 | |
| 120 | ret = ecm_bond_notifier_init(); |
| 121 | if (0 != ret) { |
| 122 | goto err_bond; |
| 123 | } |
| 124 | |
| 125 | ret = ecm_front_end_ipv4_init(); |
| 126 | if (0 != ret) { |
| 127 | goto err_fe_ipv4; |
| 128 | } |
| 129 | |
| 130 | ret = ecm_front_end_ipv6_init(); |
| 131 | if (0 != ret) { |
| 132 | goto err_fe_ipv6; |
| 133 | } |
| 134 | |
| 135 | ret = ecm_conntrack_notifier_init(); |
| 136 | if (0 != ret) { |
| 137 | goto err_ct; |
| 138 | } |
| 139 | |
| 140 | printk(KERN_INFO "ECM init complete\n"); |
| 141 | return 0; |
| 142 | |
| 143 | err_ct: |
| 144 | ecm_front_end_ipv6_exit(); |
| 145 | err_fe_ipv6: |
| 146 | ecm_front_end_ipv4_exit(); |
| 147 | err_fe_ipv4: |
| 148 | ecm_bond_notifier_exit(); |
| 149 | err_bond: |
| 150 | ecm_interface_exit(); |
| 151 | err_iface: |
Hai Shalom | 81f4e20 | 2014-06-04 09:30:27 -0700 | [diff] [blame] | 152 | #ifdef ECM_CLASSIFIER_HYFI_ENABLE |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 153 | ecm_classifier_hyfi_rules_exit(); |
| 154 | err_cls_hyfi: |
Hai Shalom | 81f4e20 | 2014-06-04 09:30:27 -0700 | [diff] [blame] | 155 | #endif |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 156 | ecm_classifier_nl_rules_exit(); |
| 157 | err_cls_nl: |
| 158 | ecm_classifier_default_exit(); |
| 159 | err_cls_default: |
| 160 | ecm_tracker_datagram_module_exit(); |
| 161 | err_tr_datagram: |
| 162 | ecm_tracker_udp_module_exit(); |
| 163 | err_tr_udp: |
| 164 | ecm_tracker_tcp_module_exit(); |
| 165 | err_tr_tcp: |
| 166 | ecm_db_exit(); |
| 167 | err_db: |
| 168 | ecm_tracker_exit(); |
| 169 | |
| 170 | printk(KERN_INFO "ECM init failed: %d\n", ret); |
| 171 | return ret; |
| 172 | } |
| 173 | |
| 174 | /* |
| 175 | * ecm_exit() |
| 176 | */ |
| 177 | static void __exit ecm_exit(void) |
| 178 | { |
| 179 | printk(KERN_INFO "ECM exit\n"); |
| 180 | |
| 181 | /* call stop on anything that requires a prepare-to-exit signal */ |
| 182 | printk(KERN_INFO "stop conntrack notifier\n"); |
| 183 | ecm_conntrack_notifier_stop(1); |
| 184 | printk(KERN_INFO "stop front_end_ipv4\n"); |
| 185 | ecm_front_end_ipv4_stop(1); |
| 186 | printk(KERN_INFO "stop front_end_ipv6\n"); |
| 187 | ecm_front_end_ipv6_stop(1); |
| 188 | printk(KERN_INFO "stop interface\n"); |
| 189 | ecm_interface_stop(1); |
| 190 | printk(KERN_INFO "stop bond notifier\n"); |
| 191 | ecm_bond_notifier_stop(1); |
| 192 | printk(KERN_INFO "defunct all db connections\n"); |
| 193 | ecm_db_connection_defunct_all(); |
| 194 | |
| 195 | /* now call exit on each module */ |
| 196 | printk(KERN_INFO "exit conntrack notifier\n"); |
| 197 | ecm_conntrack_notifier_exit(); |
| 198 | printk(KERN_INFO "exit front_end_ipv4\n"); |
| 199 | ecm_front_end_ipv4_exit(); |
| 200 | printk(KERN_INFO "exit front_end_ipv6\n"); |
| 201 | ecm_front_end_ipv6_exit(); |
| 202 | printk(KERN_INFO "exit bond notifier\n"); |
| 203 | ecm_bond_notifier_exit(); |
| 204 | printk(KERN_INFO "exit interface\n"); |
| 205 | ecm_interface_exit(); |
Hai Shalom | 81f4e20 | 2014-06-04 09:30:27 -0700 | [diff] [blame] | 206 | #ifdef ECM_CLASSIFIER_HYFI_ENABLE |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 207 | printk(KERN_INFO "exit hyfi classifier\n"); |
| 208 | ecm_classifier_hyfi_rules_exit(); |
Hai Shalom | 81f4e20 | 2014-06-04 09:30:27 -0700 | [diff] [blame] | 209 | #endif |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 210 | printk(KERN_INFO "exit nl classifier\n"); |
| 211 | ecm_classifier_nl_rules_exit(); |
| 212 | printk(KERN_INFO "exit default classifier\n"); |
| 213 | ecm_classifier_default_exit(); |
| 214 | printk(KERN_INFO "exit datagram tracker\n"); |
| 215 | ecm_tracker_datagram_module_exit(); |
| 216 | printk(KERN_INFO "exit udp tracker\n"); |
| 217 | ecm_tracker_udp_module_exit(); |
| 218 | printk(KERN_INFO "exit tcp tracker\n"); |
| 219 | ecm_tracker_tcp_module_exit(); |
| 220 | printk(KERN_INFO "exit db\n"); |
| 221 | ecm_db_exit(); |
| 222 | printk(KERN_INFO "exit tracker\n"); |
| 223 | ecm_tracker_exit(); |
| 224 | |
| 225 | printk(KERN_INFO "ECM exit complete\n"); |
| 226 | } |
| 227 | |
| 228 | module_init(ecm_init) |
| 229 | module_exit(ecm_exit) |
| 230 | |
| 231 | MODULE_AUTHOR("Qualcomm Atheros, Inc."); |
| 232 | MODULE_DESCRIPTION("ECM Core"); |
| 233 | #ifdef MODULE_LICENSE |
| 234 | MODULE_LICENSE("Dual BSD/GPL"); |
| 235 | #endif |
| 236 | |