blob: e0876fcfb459c2bc89e70ac9773b349bd8f98ef9 [file] [log] [blame]
/* cdu_init.c
*
* This file defines client data usage module init.
*
* Author: Cradlepoint Technology, Inc. <source@cradlepoint.com>
* Adrian Sitterle <asitterle@cradlepoint.com>
*
* Copyright (C) 2019 Cradlepoint Technology, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <linux/version.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/jhash.h>
#include <linux/netfilter/xt_usage.h>
#include <linux/netfilter/x_tables.h>
#include <net/netfilter/nf_conntrack.h>
#include <net/netfilter/nf_conntrack_core.h>
#include <net/netfilter/nf_conntrack_acct.h>
#include "cdu_types.h"
#include "cdu_db.h"
#include "cdu_nf_events.h"
#include "cdu_xt_target.h"
#include "cdu_seq_file.h"
int __init usage_init_module(void)
{
int ret;
CDU_DEBUG("Initializing module.\n");
/* initialize usage_hash database */
cdu_db_init();
/* initialize proc file interface */
if (cdu_seq_file_init())
goto err_seq;
/* initialize netfilter eventing triggered at beginning and end of a flow */
ret = cdu_nf_events_register();
if (ret)
goto err_nf;
/* initialize xt table callbacks, used to determine direction of ct */
ret = cdu_xt_target_register();
if (ret)
goto err_xt;
CDU_INFO("Client data usage module loaded.\n");
return 0;
err_xt:
cdu_xt_target_unregister();
err_nf:
cdu_nf_events_unregister();
err_seq:
cdu_seq_file_uninit();
cdu_db_uninit();
CDU_INFO("Client data usage module init failed. %d\n", ret);
return ret;
}
void __exit usage_exit_module(void)
{
cdu_xt_target_unregister();
cdu_nf_events_unregister();
cdu_seq_file_uninit();
cdu_db_uninit();
CDU_INFO("Client data usage module unloaded.\n");
}
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Cradlepoint, Inc");
MODULE_DESCRIPTION("Client usage statistics");
module_init(usage_init_module);
module_exit(usage_exit_module);