From: Patrick McHardy <kaber@trash.net>
To: dccp@vger.kernel.org
Subject: Re: DCCP conntrack/NAT
Date: Tue, 08 Apr 2008 11:18:20 +0000 [thread overview]
Message-ID: <47FB547C.4050507@trash.net> (raw)
In-Reply-To: <47F64C0D.5080700@trash.net>
[-- Attachment #1: Type: text/plain, Size: 817 bytes --]
Patrick McHardy wrote:
> Gerrit Renker wrote:
>>
>> - timewait transition -- question: is it possible to re-incarnate a
>> new connection
>> here instead of ignoring the (new) Request?
>
> Yes, I'll change this. The tricker case is a reincarnation in the
> reverse direction. The conntrack entry must be killed and recreated
> since the state table is directional and the client/server roles
> change. Also needs a bit more thought.
The last patch handled reincarnations in the original direction,
this one adds support for reopening a connection in the reverse
direction. I used role reversal instead of recreating the conntrack
entry since that should make it easier to add DCCP_LISTEN support
later on.
(Patch might not apply because of minor cleanups I made locally,
I'll push out a new tree later).
[-- Attachment #2: x --]
[-- Type: text/plain, Size: 4319 bytes --]
diff --git a/include/linux/netfilter/nf_conntrack_dccp.h b/include/linux/netfilter/nf_conntrack_dccp.h
index 33e57c8..f3b9ce8 100644
--- a/include/linux/netfilter/nf_conntrack_dccp.h
+++ b/include/linux/netfilter/nf_conntrack_dccp.h
@@ -15,12 +15,21 @@ enum ct_dccp_states {
CT_DCCP_INVALID,
__CT_DCCP_MAX
};
-#define CT_DCCP_MAX (__CT_DCCP_MAX - 1)
+#define CT_DCCP_MAX (__CT_DCCP_MAX - 1)
+
+enum ct_dccp_roles {
+ CT_DCCP_ROLE_CLIENT,
+ CT_DCCP_ROLE_SERVER,
+ __CT_DCCP_ROLE_MAX
+};
+#define CT_DCCP_ROLE_MAX (__CT_DCCP_ROLE_MAX - 1)
#ifdef __KERNEL__
+#include <net/netfilter/nf_conntrack_tuple.h>
struct nf_ct_dccp {
u_int8_t state;
+ u_int8_t role[IP_CT_DIR_MAX];
u_int64_t handshake_seq;
};
diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
index bad3c6a..f768936 100644
--- a/net/netfilter/nf_conntrack_proto_dccp.c
+++ b/net/netfilter/nf_conntrack_proto_dccp.c
@@ -138,8 +138,8 @@ static const char * const dccp_state_names[] = {
* or a DCCP_RESPONSE.
*/
static const u_int8_t
-dccp_state_table[IP_CT_DIR_MAX + 1][DCCP_PKT_SYNCACK + 1][CT_DCCP_MAX + 1] = {
- [IP_CT_DIR_ORIGINAL] = {
+dccp_state_table[CT_DCCP_ROLE_MAX + 1][DCCP_PKT_SYNCACK + 1][CT_DCCP_MAX + 1] = {
+ [CT_DCCP_ROLE_CLIENT] = {
[DCCP_PKT_REQUEST] = {
/*
* sNO -> sRQ Regular Request
@@ -157,7 +157,7 @@ dccp_state_table[IP_CT_DIR_MAX + 1][DCCP_PKT_SYNCACK + 1][CT_DCCP_MAX + 1] = {
},
[DCCP_PKT_RESPONSE] = {
/*
- * A Response in the original direction is always invalid.
+ * A Response from the client is always invalid.
*
* sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV,
@@ -254,13 +254,23 @@ dccp_state_table[IP_CT_DIR_MAX + 1][DCCP_PKT_SYNCACK + 1][CT_DCCP_MAX + 1] = {
sIG, sIG, sIG, sIG, sIG, sIG, sIG, sIG,
},
},
- [IP_CT_DIR_REPLY] = {
+ [CT_DCCP_ROLE_SERVER] = {
[DCCP_PKT_REQUEST] = {
/*
- * A Request in the reply direction is always invalid.
+ * A Request from the server is only valid for reopening a
+ * connection in TIMEWAIT state.
+ *
+ * sNO -> sIV
+ * sRQ -> sIV
+ * sRS -> sIV
+ * sPO -> sIV
+ * sOP -> sIV
+ * sCR -> sIV
+ * sCG -> sIV
+ * sTW -> sRQ Reincarnation, must reverse roles
*
* sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
- sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV
+ sIV, sIV, sIV, sIV, sIV, sIV, sIV, sRQ
},
[DCCP_PKT_RESPONSE] = {
/*
@@ -410,7 +420,7 @@ static int dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
BUG_ON(dh == NULL);
- state = dccp_state_table[IP_CT_DIR_ORIGINAL][dh->dccph_type][CT_DCCP_NONE];
+ state = dccp_state_table[CT_DCCP_ROLE_CLIENT][dh->dccph_type][CT_DCCP_NONE];
switch (state) {
default:
if (nf_ct_dccp_loose == 0) {
@@ -425,6 +435,8 @@ static int dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
}
ct->proto.dccp.state = CT_DCCP_NONE;
+ ct->proto.dccp.role[IP_CT_DIR_ORIGINAL] = CT_DCCP_ROLE_CLIENT;
+ ct->proto.dccp.role[IP_CT_DIR_REPLY] = CT_DCCP_ROLE_SERVER;
return 1;
out_invalid:
@@ -446,8 +458,10 @@ static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb,
unsigned int dataoff, enum ip_conntrack_info ctinfo,
int pf, unsigned int hooknum)
{
+ enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo);
struct dccp_hdr _dh, *dh;
u_int8_t type, old_state, new_state;
+ enum ct_dccp_roles role;
dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
BUG_ON(dh == NULL);
@@ -463,10 +477,20 @@ static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb,
write_lock_bh(&dccp_lock);
+ role = ct->proto.dccp.role[dir];
old_state = ct->proto.dccp.state;
- new_state = dccp_state_table[CTINFO2DIR(ctinfo)][type][old_state];
+ new_state = dccp_state_table[role][type][old_state];
switch (new_state) {
+ case CT_DCCP_REQUEST:
+ if (old_state == CT_DCCP_TIMEWAIT &&
+ role == CT_DCCP_ROLE_SERVER) {
+ /* Reincarnation in the reverse direction: reopen and
+ * reverse client/server roles. */
+ ct->proto.dccp.role[dir] = CT_DCCP_ROLE_CLIENT;
+ ct->proto.dccp.role[!dir] = CT_DCCP_ROLE_SERVER;
+ }
+ break;
case CT_DCCP_RESPOND:
if (old_state == CT_DCCP_REQUEST)
ct->proto.dccp.handshake_seq = dccp_hdr_seq(dh);
WARNING: multiple messages have this Message-ID (diff)
From: Patrick McHardy <kaber@trash.net>
To: Gerrit Renker <gerrit@erg.abdn.ac.uk>,
dccp@vger.kernel.org,
Netfilter Development Mailinglist
<netfilter-devel@vger.kernel.org>
Subject: Re: DCCP conntrack/NAT
Date: Tue, 08 Apr 2008 13:18:20 +0200 [thread overview]
Message-ID: <47FB547C.4050507@trash.net> (raw)
In-Reply-To: <47FAA40D.7010905@trash.net>
[-- Attachment #1: Type: text/plain, Size: 817 bytes --]
Patrick McHardy wrote:
> Gerrit Renker wrote:
>>
>> - timewait transition -- question: is it possible to re-incarnate a
>> new connection
>> here instead of ignoring the (new) Request?
>
> Yes, I'll change this. The tricker case is a reincarnation in the
> reverse direction. The conntrack entry must be killed and recreated
> since the state table is directional and the client/server roles
> change. Also needs a bit more thought.
The last patch handled reincarnations in the original direction,
this one adds support for reopening a connection in the reverse
direction. I used role reversal instead of recreating the conntrack
entry since that should make it easier to add DCCP_LISTEN support
later on.
(Patch might not apply because of minor cleanups I made locally,
I'll push out a new tree later).
[-- Attachment #2: x --]
[-- Type: text/plain, Size: 4319 bytes --]
diff --git a/include/linux/netfilter/nf_conntrack_dccp.h b/include/linux/netfilter/nf_conntrack_dccp.h
index 33e57c8..f3b9ce8 100644
--- a/include/linux/netfilter/nf_conntrack_dccp.h
+++ b/include/linux/netfilter/nf_conntrack_dccp.h
@@ -15,12 +15,21 @@ enum ct_dccp_states {
CT_DCCP_INVALID,
__CT_DCCP_MAX
};
-#define CT_DCCP_MAX (__CT_DCCP_MAX - 1)
+#define CT_DCCP_MAX (__CT_DCCP_MAX - 1)
+
+enum ct_dccp_roles {
+ CT_DCCP_ROLE_CLIENT,
+ CT_DCCP_ROLE_SERVER,
+ __CT_DCCP_ROLE_MAX
+};
+#define CT_DCCP_ROLE_MAX (__CT_DCCP_ROLE_MAX - 1)
#ifdef __KERNEL__
+#include <net/netfilter/nf_conntrack_tuple.h>
struct nf_ct_dccp {
u_int8_t state;
+ u_int8_t role[IP_CT_DIR_MAX];
u_int64_t handshake_seq;
};
diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
index bad3c6a..f768936 100644
--- a/net/netfilter/nf_conntrack_proto_dccp.c
+++ b/net/netfilter/nf_conntrack_proto_dccp.c
@@ -138,8 +138,8 @@ static const char * const dccp_state_names[] = {
* or a DCCP_RESPONSE.
*/
static const u_int8_t
-dccp_state_table[IP_CT_DIR_MAX + 1][DCCP_PKT_SYNCACK + 1][CT_DCCP_MAX + 1] = {
- [IP_CT_DIR_ORIGINAL] = {
+dccp_state_table[CT_DCCP_ROLE_MAX + 1][DCCP_PKT_SYNCACK + 1][CT_DCCP_MAX + 1] = {
+ [CT_DCCP_ROLE_CLIENT] = {
[DCCP_PKT_REQUEST] = {
/*
* sNO -> sRQ Regular Request
@@ -157,7 +157,7 @@ dccp_state_table[IP_CT_DIR_MAX + 1][DCCP_PKT_SYNCACK + 1][CT_DCCP_MAX + 1] = {
},
[DCCP_PKT_RESPONSE] = {
/*
- * A Response in the original direction is always invalid.
+ * A Response from the client is always invalid.
*
* sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV,
@@ -254,13 +254,23 @@ dccp_state_table[IP_CT_DIR_MAX + 1][DCCP_PKT_SYNCACK + 1][CT_DCCP_MAX + 1] = {
sIG, sIG, sIG, sIG, sIG, sIG, sIG, sIG,
},
},
- [IP_CT_DIR_REPLY] = {
+ [CT_DCCP_ROLE_SERVER] = {
[DCCP_PKT_REQUEST] = {
/*
- * A Request in the reply direction is always invalid.
+ * A Request from the server is only valid for reopening a
+ * connection in TIMEWAIT state.
+ *
+ * sNO -> sIV
+ * sRQ -> sIV
+ * sRS -> sIV
+ * sPO -> sIV
+ * sOP -> sIV
+ * sCR -> sIV
+ * sCG -> sIV
+ * sTW -> sRQ Reincarnation, must reverse roles
*
* sNO, sRQ, sRS, sPO, sOP, sCR, sCG, sTW */
- sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV
+ sIV, sIV, sIV, sIV, sIV, sIV, sIV, sRQ
},
[DCCP_PKT_RESPONSE] = {
/*
@@ -410,7 +420,7 @@ static int dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
BUG_ON(dh == NULL);
- state = dccp_state_table[IP_CT_DIR_ORIGINAL][dh->dccph_type][CT_DCCP_NONE];
+ state = dccp_state_table[CT_DCCP_ROLE_CLIENT][dh->dccph_type][CT_DCCP_NONE];
switch (state) {
default:
if (nf_ct_dccp_loose == 0) {
@@ -425,6 +435,8 @@ static int dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
}
ct->proto.dccp.state = CT_DCCP_NONE;
+ ct->proto.dccp.role[IP_CT_DIR_ORIGINAL] = CT_DCCP_ROLE_CLIENT;
+ ct->proto.dccp.role[IP_CT_DIR_REPLY] = CT_DCCP_ROLE_SERVER;
return 1;
out_invalid:
@@ -446,8 +458,10 @@ static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb,
unsigned int dataoff, enum ip_conntrack_info ctinfo,
int pf, unsigned int hooknum)
{
+ enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo);
struct dccp_hdr _dh, *dh;
u_int8_t type, old_state, new_state;
+ enum ct_dccp_roles role;
dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
BUG_ON(dh == NULL);
@@ -463,10 +477,20 @@ static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb,
write_lock_bh(&dccp_lock);
+ role = ct->proto.dccp.role[dir];
old_state = ct->proto.dccp.state;
- new_state = dccp_state_table[CTINFO2DIR(ctinfo)][type][old_state];
+ new_state = dccp_state_table[role][type][old_state];
switch (new_state) {
+ case CT_DCCP_REQUEST:
+ if (old_state == CT_DCCP_TIMEWAIT &&
+ role == CT_DCCP_ROLE_SERVER) {
+ /* Reincarnation in the reverse direction: reopen and
+ * reverse client/server roles. */
+ ct->proto.dccp.role[dir] = CT_DCCP_ROLE_CLIENT;
+ ct->proto.dccp.role[!dir] = CT_DCCP_ROLE_SERVER;
+ }
+ break;
case CT_DCCP_RESPOND:
if (old_state == CT_DCCP_REQUEST)
ct->proto.dccp.handshake_seq = dccp_hdr_seq(dh);
next prev parent reply other threads:[~2008-04-08 11:18 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-04 15:41 DCCP conntrack/NAT Patrick McHardy
2008-04-04 15:41 ` Patrick McHardy
2008-04-04 19:59 ` Jan Engelhardt
2008-04-04 19:59 ` Jan Engelhardt
2008-04-05 10:09 ` Pablo Neira Ayuso
2008-04-05 10:09 ` Pablo Neira Ayuso
2008-04-05 10:12 ` Pablo Neira Ayuso
2008-04-05 10:12 ` Pablo Neira Ayuso
2008-04-06 0:28 ` Patrick McHardy
2008-04-06 0:28 ` Patrick McHardy
2008-04-07 21:50 ` Gerrit Renker
2008-04-07 21:50 ` Gerrit Renker
2008-04-07 22:45 ` Patrick McHardy
2008-04-07 22:45 ` Patrick McHardy
2008-04-08 9:27 ` Gerrit Renker
2008-04-08 9:27 ` Gerrit Renker
2008-04-08 10:30 ` Patrick McHardy
2008-04-08 10:30 ` Patrick McHardy
2008-04-08 10:33 ` Patrick McHardy
2008-04-08 10:33 ` Patrick McHardy
2008-04-08 11:18 ` Patrick McHardy [this message]
2008-04-08 11:18 ` Patrick McHardy
2008-04-08 13:38 ` Gerrit Renker
2008-04-08 13:38 ` Gerrit Renker
2008-04-08 14:12 ` Patrick McHardy
2008-04-08 14:12 ` Patrick McHardy
2008-04-08 14:26 ` Patrick McHardy
2008-04-08 14:26 ` Patrick McHardy
2008-04-08 16:21 ` Patrick McHardy
2008-04-08 16:21 ` Patrick McHardy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=47FB547C.4050507@trash.net \
--to=kaber@trash.net \
--cc=dccp@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.