コード例 #1
0
static int __init nf_nat_standalone_init(void)
{
    int ret = 0;

    need_ipv4_conntrack();

#ifdef CONFIG_XFRM
    BUG_ON(ip_nat_decode_session != NULL);
    rcu_assign_pointer_nonull(ip_nat_decode_session, nat_decode_session);
#endif
    ret = nf_nat_rule_init();
    if (ret < 0) {
        pr_err("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) {
        pr_err("nf_nat_init: can't register hooks.\n");
        goto cleanup_rule_init;
    }
    return ret;

cleanup_rule_init:
    nf_nat_rule_cleanup();
cleanup_decode_session:
#ifdef CONFIG_XFRM
    rcu_assign_pointer(ip_nat_decode_session, NULL);
    synchronize_net();
#endif
    return ret;
}
コード例 #2
0
ファイル: nf_nat_standalone.c プロジェクト: IgnasD/Tomato-RAF
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;
}