Beispiel #1
0
static int __init nf_dummy_init(void)
{
	int err;

	printk(KERN_DEBUG "nf_dummy_init\n");	

	err = nf_register_hooks(nf_dummy_ipv4_ops, ARRAY_SIZE(nf_dummy_ipv4_ops));

	return err;
}
Beispiel #2
0
static int nic_hooks_init(void)
{
    int ret = 0;
    ret = nf_register_hooks(nic_hooks, ARRAY_SIZE(nic_hooks));
    if (ret)
        printk("Failed to register hook\n");
    else
        printk("register hook success\n");

    return ret;
}
static int __init cache_dst_and_sock_demo_init(void)  
{  
	int ret;  
	ret = nf_register_hooks(ipv4_conn_cache_ops, ARRAY_SIZE(ipv4_conn_cache_ops));  
	if (ret) {  
		goto out;;  
	}
	return 0;
out:	
	return ret;  
}  
Beispiel #4
0
static int __init graybox_init(void)
{
	int i, error;

	log_debug("%s", banner);
	log_debug("Inserting the module...");

	/* Init Packet sender's submodules. */
	error = config_init();
	if (error)
		goto config_failure;

	error = dev_init();
	if (error)
		goto device_failure;

	error = receiver_init();
	if (error)
		goto receiver_failure;

	error = skbops_init();
	if (error)
		goto skbops_failure;

	/* Hook Jool to Netfilter. */
	for (i = 0; i < ARRAY_SIZE(nfho); i++) {
		nfho[i].owner = NULL;
		nfho[i].priority = NF_IP_PRI_FIRST + 25;
	}

	error = nf_register_hooks(nfho, ARRAY_SIZE(nfho));
	if (error)
		goto nf_register_hooks_failure;

	/* Yay */
	log_info(MODULE_NAME " module inserted.\n");
	return error;


nf_register_hooks_failure:
	skbops_destroy();

skbops_failure:
	receiver_destroy();

receiver_failure:
	dev_destroy();

device_failure:
	config_destroy();

config_failure:
	return error;
}
Beispiel #5
0
static int __init init(void)
{
    int ret;
    ret = nf_register_hooks(mac_ops, ARRAY_SIZE(mac_ops));
    if (ret < 0) {
        printk("http detect:can't register mac_ops detect hook!\n");
        return ret;
    }
    printk("insmod mac_ops detect module\n");
    return 0;
}
Beispiel #6
0
int nf_register(void)
{
	int err;

	if ((err = nf_register_hooks(nf_inet_hooks, ARRAY_SIZE(nf_inet_hooks)))) {
		printk(KERN_ERR "%s: netfilter hook registration failed (error %d)\n",
				THIS_MODULE->name, err);
		return -1;
	}
	return 0;
}
static int __init switch_init(void) {
	printk("[switch] init.\n");
	if (nf_register_hooks(
		switch_hooks,
		ARRAY_SIZE(switch_hooks)) < 0
	) {
		printk("[switch] register hooks: failure.\n");
	} else {
		printk("[switch] register hooks: success.\n");
	}
	return 0;
}
Beispiel #8
0
static int __init imq_init_hooks(void)
{
	int ret;

	nf_register_queue_imq_handler(&imq_nfqh);

	ret = nf_register_hooks(imq_ops, ARRAY_SIZE(imq_ops));
	if (ret < 0)
		nf_unregister_queue_imq_handler();

	return ret;
}
Beispiel #9
0
static int __init ebtable_filter_init(void)
{
	int ret;

	ret = register_pernet_subsys(&frame_filter_net_ops);
	if (ret < 0)
		return ret;
	ret = nf_register_hooks(ebt_ops_filter, ARRAY_SIZE(ebt_ops_filter));
	if (ret < 0)
		unregister_pernet_subsys(&frame_filter_net_ops);
	return ret;
}
Beispiel #10
0
static int __init knamed_init(void)
{
    struct file  *filp;
    int           ret;
    int           err;

    PR_INFO("starting");
    PR_INFO("Author: Gu Feng <*****@*****.**>");
    PR_INFO("Version: %s", KNAMED_VERSION);
    PR_INFO("Repository: https://github.com/flygoast/knamed.git");

    filp = filp_open(KNAMED_CONF, O_RDONLY, 0);
    if (IS_ERR(filp)) {
        PR_INFO("conf file \"%s\" didn't existed, ignored", KNAMED_CONF);
        goto init;
    }

    if (filp) {
        fput(filp);
    }

init:

    ret = nf_register_hooks(knamed_ops, ARRAY_SIZE(knamed_ops));
    if (ret < 0) {
        PR_ERR("can't register hooks.");
        goto cleanup;
    }

    knamed_memory_init();

    knamed_procfs_init();
    knamed_sysctl_register();


    dns_init();

    knamed_task = kthread_run(knamed_loop, NULL, "knamedtask");
    if (IS_ERR(knamed_task)) {
        PR_ERR("Create kernel thread failed");
        err = PTR_ERR(knamed_task);
        return err;
    }

    PR_INFO("started");

    return 0;

cleanup:

    return ret;
}
Beispiel #11
0
static int __init nf_nat_standalone_init(void)
{
	int size, ret = 0;

	need_conntrack();

	size = ALIGN(sizeof(struct nf_conn), __alignof__(struct nf_conn_nat)) +
	       sizeof(struct nf_conn_nat);
	ret = nf_conntrack_register_cache(NF_CT_F_NAT, "nf_nat:base", size);
	if (ret < 0) {
		printk(KERN_ERR "nf_nat_init: Unable to create slab cache\n");
		return ret;
	}

	size = ALIGN(size, __alignof__(struct nf_conn_help)) +
	       sizeof(struct nf_conn_help);
	ret = nf_conntrack_register_cache(NF_CT_F_NAT|NF_CT_F_HELP,
					  "nf_nat:help", size);
	if (ret < 0) {
		printk(KERN_ERR "nf_nat_init: Unable to create slab cache\n");
		goto cleanup_register_cache;
	}
#ifdef CONFIG_XFRM
	BUG_ON(ip_nat_decode_session != NULL);
	ip_nat_decode_session = nat_decode_session;
#endif
	ret = nf_nat_rule_init();
	if (ret < 0) {
		printk("nf_nat_init: can't setup rules.\n");
		goto cleanup_decode_session;
	}
	ret = nf_register_hooks(nf_nat_ops, ARRAY_SIZE(nf_nat_ops));
	if (ret < 0) {
		printk("nf_nat_init: can't register hooks.\n");
		goto cleanup_rule_init;
	}
	nf_nat_module_is_loaded = 1;
	return ret;

 cleanup_rule_init:
	nf_nat_rule_cleanup();
 cleanup_decode_session:
#ifdef CONFIG_XFRM
	ip_nat_decode_session = NULL;
	synchronize_net();
#endif
	nf_conntrack_unregister_cache(NF_CT_F_NAT|NF_CT_F_HELP);
 cleanup_register_cache:
	nf_conntrack_unregister_cache(NF_CT_F_NAT);
	return ret;
}
Beispiel #12
0
static int __init smack_nf_ip_init(void)
{
    int err;

    if (smack_enabled == 0)
        return 0;

    printk(KERN_DEBUG "Smack: Registering netfilter hooks\n");

    err = nf_register_hooks(smack_nf_ops, ARRAY_SIZE(smack_nf_ops));
    if (err)
        pr_info("Smack: nf_register_hooks: error %d\n", err);

    return 0;
}
static int __init fp_netfilter_init(void)
{
	int rc;

	rc = nf_register_hooks(fp_netfilter_ops, ARRAY_SIZE(fp_netfilter_ops));
	if (rc < 0) {
		printk(KERN_ERR "fp_netfilter_ops: can't register hooks.\n");
		goto err0;
	}

	return 0;

err0:
	return rc;
}
Beispiel #14
0
static int __init iptable_raw_init(void)
{
	int ret;

	/* Register table */
	ret = ipt_register_table(&packet_raw, &initial_table.repl);
	if (ret < 0)
		return ret;

	/* Register hooks */
	ret = nf_register_hooks(ipt_ops, ARRAY_SIZE(ipt_ops));
	if (ret < 0) {
	ipt_unregister_table(&packet_raw);
	}
	
	return ret;
}
Beispiel #15
0
_STATIC int __init packet_notify_init(void)
{
    int err;

    if ((err = register_jprobes(inet_jprobes, ARRAY_SIZE(inet_jprobes)))) {
        printk(KERN_ERR "%s: jprobes registration failed (error %d)\n",
               THIS_MODULE->name, err);
        return -1;
    }
    if ((err = nf_register_hooks(nf_inet_hooks, ARRAY_SIZE(nf_inet_hooks)))) {
        printk(KERN_ERR "%s: netfilter hook registration failed (error %d)\n",
               THIS_MODULE->name, err);
        unregister_jprobes(inet_jprobes, ARRAY_SIZE(inet_jprobes));
        return -1;
    }
    return 0;
}
Beispiel #16
0
static int __init arptable_filter_init(void)
{
    int ret;

    ret = register_pernet_subsys(&arptable_filter_net_ops);
    if (ret < 0)
        return ret;

    ret = nf_register_hooks(arpt_ops, ARRAY_SIZE(arpt_ops));
    if (ret < 0)
        goto cleanup_table;
    return ret;

cleanup_table:
    unregister_pernet_subsys(&arptable_filter_net_ops);
    return ret;
}
Beispiel #17
0
static int __init arptable_filter_init(void)
{
	int ret;

	/* Register table */
	ret = arpt_register_table(&packet_filter, &initial_table.repl);
	if (ret < 0)
		return ret;

	ret = nf_register_hooks(arpt_ops, ARRAY_SIZE(arpt_ops));
	if (ret < 0)
		goto cleanup_table;
	return ret;

cleanup_table:
	arpt_unregister_table(&packet_filter);
	return ret;
}
Beispiel #18
0
int cs_bridge_hook_insert(void)
{
	/*for linux netfilter */
	nf_register_hooks(br_cs_nf_ops, ARRAY_SIZE(br_cs_nf_ops));

	/*for core hmu */
	memset(&bridge_hmu_entry, 0, sizeof(bridge_hmu_entry));
	memset(&bridge_hmu_value, 0, sizeof(bridge_hmu_value));
	bridge_hmu_value.type = CS_CORE_HMU_WATCH_SWID64;
	bridge_hmu_value.mask = 0xFF;
	bridge_hmu_value.value.swid64 = CS_MOD_BRIDGE_SWID;
	bridge_hmu_entry.watch_bitmask = CS_CORE_HMU_WATCH_SWID64;

	bridge_hmu_entry.value_mask = &bridge_hmu_value;
	bridge_hmu_entry.callback = cs_bridge_callback_core_logic_notify;
	cs_core_hmu_register_watch(&bridge_hmu_entry);
	return 0;
}
static int __init iptable_nat_init(void)
{
	int err;

	err = register_pernet_subsys(&iptable_nat_net_ops);
	if (err < 0)
		goto err1;

	err = nf_register_hooks(nf_nat_ipv4_ops, ARRAY_SIZE(nf_nat_ipv4_ops));
	if (err < 0)
		goto err2;
	return 0;

err2:
	unregister_pernet_subsys(&iptable_nat_net_ops);
err1:
	return err;
}
static int __init iptable_security_init(void)
{
	int ret;

	ret = register_pernet_subsys(&iptable_security_net_ops);
        if (ret < 0)
		return ret;

	ret = nf_register_hooks(ipt_ops, ARRAY_SIZE(ipt_ops));
	if (ret < 0)
		goto cleanup_table;

	return ret;

cleanup_table:
	unregister_pernet_subsys(&iptable_security_net_ops);
	return ret;
}
Beispiel #21
0
static int __init ip6table_raw_init(void)
{
	int ret;

	ret = register_pernet_subsys(&ip6table_raw_net_ops);
	if (ret < 0)
		return ret;

	/* Register hooks */
	ret = nf_register_hooks(ip6t_ops, ARRAY_SIZE(ip6t_ops));
	if (ret < 0)
		goto cleanup_table;

	return ret;

 cleanup_table:
	unregister_pernet_subsys(&ip6table_raw_net_ops);
	return ret;
}
Beispiel #22
0
static int __init jool_init(void)
{
	int error;

	log_debug("Inserting %s...", xlat_get_name());

	/* Init Jool's submodules. */
	error = xlator_init();
	if (error)
		goto xlator_fail;
	error = logtime_init();
	if (error)
		goto log_time_fail;
	error = nlhandler_init();
	if (error)
		goto nlhandler_fail;

	/* This needs to be last! (except for the hook registering.) */
	error = add_instance();
	if (error)
		goto instance_fail;

	/* Hook Jool to Netfilter. */
	error = nf_register_hooks(nfho, ARRAY_SIZE(nfho));
	if (error)
		goto nf_register_hooks_fail;

	/* Yay */
	log_info("%s v" JOOL_VERSION_STR " module inserted.", xlat_get_name());
	return 0;

nf_register_hooks_fail:
	xlator_rm();
instance_fail:
	nlhandler_destroy();
nlhandler_fail:
	logtime_destroy();
log_time_fail:
	xlator_destroy();
xlator_fail:
	return error;
}
Beispiel #23
0
static int __init br_netfilter_init(void)
{
	int ret;

	ret = nf_register_hooks(br_nf_ops, ARRAY_SIZE(br_nf_ops));
	if (ret < 0)
		return ret;

#ifdef CONFIG_SYSCTL
	brnf_sysctl_header = register_net_sysctl(&init_net, "net/bridge", brnf_table);
	if (brnf_sysctl_header == NULL) {
		printk(KERN_WARNING
		       "br_netfilter: can't register to sysctl.\n");
		nf_unregister_hooks(br_nf_ops, ARRAY_SIZE(br_nf_ops));
		return -ENOMEM;
	}
#endif
	printk(KERN_NOTICE "Bridge firewalling registered\n");
	return 0;
}
static int __init ip6table_mangle_init(void)
{
	int ret;

	/* Register table */
	ret = ip6t_register_table(&packet_mangler, &initial_table.repl);
	if (ret < 0)
		return ret;

	/* Register hooks */
	ret = nf_register_hooks(ip6t_ops, ARRAY_SIZE(ip6t_ops));
	if (ret < 0)
		goto cleanup_table;

	return ret;

 cleanup_table:
	ip6t_unregister_table(&packet_mangler);
	return ret;
}
static int __init synproxy_tg6_init(void)
{
	int err;

	err = nf_register_hooks(ipv6_synproxy_ops,
				ARRAY_SIZE(ipv6_synproxy_ops));
	if (err < 0)
		goto err1;

	err = xt_register_target(&synproxy_tg6_reg);
	if (err < 0)
		goto err2;

	return 0;

err2:
	nf_unregister_hooks(ipv6_synproxy_ops, ARRAY_SIZE(ipv6_synproxy_ops));
err1:
	return err;
}
static int __init nf_conntrack_l3proto_ipv4_init(void)
{
	int ret = 0;

	need_conntrack();
	nf_defrag_ipv4_enable();

	ret = nf_register_sockopt(&so_getorigdst);
	if (ret < 0) {
		printk(KERN_ERR "Unable to register netfilter socket option\n");
		return ret;
	}

	ret = register_pernet_subsys(&ipv4_net_ops);
	if (ret < 0) {
		pr_err("nf_conntrack_ipv4: can't register pernet ops\n");
		goto cleanup_sockopt;
	}

	ret = nf_register_hooks(ipv4_conntrack_ops,
				ARRAY_SIZE(ipv4_conntrack_ops));
	if (ret < 0) {
		pr_err("nf_conntrack_ipv4: can't register hooks.\n");
		goto cleanup_pernet;
	}
#if defined(CONFIG_PROC_FS) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
	ret = nf_conntrack_ipv4_compat_init();
	if (ret < 0)
		goto cleanup_hooks;
#endif
	return ret;
#if defined(CONFIG_PROC_FS) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
 cleanup_hooks:
	nf_unregister_hooks(ipv4_conntrack_ops, ARRAY_SIZE(ipv4_conntrack_ops));
#endif
 cleanup_pernet:
	unregister_pernet_subsys(&ipv4_net_ops);
 cleanup_sockopt:
	nf_unregister_sockopt(&so_getorigdst);
	return ret;
}
static int __init nf_defrag_init(void)
{
	int ret = 0;

	ret = nf_ct_frag6_init();
	if (ret < 0) {
		pr_err("nf_defrag_ipv6: can't initialize frag6.\n");
		return ret;
	}
	ret = nf_register_hooks(ipv6_defrag_ops, ARRAY_SIZE(ipv6_defrag_ops));
	if (ret < 0) {
		pr_err("nf_defrag_ipv6: can't register hooks\n");
		goto cleanup_frag6;
	}
	return ret;

cleanup_frag6:
	nf_ct_frag6_cleanup();
	return ret;

}
static int __init ct_modules_init(void)
{
	int ret = 0;

	ct_klog_fd = klog_init("ntrack", 0x0e, 0);
	if(!ct_klog_fd) {
		return -ENOMEM;
	}

	nt_info("init nf hooks.\n");
	ret = nf_register_hooks(ntrack_nf_hook_ops, ARRAY_SIZE(ntrack_nf_hook_ops));
	if (ret) {
		goto __err;
	}

	return 0;
__err:
	if(ct_klog_fd) {
		klog_fini(ct_klog_fd);
	}
	return ret;
}
Beispiel #29
0
static int __init custom_init_module(void)
{
    int ret = 0;

      outside_ip = in_aton(masq_ip);
      if(outside_ip == 0){
                printk("Error: try 'insmod eipnat.ko masq_ip=\"1.1.1.1\"'\n");
                return -1;
      }

      printk("masq_ip = %s/%x\n", masq_ip, ntohl(outside_ip));
      printk("nic_name= %s\n", nic_name);

 
    ret = nf_register_hooks(myhook_ops, ARRAY_SIZE(myhook_ops));
    if(ret < 0){
	return -1;
    }

    printk(KERN_INFO "init_module() called\n");
    return 0;
}
static int __init nf_defrag_init(void)
{
	return nf_register_hooks(ipv4_defrag_ops, ARRAY_SIZE(ipv4_defrag_ops));
}