net: sctp, forbid negative length
[cascardo/linux.git] / net / netfilter / nf_conntrack_tftp.c
index 2e65b54..b1227dc 100644 (file)
@@ -97,7 +97,7 @@ static int tftp_help(struct sk_buff *skb,
        return ret;
 }
 
-static struct nf_conntrack_helper tftp[MAX_PORTS][2] __read_mostly;
+static struct nf_conntrack_helper tftp[MAX_PORTS * 2] __read_mostly;
 
 static const struct nf_conntrack_expect_policy tftp_exp_policy = {
        .max_expected   = 1,
@@ -106,47 +106,29 @@ static const struct nf_conntrack_expect_policy tftp_exp_policy = {
 
 static void nf_conntrack_tftp_fini(void)
 {
-       int i, j;
-
-       for (i = 0; i < ports_c; i++) {
-               for (j = 0; j < 2; j++)
-                       nf_conntrack_helper_unregister(&tftp[i][j]);
-       }
+       nf_conntrack_helpers_unregister(tftp, ports_c * 2);
 }
 
 static int __init nf_conntrack_tftp_init(void)
 {
-       int i, j, ret;
+       int i, ret;
 
        if (ports_c == 0)
                ports[ports_c++] = TFTP_PORT;
 
        for (i = 0; i < ports_c; i++) {
-               memset(&tftp[i], 0, sizeof(tftp[i]));
-
-               tftp[i][0].tuple.src.l3num = AF_INET;
-               tftp[i][1].tuple.src.l3num = AF_INET6;
-               for (j = 0; j < 2; j++) {
-                       tftp[i][j].tuple.dst.protonum = IPPROTO_UDP;
-                       tftp[i][j].tuple.src.u.udp.port = htons(ports[i]);
-                       tftp[i][j].expect_policy = &tftp_exp_policy;
-                       tftp[i][j].me = THIS_MODULE;
-                       tftp[i][j].help = tftp_help;
-
-                       if (ports[i] == TFTP_PORT)
-                               sprintf(tftp[i][j].name, "tftp");
-                       else
-                               sprintf(tftp[i][j].name, "tftp-%u", i);
-
-                       ret = nf_conntrack_helper_register(&tftp[i][j]);
-                       if (ret) {
-                               pr_err("failed to register helper for pf: %u port: %u\n",
-                                      tftp[i][j].tuple.src.l3num, ports[i]);
-                               ports_c = i;
-                               nf_conntrack_tftp_fini();
-                               return ret;
-                       }
-               }
+               nf_ct_helper_init(&tftp[2 * i], AF_INET, IPPROTO_UDP, "tftp",
+                                 TFTP_PORT, ports[i], i, &tftp_exp_policy,
+                                 0, 0, tftp_help, NULL, THIS_MODULE);
+               nf_ct_helper_init(&tftp[2 * i + 1], AF_INET6, IPPROTO_UDP, "tftp",
+                                 TFTP_PORT, ports[i], i, &tftp_exp_policy,
+                                 0, 0, tftp_help, NULL, THIS_MODULE);
+       }
+
+       ret = nf_conntrack_helpers_register(tftp, ports_c * 2);
+       if (ret < 0) {
+               pr_err("failed to register helpers\n");
+               return ret;
        }
        return 0;
 }