netfilter: nf_ct_dccp: add missing role attributes for DCCP
authorPablo Neira Ayuso <pablo@netfilter.org>
Fri, 24 Apr 2009 14:58:41 +0000 (16:58 +0200)
committerPatrick McHardy <kaber@trash.net>
Fri, 24 Apr 2009 14:58:41 +0000 (16:58 +0200)
This patch adds missing role attribute to the DCCP type, otherwise
the creation of entries is not of any use.

The attribute added is CTA_PROTOINFO_DCCP_ROLE which contains the
role of the conntrack original tuple.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Patrick McHardy <kaber@trash.net>
include/linux/netfilter/nfnetlink_conntrack.h
net/netfilter/nf_conntrack_proto_dccp.c

index 29fe9ea1d3463a5964ee158eeb1a39211b1c756f..1a865e48b8ebf583a1e6235b64d4ed9fb9eb24d5 100644 (file)
@@ -100,6 +100,7 @@ enum ctattr_protoinfo_tcp {
 enum ctattr_protoinfo_dccp {
        CTA_PROTOINFO_DCCP_UNSPEC,
        CTA_PROTOINFO_DCCP_STATE,
+       CTA_PROTOINFO_DCCP_ROLE,
        __CTA_PROTOINFO_DCCP_MAX,
 };
 #define CTA_PROTOINFO_DCCP_MAX (__CTA_PROTOINFO_DCCP_MAX - 1)
index 5411d63f31a54bb5db00785a6e7039ea088ede18..8e757dd533966bdfd6c1d0ab8b48334e9bab1af7 100644 (file)
@@ -633,6 +633,8 @@ static int dccp_to_nlattr(struct sk_buff *skb, struct nlattr *nla,
        if (!nest_parms)
                goto nla_put_failure;
        NLA_PUT_U8(skb, CTA_PROTOINFO_DCCP_STATE, ct->proto.dccp.state);
+       NLA_PUT_U8(skb, CTA_PROTOINFO_DCCP_ROLE,
+                  ct->proto.dccp.role[IP_CT_DIR_ORIGINAL]);
        nla_nest_end(skb, nest_parms);
        read_unlock_bh(&dccp_lock);
        return 0;
@@ -644,6 +646,7 @@ nla_put_failure:
 
 static const struct nla_policy dccp_nla_policy[CTA_PROTOINFO_DCCP_MAX + 1] = {
        [CTA_PROTOINFO_DCCP_STATE]      = { .type = NLA_U8 },
+       [CTA_PROTOINFO_DCCP_ROLE]       = { .type = NLA_U8 },
 };
 
 static int nlattr_to_dccp(struct nlattr *cda[], struct nf_conn *ct)
@@ -661,11 +664,21 @@ static int nlattr_to_dccp(struct nlattr *cda[], struct nf_conn *ct)
                return err;
 
        if (!tb[CTA_PROTOINFO_DCCP_STATE] ||
-           nla_get_u8(tb[CTA_PROTOINFO_DCCP_STATE]) >= CT_DCCP_IGNORE)
+           !tb[CTA_PROTOINFO_DCCP_ROLE] ||
+           nla_get_u8(tb[CTA_PROTOINFO_DCCP_ROLE]) > CT_DCCP_ROLE_MAX ||
+           nla_get_u8(tb[CTA_PROTOINFO_DCCP_STATE]) >= CT_DCCP_IGNORE) {
                return -EINVAL;
+       }
 
        write_lock_bh(&dccp_lock);
        ct->proto.dccp.state = nla_get_u8(tb[CTA_PROTOINFO_DCCP_STATE]);
+       if (nla_get_u8(tb[CTA_PROTOINFO_DCCP_ROLE]) == CT_DCCP_ROLE_CLIENT) {
+               ct->proto.dccp.role[IP_CT_DIR_ORIGINAL] = CT_DCCP_ROLE_CLIENT;
+               ct->proto.dccp.role[IP_CT_DIR_REPLY] = CT_DCCP_ROLE_SERVER;
+       } else {
+               ct->proto.dccp.role[IP_CT_DIR_ORIGINAL] = CT_DCCP_ROLE_SERVER;
+               ct->proto.dccp.role[IP_CT_DIR_REPLY] = CT_DCCP_ROLE_CLIENT;
+       }
        write_unlock_bh(&dccp_lock);
        return 0;
 }