1 /* (C) 2001-2002 Magnus Boden <mb@ozaba.mine.nu> 2 * 3 * This program is free software; you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License version 2 as 5 * published by the Free Software Foundation. 6 */ 7 8 #include <linux/module.h> 9 #include <linux/udp.h> 10 11 #include <net/netfilter/nf_conntrack_helper.h> 12 #include <net/netfilter/nf_conntrack_expect.h> 13 #include <net/netfilter/nf_nat_helper.h> 14 #include <linux/netfilter/nf_conntrack_tftp.h> 15 16 #define NAT_HELPER_NAME "tftp" 17 18 MODULE_AUTHOR("Magnus Boden <mb@ozaba.mine.nu>"); 19 MODULE_DESCRIPTION("TFTP NAT helper"); 20 MODULE_LICENSE("GPL"); 21 MODULE_ALIAS_NF_NAT_HELPER(NAT_HELPER_NAME); 22 23 static struct nf_conntrack_nat_helper nat_helper_tftp = 24 NF_CT_NAT_HELPER_INIT(NAT_HELPER_NAME); 25 26 static unsigned int help(struct sk_buff *skb, 27 enum ip_conntrack_info ctinfo, 28 struct nf_conntrack_expect *exp) 29 { 30 const struct nf_conn *ct = exp->master; 31 32 exp->saved_proto.udp.port 33 = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u.udp.port; 34 exp->dir = IP_CT_DIR_REPLY; 35 exp->expectfn = nf_nat_follow_master; 36 if (nf_ct_expect_related(exp) != 0) { 37 nf_ct_helper_log(skb, exp->master, "cannot add expectation"); 38 return NF_DROP; 39 } 40 return NF_ACCEPT; 41 } 42 43 static void __exit nf_nat_tftp_fini(void) 44 { 45 nf_nat_helper_unregister(&nat_helper_tftp); 46 RCU_INIT_POINTER(nf_nat_tftp_hook, NULL); 47 synchronize_rcu(); 48 } 49 50 static int __init nf_nat_tftp_init(void) 51 { 52 BUG_ON(nf_nat_tftp_hook != NULL); 53 nf_nat_helper_register(&nat_helper_tftp); 54 RCU_INIT_POINTER(nf_nat_tftp_hook, help); 55 return 0; 56 } 57 58 module_init(nf_nat_tftp_init); 59 module_exit(nf_nat_tftp_fini); 60