~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/ipv4/netfilter/ip_conntrack_tftp.c

Version: ~ [ linux-5.10-rc1 ] ~ [ linux-5.9.1 ] ~ [ linux-5.8.16 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.72 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.152 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.202 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.240 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.240 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * Licensed under GNU GPL version 2 Copyright Magnus Boden <mb@ozaba.mine.nu>
  3  * Version: 0.0.7
  4  *
  5  * Thu 21 Mar 2002 Harald Welte <laforge@gnumonks.org>
  6  *      - port to newnat API
  7  *
  8  */
  9 
 10 #include <linux/module.h>
 11 #include <linux/ip.h>
 12 #include <linux/udp.h>
 13 
 14 #include <linux/netfilter.h>
 15 #include <linux/netfilter_ipv4/ip_tables.h>
 16 #include <linux/netfilter_ipv4/ip_conntrack_helper.h>
 17 #include <linux/netfilter_ipv4/ip_conntrack_tftp.h>
 18 
 19 MODULE_AUTHOR("Magnus Boden <mb@ozaba.mine.nu>");
 20 MODULE_DESCRIPTION("tftp connection tracking helper");
 21 MODULE_LICENSE("GPL");
 22 
 23 #define MAX_PORTS 8
 24 static int ports[MAX_PORTS];
 25 static int ports_c;
 26 #ifdef MODULE_PARM
 27 MODULE_PARM(ports, "1-" __MODULE_STRING(MAX_PORTS) "i");
 28 MODULE_PARM_DESC(ports, "port numbers of tftp servers");
 29 #endif
 30 
 31 #if 0
 32 #define DEBUGP(format, args...) printk(__FILE__ ":" __FUNCTION__ ": " \
 33                                        format, ## args)
 34 #else
 35 #define DEBUGP(format, args...)
 36 #endif
 37 
 38 static int tftp_help(struct sk_buff *skb,
 39                      struct ip_conntrack *ct,
 40                      enum ip_conntrack_info ctinfo)
 41 {
 42         struct tftphdr tftph;
 43         struct ip_conntrack_expect exp;
 44 
 45         if (skb_copy_bits(skb, skb->nh.iph->ihl * 4 + sizeof(struct udphdr),
 46                           &tftph, sizeof(tftph)) != 0)
 47                 return NF_ACCEPT;
 48 
 49         switch (ntohs(tftph.opcode)) {
 50         /* RRQ and WRQ works the same way */
 51         case TFTP_OPCODE_READ:
 52         case TFTP_OPCODE_WRITE:
 53                 DEBUGP("");
 54                 DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
 55                 DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_REPLY].tuple);
 56                 memset(&exp, 0, sizeof(exp));
 57 
 58                 exp.tuple = ct->tuplehash[IP_CT_DIR_REPLY].tuple;
 59                 exp.mask.src.ip = 0xffffffff;
 60                 exp.mask.dst.ip = 0xffffffff;
 61                 exp.mask.dst.u.udp.port = 0xffff;
 62                 exp.mask.dst.protonum = 0xffff;
 63                 exp.expectfn = NULL;
 64 
 65                 DEBUGP("expect: ");
 66                 DUMP_TUPLE(&exp.tuple);
 67                 DUMP_TUPLE(&exp.mask);
 68                 ip_conntrack_expect_related(ct, &exp);
 69                 break;
 70         default:
 71                 DEBUGP("Unknown opcode\n");
 72         }
 73         return NF_ACCEPT;
 74 }
 75 
 76 static struct ip_conntrack_helper tftp[MAX_PORTS];
 77 static char tftp_names[MAX_PORTS][10];
 78 
 79 static void fini(void)
 80 {
 81         int i;
 82 
 83         for (i = 0 ; i < ports_c; i++) {
 84                 DEBUGP("unregistering helper for port %d\n",
 85                         ports[i]);
 86                 ip_conntrack_helper_unregister(&tftp[i]);
 87         } 
 88 }
 89 
 90 static int __init init(void)
 91 {
 92         int i, ret;
 93         char *tmpname;
 94 
 95         if (!ports[0])
 96                 ports[0]=TFTP_PORT;
 97 
 98         for (i = 0 ; (i < MAX_PORTS) && ports[i] ; i++) {
 99                 /* Create helper structure */
100                 memset(&tftp[i], 0, sizeof(struct ip_conntrack_helper));
101 
102                 tftp[i].tuple.dst.protonum = IPPROTO_UDP;
103                 tftp[i].tuple.src.u.udp.port = htons(ports[i]);
104                 tftp[i].mask.dst.protonum = 0xFFFF;
105                 tftp[i].mask.src.u.udp.port = 0xFFFF;
106                 tftp[i].max_expected = 1;
107                 tftp[i].timeout = 0;
108                 tftp[i].flags = IP_CT_HELPER_F_REUSE_EXPECT;
109                 tftp[i].me = THIS_MODULE;
110                 tftp[i].help = tftp_help;
111 
112                 tmpname = &tftp_names[i][0];
113                 if (ports[i] == TFTP_PORT)
114                         sprintf(tmpname, "tftp");
115                 else
116                         sprintf(tmpname, "tftp-%d", i);
117                 tftp[i].name = tmpname;
118 
119                 DEBUGP("port #%d: %d\n", i, ports[i]);
120 
121                 ret=ip_conntrack_helper_register(&tftp[i]);
122                 if (ret) {
123                         printk("ERROR registering helper for port %d\n",
124                                 ports[i]);
125                         fini();
126                         return(ret);
127                 }
128                 ports_c++;
129         }
130         return(0);
131 }
132 
133 PROVIDES_CONNTRACK(tftp);
134 
135 module_init(init);
136 module_exit(fini);
137 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp