Kyle Swenson | 7900a3c | 2021-08-12 14:34:44 -0600 | [diff] [blame] | 1 | /* cdu_init.c |
| 2 | * |
| 3 | * This file defines client data usage module init. |
| 4 | * |
| 5 | * Author: Cradlepoint Technology, Inc. <source@cradlepoint.com> |
| 6 | * Adrian Sitterle <asitterle@cradlepoint.com> |
| 7 | * |
| 8 | * Copyright (C) 2019 Cradlepoint Technology, Inc. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License version 2 |
| 12 | * as published by the Free Software Foundation. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | */ |
| 19 | |
| 20 | #include <linux/version.h> |
| 21 | #include <linux/types.h> |
| 22 | #include <linux/kernel.h> |
| 23 | #include <linux/module.h> |
| 24 | #include <linux/jhash.h> |
Kyle Swenson | f3539a6 | 2023-08-29 14:22:53 -0600 | [diff] [blame] | 25 | #include <linux/netfilter/x_tables.h> |
Kyle Swenson | 7900a3c | 2021-08-12 14:34:44 -0600 | [diff] [blame] | 26 | #include <net/netfilter/nf_conntrack.h> |
| 27 | #include <net/netfilter/nf_conntrack_core.h> |
| 28 | #include <net/netfilter/nf_conntrack_acct.h> |
| 29 | |
| 30 | #include "cdu_types.h" |
| 31 | #include "cdu_db.h" |
| 32 | #include "cdu_nf_events.h" |
| 33 | #include "cdu_xt_target.h" |
| 34 | #include "cdu_seq_file.h" |
| 35 | |
| 36 | |
| 37 | int __init usage_init_module(void) |
| 38 | { |
| 39 | int ret; |
| 40 | |
| 41 | CDU_DEBUG("Initializing module.\n"); |
| 42 | |
| 43 | /* initialize usage_hash database */ |
| 44 | cdu_db_init(); |
| 45 | |
| 46 | /* initialize proc file interface */ |
| 47 | if (cdu_seq_file_init()) |
| 48 | goto err_seq; |
| 49 | |
| 50 | /* initialize netfilter eventing triggered at beginning and end of a flow */ |
| 51 | ret = cdu_nf_events_register(); |
| 52 | if (ret) |
| 53 | goto err_nf; |
| 54 | |
| 55 | /* initialize xt table callbacks, used to determine direction of ct */ |
| 56 | ret = cdu_xt_target_register(); |
| 57 | if (ret) |
| 58 | goto err_xt; |
| 59 | |
| 60 | CDU_INFO("Client data usage module loaded.\n"); |
| 61 | return 0; |
| 62 | |
| 63 | err_xt: |
| 64 | cdu_xt_target_unregister(); |
| 65 | err_nf: |
| 66 | cdu_nf_events_unregister(); |
| 67 | err_seq: |
| 68 | cdu_seq_file_uninit(); |
| 69 | |
| 70 | cdu_db_uninit(); |
| 71 | |
| 72 | CDU_INFO("Client data usage module init failed. %d\n", ret); |
| 73 | return ret; |
| 74 | |
| 75 | } |
| 76 | |
| 77 | void __exit usage_exit_module(void) |
| 78 | { |
| 79 | cdu_xt_target_unregister(); |
| 80 | cdu_nf_events_unregister(); |
| 81 | cdu_seq_file_uninit(); |
| 82 | cdu_db_uninit(); |
| 83 | CDU_INFO("Client data usage module unloaded.\n"); |
| 84 | } |
| 85 | |
| 86 | MODULE_LICENSE("GPL"); |
| 87 | MODULE_AUTHOR("Cradlepoint, Inc"); |
| 88 | MODULE_DESCRIPTION("Client usage statistics"); |
| 89 | |
| 90 | module_init(usage_init_module); |
| 91 | module_exit(usage_exit_module); |