blob: 5681807435684220baf7256565f4b8f83e586da6 [file] [log] [blame]
Nicolas Costaf46c33b2014-05-15 10:02:00 -05001/*
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
18extern int ecm_tracker_init(void);
19extern void ecm_tracker_exit(void);
20
21extern int ecm_db_init(void);
22extern void ecm_db_connection_defunct_all(void);
23extern void ecm_db_exit(void);
24
25extern int ecm_tracker_tcp_module_init(void);
26extern void ecm_tracker_tcp_module_exit(void);
27
28extern int ecm_tracker_udp_module_init(void);
29extern void ecm_tracker_udp_module_exit(void);
30
31extern int ecm_tracker_datagram_module_init(void);
32extern void ecm_tracker_datagram_module_exit(void);
33
34extern int ecm_classifier_default_init(void);
35extern void ecm_classifier_default_exit(void);
36
37extern int ecm_classifier_nl_rules_init(void);
38extern void ecm_classifier_nl_rules_exit(void);
39
Hai Shalom81f4e202014-06-04 09:30:27 -070040#ifdef ECM_CLASSIFIER_HYFI_ENABLE
Nicolas Costaf46c33b2014-05-15 10:02:00 -050041extern int ecm_classifier_hyfi_rules_init(void);
42extern void ecm_classifier_hyfi_rules_exit(void);
Hai Shalom81f4e202014-06-04 09:30:27 -070043#endif
Nicolas Costaf46c33b2014-05-15 10:02:00 -050044
45extern int ecm_interface_init(void);
46extern void ecm_interface_stop(int);
47extern void ecm_interface_exit(void);
48
49extern int ecm_bond_notifier_init(void);
50extern void ecm_bond_notifier_stop(int);
51extern void ecm_bond_notifier_exit(void);
52
53extern int ecm_front_end_ipv4_init(void);
54extern void ecm_front_end_ipv4_stop(int);
55extern void ecm_front_end_ipv4_exit(void);
56
57extern int ecm_front_end_ipv6_init(void);
58extern void ecm_front_end_ipv6_stop(int);
59extern void ecm_front_end_ipv6_exit(void);
60
61extern int ecm_conntrack_notifier_init(void);
62extern void ecm_conntrack_notifier_stop(int);
63extern void ecm_conntrack_notifier_exit(void);
64
65/*
66 * ecm_init()
67 */
68static 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 Shalom81f4e202014-06-04 09:30:27 -0700108#ifdef ECM_CLASSIFIER_HYFI_ENABLE
Nicolas Costaf46c33b2014-05-15 10:02:00 -0500109 ret = ecm_classifier_hyfi_rules_init();
110 if (0 != ret) {
111 goto err_cls_hyfi;
112 }
Hai Shalom81f4e202014-06-04 09:30:27 -0700113#endif
Nicolas Costaf46c33b2014-05-15 10:02:00 -0500114
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
143err_ct:
144 ecm_front_end_ipv6_exit();
145err_fe_ipv6:
146 ecm_front_end_ipv4_exit();
147err_fe_ipv4:
148 ecm_bond_notifier_exit();
149err_bond:
150 ecm_interface_exit();
151err_iface:
Hai Shalom81f4e202014-06-04 09:30:27 -0700152#ifdef ECM_CLASSIFIER_HYFI_ENABLE
Nicolas Costaf46c33b2014-05-15 10:02:00 -0500153 ecm_classifier_hyfi_rules_exit();
154err_cls_hyfi:
Hai Shalom81f4e202014-06-04 09:30:27 -0700155#endif
Nicolas Costaf46c33b2014-05-15 10:02:00 -0500156 ecm_classifier_nl_rules_exit();
157err_cls_nl:
158 ecm_classifier_default_exit();
159err_cls_default:
160 ecm_tracker_datagram_module_exit();
161err_tr_datagram:
162 ecm_tracker_udp_module_exit();
163err_tr_udp:
164 ecm_tracker_tcp_module_exit();
165err_tr_tcp:
166 ecm_db_exit();
167err_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 */
177static 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 Shalom81f4e202014-06-04 09:30:27 -0700206#ifdef ECM_CLASSIFIER_HYFI_ENABLE
Nicolas Costaf46c33b2014-05-15 10:02:00 -0500207 printk(KERN_INFO "exit hyfi classifier\n");
208 ecm_classifier_hyfi_rules_exit();
Hai Shalom81f4e202014-06-04 09:30:27 -0700209#endif
Nicolas Costaf46c33b2014-05-15 10:02:00 -0500210 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
228module_init(ecm_init)
229module_exit(ecm_exit)
230
231MODULE_AUTHOR("Qualcomm Atheros, Inc.");
232MODULE_DESCRIPTION("ECM Core");
233#ifdef MODULE_LICENSE
234MODULE_LICENSE("Dual BSD/GPL");
235#endif
236