{
        if (cb->args[1])
                nf_ct_put((struct nf_conn *)cb->args[1]);
+       if (cb->data)
+               kfree(cb->data);
        return 0;
 }
 
+struct ctnetlink_dump_filter {
+       struct {
+               u_int32_t val;
+               u_int32_t mask;
+       } mark;
+};
+
 static int
 ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb)
 {
        struct hlist_nulls_node *n;
        struct nfgenmsg *nfmsg = nlmsg_data(cb->nlh);
        u_int8_t l3proto = nfmsg->nfgen_family;
-
+#ifdef CONFIG_NF_CONNTRACK_MARK
+       const struct ctnetlink_dump_filter *filter = cb->data;
+#endif
        spin_lock_bh(&nf_conntrack_lock);
        last = (struct nf_conn *)cb->args[1];
        for (; cb->args[0] < net->ct.htable_size; cb->args[0]++) {
                                        continue;
                                cb->args[1] = 0;
                        }
+#ifdef CONFIG_NF_CONNTRACK_MARK
+                       if (filter && !((ct->mark & filter->mark.mask) ==
+                                       filter->mark.val)) {
+                               continue;
+                       }
+#endif
                        if (ctnetlink_fill_info(skb, NETLINK_CB(cb->skb).pid,
                                                cb->nlh->nlmsg_seq,
                                                NFNL_MSG_TYPE(
        [CTA_NAT_DST]           = { .type = NLA_NESTED },
        [CTA_TUPLE_MASTER]      = { .type = NLA_NESTED },
        [CTA_ZONE]              = { .type = NLA_U16 },
+       [CTA_MARK_MASK]         = { .type = NLA_U32 },
 };
 
 static int
                        .dump = ctnetlink_dump_table,
                        .done = ctnetlink_done,
                };
+#ifdef CONFIG_NF_CONNTRACK_MARK
+               if (cda[CTA_MARK] && cda[CTA_MARK_MASK]) {
+                       struct ctnetlink_dump_filter *filter;
+
+                       filter = kzalloc(sizeof(struct ctnetlink_dump_filter),
+                                        GFP_ATOMIC);
+                       if (filter == NULL)
+                               return -ENOMEM;
+
+                       filter->mark.val = ntohl(nla_get_be32(cda[CTA_MARK]));
+                       filter->mark.mask =
+                               ntohl(nla_get_be32(cda[CTA_MARK_MASK]));
+                       c.data = filter;
+               }
+#endif
                return netlink_dump_start(ctnl, skb, nlh, &c);
        }