IPVS changes
Subsystems (5)
Julian Anastasov
maintainercover IPVS changes
This patchset adds new backup_only flag and fixes
some warnings found by sparse. I hope the SCTP part is correct. In fact I see other problems with the SCTP state machine that need to be resolved.
The patchset does not overlap with the other
patchset for IPVS optimizations, so can be applied independently.
Julian Anastasov (5):
ipvs: add backup_only flag to avoid loops
ipvs: remove extra rcu lock
ipvs: fix sctp chunk length order
ipvs: fix hashing in ip_vs_svc_hashkey
ipvs: fix some sparse warnings
Documentation/networking/ipvs-sysctl.txt | 7 +++++++ include/net/ip_vs.h | 14 +++++++++++++- net/netfilter/ipvs/ip_vs_core.c | 22 +++++++++------------- net/netfilter/ipvs/ip_vs_ctl.c | 15 ++++++++++++--- net/netfilter/ipvs/ip_vs_est.c | 2 +- net/netfilter/ipvs/ip_vs_proto_sctp.c | 16 +++++++++------- 6 files changed, 51 insertions(+), 25 deletions(-)
Signature · 1 line
1.7.3.4
Julian Anastasov
maintainerPATCH 1/5 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 flagbackup_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.
--- Documentation/networking/ipvs-sysctl.txt | 7 +++++++ include/net/ip_vs.h | 12 ++++++++++++ net/netfilter/ipvs/ip_vs_core.c | 12 ++++++++---- net/netfilter/ipvs/ip_vs_ctl.c | 7 +++++++ 4 files changed, 34 insertions(+), 4 deletions(-)
Documentation/networking/ipvs-sysctl.txt +7 -0
@@ -15,6 +15,13 @@ amemthresh - INTEGER enabled and the variable is automatically set to 2, otherwise the strategy is disabled and the variable is set to 1. +backup_only - BOOLEAN + 0 - disabled (default) + not 0 - enabled + + If set, disable the director function while the server is + in backup mode to avoid packet loops for DR/TUN methods. + conntrack - BOOLEAN 0 - disabled (default) not 0 - enabled
include/net/ip_vs.h +12 -0
@@ -997,6 +997,7 @@ struct netns_ipvs {int sysctl_sync_retries;int sysctl_nat_icmp_send;int sysctl_pmtu_disc; +int sysctl_backup_only;/* ip_vs_lblc */ int sysctl_lblc_expiration;
@@ -1088,6 +1089,12 @@ static inline int sysctl_pmtu_disc(struct netns_ipvs *ipvs) return ipvs->sysctl_pmtu_disc; } +static inline int sysctl_backup_only (struct netns_ipvs *ipvs) +{ +return ipvs->sync_state &IP_VS_STATE_BACKUP && + ipvs->sysctl_backup_only; +} +#else static inline int sysctl_sync_threshold (struct netns_ipvs *ipvs)
@@ -1135,6 +1142,11 @@ static inline int sysctl_pmtu_disc(struct netns_ipvs *ipvs) return 1; } +static inline int sysctl_backup_only (struct netns_ipvs *ipvs) +{ +return 0 ; +} +#endif /*
net/netfilter/ipvs/ip_vs_core.c +8 -4
@@ -1579,7 +1579,8 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af) }/* ipvs enabled in this netns ? */ net =skb_net (skb); -if (!net_ipvs (net)->enable) + ipvs =net_ipvs (net); +if (unlikely (sysctl_backup_only (ipvs) || !ipvs->enable))return NF_ACCEPT ;ip_vs_fill_iph_skb (af, skb, &iph);
@@ -1656,7 +1657,6 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af) }IP_VS_DBG_PKT (11 , af, pp, skb,0 ,"Incoming packet" ); - ipvs =net_ipvs (net);/* Check the server status */ if (cp->dest && !(cp->dest->flags &IP_VS_DEST_F_AVAILABLE )) {/* the destination server is not available */
@@ -1817,13 +1817,15 @@ ip_vs_forward_icmp(unsigned int hooknum, struct sk_buff *skb, {int r;struct net *net; +struct netns_ipvs *ipvs;if (ip_hdr (skb)->protocol !=IPPROTO_ICMP )return NF_ACCEPT ;/* ipvs enabled in this netns ? */ net =skb_net (skb); -if (!net_ipvs (net)->enable) + ipvs =net_ipvs (net); +if (unlikely (sysctl_backup_only (ipvs) || !ipvs->enable))return NF_ACCEPT ;return ip_vs_in_icmp (skb, &r, hooknum);
@@ -1837,6 +1839,7 @@ ip_vs_forward_icmp_v6(unsigned int hooknum, struct sk_buff *skb, {int r;struct net *net; +struct netns_ipvs *ipvs;struct ip_vs_iphdr iphdr;ip_vs_fill_iph_skb (AF_INET6 , skb, &iphdr);
@@ -1845,7 +1848,8 @@ ip_vs_forward_icmp_v6(unsigned int hooknum, struct sk_buff *skb,/* ipvs enabled in this netns ? */ net =skb_net (skb); -if (!net_ipvs (net)->enable) + ipvs =net_ipvs (net); +if (unlikely (sysctl_backup_only (ipvs) || !ipvs->enable))return NF_ACCEPT ;return ip_vs_in_icmp_v6 (skb, &r, hooknum, &iphdr);
net/netfilter/ipvs/ip_vs_ctl.c +7 -0
@@ -1806,6 +1806,12 @@ static struct ctl_table vs_vars[] = { .mode = 0644, .proc_handler = proc_dointvec, }, + { + .procname = "backup_only", + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec, + }, #ifdef CONFIG_IP_VS_DEBUG { .procname = "debug_level",
@@ -3739,6 +3745,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net) tbl[idx++].data = &ipvs->sysctl_nat_icmp_send; ipvs->sysctl_pmtu_disc =1 ; tbl[idx++].data = &ipvs->sysctl_pmtu_disc; + tbl[idx++].data = &ipvs->sysctl_backup_only; ipvs->sysctl_hdr =register_net_sysctl (net,"net/ipv4/vs" , tbl);
Signature · 1 line
1.7.3.4
Julian Anastasov
maintainerPATCH 2/5 ipvs: remove extra rcu lock
In reply to Julian Anastasov In 3.7 we added code that uses ipv4_update_pmtu
but after commit c5ae7d4192 (ipv4: must use rcu protection while calling fib_lookup) the RCU lock is not needed.
--- net/netfilter/ipvs/ip_vs_core.c | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-)
net/netfilter/ipvs/ip_vs_core.c +0 -2
@@ -1393,10 +1393,8 @@ ip_vs_in_icmp(struct sk_buff *skb, int *related, unsigned int hooknum)skb_reset_network_header (skb);IP_VS_DBG (12 ,"ICMP for IPIP %pI4->%pI4: mtu=%u\n" , &ip_hdr (skb)->saddr, &ip_hdr (skb)->daddr, mtu); -rcu_read_lock ();ipv4_update_pmtu (skb,dev_net (skb->dev), mtu,0 ,0 ,0 ,0 ); -rcu_read_unlock ();/* Client uses PMTUD? */ if (!(cih->frag_off &htons (IP_DF ))) goto ignore_ipip;
Signature · 1 line
1.7.3.4
Julian Anastasov
maintainerPATCH 3/5 ipvs: fix sctp chunk length order
In reply to Julian Anastasov Fix wrong but non-fatal access to chunk length.sch->length should be in network order, next chunk should be aligned to 4 bytes. Problem noticed in sparse output.
--- net/netfilter/ipvs/ip_vs_proto_sctp.c | 16 +++++++++------- 1 files changed, 9 insertions(+), 7 deletions(-)
net/netfilter/ipvs/ip_vs_proto_sctp.c +9 -7
@@ -906,7 +906,7 @@ set_sctp_state(struct ip_vs_proto_data *pd, struct ip_vs_conn *cp,sctp_chunkhdr_t _sctpch, *sch;unsigned char chunk_type;int event, next_state; -int ihl; +int ihl, cofs;#ifdef CONFIG_IP_VS_IPV6 ihl = cp->af ==AF_INET ?ip_hdrlen (skb) :sizeof (struct ipv6hdr );
@@ -914,8 +914,8 @@ set_sctp_state(struct ip_vs_proto_data *pd, struct ip_vs_conn *cp, ihl =ip_hdrlen (skb);#endif - sch =skb_header_pointer (skb, ihl +sizeof (sctp_sctphdr_t), -sizeof (_sctpch), &_sctpch); + cofs = ihl +sizeof (sctp_sctphdr_t); + sch =skb_header_pointer (skb, cofs,sizeof (_sctpch), &_sctpch);if (sch ==NULL )return ;
@@ -933,10 +933,12 @@ set_sctp_state(struct ip_vs_proto_data *pd, struct ip_vs_conn *cp,*/ if ((sch->type ==SCTP_CID_COOKIE_ECHO ) || (sch->type ==SCTP_CID_COOKIE_ACK )) { - sch =skb_header_pointer (skb, (ihl +sizeof (sctp_sctphdr_t) + - sch->length),sizeof (_sctpch), &_sctpch); -if (sch) { -if (sch->type ==SCTP_CID_ABORT ) +int clen =ntohs (sch->length); + +if (clen >=sizeof (sctp_chunkhdr_t)) { + sch =skb_header_pointer (skb, cofs +ALIGN (clen,4 ), +sizeof (_sctpch), &_sctpch); +if (sch && sch->type ==SCTP_CID_ABORT ) chunk_type = sch->type; } }
Signature · 1 line
1.7.3.4
Julian Anastasov
maintainerPATCH 4/5 ipvs: fix hashing in ip_vs_svc_hashkey
In reply to Julian Anastasov net is a pointer in host order, mix it properly
with other keys in network order. Fixes sparse warning.
--- net/netfilter/ipvs/ip_vs_ctl.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-)
net/netfilter/ipvs/ip_vs_ctl.c +5 -3
@@ -271,16 +271,18 @@ ip_vs_svc_hashkey(struct net *net, int af, unsigned int proto, { registerunsigned int porth =ntohs (port);__be32 addr_fold = addr->ip; +__u32 ahash;#ifdef CONFIG_IP_VS_IPV6 if (af ==AF_INET6 ) addr_fold = addr->ip6[0 ]^addr->ip6[1 ]^ addr->ip6[2 ]^addr->ip6[3 ];#endif - addr_fold ^= ((size_t )net>>8 ); + ahash =ntohl (addr_fold); + ahash ^= ((size_t ) net >>8 ); -return (proto^ntohl (addr_fold)^(porth>>IP_VS_SVC_TAB_BITS )^porth) - &IP_VS_SVC_TAB_MASK ; +return (proto ^ ahash ^ (porth >>IP_VS_SVC_TAB_BITS ) ^ porth) & +IP_VS_SVC_TAB_MASK ; }/*
Signature · 1 line
1.7.3.4
Julian Anastasov
maintainerPATCH 5/5 ipvs: fix some sparse warnings
In reply to Julian Anastasov Add missing __percpu annotations and makeip_vs_net_id static.
--- include/net/ip_vs.h | 2 +- net/netfilter/ipvs/ip_vs_core.c | 8 +------- net/netfilter/ipvs/ip_vs_est.c | 2 +- 3 files changed, 3 insertions(+), 9 deletions(-)
include/net/ip_vs.h +1 -1
@@ -474,7 +474,7 @@ struct ip_vs_estimator {struct ip_vs_stats {struct ip_vs_stats_user ustats;/* statistics */ struct ip_vs_estimator est;/* estimator */ -struct ip_vs_cpu_stats *cpustats;/* per cpu counters */ +struct ip_vs_cpu_stats __percpu *cpustats;/* per cpu counters */ spinlock_t lock;/* spin lock */ struct ip_vs_stats_user ustats0;/* reset values */ };
net/netfilter/ipvs/ip_vs_core.c +1 -6
@@ -69,10 +69,7 @@ EXPORT_SYMBOL(ip_vs_conn_put);EXPORT_SYMBOL (ip_vs_get_debug_level);#endif -int ip_vs_net_id__read_mostly ; -#ifdef IP_VS_GENERIC_NETNS -EXPORT_SYMBOL (ip_vs_net_id); -#endif +static int ip_vs_net_id__read_mostly ;/* netns cnt used for uniqueness */ static atomic_t ipvs_netns_cnt =ATOMIC_INIT (0 );
@@ -1180,9 +1177,6 @@ ip_vs_out(unsigned int hooknum, struct sk_buff *skb, int af) iph.len)))) {#ifdef CONFIG_IP_VS_IPV6 if (af ==AF_INET6 ) { -struct net *net = -dev_net (skb_dst (skb)->dev);
Quoted 8 lines · Julian Anastasov
This patchset adds new
backup_onlyflag and fixes
some warnings found by sparse. I hope the SCTP part is correct. In fact I see other problems with the SCTP state machine that need to be resolved.The patchset does not overlap with the other
patchset for IPVS optimizations, so can be applied independently.
Thanks, applied.