Skip to contentSkip to conversation

A couple of netfilter fixes

PATCH Applied Pablo Neira Ayuso 2 participants 7 messages May 27, 2009

Subsystems (2)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

cover A couple of netfilter fixes

Hi Patrick,

Are we in time to put these patches into 2.6.30-rc?

---

Pablo Neira Ayuso (2):
netfilter: conntrack: add support for DCCP handshake sequence to ctnetlink
netfilter: nfnetlink_log: fix wrong skbuff size calculation

 include/linux/netfilter/nfnetlink_conntrack.h |    1 +
 net/netfilter/nf_conntrack_proto_dccp.c       |    7 +++++++
 net/netfilter/nfnetlink_log.c                 |    6 ++++++
 3 files changed, 14 insertions(+), 0 deletions(-)
author maintainer
#1 lore raw

PATCH 1/2 netfilter: nfnetlink_log: fix wrong skbuff size calculation

This problem was introduced in 72961ecf84d67d6359a1b30f9b2a8427f13e1e71 since no space was reserved for the new attributes NFULA_HWTYPE, NFULA_HWLEN and NFULA_HWHEADER.

---

 net/netfilter/nfnetlink_log.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
net/netfilter/nfnetlink_log.c +6 -0
index fd326ac..66a6dd5 100644
@@ -581,6 +581,12 @@ nfulnl_log_packet(u_int8_t pf,
 		+ nla_total_size(sizeof(struct nfulnl_msg_packet_hw))
 		+ nla_total_size(sizeof(struct nfulnl_msg_packet_timestamp));
 
+	if (in && skb_mac_header_was_set(skb)) {
+		size +=   nla_total_size(skb->dev->hard_header_len)
+			+ nla_total_size(sizeof(u_int16_t))	/* hwtype */
+			+ nla_total_size(sizeof(u_int16_t));	/* hwlen */
+	}
+
 	spin_lock_bh(&inst->lock);
 
 	if (inst->flags & NFULNL_CFG_F_SEQ)
#2 lore raw

Re: [PATCH 1/2] netfilter: nfnetlink_log: fix wrong skbuff size calculation

Quoted 3 lines · Pablo Neira Ayuso

This problem was introduced in 72961ecf84d67d6359a1b30f9b2a8427f13e1e71 since no space was reserved for the new attributes NFULA_HWTYPE, NFULA_HWLEN and NFULA_HWHEADER.

Applied, thanks Pablo.

author maintainer
#3 lore raw

PATCH 2/2 netfilter: conntrack: add support for DCCP handshake sequence to ctnetlink

In reply to Pablo Neira Ayuso

This patch adds CTA_PROTOINFO_DCCP_HANDSHAKE_SEQ that exposes the u64 handshake sequence number to user-space.

---

 include/linux/netfilter/nfnetlink_conntrack.h |    1 +
 net/netfilter/nf_conntrack_proto_dccp.c       |    7 +++++++
 2 files changed, 8 insertions(+), 0 deletions(-)
include/linux/netfilter/nfnetlink_conntrack.h +1 -0
index 1a865e4..ed4ef8d 100644
@@ -101,6 +101,7 @@ enum ctattr_protoinfo_dccp {
 	CTA_PROTOINFO_DCCP_UNSPEC,
 	CTA_PROTOINFO_DCCP_STATE,
 	CTA_PROTOINFO_DCCP_ROLE,
+	CTA_PROTOINFO_DCCP_HANDSHAKE_SEQ,
 	__CTA_PROTOINFO_DCCP_MAX,
 };
 #define CTA_PROTOINFO_DCCP_MAX (__CTA_PROTOINFO_DCCP_MAX - 1)
net/netfilter/nf_conntrack_proto_dccp.c +7 -0
index aee0d6b..0831b5e 100644
@@ -639,6 +639,8 @@ static int dccp_to_nlattr(struct sk_buff *skb, struct nlattr *nla,
 	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_PUT_U64(skb, CTA_PROTOINFO_DCCP_HANDSHAKE_SEQ,
+		    ct->proto.dccp.handshake_seq);
 	nla_nest_end(skb, nest_parms);
 	read_unlock_bh(&dccp_lock);
 	return 0;
@@ -651,6 +653,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 },
+	[CTA_PROTOINFO_DCCP_HANDSHAKE_SEQ] = { .type = NLA_U64 },
 };
 
 static int nlattr_to_dccp(struct nlattr *cda[], struct nf_conn *ct)
@@ -683,6 +686,10 @@ static int nlattr_to_dccp(struct nlattr *cda[], struct nf_conn *ct)
 		ct->proto.dccp.role[IP_CT_DIR_ORIGINAL] = CT_DCCP_ROLE_SERVER;
 		ct->proto.dccp.role[IP_CT_DIR_REPLY] = CT_DCCP_ROLE_CLIENT;
 	}
+	if (tb[CTA_PROTOINFO_DCCP_HANDSHAKE_SEQ]) {
+		ct->proto.dccp.handshake_seq =
+			nla_get_u64(tb[CTA_PROTOINFO_DCCP_HANDSHAKE_SEQ]);
+	}
 	write_unlock_bh(&dccp_lock);
 	return 0;
 }
#4 lore raw

Re: [PATCH 2/2] netfilter: conntrack: add support for DCCP handshake sequence to ctnetlink

net/netfilter/nf_conntrack_proto_dccp.c static int dccp_to_nlattr(struct sk_buff *skb, struct nlattr *nla, · line 643

Quoted 8 lines · Pablo Neira Ayuso
net/netfilter/nf_conntrack_proto_dccp.c +2 -0
@@ -639,6 +639,8 @@ static int dccp_to_nlattr(struct sk_buff *skb, struct nlattr *nla,
 	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_PUT_U64(skb, CTA_PROTOINFO_DCCP_HANDSHAKE_SEQ,
+		    ct->proto.dccp.handshake_seq);

This should use big endian byteorder.

author maintainer
#5 lore raw

Re: [PATCH 2/2] netfilter: conntrack: add support for DCCP handshake sequence to ctnetlink

Quoted 12 lines · Patrick McHardy

net/netfilter/nf_conntrack_proto_dccp.c static int dccp_to_nlattr(struct sk_buff *skb, · line 644

Quoted 9 lines · Pablo Neira Ayuso
net/netfilter/nf_conntrack_proto_dccp.c +2 -0
@@ -639,6 +639,8 @@ static int dccp_to_nlattr(struct sk_buff *skb,
 struct nlattr *nla,
     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_PUT_U64(skb, CTA_PROTOINFO_DCCP_HANDSHAKE_SEQ,
+            ct->proto.dccp.handshake_seq);

This should use big endian byteorder.

dccp_hdr_seq() returns a value in host byte order, which is used to assign the value to handshake_seq. So, we need to use cpu_to_be64() to convert the value to network byte order as other attributes in ctnetlink which are in network byte order, right? :)

Patch attached.

Signature · 1 line
"Los honestos son inadaptados sociales" -- Les Luthiers

netfilter: conntrack: add support for DCCP handshake sequence to ctnetlink

This patch adds CTA_PROTOINFO_DCCP_HANDSHAKE_SEQ that exposes the u64 handshake sequence number to user-space.

---

 include/linux/netfilter/nfnetlink_conntrack.h |    1 +
 include/net/netlink.h                         |    9 +++++++++
 net/netfilter/nf_conntrack_proto_dccp.c       |    7 +++++++
 3 files changed, 17 insertions(+), 0 deletions(-)
include/linux/netfilter/nfnetlink_conntrack.h +1 -0
index 1a865e4..ed4ef8d 100644
@@ -101,6 +101,7 @@ enum ctattr_protoinfo_dccp {
 	CTA_PROTOINFO_DCCP_UNSPEC,
 	CTA_PROTOINFO_DCCP_STATE,
 	CTA_PROTOINFO_DCCP_ROLE,
+	CTA_PROTOINFO_DCCP_HANDSHAKE_SEQ,
 	__CTA_PROTOINFO_DCCP_MAX,
 };
 #define CTA_PROTOINFO_DCCP_MAX (__CTA_PROTOINFO_DCCP_MAX - 1)
include/net/netlink.h +9 -0
index eddb502..007bdb0 100644
@@ -940,6 +940,15 @@ static inline u64 nla_get_u64(const struct nlattr *nla)
 }
 
 /**
+ * nla_get_be64 - return payload of __be64 attribute
+ * @nla: __be64 netlink attribute
+ */
+static inline __be64 nla_get_be64(const struct nlattr *nla)
+{
+	return *(__be64 *) nla_data(nla);
+}
+
+/**
  * nla_get_flag - return payload of flag attribute
  * @nla: flag netlink attribute
  */
net/netfilter/nf_conntrack_proto_dccp.c +7 -0
index aee0d6b..2952269 100644
@@ -639,6 +639,8 @@ static int dccp_to_nlattr(struct sk_buff *skb, struct nlattr *nla,
 	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_PUT_BE64(skb, CTA_PROTOINFO_DCCP_HANDSHAKE_SEQ,
+		     cpu_to_be64(ct->proto.dccp.handshake_seq));
 	nla_nest_end(skb, nest_parms);
 	read_unlock_bh(&dccp_lock);
 	return 0;
@@ -651,6 +653,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 },
+	[CTA_PROTOINFO_DCCP_HANDSHAKE_SEQ] = { .type = NLA_U64 },
 };
 
 static int nlattr_to_dccp(struct nlattr *cda[], struct nf_conn *ct)
@@ -683,6 +686,10 @@ static int nlattr_to_dccp(struct nlattr *cda[], struct nf_conn *ct)
 		ct->proto.dccp.role[IP_CT_DIR_ORIGINAL] = CT_DCCP_ROLE_SERVER;
 		ct->proto.dccp.role[IP_CT_DIR_REPLY] = CT_DCCP_ROLE_CLIENT;
 	}
+	if (tb[CTA_PROTOINFO_DCCP_HANDSHAKE_SEQ]) {
+		ct->proto.dccp.handshake_seq =
+		be64_to_cpu(nla_get_be64(tb[CTA_PROTOINFO_DCCP_HANDSHAKE_SEQ]));
+	}
 	write_unlock_bh(&dccp_lock);
 	return 0;
 }
#6 lore raw

Re: [PATCH 2/2] netfilter: conntrack: add support for DCCP handshake sequence to ctnetlink

Quoted 13 lines · Pablo Neira Ayuso
Quoted 11 lines · Patrick McHardy

net/netfilter/nf_conntrack_proto_dccp.c static int dccp_to_nlattr(struct sk_buff *skb, · line 644

Quoted 9 lines · Pablo Neira Ayuso
net/netfilter/nf_conntrack_proto_dccp.c +2 -0
@@ -639,6 +639,8 @@ static int dccp_to_nlattr(struct sk_buff *skb,
 struct nlattr *nla,
     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_PUT_U64(skb, CTA_PROTOINFO_DCCP_HANDSHAKE_SEQ,
+            ct->proto.dccp.handshake_seq);

This should use big endian byteorder.

Quoted 4 lines

dccp_hdr_seq() returns a value in host byte order, which is used to assign the value to handshake_seq. So, we need to use cpu_to_be64() to convert the value to network byte order as other attributes in ctnetlink which are in network byte order, right? :)

Absolutely :)

Quoted 1 line

Patch attached.

Applied to nf-next, thanks.