Skip to content

Commit 0c12582

Browse files
Julian Anastasovhorms
authored andcommitted
ipvs: add backup_only flag to avoid loops
Dmitry Akindinov is reporting for a problem where SYNs are looping between the master and backup server when the backup server is used as real server in DR mode and has IPVS rules to function as director. Even when the backup function is enabled we continue to forward traffic and schedule new connections when the current master is using the backup server as real server. While this is not a problem for NAT, for DR and TUN method the backup server can not determine if a request comes from client or from director. To avoid such loops add new sysctl flag backup_only. It can be needed for DR/TUN setups that do not need backup and director function at the same time. When the backup function is enabled we stop any forwarding and pass the traffic to the local stack (real server mode). The flag disables the director function when the backup function is enabled. For setups that enable backup function for some virtual services and director function for other virtual services there should be another more complex solution to support DR/TUN mode, may be to assign per-virtual service syncid value, so that we can differentiate the requests. Reported-by: Dmitry Akindinov <dimak@stalker.com> Tested-by: German Myzovsky <lawyer@sipnet.ru> Signed-off-by: Julian Anastasov <ja@ssi.bg> Signed-off-by: Simon Horman <horms@verge.net.au>
1 parent cf2e394 commit 0c12582

4 files changed

Lines changed: 34 additions & 4 deletions

File tree

‎Documentation/networking/ipvs-sysctl.txt‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ amemthresh - INTEGER
1515
enabled and the variable is automatically set to 2, otherwise
1616
the strategy is disabled and the variable is set to 1.
1717

18+
backup_only - BOOLEAN
19+
0 - disabled (default)
20+
not 0 - enabled
21+
22+
If set, disable the director function while the server is
23+
in backup mode to avoid packet loops for DR/TUN methods.
24+
1825
conntrack - BOOLEAN
1926
0 - disabled (default)
2027
not 0 - enabled

‎include/net/ip_vs.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,7 @@ struct netns_ipvs {
976976
int sysctl_sync_retries;
977977
int sysctl_nat_icmp_send;
978978
int sysctl_pmtu_disc;
979+
int sysctl_backup_only;
979980

980981
/* ip_vs_lblc */
981982
int sysctl_lblc_expiration;
@@ -1067,6 +1068,12 @@ static inline int sysctl_pmtu_disc(struct netns_ipvs *ipvs)
10671068
return ipvs->sysctl_pmtu_disc;
10681069
}
10691070

1071+
static inline int sysctl_backup_only(struct netns_ipvs *ipvs)
1072+
{
1073+
return ipvs->sync_state & IP_VS_STATE_BACKUP &&
1074+
ipvs->sysctl_backup_only;
1075+
}
1076+
10701077
#else
10711078

10721079
static inline int sysctl_sync_threshold(struct netns_ipvs *ipvs)
@@ -1114,6 +1121,11 @@ static inline int sysctl_pmtu_disc(struct netns_ipvs *ipvs)
11141121
return 1;
11151122
}
11161123

1124+
static inline int sysctl_backup_only(struct netns_ipvs *ipvs)
1125+
{
1126+
return 0;
1127+
}
1128+
11171129
#endif
11181130

11191131
/*

‎net/netfilter/ipvs/ip_vs_core.c‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,7 +1577,8 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
15771577
}
15781578
/* ipvs enabled in this netns ? */
15791579
net = skb_net(skb);
1580-
if (!net_ipvs(net)->enable)
1580+
ipvs = net_ipvs(net);
1581+
if (unlikely(sysctl_backup_only(ipvs) || !ipvs->enable))
15811582
return NF_ACCEPT;
15821583

15831584
ip_vs_fill_iph_skb(af, skb, &iph);
@@ -1654,7 +1655,6 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
16541655
}
16551656

16561657
IP_VS_DBG_PKT(11, af, pp, skb, 0, "Incoming packet");
1657-
ipvs = net_ipvs(net);
16581658
/* Check the server status */
16591659
if (cp->dest && !(cp->dest->flags & IP_VS_DEST_F_AVAILABLE)) {
16601660
/* the destination server is not available */
@@ -1815,13 +1815,15 @@ ip_vs_forward_icmp(unsigned int hooknum, struct sk_buff *skb,
18151815
{
18161816
int r;
18171817
struct net *net;
1818+
struct netns_ipvs *ipvs;
18181819

18191820
if (ip_hdr(skb)->protocol != IPPROTO_ICMP)
18201821
return NF_ACCEPT;
18211822

18221823
/* ipvs enabled in this netns ? */
18231824
net = skb_net(skb);
1824-
if (!net_ipvs(net)->enable)
1825+
ipvs = net_ipvs(net);
1826+
if (unlikely(sysctl_backup_only(ipvs) || !ipvs->enable))
18251827
return NF_ACCEPT;
18261828

18271829
return ip_vs_in_icmp(skb, &r, hooknum);
@@ -1835,6 +1837,7 @@ ip_vs_forward_icmp_v6(unsigned int hooknum, struct sk_buff *skb,
18351837
{
18361838
int r;
18371839
struct net *net;
1840+
struct netns_ipvs *ipvs;
18381841
struct ip_vs_iphdr iphdr;
18391842

18401843
ip_vs_fill_iph_skb(AF_INET6, skb, &iphdr);
@@ -1843,7 +1846,8 @@ ip_vs_forward_icmp_v6(unsigned int hooknum, struct sk_buff *skb,
18431846

18441847
/* ipvs enabled in this netns ? */
18451848
net = skb_net(skb);
1846-
if (!net_ipvs(net)->enable)
1849+
ipvs = net_ipvs(net);
1850+
if (unlikely(sysctl_backup_only(ipvs) || !ipvs->enable))
18471851
return NF_ACCEPT;
18481852

18491853
return ip_vs_in_icmp_v6(skb, &r, hooknum, &iphdr);

‎net/netfilter/ipvs/ip_vs_ctl.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1808,6 +1808,12 @@ static struct ctl_table vs_vars[] = {
18081808
.mode = 0644,
18091809
.proc_handler = proc_dointvec,
18101810
},
1811+
{
1812+
.procname = "backup_only",
1813+
.maxlen = sizeof(int),
1814+
.mode = 0644,
1815+
.proc_handler = proc_dointvec,
1816+
},
18111817
#ifdef CONFIG_IP_VS_DEBUG
18121818
{
18131819
.procname = "debug_level",
@@ -3741,6 +3747,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
37413747
tbl[idx++].data = &ipvs->sysctl_nat_icmp_send;
37423748
ipvs->sysctl_pmtu_disc = 1;
37433749
tbl[idx++].data = &ipvs->sysctl_pmtu_disc;
3750+
tbl[idx++].data = &ipvs->sysctl_backup_only;
37443751

37453752

37463753
ipvs->sysctl_hdr = register_net_sysctl(net, "net/ipv4/vs", tbl);

0 commit comments

Comments
 (0)