printk("ip_nat_init: can't setup rules.\n");
goto cleanup_rule_init;
}
/* 注册 hook,共在四个 hook 点上注册了函数,分别是:
NF_IP_PRE_ROUTING ip_nat_fn
NF_IP_POST_ROUTING ip_nat_out
NF_IP_LOCAL_OUT ip_nat_local_fn
NF_IP_LOCAL_IN ip_nat_fn
NF_IP_LOCAL_OUT 和 NF_IP_LOCAL_IN 需要定义
CONFIG_IP_NF_NAT_LOCAL
其中在 ip_nat_out 和 ip_nat_local_fn 中都会调用 ip_nat_fn
*/
ret = nf_register_hook(&ip_nat_in_ops);
if (ret < 0) {
printk("ip_nat_init: can't register in hook.\n");
goto cleanup_nat;
}
ret = nf_register_hook(&ip_nat_out_ops);
if (ret < 0) {
printk("ip_nat_init: can't register out hook.\n");
goto cleanup_inops;
}
#ifdef CONFIG_IP_NF_NAT_LOCAL
ret = nf_register_hook(&ip_nat_local_out_ops);
if (ret < 0) {
printk("ip_nat_init: can't register local out hook.\n");
goto cleanup_outops;
}
ret = nf_register_hook(&ip_nat_local_in_ops);
if (ret < 0) {
printk("ip_nat_init: can't register local in hook.\n");
goto cleanup_localoutops;
}
#endif
return ret;
cleanup:
#ifdef CONFIG_IP_NF_NAT_LOCAL
nf_unregister_hook(&ip_nat_local_in_ops);
cleanup_localoutops:
nf_unregister_hook(&ip_nat_local_out_ops);
cleanup_outops:
#endif
nf_unregister_hook(&ip_nat_out_ops);