]> err.no Git - linux-2.6/blobdiff - net/netfilter/nf_conntrack_netlink.c
[NETFILTER]: nf_conntrack_ftp: fix missing helper mask initilization
[linux-2.6] / net / netfilter / nf_conntrack_netlink.c
index 1721f7c78c77b5dcc5ca59d3a82962d7230ee29a..dc0830220130de4e154b21ac2879eb0133fd96d1 100644 (file)
 #include <linux/netfilter.h>
 #include <net/netfilter/nf_conntrack.h>
 #include <net/netfilter/nf_conntrack_core.h>
+#include <net/netfilter/nf_conntrack_expect.h>
 #include <net/netfilter/nf_conntrack_helper.h>
 #include <net/netfilter/nf_conntrack_l3proto.h>
-#include <net/netfilter/nf_conntrack_protocol.h>
+#include <net/netfilter/nf_conntrack_l4proto.h>
 #include <linux/netfilter_ipv4/ip_nat_protocol.h>
 
 #include <linux/netfilter/nfnetlink.h>
@@ -47,25 +48,18 @@ MODULE_LICENSE("GPL");
 
 static char __initdata version[] = "0.93";
 
-#if 0
-#define DEBUGP printk
-#else
-#define DEBUGP(format, args...)
-#endif
-
-
 static inline int
 ctnetlink_dump_tuples_proto(struct sk_buff *skb, 
                            const struct nf_conntrack_tuple *tuple,
-                           struct nf_conntrack_protocol *proto)
+                           struct nf_conntrack_l4proto *l4proto)
 {
        int ret = 0;
        struct nfattr *nest_parms = NFA_NEST(skb, CTA_TUPLE_PROTO);
 
        NFA_PUT(skb, CTA_PROTO_NUM, sizeof(u_int8_t), &tuple->dst.protonum);
 
-       if (likely(proto->tuple_to_nfattr))
-               ret = proto->tuple_to_nfattr(skb, tuple);
+       if (likely(l4proto->tuple_to_nfattr))
+               ret = l4proto->tuple_to_nfattr(skb, tuple);
        
        NFA_NEST_END(skb, nest_parms);
 
@@ -100,7 +94,7 @@ ctnetlink_dump_tuples(struct sk_buff *skb,
 {
        int ret;
        struct nf_conntrack_l3proto *l3proto;
-       struct nf_conntrack_protocol *proto;
+       struct nf_conntrack_l4proto *l4proto;
 
        l3proto = nf_ct_l3proto_find_get(tuple->src.l3num);
        ret = ctnetlink_dump_tuples_ip(skb, tuple, l3proto);
@@ -109,9 +103,9 @@ ctnetlink_dump_tuples(struct sk_buff *skb,
        if (unlikely(ret < 0))
                return ret;
 
-       proto = nf_ct_proto_find_get(tuple->src.l3num, tuple->dst.protonum);
-       ret = ctnetlink_dump_tuples_proto(skb, tuple, proto);
-       nf_ct_proto_put(proto);
+       l4proto = nf_ct_l4proto_find_get(tuple->src.l3num, tuple->dst.protonum);
+       ret = ctnetlink_dump_tuples_proto(skb, tuple, l4proto);
+       nf_ct_l4proto_put(l4proto);
 
        return ret;
 }
@@ -148,26 +142,27 @@ nfattr_failure:
 static inline int
 ctnetlink_dump_protoinfo(struct sk_buff *skb, const struct nf_conn *ct)
 {
-       struct nf_conntrack_protocol *proto = nf_ct_proto_find_get(ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.l3num, ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum);
+       struct nf_conntrack_l4proto *l4proto = nf_ct_l4proto_find_get(ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.l3num, ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum);
        struct nfattr *nest_proto;
        int ret;
 
-       if (!proto->to_nfattr) {
-               nf_ct_proto_put(proto);
+       if (!l4proto->to_nfattr) {
+               nf_ct_l4proto_put(l4proto);
                return 0;
        }
        
        nest_proto = NFA_NEST(skb, CTA_PROTOINFO);
 
-       ret = proto->to_nfattr(skb, nest_proto, ct);
+       ret = l4proto->to_nfattr(skb, nest_proto, ct);
 
-       nf_ct_proto_put(proto);
+       nf_ct_l4proto_put(l4proto);
 
        NFA_NEST_END(skb, nest_proto);
 
        return ret;
 
 nfattr_failure:
+       nf_ct_l4proto_put(l4proto);
        return -1;
 }
 
@@ -410,7 +405,6 @@ static int ctnetlink_done(struct netlink_callback *cb)
 {
        if (cb->args[1])
                nf_ct_put((struct nf_conn *)cb->args[1]);
-       DEBUGP("entered %s\n", __FUNCTION__);
        return 0;
 }
 
@@ -425,9 +419,6 @@ ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb)
        struct nfgenmsg *nfmsg = NLMSG_DATA(cb->nlh);
        u_int8_t l3proto = nfmsg->nfgen_family;
 
-       DEBUGP("entered %s, last bucket=%lu id=%u\n", __FUNCTION__, 
-                       cb->args[0], *id);
-
        read_lock_bh(&nf_conntrack_lock);
        last = (struct nf_conn *)cb->args[1];
        for (; cb->args[0] < nf_conntrack_htable_size; cb->args[0]++) {
@@ -471,7 +462,6 @@ out:
        if (last)
                nf_ct_put(last);
 
-       DEBUGP("leaving, last bucket=%lu id=%u\n", cb->args[0], *id);
        return skb->len;
 }
 
@@ -482,8 +472,6 @@ ctnetlink_parse_tuple_ip(struct nfattr *attr, struct nf_conntrack_tuple *tuple)
        struct nf_conntrack_l3proto *l3proto;
        int ret = 0;
 
-       DEBUGP("entered %s\n", __FUNCTION__);
-
        nfattr_parse_nested(tb, CTA_IP_MAX, attr);
 
        l3proto = nf_ct_l3proto_find_get(tuple->src.l3num);
@@ -493,8 +481,6 @@ ctnetlink_parse_tuple_ip(struct nfattr *attr, struct nf_conntrack_tuple *tuple)
 
        nf_ct_l3proto_put(l3proto);
 
-       DEBUGP("leaving\n");
-
        return ret;
 }
 
@@ -507,11 +493,9 @@ ctnetlink_parse_tuple_proto(struct nfattr *attr,
                            struct nf_conntrack_tuple *tuple)
 {
        struct nfattr *tb[CTA_PROTO_MAX];
-       struct nf_conntrack_protocol *proto;
+       struct nf_conntrack_l4proto *l4proto;
        int ret = 0;
 
-       DEBUGP("entered %s\n", __FUNCTION__);
-
        nfattr_parse_nested(tb, CTA_PROTO_MAX, attr);
 
        if (nfattr_bad_size(tb, CTA_PROTO_MAX, cta_min_proto))
@@ -521,12 +505,12 @@ ctnetlink_parse_tuple_proto(struct nfattr *attr,
                return -EINVAL;
        tuple->dst.protonum = *(u_int8_t *)NFA_DATA(tb[CTA_PROTO_NUM-1]);
 
-       proto = nf_ct_proto_find_get(tuple->src.l3num, tuple->dst.protonum);
+       l4proto = nf_ct_l4proto_find_get(tuple->src.l3num, tuple->dst.protonum);
 
-       if (likely(proto->nfattr_to_tuple))
-               ret = proto->nfattr_to_tuple(tb, tuple);
+       if (likely(l4proto->nfattr_to_tuple))
+               ret = l4proto->nfattr_to_tuple(tb, tuple);
 
-       nf_ct_proto_put(proto);
+       nf_ct_l4proto_put(l4proto);
        
        return ret;
 }
@@ -538,8 +522,6 @@ ctnetlink_parse_tuple(struct nfattr *cda[], struct nf_conntrack_tuple *tuple,
        struct nfattr *tb[CTA_TUPLE_MAX];
        int err;
 
-       DEBUGP("entered %s\n", __FUNCTION__);
-
        memset(tuple, 0, sizeof(*tuple));
 
        nfattr_parse_nested(tb, CTA_TUPLE_MAX, cda[type-1]);
@@ -566,10 +548,6 @@ ctnetlink_parse_tuple(struct nfattr *cda[], struct nf_conntrack_tuple *tuple,
        else
                tuple->dst.dir = IP_CT_DIR_ORIGINAL;
 
-       NF_CT_DUMP_TUPLE(tuple);
-
-       DEBUGP("leaving\n");
-
        return 0;
 }
 
@@ -586,8 +564,6 @@ static int ctnetlink_parse_nat_proto(struct nfattr *attr,
        struct nfattr *tb[CTA_PROTONAT_MAX];
        struct ip_nat_protocol *npt;
 
-       DEBUGP("entered %s\n", __FUNCTION__);
-
        nfattr_parse_nested(tb, CTA_PROTONAT_MAX, attr);
 
        if (nfattr_bad_size(tb, CTA_PROTONAT_MAX, cta_min_protonat))
@@ -606,7 +582,6 @@ static int ctnetlink_parse_nat_proto(struct nfattr *attr,
 
        ip_nat_proto_put(npt);
 
-       DEBUGP("leaving\n");
        return 0;
 }
 
@@ -622,8 +597,6 @@ ctnetlink_parse_nat(struct nfattr *nat,
        struct nfattr *tb[CTA_NAT_MAX];
        int err;
 
-       DEBUGP("entered %s\n", __FUNCTION__);
-
        memset(range, 0, sizeof(*range));
        
        nfattr_parse_nested(tb, CTA_NAT_MAX, nat);
@@ -649,7 +622,6 @@ ctnetlink_parse_nat(struct nfattr *nat,
        if (err < 0)
                return err;
 
-       DEBUGP("leaving\n");
        return 0;
 }
 #endif
@@ -659,8 +631,6 @@ ctnetlink_parse_help(struct nfattr *attr, char **helper_name)
 {
        struct nfattr *tb[CTA_HELP_MAX];
 
-       DEBUGP("entered %s\n", __FUNCTION__);
-
        nfattr_parse_nested(tb, CTA_HELP_MAX, attr);
 
        if (!tb[CTA_HELP_NAME-1])
@@ -690,8 +660,6 @@ ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb,
        u_int8_t u3 = nfmsg->nfgen_family;
        int err = 0;
 
-       DEBUGP("entered %s\n", __FUNCTION__);
-
        if (nfattr_bad_size(cda, CTA_MAX, cta_min))
                return -EINVAL;
 
@@ -709,10 +677,8 @@ ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb,
                return err;
 
        h = nf_conntrack_find_get(&tuple, NULL);
-       if (!h) {
-               DEBUGP("tuple not found in conntrack hash\n");
+       if (!h)
                return -ENOENT;
-       }
 
        ct = nf_ct_tuplehash_to_ctrack(h);
        
@@ -727,7 +693,6 @@ ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb,
                ct->timeout.function((unsigned long)ct);
 
        nf_ct_put(ct);
-       DEBUGP("leaving\n");
 
        return 0;
 }
@@ -744,8 +709,6 @@ ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb,
        u_int8_t u3 = nfmsg->nfgen_family;
        int err = 0;
 
-       DEBUGP("entered %s\n", __FUNCTION__);
-
        if (nlh->nlmsg_flags & NLM_F_DUMP) {
                u32 rlen;
 
@@ -779,11 +742,9 @@ ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb,
                return err;
 
        h = nf_conntrack_find_get(&tuple, NULL);
-       if (!h) {
-               DEBUGP("tuple not found in conntrack hash");
+       if (!h)
                return -ENOENT;
-       }
-       DEBUGP("tuple found\n");
+
        ct = nf_ct_tuplehash_to_ctrack(h);
 
        err = -ENOMEM;
@@ -792,7 +753,6 @@ ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb,
                nf_ct_put(ct);
                return -ENOMEM;
        }
-       NETLINK_CB(skb2).dst_pid = NETLINK_CB(skb).pid;
 
        err = ctnetlink_fill_info(skb2, NETLINK_CB(skb).pid, nlh->nlmsg_seq, 
                                  IPCTNL_MSG_CT_NEW, 1, ct);
@@ -804,7 +764,6 @@ ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb,
        if (err < 0)
                goto out;
 
-       DEBUGP("leaving\n");
        return 0;
 
 free:
@@ -876,8 +835,6 @@ ctnetlink_change_helper(struct nf_conn *ct, struct nfattr *cda[])
        char *helpname;
        int err;
 
-       DEBUGP("entered %s\n", __FUNCTION__);
-
        if (!help) {
                /* FIXME: we need to reallocate and rehash */
                return -EBUSY;
@@ -933,18 +890,18 @@ static inline int
 ctnetlink_change_protoinfo(struct nf_conn *ct, struct nfattr *cda[])
 {
        struct nfattr *tb[CTA_PROTOINFO_MAX], *attr = cda[CTA_PROTOINFO-1];
-       struct nf_conntrack_protocol *proto;
+       struct nf_conntrack_l4proto *l4proto;
        u_int16_t npt = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum;
        u_int16_t l3num = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.l3num;
        int err = 0;
 
        nfattr_parse_nested(tb, CTA_PROTOINFO_MAX, attr);
 
-       proto = nf_ct_proto_find_get(l3num, npt);
+       l4proto = nf_ct_l4proto_find_get(l3num, npt);
 
-       if (proto->from_nfattr)
-               err = proto->from_nfattr(tb, ct);
-       nf_ct_proto_put(proto); 
+       if (l4proto->from_nfattr)
+               err = l4proto->from_nfattr(tb, ct);
+       nf_ct_l4proto_put(l4proto);
 
        return err;
 }
@@ -954,8 +911,6 @@ ctnetlink_change_conntrack(struct nf_conn *ct, struct nfattr *cda[])
 {
        int err;
 
-       DEBUGP("entered %s\n", __FUNCTION__);
-
        if (cda[CTA_HELP-1]) {
                err = ctnetlink_change_helper(ct, cda);
                if (err < 0)
@@ -985,7 +940,6 @@ ctnetlink_change_conntrack(struct nf_conn *ct, struct nfattr *cda[])
                ct->mark = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_MARK-1]));
 #endif
 
-       DEBUGP("all done\n");
        return 0;
 }
 
@@ -996,8 +950,7 @@ ctnetlink_create_conntrack(struct nfattr *cda[],
 {
        struct nf_conn *ct;
        int err = -EINVAL;
-
-       DEBUGP("entered %s\n", __FUNCTION__);
+       struct nf_conn_help *help;
 
        ct = nf_conntrack_alloc(otuple, rtuple);
        if (ct == NULL || IS_ERR(ct))
@@ -1025,10 +978,16 @@ ctnetlink_create_conntrack(struct nfattr *cda[],
                ct->mark = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_MARK-1]));
 #endif
 
+       help = nfct_help(ct);
+       if (help)
+               help->helper = nf_ct_helper_find_get(rtuple);
+
        add_timer(&ct->timeout);
        nf_conntrack_hash_insert(ct);
 
-       DEBUGP("conntrack with id %u inserted\n", ct->id);
+       if (help && help->helper)
+               nf_ct_helper_put(help->helper);
+
        return 0;
 
 err:   
@@ -1046,8 +1005,6 @@ ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,
        u_int8_t u3 = nfmsg->nfgen_family;
        int err = 0;
 
-       DEBUGP("entered %s\n", __FUNCTION__);
-
        if (nfattr_bad_size(cda, CTA_MAX, cta_min))
                return -EINVAL;
 
@@ -1071,7 +1028,6 @@ ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,
 
        if (h == NULL) {
                write_unlock_bh(&nf_conntrack_lock);
-               DEBUGP("no such conntrack, create new\n");
                err = -ENOENT;
                if (nlh->nlmsg_flags & NLM_F_CREATE)
                        err = ctnetlink_create_conntrack(cda, &otuple, &rtuple);
@@ -1087,7 +1043,6 @@ ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,
 
        /* We manipulate the conntrack inside the global conntrack table lock,
         * so there's no need to increase the refcount */
-       DEBUGP("conntrack found\n");
        err = -EEXIST;
        if (!(nlh->nlmsg_flags & NLM_F_EXCL))
                err = ctnetlink_change_conntrack(nf_ct_tuplehash_to_ctrack(h), cda);
@@ -1126,7 +1081,7 @@ ctnetlink_exp_dump_mask(struct sk_buff *skb,
 {
        int ret;
        struct nf_conntrack_l3proto *l3proto;
-       struct nf_conntrack_protocol *proto;
+       struct nf_conntrack_l4proto *l4proto;
        struct nfattr *nest_parms = NFA_NEST(skb, CTA_EXPECT_MASK);
 
        l3proto = nf_ct_l3proto_find_get(tuple->src.l3num);
@@ -1136,9 +1091,9 @@ ctnetlink_exp_dump_mask(struct sk_buff *skb,
        if (unlikely(ret < 0))
                goto nfattr_failure;
 
-       proto = nf_ct_proto_find_get(tuple->src.l3num, tuple->dst.protonum);
-       ret = ctnetlink_dump_tuples_proto(skb, mask, proto);
-       nf_ct_proto_put(proto);
+       l4proto = nf_ct_l4proto_find_get(tuple->src.l3num, tuple->dst.protonum);
+       ret = ctnetlink_dump_tuples_proto(skb, mask, l4proto);
+       nf_ct_l4proto_put(l4proto);
        if (unlikely(ret < 0))
                goto nfattr_failure;
 
@@ -1268,8 +1223,6 @@ ctnetlink_exp_dump_table(struct sk_buff *skb, struct netlink_callback *cb)
        struct nfgenmsg *nfmsg = NLMSG_DATA(cb->nlh);
        u_int8_t l3proto = nfmsg->nfgen_family;
 
-       DEBUGP("entered %s, last id=%llu\n", __FUNCTION__, *id);
-
        read_lock_bh(&nf_conntrack_lock);
        list_for_each_prev(i, &nf_conntrack_expect_list) {
                exp = (struct nf_conntrack_expect *) i;
@@ -1287,8 +1240,6 @@ ctnetlink_exp_dump_table(struct sk_buff *skb, struct netlink_callback *cb)
 out:   
        read_unlock_bh(&nf_conntrack_lock);
 
-       DEBUGP("leaving, last id=%llu\n", *id);
-
        return skb->len;
 }
 
@@ -1308,8 +1259,6 @@ ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb,
        u_int8_t u3 = nfmsg->nfgen_family;
        int err = 0;
 
-       DEBUGP("entered %s\n", __FUNCTION__);
-
        if (nfattr_bad_size(cda, CTA_EXPECT_MAX, cta_min_exp))
                return -EINVAL;
 
@@ -1351,8 +1300,7 @@ ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb,
        skb2 = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
        if (!skb2)
                goto out;
-       NETLINK_CB(skb2).dst_pid = NETLINK_CB(skb).pid;
-       
+
        err = ctnetlink_exp_fill_info(skb2, NETLINK_CB(skb).pid, 
                                      nlh->nlmsg_seq, IPCTNL_MSG_EXP_NEW,
                                      1, exp);
@@ -1460,8 +1408,6 @@ ctnetlink_create_expect(struct nfattr *cda[], u_int8_t u3)
        struct nf_conn_help *help;
        int err = 0;
 
-       DEBUGP("entered %s\n", __FUNCTION__);
-
        /* caller guarantees that those three CTA_EXPECT_* exist */
        err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_TUPLE, u3);
        if (err < 0)
@@ -1516,8 +1462,6 @@ ctnetlink_new_expect(struct sock *ctnl, struct sk_buff *skb,
        u_int8_t u3 = nfmsg->nfgen_family;
        int err = 0;
 
-       DEBUGP("entered %s\n", __FUNCTION__);   
-
        if (nfattr_bad_size(cda, CTA_EXPECT_MAX, cta_min_exp))
                return -EINVAL;
 
@@ -1546,8 +1490,6 @@ ctnetlink_new_expect(struct sock *ctnl, struct sk_buff *skb,
                err = ctnetlink_change_expect(exp, cda);
        write_unlock_bh(&nf_conntrack_lock);
 
-       DEBUGP("leaving\n");
-       
        return err;
 }