cfg80211: fix refcount imbalance when wext is disabled
[safe/jmp/linux-2.6] / net / netfilter / nf_conntrack_h323_main.c
index 898f192..6636949 100644 (file)
@@ -218,7 +218,6 @@ static int get_h245_addr(struct nf_conn *ct, const unsigned char *data,
                         union nf_inet_addr *addr, __be16 *port)
 {
        const unsigned char *p;
-       int family = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.l3num;
        int len;
 
        if (taddr->choice != eH245_TransportAddress_unicastAddress)
@@ -226,13 +225,13 @@ static int get_h245_addr(struct nf_conn *ct, const unsigned char *data,
 
        switch (taddr->unicastAddress.choice) {
        case eUnicastAddress_iPAddress:
-               if (family != AF_INET)
+               if (nf_ct_l3num(ct) != AF_INET)
                        return 0;
                p = data + taddr->unicastAddress.iPAddress.network;
                len = 4;
                break;
        case eUnicastAddress_iP6Address:
-               if (family != AF_INET6)
+               if (nf_ct_l3num(ct) != AF_INET6)
                        return 0;
                p = data + taddr->unicastAddress.iP6Address.network;
                len = 16;
@@ -277,7 +276,7 @@ static int expect_rtp_rtcp(struct sk_buff *skb, struct nf_conn *ct,
        /* Create expect for RTP */
        if ((rtp_exp = nf_ct_expect_alloc(ct)) == NULL)
                return -1;
-       nf_ct_expect_init(rtp_exp, ct->tuplehash[!dir].tuple.src.l3num,
+       nf_ct_expect_init(rtp_exp, NF_CT_EXPECT_CLASS_DEFAULT, nf_ct_l3num(ct),
                          &ct->tuplehash[!dir].tuple.src.u3,
                          &ct->tuplehash[!dir].tuple.dst.u3,
                          IPPROTO_UDP, NULL, &rtp_port);
@@ -287,7 +286,7 @@ static int expect_rtp_rtcp(struct sk_buff *skb, struct nf_conn *ct,
                nf_ct_expect_put(rtp_exp);
                return -1;
        }
-       nf_ct_expect_init(rtcp_exp, ct->tuplehash[!dir].tuple.src.l3num,
+       nf_ct_expect_init(rtcp_exp, NF_CT_EXPECT_CLASS_DEFAULT, nf_ct_l3num(ct),
                          &ct->tuplehash[!dir].tuple.src.u3,
                          &ct->tuplehash[!dir].tuple.dst.u3,
                          IPPROTO_UDP, NULL, &rtcp_port);
@@ -304,9 +303,9 @@ static int expect_rtp_rtcp(struct sk_buff *skb, struct nf_conn *ct,
                if (nf_ct_expect_related(rtp_exp) == 0) {
                        if (nf_ct_expect_related(rtcp_exp) == 0) {
                                pr_debug("nf_ct_h323: expect RTP ");
-                               NF_CT_DUMP_TUPLE(&rtp_exp->tuple);
+                               nf_ct_dump_tuple(&rtp_exp->tuple);
                                pr_debug("nf_ct_h323: expect RTCP ");
-                               NF_CT_DUMP_TUPLE(&rtcp_exp->tuple);
+                               nf_ct_dump_tuple(&rtcp_exp->tuple);
                        } else {
                                nf_ct_unexpect_related(rtp_exp);
                                ret = -1;
@@ -344,7 +343,7 @@ static int expect_t120(struct sk_buff *skb,
        /* Create expect for T.120 connections */
        if ((exp = nf_ct_expect_alloc(ct)) == NULL)
                return -1;
-       nf_ct_expect_init(exp, ct->tuplehash[!dir].tuple.src.l3num,
+       nf_ct_expect_init(exp, NF_CT_EXPECT_CLASS_DEFAULT, nf_ct_l3num(ct),
                          &ct->tuplehash[!dir].tuple.src.u3,
                          &ct->tuplehash[!dir].tuple.dst.u3,
                          IPPROTO_TCP, NULL, &port);
@@ -361,7 +360,7 @@ static int expect_t120(struct sk_buff *skb,
        } else {                /* Conntrack only */
                if (nf_ct_expect_related(exp) == 0) {
                        pr_debug("nf_ct_h323: expect T.120 ");
-                       NF_CT_DUMP_TUPLE(&exp->tuple);
+                       nf_ct_dump_tuple(&exp->tuple);
                } else
                        ret = -1;
        }
@@ -583,7 +582,7 @@ static int h245_help(struct sk_buff *skb, unsigned int protoff,
        while (get_tpkt_data(skb, protoff, ct, ctinfo,
                             &data, &datalen, &dataoff)) {
                pr_debug("nf_ct_h245: TPKT len=%d ", datalen);
-               NF_CT_DUMP_TUPLE(&ct->tuplehash[CTINFO2DIR(ctinfo)].tuple);
+               nf_ct_dump_tuple(&ct->tuplehash[CTINFO2DIR(ctinfo)].tuple);
 
                /* Decode H.245 signal */
                ret = DecodeMultimediaSystemControlMessage(data, datalen,
@@ -612,13 +611,18 @@ static int h245_help(struct sk_buff *skb, unsigned int protoff,
 }
 
 /****************************************************************************/
+static const struct nf_conntrack_expect_policy h245_exp_policy = {
+       .max_expected   = H323_RTP_CHANNEL_MAX * 4 + 2 /* T.120 */,
+       .timeout        = 240,
+};
+
 static struct nf_conntrack_helper nf_conntrack_helper_h245 __read_mostly = {
        .name                   = "H.245",
        .me                     = THIS_MODULE,
-       .max_expected           = H323_RTP_CHANNEL_MAX * 4 + 2 /* T.120 */,
-       .timeout                = 240,
+       .tuple.src.l3num        = AF_UNSPEC,
        .tuple.dst.protonum     = IPPROTO_UDP,
-       .help                   = h245_help
+       .help                   = h245_help,
+       .expect_policy          = &h245_exp_policy,
 };
 
 /****************************************************************************/
@@ -627,18 +631,17 @@ int get_h225_addr(struct nf_conn *ct, unsigned char *data,
                  union nf_inet_addr *addr, __be16 *port)
 {
        const unsigned char *p;
-       int family = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.l3num;
        int len;
 
        switch (taddr->choice) {
        case eTransportAddress_ipAddress:
-               if (family != AF_INET)
+               if (nf_ct_l3num(ct) != AF_INET)
                        return 0;
                p = data + taddr->ipAddress.ip;
                len = 4;
                break;
        case eTransportAddress_ip6Address:
-               if (family != AF_INET6)
+               if (nf_ct_l3num(ct) != AF_INET6)
                        return 0;
                p = data + taddr->ip6Address.ip;
                len = 16;
@@ -676,7 +679,7 @@ static int expect_h245(struct sk_buff *skb, struct nf_conn *ct,
        /* Create expect for h245 connection */
        if ((exp = nf_ct_expect_alloc(ct)) == NULL)
                return -1;
-       nf_ct_expect_init(exp, ct->tuplehash[!dir].tuple.src.l3num,
+       nf_ct_expect_init(exp, NF_CT_EXPECT_CLASS_DEFAULT, nf_ct_l3num(ct),
                          &ct->tuplehash[!dir].tuple.src.u3,
                          &ct->tuplehash[!dir].tuple.dst.u3,
                          IPPROTO_TCP, NULL, &port);
@@ -693,7 +696,7 @@ static int expect_h245(struct sk_buff *skb, struct nf_conn *ct,
        } else {                /* Conntrack only */
                if (nf_ct_expect_related(exp) == 0) {
                        pr_debug("nf_ct_q931: expect H.245 ");
-                       NF_CT_DUMP_TUPLE(&exp->tuple);
+                       nf_ct_dump_tuple(&exp->tuple);
                } else
                        ret = -1;
        }
@@ -706,7 +709,8 @@ static int expect_h245(struct sk_buff *skb, struct nf_conn *ct,
 /* If the calling party is on the same side of the forward-to party,
  * we don't need to track the second call */
 static int callforward_do_filter(const union nf_inet_addr *src,
-                                 const union nf_inet_addr *dst, int family)
+                                const union nf_inet_addr *dst,
+                                u_int8_t family)
 {
        const struct nf_afinfo *afinfo;
        struct flowi fl1, fl2;
@@ -784,7 +788,7 @@ static int expect_callforwarding(struct sk_buff *skb,
         * we don't need to track the second call */
        if (callforward_filter &&
            callforward_do_filter(&addr, &ct->tuplehash[!dir].tuple.src.u3,
-                                 ct->tuplehash[!dir].tuple.src.l3num)) {
+                                 nf_ct_l3num(ct))) {
                pr_debug("nf_ct_q931: Call Forwarding not tracked\n");
                return 0;
        }
@@ -792,7 +796,7 @@ static int expect_callforwarding(struct sk_buff *skb,
        /* Create expect for the second call leg */
        if ((exp = nf_ct_expect_alloc(ct)) == NULL)
                return -1;
-       nf_ct_expect_init(exp, ct->tuplehash[!dir].tuple.src.l3num,
+       nf_ct_expect_init(exp, NF_CT_EXPECT_CLASS_DEFAULT, nf_ct_l3num(ct),
                          &ct->tuplehash[!dir].tuple.src.u3, &addr,
                          IPPROTO_TCP, NULL, &port);
        exp->helper = nf_conntrack_helper_q931;
@@ -808,7 +812,7 @@ static int expect_callforwarding(struct sk_buff *skb,
        } else {                /* Conntrack only */
                if (nf_ct_expect_related(exp) == 0) {
                        pr_debug("nf_ct_q931: expect Call Forwarding ");
-                       NF_CT_DUMP_TUPLE(&exp->tuple);
+                       nf_ct_dump_tuple(&exp->tuple);
                } else
                        ret = -1;
        }
@@ -846,10 +850,8 @@ static int process_setup(struct sk_buff *skb, struct nf_conn *ct,
            get_h225_addr(ct, *data, &setup->destCallSignalAddress,
                          &addr, &port) &&
            memcmp(&addr, &ct->tuplehash[!dir].tuple.src.u3, sizeof(addr))) {
-               pr_debug("nf_ct_q931: set destCallSignalAddress "
-                        NIP6_FMT ":%hu->" NIP6_FMT ":%hu\n",
-                        NIP6(*(struct in6_addr *)&addr), ntohs(port),
-                        NIP6(*(struct in6_addr *)&ct->tuplehash[!dir].tuple.src.u3),
+               pr_debug("nf_ct_q931: set destCallSignalAddress %pI6:%hu->%pI6:%hu\n",
+                        &addr, ntohs(port), &ct->tuplehash[!dir].tuple.src.u3,
                         ntohs(ct->tuplehash[!dir].tuple.src.u.tcp.port));
                ret = set_h225_addr(skb, data, dataoff,
                                    &setup->destCallSignalAddress,
@@ -864,10 +866,8 @@ static int process_setup(struct sk_buff *skb, struct nf_conn *ct,
            get_h225_addr(ct, *data, &setup->sourceCallSignalAddress,
                          &addr, &port) &&
            memcmp(&addr, &ct->tuplehash[!dir].tuple.dst.u3, sizeof(addr))) {
-               pr_debug("nf_ct_q931: set sourceCallSignalAddress "
-                        NIP6_FMT ":%hu->" NIP6_FMT ":%hu\n",
-                        NIP6(*(struct in6_addr *)&addr), ntohs(port),
-                        NIP6(*(struct in6_addr *)&ct->tuplehash[!dir].tuple.dst.u3),
+               pr_debug("nf_ct_q931: set sourceCallSignalAddress %pI6:%hu->%pI6:%hu\n",
+                        &addr, ntohs(port), &ct->tuplehash[!dir].tuple.dst.u3,
                         ntohs(ct->tuplehash[!dir].tuple.dst.u.tcp.port));
                ret = set_h225_addr(skb, data, dataoff,
                                    &setup->sourceCallSignalAddress,
@@ -1128,7 +1128,7 @@ static int q931_help(struct sk_buff *skb, unsigned int protoff,
        while (get_tpkt_data(skb, protoff, ct, ctinfo,
                             &data, &datalen, &dataoff)) {
                pr_debug("nf_ct_q931: TPKT len=%d ", datalen);
-               NF_CT_DUMP_TUPLE(&ct->tuplehash[CTINFO2DIR(ctinfo)].tuple);
+               nf_ct_dump_tuple(&ct->tuplehash[CTINFO2DIR(ctinfo)].tuple);
 
                /* Decode Q.931 signal */
                ret = DecodeQ931(data, datalen, &q931);
@@ -1156,28 +1156,30 @@ static int q931_help(struct sk_buff *skb, unsigned int protoff,
 }
 
 /****************************************************************************/
+static const struct nf_conntrack_expect_policy q931_exp_policy = {
+       /* T.120 and H.245 */
+       .max_expected           = H323_RTP_CHANNEL_MAX * 4 + 4,
+       .timeout                = 240,
+};
+
 static struct nf_conntrack_helper nf_conntrack_helper_q931[] __read_mostly = {
        {
                .name                   = "Q.931",
                .me                     = THIS_MODULE,
-                                         /* T.120 and H.245 */
-               .max_expected           = H323_RTP_CHANNEL_MAX * 4 + 4,
-               .timeout                = 240,
                .tuple.src.l3num        = AF_INET,
-               .tuple.src.u.tcp.port   = __constant_htons(Q931_PORT),
+               .tuple.src.u.tcp.port   = cpu_to_be16(Q931_PORT),
                .tuple.dst.protonum     = IPPROTO_TCP,
-               .help                   = q931_help
+               .help                   = q931_help,
+               .expect_policy          = &q931_exp_policy,
        },
        {
                .name                   = "Q.931",
                .me                     = THIS_MODULE,
-                                         /* T.120 and H.245 */
-               .max_expected           = H323_RTP_CHANNEL_MAX * 4 + 4,
-               .timeout                = 240,
                .tuple.src.l3num        = AF_INET6,
-               .tuple.src.u.tcp.port   = __constant_htons(Q931_PORT),
+               .tuple.src.u.tcp.port   = cpu_to_be16(Q931_PORT),
                .tuple.dst.protonum     = IPPROTO_TCP,
-               .help                   = q931_help
+               .help                   = q931_help,
+               .expect_policy          = &q931_exp_policy,
        },
 };
 
@@ -1204,6 +1206,7 @@ static struct nf_conntrack_expect *find_expect(struct nf_conn *ct,
                                               union nf_inet_addr *addr,
                                               __be16 port)
 {
+       struct net *net = nf_ct_net(ct);
        struct nf_conntrack_expect *exp;
        struct nf_conntrack_tuple tuple;
 
@@ -1213,7 +1216,7 @@ static struct nf_conntrack_expect *find_expect(struct nf_conn *ct,
        tuple.dst.u.tcp.port = port;
        tuple.dst.protonum = IPPROTO_TCP;
 
-       exp = __nf_ct_expect_find(&tuple);
+       exp = __nf_ct_expect_find(net, &tuple);
        if (exp && exp->master == ct)
                return exp;
        return NULL;
@@ -1261,7 +1264,7 @@ static int expect_q931(struct sk_buff *skb, struct nf_conn *ct,
        /* Create expect for Q.931 */
        if ((exp = nf_ct_expect_alloc(ct)) == NULL)
                return -1;
-       nf_ct_expect_init(exp, ct->tuplehash[!dir].tuple.src.l3num,
+       nf_ct_expect_init(exp, NF_CT_EXPECT_CLASS_DEFAULT, nf_ct_l3num(ct),
                          gkrouted_only ? /* only accept calls from GK? */
                                &ct->tuplehash[!dir].tuple.src.u3 : NULL,
                          &ct->tuplehash[!dir].tuple.dst.u3,
@@ -1275,7 +1278,7 @@ static int expect_q931(struct sk_buff *skb, struct nf_conn *ct,
        } else {                /* Conntrack only */
                if (nf_ct_expect_related(exp) == 0) {
                        pr_debug("nf_ct_ras: expect Q.931 ");
-                       NF_CT_DUMP_TUPLE(&exp->tuple);
+                       nf_ct_dump_tuple(&exp->tuple);
 
                        /* Save port for looking up expect in processing RCF */
                        info->sig_port[dir] = port;
@@ -1332,14 +1335,14 @@ static int process_gcf(struct sk_buff *skb, struct nf_conn *ct,
        /* Need new expect */
        if ((exp = nf_ct_expect_alloc(ct)) == NULL)
                return -1;
-       nf_ct_expect_init(exp, ct->tuplehash[!dir].tuple.src.l3num,
+       nf_ct_expect_init(exp, NF_CT_EXPECT_CLASS_DEFAULT, nf_ct_l3num(ct),
                          &ct->tuplehash[!dir].tuple.src.u3, &addr,
                          IPPROTO_UDP, NULL, &port);
        exp->helper = nf_conntrack_helper_ras;
 
        if (nf_ct_expect_related(exp) == 0) {
                pr_debug("nf_ct_ras: expect RAS ");
-               NF_CT_DUMP_TUPLE(&exp->tuple);
+               nf_ct_dump_tuple(&exp->tuple);
        } else
                ret = -1;
 
@@ -1423,7 +1426,7 @@ static int process_rcf(struct sk_buff *skb, struct nf_conn *ct,
                        pr_debug("nf_ct_ras: set Q.931 expect "
                                 "timeout to %u seconds for",
                                 info->timeout);
-                       NF_CT_DUMP_TUPLE(&exp->tuple);
+                       nf_ct_dump_tuple(&exp->tuple);
                        set_expect_timeout(exp, info->timeout);
                }
                spin_unlock_bh(&nf_conntrack_lock);
@@ -1536,7 +1539,7 @@ static int process_acf(struct sk_buff *skb, struct nf_conn *ct,
        /* Need new expect */
        if ((exp = nf_ct_expect_alloc(ct)) == NULL)
                return -1;
-       nf_ct_expect_init(exp, ct->tuplehash[!dir].tuple.src.l3num,
+       nf_ct_expect_init(exp, NF_CT_EXPECT_CLASS_DEFAULT, nf_ct_l3num(ct),
                          &ct->tuplehash[!dir].tuple.src.u3, &addr,
                          IPPROTO_TCP, NULL, &port);
        exp->flags = NF_CT_EXPECT_PERMANENT;
@@ -1544,7 +1547,7 @@ static int process_acf(struct sk_buff *skb, struct nf_conn *ct,
 
        if (nf_ct_expect_related(exp) == 0) {
                pr_debug("nf_ct_ras: expect Q.931 ");
-               NF_CT_DUMP_TUPLE(&exp->tuple);
+               nf_ct_dump_tuple(&exp->tuple);
        } else
                ret = -1;
 
@@ -1589,7 +1592,7 @@ static int process_lcf(struct sk_buff *skb, struct nf_conn *ct,
        /* Need new expect for call signal */
        if ((exp = nf_ct_expect_alloc(ct)) == NULL)
                return -1;
-       nf_ct_expect_init(exp, ct->tuplehash[!dir].tuple.src.l3num,
+       nf_ct_expect_init(exp, NF_CT_EXPECT_CLASS_DEFAULT, nf_ct_l3num(ct),
                          &ct->tuplehash[!dir].tuple.src.u3, &addr,
                          IPPROTO_TCP, NULL, &port);
        exp->flags = NF_CT_EXPECT_PERMANENT;
@@ -1597,7 +1600,7 @@ static int process_lcf(struct sk_buff *skb, struct nf_conn *ct,
 
        if (nf_ct_expect_related(exp) == 0) {
                pr_debug("nf_ct_ras: expect Q.931 ");
-               NF_CT_DUMP_TUPLE(&exp->tuple);
+               nf_ct_dump_tuple(&exp->tuple);
        } else
                ret = -1;
 
@@ -1701,7 +1704,7 @@ static int ras_help(struct sk_buff *skb, unsigned int protoff,
        if (data == NULL)
                goto accept;
        pr_debug("nf_ct_ras: RAS message len=%d ", datalen);
-       NF_CT_DUMP_TUPLE(&ct->tuplehash[CTINFO2DIR(ctinfo)].tuple);
+       nf_ct_dump_tuple(&ct->tuplehash[CTINFO2DIR(ctinfo)].tuple);
 
        /* Decode RAS message */
        ret = DecodeRasMessage(data, datalen, &ras);
@@ -1728,26 +1731,29 @@ static int ras_help(struct sk_buff *skb, unsigned int protoff,
 }
 
 /****************************************************************************/
+static const struct nf_conntrack_expect_policy ras_exp_policy = {
+       .max_expected           = 32,
+       .timeout                = 240,
+};
+
 static struct nf_conntrack_helper nf_conntrack_helper_ras[] __read_mostly = {
        {
                .name                   = "RAS",
                .me                     = THIS_MODULE,
-               .max_expected           = 32,
-               .timeout                = 240,
                .tuple.src.l3num        = AF_INET,
-               .tuple.src.u.udp.port   = __constant_htons(RAS_PORT),
+               .tuple.src.u.udp.port   = cpu_to_be16(RAS_PORT),
                .tuple.dst.protonum     = IPPROTO_UDP,
                .help                   = ras_help,
+               .expect_policy          = &ras_exp_policy,
        },
        {
                .name                   = "RAS",
                .me                     = THIS_MODULE,
-               .max_expected           = 32,
-               .timeout                = 240,
                .tuple.src.l3num        = AF_INET6,
-               .tuple.src.u.udp.port   = __constant_htons(RAS_PORT),
+               .tuple.src.u.udp.port   = cpu_to_be16(RAS_PORT),
                .tuple.dst.protonum     = IPPROTO_UDP,
                .help                   = ras_help,
+               .expect_policy          = &ras_exp_policy,
        },
 };
 
@@ -1758,6 +1764,7 @@ static void __exit nf_conntrack_h323_fini(void)
        nf_conntrack_helper_unregister(&nf_conntrack_helper_ras[0]);
        nf_conntrack_helper_unregister(&nf_conntrack_helper_q931[1]);
        nf_conntrack_helper_unregister(&nf_conntrack_helper_q931[0]);
+       nf_conntrack_helper_unregister(&nf_conntrack_helper_h245);
        kfree(h323_buffer);
        pr_debug("nf_ct_h323: fini\n");
 }
@@ -1770,28 +1777,34 @@ static int __init nf_conntrack_h323_init(void)
        h323_buffer = kmalloc(65536, GFP_KERNEL);
        if (!h323_buffer)
                return -ENOMEM;
-       ret = nf_conntrack_helper_register(&nf_conntrack_helper_q931[0]);
+       ret = nf_conntrack_helper_register(&nf_conntrack_helper_h245);
        if (ret < 0)
                goto err1;
-       ret = nf_conntrack_helper_register(&nf_conntrack_helper_q931[1]);
+       ret = nf_conntrack_helper_register(&nf_conntrack_helper_q931[0]);
        if (ret < 0)
                goto err2;
-       ret = nf_conntrack_helper_register(&nf_conntrack_helper_ras[0]);
+       ret = nf_conntrack_helper_register(&nf_conntrack_helper_q931[1]);
        if (ret < 0)
                goto err3;
-       ret = nf_conntrack_helper_register(&nf_conntrack_helper_ras[1]);
+       ret = nf_conntrack_helper_register(&nf_conntrack_helper_ras[0]);
        if (ret < 0)
                goto err4;
+       ret = nf_conntrack_helper_register(&nf_conntrack_helper_ras[1]);
+       if (ret < 0)
+               goto err5;
        pr_debug("nf_ct_h323: init success\n");
        return 0;
 
-err4:
+err5:
        nf_conntrack_helper_unregister(&nf_conntrack_helper_ras[0]);
-err3:
+err4:
        nf_conntrack_helper_unregister(&nf_conntrack_helper_q931[1]);
-err2:
+err3:
        nf_conntrack_helper_unregister(&nf_conntrack_helper_q931[0]);
+err2:
+       nf_conntrack_helper_unregister(&nf_conntrack_helper_h245);
 err1:
+       kfree(h323_buffer);
        return ret;
 }
 
@@ -1814,3 +1827,4 @@ MODULE_AUTHOR("Jing Min Zhao <zhaojingmin@users.sourceforge.net>");
 MODULE_DESCRIPTION("H.323 connection tracking helper");
 MODULE_LICENSE("GPL");
 MODULE_ALIAS("ip_conntrack_h323");
+MODULE_ALIAS_NFCT_HELPER("h323");