linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / net / ipv4 / netfilter / ip_conntrack_ftp.c
index 1d18c86..e627e58 100644 (file)
@@ -8,6 +8,7 @@
  * published by the Free Software Foundation.
  */
 
+#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/netfilter.h>
 #include <linux/ip.h>
@@ -55,48 +56,37 @@ static int try_eprt(const char *, size_t, u_int32_t [], char);
 static int try_epsv_response(const char *, size_t, u_int32_t [], char);
 
 static const struct ftp_search {
+       enum ip_conntrack_dir dir;
        const char *pattern;
        size_t plen;
        char skip;
        char term;
        enum ip_ct_ftp_type ftptype;
        int (*getnum)(const char *, size_t, u_int32_t[], char);
-} search[IP_CT_DIR_MAX][2] = {
-       [IP_CT_DIR_ORIGINAL] = {
-               {
-                       .pattern        =  "PORT",
-                       .plen           = sizeof("PORT") - 1,
-                       .skip           = ' ',
-                       .term           = '\r',
-                       .ftptype        = IP_CT_FTP_PORT,
-                       .getnum         = try_rfc959,
-               },
-               {
-                       .pattern        = "EPRT",
-                       .plen           = sizeof("EPRT") - 1,
-                       .skip           = ' ',
-                       .term           = '\r',
-                       .ftptype        = IP_CT_FTP_EPRT,
-                       .getnum         = try_eprt,
-               },
+} search[] = {
+       {
+               IP_CT_DIR_ORIGINAL,
+               "PORT", sizeof("PORT") - 1, ' ', '\r',
+               IP_CT_FTP_PORT,
+               try_rfc959,
        },
-       [IP_CT_DIR_REPLY] = {
-               {
-                       .pattern        = "227 ",
-                       .plen           = sizeof("227 ") - 1,
-                       .skip           = '(',
-                       .term           = ')',
-                       .ftptype        = IP_CT_FTP_PASV,
-                       .getnum         = try_rfc959,
-               },
-               {
-                       .pattern        = "229 ",
-                       .plen           = sizeof("229 ") - 1,
-                       .skip           = '(',
-                       .term           = ')',
-                       .ftptype        = IP_CT_FTP_EPSV,
-                       .getnum         = try_epsv_response,
-               },
+       {
+               IP_CT_DIR_REPLY,
+               "227 ", sizeof("227 ") - 1, '(', ')',
+               IP_CT_FTP_PASV,
+               try_rfc959,
+       },
+       {
+               IP_CT_DIR_ORIGINAL,
+               "EPRT", sizeof("EPRT") - 1, ' ', '\r',
+               IP_CT_FTP_EPRT,
+               try_eprt,
+       },
+       {
+               IP_CT_DIR_REPLY,
+               "229 ", sizeof("229 ") - 1, '(', ')',
+               IP_CT_FTP_EPSV,
+               try_epsv_response,
        },
 };
 
@@ -356,15 +346,17 @@ static int help(struct sk_buff **pskb,
        array[2] = (ntohl(ct->tuplehash[dir].tuple.src.ip) >> 8) & 0xFF;
        array[3] = ntohl(ct->tuplehash[dir].tuple.src.ip) & 0xFF;
 
-       for (i = 0; i < ARRAY_SIZE(search[dir]); i++) {
+       for (i = 0; i < ARRAY_SIZE(search); i++) {
+               if (search[i].dir != dir) continue;
+
                found = find_pattern(fb_ptr, (*pskb)->len - dataoff,
-                                    search[dir][i].pattern,
-                                    search[dir][i].plen,
-                                    search[dir][i].skip,
-                                    search[dir][i].term,
+                                    search[i].pattern,
+                                    search[i].plen,
+                                    search[i].skip,
+                                    search[i].term,
                                     &matchoff, &matchlen,
                                     array,
-                                    search[dir][i].getnum);
+                                    search[i].getnum);
                if (found) break;
        }
        if (found == -1) {
@@ -374,7 +366,7 @@ static int help(struct sk_buff **pskb,
                   this case. */
                if (net_ratelimit())
                        printk("conntrack_ftp: partial %s %u+%u\n",
-                              search[dir][i].pattern,
+                              search[i].pattern,
                               ntohl(th->seq), datalen);
                ret = NF_DROP;
                goto out;
@@ -434,7 +426,7 @@ static int help(struct sk_buff **pskb,
        /* Now, NAT might want to mangle the packet, and register the
         * (possibly changed) expectation itself. */
        if (ip_nat_ftp_hook)
-               ret = ip_nat_ftp_hook(pskb, ctinfo, search[dir][i].ftptype,
+               ret = ip_nat_ftp_hook(pskb, ctinfo, search[i].ftptype,
                                      matchoff, matchlen, exp, &seq);
        else {
                /* Can't expect this?  Best to drop packet now. */
@@ -461,7 +453,7 @@ static struct ip_conntrack_helper ftp[MAX_PORTS];
 static char ftp_names[MAX_PORTS][sizeof("ftp-65535")];
 
 /* Not __exit: called from init() */
-static void ip_conntrack_ftp_fini(void)
+static void fini(void)
 {
        int i;
        for (i = 0; i < ports_c; i++) {
@@ -473,7 +465,7 @@ static void ip_conntrack_ftp_fini(void)
        kfree(ftp_buffer);
 }
 
-static int __init ip_conntrack_ftp_init(void)
+static int __init init(void)
 {
        int i, ret;
        char *tmpname;
@@ -507,12 +499,12 @@ static int __init ip_conntrack_ftp_init(void)
                ret = ip_conntrack_helper_register(&ftp[i]);
 
                if (ret) {
-                       ip_conntrack_ftp_fini();
+                       fini();
                        return ret;
                }
        }
        return 0;
 }
 
-module_init(ip_conntrack_ftp_init);
-module_exit(ip_conntrack_ftp_fini);
+module_init(init);
+module_exit(fini);