Skip to content

Commit dc7b3eb

Browse files
grzegorzlyczbaummakynes
authored andcommitted
ipvs: Fix reuse connection if real server is dead
Expire cached connection for new TCP/SCTP connection if real server is down. Otherwise, IPVS uses the dead server for the reused connection, instead of a new working one. Signed-off-by: Grzegorz Lyczba <grzegorz.lyczba@gmail.com> Acked-by: Hans Schillstrom <hans@schillstrom.com> Acked-by: Julian Anastasov <ja@ssi.bg> Signed-off-by: Simon Horman <horms@verge.net.au> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent 4f36ea6 commit dc7b3eb

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

‎net/netfilter/ipvs/ip_vs_core.c‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,32 @@ static inline int is_tcp_reset(const struct sk_buff *skb, int nh_len)
10011001
return th->rst;
10021002
}
10031003

1004+
static inline bool is_new_conn(const struct sk_buff *skb,
1005+
struct ip_vs_iphdr *iph)
1006+
{
1007+
switch (iph->protocol) {
1008+
case IPPROTO_TCP: {
1009+
struct tcphdr _tcph, *th;
1010+
1011+
th = skb_header_pointer(skb, iph->len, sizeof(_tcph), &_tcph);
1012+
if (th == NULL)
1013+
return false;
1014+
return th->syn;
1015+
}
1016+
case IPPROTO_SCTP: {
1017+
sctp_chunkhdr_t *sch, schunk;
1018+
1019+
sch = skb_header_pointer(skb, iph->len + sizeof(sctp_sctphdr_t),
1020+
sizeof(schunk), &schunk);
1021+
if (sch == NULL)
1022+
return false;
1023+
return sch->type == SCTP_CID_INIT;
1024+
}
1025+
default:
1026+
return false;
1027+
}
1028+
}
1029+
10041030
/* Handle response packets: rewrite addresses and send away...
10051031
*/
10061032
static unsigned int
@@ -1612,6 +1638,15 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
16121638
* Check if the packet belongs to an existing connection entry
16131639
*/
16141640
cp = pp->conn_in_get(af, skb, &iph, 0);
1641+
1642+
if (unlikely(sysctl_expire_nodest_conn(ipvs)) && cp && cp->dest &&
1643+
unlikely(!atomic_read(&cp->dest->weight)) && !iph.fragoffs &&
1644+
is_new_conn(skb, &iph)) {
1645+
ip_vs_conn_expire_now(cp);
1646+
__ip_vs_conn_put(cp);
1647+
cp = NULL;
1648+
}
1649+
16151650
if (unlikely(!cp) && !iph.fragoffs) {
16161651
/* No (second) fragments need to enter here, as nf_defrag_ipv6
16171652
* replayed fragment zero will already have created the cp

0 commit comments

Comments
 (0)