static const struct file_operations proc_snat_operations = {
.read = read_snat,
.write = write_snat,
};
static const struct file_operations proc_dnat_operations = {
.read = read_dnat,
.write = write_dnat,
};
static int __init static_nat_zy_init(void)
{
int ret = 0;
ret = nf_register_hooks(ipv4_static_nat, ARRAY_SIZE(ipv4_static_nat));
if (ret < 0) {
printk("ipv4_static_nat: can't register hooks.\n");
} /* test */else {
nat_entry = proc_mkdir("STATIC_Nat", NULL);
proc_create("source", S_IWUSR, nat_entry, &proc_snat_operations);
proc_create("destination", S_IWUSR, nat_entry, &proc_dnat_operations);
}
return ret;
}
static void __exit static_nat_zy_exit(void)
{
remove_proc_entry("source", nat_entry);
remove_proc_entry("destination", nat_entry);
remove_proc_entry("STATIC_Nat", NULL);
nf_unregister_hooks(ipv4_static_nat, ARRAY_SIZE(ipv4_static_nat));
return;
}
module_init(static_nat_zy_init);
module_exit(static_nat_zy_exit);
//保留原作者
MODULE_AUTHOR("Jan Engelhardt <jengelh@medozas.de>");
MODULE_AUTHOR("wangran <marywangran@126.com>");
MODULE_DESCRIPTION("Static NAT");
MODULE_LICENSE("GPL");
如此就可以实现Cisoc风格的NAT了。代码的优化空间还是有很多的,比如list可以换成hash...