aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKOVACS Krisztian <hidden@sch.bme.hu>2008-10-01 10:46:49 -0400
committerDavid S. Miller <davem@davemloft.net>2008-10-01 10:46:49 -0400
commita3116ac5c216fc3c145906a46df9ce542ff7dcf2 (patch)
tree6b2b43b5bacac2b358566e4b7ca0adda45a3e52b
parent86b08d867d7de001ab224180ed7865fab93fd56e (diff)
tcp: Port redirection support for TCP
Current TCP code relies on the local port of the listening socket being the same as the destination address of the incoming connection. Port redirection used by many transparent proxying techniques obviously breaks this, so we have to store the original destination port address. This patch extends struct inet_request_sock and stores the incoming destination port value there. It also modifies the handshake code to use that value as the source port when sending reply packets. Signed-off-by: KOVACS Krisztian <hidden@sch.bme.hu> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/net/inet_sock.h2
-rw-r--r--include/net/tcp.h1
-rw-r--r--net/ipv4/inet_connection_sock.c2
-rw-r--r--net/ipv4/syncookies.c1
-rw-r--r--net/ipv4/tcp_output.c2
5 files changed, 6 insertions, 2 deletions
diff --git a/include/net/inet_sock.h b/include/net/inet_sock.h
index dced3f64f975..de0ecc71cf03 100644
--- a/include/net/inet_sock.h
+++ b/include/net/inet_sock.h
@@ -61,8 +61,8 @@ struct inet_request_sock {
61 struct request_sock req; 61 struct request_sock req;
62#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) 62#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
63 u16 inet6_rsk_offset; 63 u16 inet6_rsk_offset;
64 /* 2 bytes hole, try to pack */
65#endif 64#endif
65 __be16 loc_port;
66 __be32 loc_addr; 66 __be32 loc_addr;
67 __be32 rmt_addr; 67 __be32 rmt_addr;
68 __be16 rmt_port; 68 __be16 rmt_port;
diff --git a/include/net/tcp.h b/include/net/tcp.h
index 12c9b4fec040..f6cc34143154 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -976,6 +976,7 @@ static inline void tcp_openreq_init(struct request_sock *req,
976 ireq->acked = 0; 976 ireq->acked = 0;
977 ireq->ecn_ok = 0; 977 ireq->ecn_ok = 0;
978 ireq->rmt_port = tcp_hdr(skb)->source; 978 ireq->rmt_port = tcp_hdr(skb)->source;
979 ireq->loc_port = tcp_hdr(skb)->dest;
979} 980}
980 981
981extern void tcp_enter_memory_pressure(struct sock *sk); 982extern void tcp_enter_memory_pressure(struct sock *sk);
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index 432c570c9f5f..21fcc5a9045f 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -516,6 +516,8 @@ struct sock *inet_csk_clone(struct sock *sk, const struct request_sock *req,
516 newicsk->icsk_bind_hash = NULL; 516 newicsk->icsk_bind_hash = NULL;
517 517
518 inet_sk(newsk)->dport = inet_rsk(req)->rmt_port; 518 inet_sk(newsk)->dport = inet_rsk(req)->rmt_port;
519 inet_sk(newsk)->num = ntohs(inet_rsk(req)->loc_port);
520 inet_sk(newsk)->sport = inet_rsk(req)->loc_port;
519 newsk->sk_write_space = sk_stream_write_space; 521 newsk->sk_write_space = sk_stream_write_space;
520 522
521 newicsk->icsk_retransmits = 0; 523 newicsk->icsk_retransmits = 0;
diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c
index 929302b2ba94..d346c22aa6ae 100644
--- a/net/ipv4/syncookies.c
+++ b/net/ipv4/syncookies.c
@@ -297,6 +297,7 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
297 treq->rcv_isn = ntohl(th->seq) - 1; 297 treq->rcv_isn = ntohl(th->seq) - 1;
298 treq->snt_isn = cookie; 298 treq->snt_isn = cookie;
299 req->mss = mss; 299 req->mss = mss;
300 ireq->loc_port = th->dest;
300 ireq->rmt_port = th->source; 301 ireq->rmt_port = th->source;
301 ireq->loc_addr = ip_hdr(skb)->daddr; 302 ireq->loc_addr = ip_hdr(skb)->daddr;
302 ireq->rmt_addr = ip_hdr(skb)->saddr; 303 ireq->rmt_addr = ip_hdr(skb)->saddr;
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index a8499ef3234a..493553c71d32 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -2275,7 +2275,7 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst,
2275 th->syn = 1; 2275 th->syn = 1;
2276 th->ack = 1; 2276 th->ack = 1;
2277 TCP_ECN_make_synack(req, th); 2277 TCP_ECN_make_synack(req, th);
2278 th->source = inet_sk(sk)->sport; 2278 th->source = ireq->loc_port;
2279 th->dest = ireq->rmt_port; 2279 th->dest = ireq->rmt_port;
2280 /* Setting of flags are superfluous here for callers (and ECE is 2280 /* Setting of flags are superfluous here for callers (and ECE is
2281 * not even correctly set) 2281 * not even correctly set)