예제 #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
int __init nat64_init(void)
{
	pr_debug("\n\n\n%s", banner);
    pr_debug("\n\nNAT64 module inserted!");

	// Load default configuration
	init_nat_config(&cs);

    /*
     * Include nf_conntrack dependency
     */
    need_conntrack();

    /*
     * Include nf_conntrack_ipv4 dependency.
     * IPv4 conntrack is needed in order to handle complete packets, and not
     * fragments.
     */
    need_ipv4_conntrack();
    nat64_determine_incoming_tuple_init();

    // BEGIN: code imported from nat64_init of Julius Kriukas' implementation

    // Init IPv4 addresses pool
    init_pools(&cs); // Bernardo

    nat64_create_bib_session_memory();
    pr_debug("NAT64: The bib table slab cache was succesfully created.");
    // END: code imported from nat64_init of Julius Kriukas' implementation

	nat64_create_character_device();

    // Load netlink sockets. Rob
    // BEGIN
    // Create netlink socket, register 'my_nl_rcv_msg' as callback function. // Rob
    my_nl_sock = netlink_kernel_create(&init_net, NETLINK_USERSOCK, 0,
            my_nl_rcv_msg, NULL, THIS_MODULE);
    if (!my_nl_sock) 
    {
        pr_warning("NAT64: %s: Creation of netlink socket failed.\n", __func__);
        goto error;
    } 
    // END

    return xt_register_target(&nat64_tg_reg);

    // The following goto were inspired by Julius Kriukas' nat64_init's goto
error:
    return -EINVAL;

}