Skip to contentSkip to conversation

NETFILTER ctnetlink: allow userspace to change tcp state

PATCH In review Harald Welte 2 participants 3 messages Oct 7, 2005 – Oct 10, 2005

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 4/5 NETFILTER ctnetlink: allow userspace to change tcp state

Hi Dave,

this is clearly a new feature, so it can wait for 2.6.15.

Please apply to your 2.6.15 queue, or tell me to resubmit later, thanks.

[NETFILTER] ctnetlink: allow userspace to change TCP state

This patch adds the ability of changing the state a TCP connection. I know that this must be used with care but it's required to provide a complete conntrack creation via conntrack_netlink. So I'll document this aspect on the upcoming docs.

---
commit ba8264034a65ccb9a84e3be2ab1fe5b2b20dc692
tree b2b29df9a5f6a5e79e8e12838bea111723554306
parent d02c08d8d64333867d569535ed02f9600bcfb91d
author Harald Welte <[email protected]> Fri, 07 Oct 2005 23:40:39 +0200 committer Harald Welte <[email protected]> Fri, 07 Oct 2005 23:40:39 +0200

 clude/linux/netfilter_ipv4/ip_conntrack_protocol.h |    3 +++
 net/ipv4/netfilter/ip_conntrack_proto_tcp.c        |   23 ++++++++++++++++++++
 2 files changed, 26 insertions(+), 0 deletions(-)
include/linux/netfilter_ipv4/ip_conntrack_protocol.h +3 -0
@@ -52,6 +52,9 @@ struct ip_conntrack_protocol
 	int (*to_nfattr)(struct sk_buff *skb, struct nfattr *nfa,
 			 const struct ip_conntrack *ct);
 
+	/* convert nfnetlink attributes to protoinfo */
+	int (*from_nfattr)(struct nfattr *tb[], struct ip_conntrack *ct);
+
 	int (*tuple_to_nfattr)(struct sk_buff *skb,
 			       const struct ip_conntrack_tuple *t);
 	int (*nfattr_to_tuple)(struct nfattr *tb[],
net/ipv4/netfilter/ip_conntrack_proto_tcp.c +23 -0
@@ -356,6 +356,28 @@ nfattr_failure:
 	read_unlock_bh(&tcp_lock);
 	return -ENOMEM;
 }
+
+static int nfattr_to_tcp(struct nfattr *cda[], struct ip_conntrack *ct)
+{
+	struct nfattr *attr = cda[CTA_PROTOINFO_TCP-1];
+	struct nfattr *tb[CTA_PROTOINFO_TCP_MAX];
+
+        if (nfattr_parse_nested(tb, CTA_PROTOINFO_TCP_MAX, attr) < 0)
+                goto nfattr_failure;
+
+	if (!tb[CTA_PROTOINFO_TCP_STATE-1])
+		return -EINVAL;
+
+	write_lock_bh(&tcp_lock);
+	ct->proto.tcp.state = 
+		*(u_int8_t *)NFA_DATA(tb[CTA_PROTOINFO_TCP_STATE-1]);
+	write_unlock_bh(&tcp_lock);
+
+	return 0;
+
+nfattr_failure:
+	return -ENOMEM;
+}
 #endif
 
 static unsigned int get_conntrack_index(const struct tcphdr *tcph)
@@ -1127,6 +1149,7 @@ struct ip_conntrack_protocol ip_conntrac
 #if defined(CONFIG_IP_NF_CONNTRACK_NETLINK) || \
     defined(CONFIG_IP_NF_CONNTRACK_NETLINK_MODULE)
 	.to_nfattr		= tcp_to_nfattr,
+	.from_nfattr		= nfattr_to_tcp,
 	.tuple_to_nfattr	= ip_ct_port_tuple_to_nfattr,
 	.nfattr_to_tuple	= ip_ct_port_nfattr_to_tuple,
 #endif
Signature · 5 lines
- Harald Welte <[email protected]>                 http://netfilter.org/
============================================================================
  "Fragmentation is like classful addressing -- an interesting early
   architectural error that shows how much experimentation was going
   on while IP was being designed."                    -- Paul Vixie
maintainer
#1 lore raw

From: Harald Welte <[email protected]>
Date: Sat, 8 Oct 2005 00:26:25 +0200

Quoted 3 lines

this is clearly a new feature, so it can wait for 2.6.15.

Please apply to your 2.6.15 queue, or tell me to resubmit later, thanks.

It's be a shame for ctnetlink to be handicapped in it's first release in 2.6.14, so I applied both patches 4 and 5 :)

Thanks.

#2 lore raw
Quoted 9 lines · David S. Miller

From: Harald Welte <[email protected]>
Date: Sat, 8 Oct 2005 00:26:25 +0200

Quoted 3 lines

this is clearly a new feature, so it can wait for 2.6.15.

Please apply to your 2.6.15 queue, or tell me to resubmit later, thanks.

It's be a shame for ctnetlink to be handicapped in it's first release in 2.6.14, so I applied both patches 4 and 5 :)

Thanks a lot for merging everything. Let's hope we now finally have resolved all issues with netfilter netlink.

As indicated, I'll work on that iptables cpu-count issue asap. I'm unable to test it on my notebook (still travelling), but since you're running various sparc beastst, maybe you can give it a test once I've worked it out.

Signature · 5 lines
- Harald Welte <[email protected]>                 http://netfilter.org/
============================================================================
  "Fragmentation is like classful addressing -- an interesting early
   architectural error that shows how much experimentation was going
   on while IP was being designed."                    -- Paul Vixie