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