Skip to contentSkip to conversation

Support v6 real servers in v4 pools and vice versa

PATCH Superseded Alex Gartrell 2 participants 21 messages Aug 15, 2014 – Aug 27, 2014

Subsystems (4)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover Support v6 real servers in v4 pools and vice versa

At Facebook we use ipip forwarding to deliver packets from our layer 4 ipvs load balancers to our layer 7 proxies. Today these layer 7 proxies are all dual stacked, so we can simply send v4 over v4 and v6 over v6. In the future, we're going to have v6-only layer 7 load balancers (no internal v4 address). To deal with this, we'll forward v4 packets in v6 tunnels. This patchset introduces the necessary functionality into ipvs.

The noteworthy limitation of this is that it is not compatible with state synchronization, so great care is taken to keep these things mutually exclusive.

This patchset includes changes that add an additional netlink attribute to destinations and changes that plumb the destination address family through parts of the code where it was assumed that it was the same as the service. Finally, there's a change that updates the transmit functions for tunneling to share common code and support v4 in v6 and vice versa.

Changes for v2:

Introduced crosses_local_route_boundary and update_pmtu functions and conditionally do the ip_hdr operations. The latter means that df will be effectively zero when we forward an ipv6 packet over an ipv4 tunnel.

Additionally, I addressed Julian's other statements.

Alex Gartrell (9):
ipvs: Pass destination address family to ip_vs_trash_get_dest
ipvs: Supply destination address family to ip_vs_conn_new
ipvs: maintain a mixed_address_family_dest count
ipvs: prevent mixing heterogeneous pools and synchronization
ipvs: Supply skb_af to out_rt* functions
ipvs: Pull out crosses_local_route_boundary logic
ipvs: Pull out update_pmtu code
ipvs: Only do ip_hdr operations in *out_rt when skb_af is AF_INET
ipvs: support ipv4 in ipv6 and ipv6 in ipv4 tunnel forwarding

Julian Anastasov (9):
ipvs: address family of LBLC entry depends on svc family
ipvs: address family of LBLCR entry depends on svc family
ipvs: use correct address family in DH logs
ipvs: use correct address family in LC logs
ipvs: use correct address family in NQ logs
ipvs: use correct address family in RR logs
ipvs: use correct address family in SED logs
ipvs: use correct address family in SH logs
ipvs: use correct address family in WLC logs

 include/net/ip_vs.h              |   7 +-
 net/netfilter/ipvs/ip_vs_conn.c  |  17 +-
 net/netfilter/ipvs/ip_vs_core.c  |   9 +-
 net/netfilter/ipvs/ip_vs_ctl.c   |  55 +++++--
 net/netfilter/ipvs/ip_vs_dh.c    |   2 +-
 net/netfilter/ipvs/ip_vs_ftp.c   |   6 +-
 net/netfilter/ipvs/ip_vs_lblc.c  |  12 +-
 net/netfilter/ipvs/ip_vs_lblcr.c |  12 +-
 net/netfilter/ipvs/ip_vs_lc.c    |   2 +-
 net/netfilter/ipvs/ip_vs_nq.c    |   3 +-
 net/netfilter/ipvs/ip_vs_rr.c    |   2 +-
 net/netfilter/ipvs/ip_vs_sed.c   |   3 +-
 net/netfilter/ipvs/ip_vs_sh.c    |   8 +-
 net/netfilter/ipvs/ip_vs_sync.c  |   3 +-
 net/netfilter/ipvs/ip_vs_wlc.c   |   3 +-
 net/netfilter/ipvs/ip_vs_xmit.c  | 329 ++++++++++++++++++++++++---------------
 16 files changed, 304 insertions(+), 169 deletions(-)
Signature · 1 line
1.8.1
#1 lore raw

PATCH v2 1/18 ipvs: Pass destination address family to ip_vs_trash_get_dest

Part of a series of diffs to tease out destination family from virtual family. This diff just adds a parameter to ip_vs_trash_get and then uses it for comparison rather than svc->af.

---
 net/netfilter/ipvs/ip_vs_ctl.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
net/netfilter/ipvs/ip_vs_ctl.c +6 -6
index eec8dee..01c813e 100644
@@ -657,8 +657,8 @@ static void __ip_vs_dst_cache_reset(struct ip_vs_dest *dest)
  *  scheduling.
  */
 static struct ip_vs_dest *
-ip_vs_trash_get_dest(struct ip_vs_service *svc, const union nf_inet_addr *daddr,
-		     __be16 dport)
+ip_vs_trash_get_dest(struct ip_vs_service *svc, int dest_af,
+		     const union nf_inet_addr *daddr, __be16 dport)
 {
 	struct ip_vs_dest *dest;
 	struct netns_ipvs *ipvs = net_ipvs(svc->net);
@@ -671,11 +671,11 @@ ip_vs_trash_get_dest(struct ip_vs_service *svc, const union nf_inet_addr *daddr,
 		IP_VS_DBG_BUF(3, "Destination %u/%s:%u still in trash, "
 			      "dest->refcnt=%d\n",
 			      dest->vfwmark,
-			      IP_VS_DBG_ADDR(svc->af, &dest->addr),
+			      IP_VS_DBG_ADDR(dest->af, &dest->addr),
 			      ntohs(dest->port),
 			      atomic_read(&dest->refcnt));
-		if (dest->af == svc->af &&
-		    ip_vs_addr_equal(svc->af, &dest->addr, daddr) &&
+		if (dest->af == dest_af &&
+		    ip_vs_addr_equal(dest_af, &dest->addr, daddr) &&
 		    dest->port == dport &&
 		    dest->vfwmark == svc->fwmark &&
 		    dest->protocol == svc->protocol &&
@@ -950,7 +950,7 @@ ip_vs_add_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
 	 * Check if the dest already exists in the trash and
 	 * is from the same service
 	 */
-	dest = ip_vs_trash_get_dest(svc, &daddr, dport);
+	dest = ip_vs_trash_get_dest(svc, udest->af, &daddr, dport);
 
 	if (dest != NULL) {
 		IP_VS_DBG_BUF(3, "Get destination %s:%u from trash, "
Signature · 1 line
1.8.1
#2 lore raw

PATCH v2 2/18 ipvs: Supply destination address family to ip_vs_conn_new

In reply to Alex Gartrell

The assumption that dest af is equal to service af is now unreliable, so we must specify it manually so as not to copy just the first 4 bytes of a v6 address or doing an illegal read of 16 butes on a v6 address.

We "lie" in two places: for synchronization (which we will explicitly disallow from happening when we have heterogeneous pools) and for black hole addresses where there's no real dest.

---
 include/net/ip_vs.h             | 3 ++-
 net/netfilter/ipvs/ip_vs_conn.c | 5 +++--
 net/netfilter/ipvs/ip_vs_core.c | 9 +++++----
 net/netfilter/ipvs/ip_vs_ftp.c  | 6 ++++--
 net/netfilter/ipvs/ip_vs_sync.c | 3 ++-
 5 files changed, 16 insertions(+), 10 deletions(-)
include/net/ip_vs.h +2 -1
index 2fa1155..7600dbe 100644
@@ -535,6 +535,7 @@ struct ip_vs_conn {
 	union nf_inet_addr      daddr;          /* destination address */
 	volatile __u32          flags;          /* status flags */
 	__u16                   protocol;       /* Which protocol (TCP/UDP) */
+	__u16			daf;		/* Address family of the dest */
 #ifdef CONFIG_NET_NS
 	struct net              *net;           /* Name space */
 #endif
@@ -1213,7 +1214,7 @@ static inline void __ip_vs_conn_put(struct ip_vs_conn *cp)
 void ip_vs_conn_put(struct ip_vs_conn *cp);
 void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __be16 cport);
 
-struct ip_vs_conn *ip_vs_conn_new(const struct ip_vs_conn_param *p,
+struct ip_vs_conn *ip_vs_conn_new(const struct ip_vs_conn_param *p, int dest_af,
 				  const union nf_inet_addr *daddr,
 				  __be16 dport, unsigned int flags,
 				  struct ip_vs_dest *dest, __u32 fwmark);
net/netfilter/ipvs/ip_vs_conn.c +3 -2
index 8f4c602..fdb4880 100644
@@ -854,7 +854,7 @@ void ip_vs_conn_expire_now(struct ip_vs_conn *cp)
  *	Create a new connection entry and hash it into the ip_vs_conn_tab
  */
 struct ip_vs_conn *
-ip_vs_conn_new(const struct ip_vs_conn_param *p,
+ip_vs_conn_new(const struct ip_vs_conn_param *p, int dest_af,
 	       const union nf_inet_addr *daddr, __be16 dport, unsigned int flags,
 	       struct ip_vs_dest *dest, __u32 fwmark)
 {
@@ -873,6 +873,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
 	setup_timer(&cp->timer, ip_vs_conn_expire, (unsigned long)cp);
 	ip_vs_conn_net_set(cp, p->net);
 	cp->af		   = p->af;
+	cp->daf		   = dest_af;
 	cp->protocol	   = p->protocol;
 	ip_vs_addr_set(p->af, &cp->caddr, p->caddr);
 	cp->cport	   = p->cport;
@@ -880,7 +881,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
 	ip_vs_addr_set(p->protocol == IPPROTO_IP ? AF_UNSPEC : p->af,
 		       &cp->vaddr, p->vaddr);
 	cp->vport	   = p->vport;
-	ip_vs_addr_set(p->af, &cp->daddr, daddr);
+	ip_vs_addr_set(cp->daf, &cp->daddr, daddr);
 	cp->dport          = dport;
 	cp->flags	   = flags;
 	cp->fwmark         = fwmark;
net/netfilter/ipvs/ip_vs_core.c +5 -4
index e683675..0cf952a 100644
@@ -328,7 +328,7 @@ ip_vs_sched_persist(struct ip_vs_service *svc,
 		 * This adds param.pe_data to the template,
 		 * and thus param.pe_data will be destroyed
 		 * when the template expires */
-		ct = ip_vs_conn_new(&param, &dest->addr, dport,
+		ct = ip_vs_conn_new(&param, dest->af, &dest->addr, dport,
 				    IP_VS_CONN_F_TEMPLATE, dest, skb->mark);
 		if (ct == NULL) {
 			kfree(param.pe_data);
@@ -357,7 +357,8 @@ ip_vs_sched_persist(struct ip_vs_service *svc,
 	ip_vs_conn_fill_param(svc->net, svc->af, iph->protocol, &iph->saddr,
 			      src_port, &iph->daddr, dst_port, &param);
 
-	cp = ip_vs_conn_new(&param, &dest->addr, dport, flags, dest, skb->mark);
+	cp = ip_vs_conn_new(&param, dest->af, &dest->addr, dport, flags, dest,
+			    skb->mark);
 	if (cp == NULL) {
 		ip_vs_conn_put(ct);
 		*ignored = -1;
@@ -479,7 +480,7 @@ ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb,
 		ip_vs_conn_fill_param(svc->net, svc->af, iph->protocol,
 				      &iph->saddr, pptr[0], &iph->daddr,
 				      pptr[1], &p);
-		cp = ip_vs_conn_new(&p, &dest->addr,
+		cp = ip_vs_conn_new(&p, dest->af, &dest->addr,
 				    dest->port ? dest->port : pptr[1],
 				    flags, dest, skb->mark);
 		if (!cp) {
@@ -550,7 +551,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
 			ip_vs_conn_fill_param(svc->net, svc->af, iph->protocol,
 					      &iph->saddr, pptr[0],
 					      &iph->daddr, pptr[1], &p);
-			cp = ip_vs_conn_new(&p, &daddr, 0,
+			cp = ip_vs_conn_new(&p, svc->af, &daddr, 0,
 					    IP_VS_CONN_F_BYPASS | flags,
 					    NULL, skb->mark);
 			if (!cp)
net/netfilter/ipvs/ip_vs_ftp.c +4 -2
index 77c1732..a64fa15 100644
@@ -233,7 +233,8 @@ static int ip_vs_ftp_out(struct ip_vs_app *app, struct ip_vs_conn *cp,
 			ip_vs_conn_fill_param(ip_vs_conn_net(cp),
 					      AF_INET, IPPROTO_TCP, &cp->caddr,
 					      0, &cp->vaddr, port, &p);
-			n_cp = ip_vs_conn_new(&p, &from, port,
+			/* As above, this is ipv4 only */
+			n_cp = ip_vs_conn_new(&p, AF_INET, &from, port,
 					      IP_VS_CONN_F_NO_CPORT |
 					      IP_VS_CONN_F_NFCT,
 					      cp->dest, skb->mark);
@@ -396,7 +397,8 @@ static int ip_vs_ftp_in(struct ip_vs_app *app, struct ip_vs_conn *cp,
 				      htons(ntohs(cp->vport)-1), &p);
 		n_cp = ip_vs_conn_in_get(&p);
 		if (!n_cp) {
-			n_cp = ip_vs_conn_new(&p, &cp->daddr,
+			/* This is ipv4 only */
+			n_cp = ip_vs_conn_new(&p, AF_INET, &cp->daddr,
 					      htons(ntohs(cp->dport)-1),
 					      IP_VS_CONN_F_NFCT, cp->dest,
 					      skb->mark);
net/netfilter/ipvs/ip_vs_sync.c +2 -1
index 61701ed..da7e0a2 100644
@@ -889,7 +889,8 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
 				       param->vaddr, param->vport, protocol,
 				       fwmark, flags);
 
-		cp = ip_vs_conn_new(param, daddr, dport, flags, dest, fwmark);
+		cp = ip_vs_conn_new(param, type, daddr, dport, flags, dest,
+				    fwmark);
 		rcu_read_unlock();
 		if (!cp) {
 			if (param->pe_data)
Signature · 1 line
1.8.1
#3 lore raw

PATCH v2 3/18 ipvs: maintain a mixed_address_family_dest count

In reply to Alex Gartrell

This is necessary to validate that we're not accidentally enabling heterogeneous pool incompatible features like syncing.

---
 include/net/ip_vs.h            |  4 ++++
 net/netfilter/ipvs/ip_vs_ctl.c | 13 +++++++++++++
 2 files changed, 17 insertions(+)
include/net/ip_vs.h +4 -0
index 7600dbe..576d7f0 100644
@@ -990,6 +990,10 @@ struct netns_ipvs {
 	char			backup_mcast_ifn[IP_VS_IFNAME_MAXLEN];
 	/* net name space ptr */
 	struct net		*net;            /* Needed by timer routines */
+	/* Number of heterogeneous destinations, needed because
+	 * heterogeneous are not supported when synchronization is
+	 * enabled */
+	unsigned int		mixed_address_family_dests;
 };
 
 #define DEFAULT_SYNC_THRESHOLD	3
net/netfilter/ipvs/ip_vs_ctl.c +13 -0
index 01c813e..2356f1d 100644
@@ -778,6 +778,16 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
 	struct ip_vs_service *old_svc;
 	struct ip_vs_scheduler *sched;
 	int conn_flags;
+	u16 old_af, new_af;
+
+	new_af = udest->af;
+	old_af = dest->af;
+
+	/* We cannot modify an address and change the address family */
+	BUG_ON(!add && udest->af != dest->af);
+
+	if (add && udest->af != svc->af)
+		ipvs->mixed_address_family_dests++;
 
 	/* set the weight and the flags */
 	atomic_set(&dest->weight, udest->weight);
@@ -1061,6 +1071,9 @@ static void __ip_vs_unlink_dest(struct ip_vs_service *svc,
 	list_del_rcu(&dest->n_list);
 	svc->num_dests--;
 
+	if (dest->af != svc->af)
+		net_ipvs(svc->net)->mixed_address_family_dests--;
+
 	if (svcupd) {
 		struct ip_vs_scheduler *sched;
 
Signature · 1 line
1.8.1
#4 lore raw

PATCH v2 4/18 ipvs: prevent mixing heterogeneous pools and synchronization

In reply to Alex Gartrell

The synchronization protocol is not compatible with heterogeneous pools, so we need to verify that we're not turning both on at the same time.

This also introduces a switch statement that we'll use to turn on forwarding types on a case by case basis.

---
 net/netfilter/ipvs/ip_vs_ctl.c | 30 ++++++++++++++++++++++++++----
 1 file changed, 26 insertions(+), 4 deletions(-)
net/netfilter/ipvs/ip_vs_ctl.c +26 -4
index 2356f1d..6d07a51 100644
@@ -858,10 +858,6 @@ ip_vs_new_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest,
 
 	EnterFunction(2);
 
-	/* Temporary for consistency */
-	if (udest->af != svc->af)
-		return -EINVAL;
-
 #ifdef CONFIG_IP_VS_IPV6
 	if (udest->af == AF_INET6) {
 		atype = ipv6_addr_type(&udest->addr.in6);
@@ -3355,6 +3351,12 @@ static int ip_vs_genl_new_daemon(struct net *net, struct nlattr **attrs)
 	      attrs[IPVS_DAEMON_ATTR_SYNC_ID]))
 		return -EINVAL;
 
+	/* The synchronization protocol is incompatible with mixed family
+	 * services
+	 */
+	if (net_ipvs(net)->mixed_address_family_dests > 0)
+		return -EINVAL;
+
 	return start_sync_thread(net,
 				 nla_get_u32(attrs[IPVS_DAEMON_ATTR_STATE]),
 				 nla_data(attrs[IPVS_DAEMON_ATTR_MCAST_IFN]),
@@ -3487,6 +3489,26 @@ static int ip_vs_genl_set_cmd(struct sk_buff *skb, struct genl_info *info)
 		 */
 		if (udest.af == 0)
 			udest.af = svc->af;
+
+		if (udest.af != svc->af) {
+			/* The synchronization protocol is incompatible
+			 * with mixed family services
+			 */
+			if (net_ipvs(net)->sync_state) {
+				ret = -EINVAL;
+				goto out;
+			}
+
+			/* Which connection types do we support? */
+			switch (udest.conn_flags) {
+			case IP_VS_CONN_F_TUNNEL:
+				/* We are able to forward this */
+				break;
+			default:
+				ret = -EINVAL;
+				goto out;
+			}
+		}
 	}
 
 	switch (cmd) {
Signature · 1 line
1.8.1
#5 lore raw

PATCH v2 5/18 ipvs: Supply skb_af to out_rt* functions

In reply to Alex Gartrell

The out_rt functions inspect the skb's to ensure that we aren't breaking any rules by crossing local/external boundaries. Right now, they assume that the address family of the skb packets is the same as they are, but that assumption will no longer be true.

This patch introduces an additional parameter to the out route functions so that we can make more intelligent decisions based upon the actual skb address family later.

---
 net/netfilter/ipvs/ip_vs_xmit.c | 33 +++++++++++++++++----------------
 1 file changed, 17 insertions(+), 16 deletions(-)
net/netfilter/ipvs/ip_vs_xmit.c +17 -16
index 56896a4..94c7466 100644
@@ -159,7 +159,7 @@ retry:
 
 /* Get route to destination or remote server */
 static int
-__ip_vs_get_out_rt(struct sk_buff *skb, struct ip_vs_dest *dest,
+__ip_vs_get_out_rt(int skb_af, struct sk_buff *skb, struct ip_vs_dest *dest,
 		   __be32 daddr, int rt_mode, __be32 *ret_saddr)
 {
 	struct net *net = dev_net(skb_dst(skb)->dev);
@@ -339,7 +339,7 @@ out_err:
  * Get route to destination or remote server
  */
 static int
-__ip_vs_get_out_rt_v6(struct sk_buff *skb, struct ip_vs_dest *dest,
+__ip_vs_get_out_rt_v6(int skb_af, struct sk_buff *skb, struct ip_vs_dest *dest,
 		      struct in6_addr *daddr, struct in6_addr *ret_saddr,
 		      struct ip_vs_iphdr *ipvsh, int do_xfrm, int rt_mode)
 {
@@ -556,8 +556,8 @@ ip_vs_bypass_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
 	EnterFunction(10);
 
 	rcu_read_lock();
-	if (__ip_vs_get_out_rt(skb, NULL, iph->daddr, IP_VS_RT_MODE_NON_LOCAL,
-			       NULL) < 0)
+	if (__ip_vs_get_out_rt(cp->af, skb, NULL, iph->daddr,
+			       IP_VS_RT_MODE_NON_LOCAL, NULL) < 0)
 		goto tx_error;
 
 	ip_send_check(iph);
@@ -586,7 +586,7 @@ ip_vs_bypass_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
 	EnterFunction(10);
 
 	rcu_read_lock();
-	if (__ip_vs_get_out_rt_v6(skb, NULL, &ipvsh->daddr.in6, NULL,
+	if (__ip_vs_get_out_rt_v6(cp->af, skb, NULL, &ipvsh->daddr.in6, NULL,
 				  ipvsh, 0, IP_VS_RT_MODE_NON_LOCAL) < 0)
 		goto tx_error;
 
@@ -633,7 +633,7 @@ ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
 	}
 
 	was_input = rt_is_input_route(skb_rtable(skb));
-	local = __ip_vs_get_out_rt(skb, cp->dest, cp->daddr.ip,
+	local = __ip_vs_get_out_rt(cp->af, skb, cp->dest, cp->daddr.ip,
 				   IP_VS_RT_MODE_LOCAL |
 				   IP_VS_RT_MODE_NON_LOCAL |
 				   IP_VS_RT_MODE_RDR, NULL);
@@ -721,8 +721,8 @@ ip_vs_nat_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
 		IP_VS_DBG(10, "filled cport=%d\n", ntohs(*p));
 	}
 
-	local = __ip_vs_get_out_rt_v6(skb, cp->dest, &cp->daddr.in6, NULL,
-				      ipvsh, 0,
+	local = __ip_vs_get_out_rt_v6(cp->af, skb, cp->dest, &cp->daddr.in6,
+				      NULL, ipvsh, 0,
 				      IP_VS_RT_MODE_LOCAL |
 				      IP_VS_RT_MODE_NON_LOCAL |
 				      IP_VS_RT_MODE_RDR);
@@ -829,7 +829,7 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
 	EnterFunction(10);
 
 	rcu_read_lock();
-	local = __ip_vs_get_out_rt(skb, cp->dest, cp->daddr.ip,
+	local = __ip_vs_get_out_rt(cp->af, skb, cp->dest, cp->daddr.ip,
 				   IP_VS_RT_MODE_LOCAL |
 				   IP_VS_RT_MODE_NON_LOCAL |
 				   IP_VS_RT_MODE_CONNECT |
@@ -928,7 +928,7 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
 	EnterFunction(10);
 
 	rcu_read_lock();
-	local = __ip_vs_get_out_rt_v6(skb, cp->dest, &cp->daddr.in6,
+	local = __ip_vs_get_out_rt_v6(cp->af, skb, cp->dest, &cp->daddr.in6,
 				      &saddr, ipvsh, 1,
 				      IP_VS_RT_MODE_LOCAL |
 				      IP_VS_RT_MODE_NON_LOCAL |
@@ -1021,7 +1021,7 @@ ip_vs_dr_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
 	EnterFunction(10);
 
 	rcu_read_lock();
-	local = __ip_vs_get_out_rt(skb, cp->dest, cp->daddr.ip,
+	local = __ip_vs_get_out_rt(cp->af, skb, cp->dest, cp->daddr.ip,
 				   IP_VS_RT_MODE_LOCAL |
 				   IP_VS_RT_MODE_NON_LOCAL |
 				   IP_VS_RT_MODE_KNOWN_NH, NULL);
@@ -1060,8 +1060,8 @@ ip_vs_dr_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
 	EnterFunction(10);
 
 	rcu_read_lock();
-	local = __ip_vs_get_out_rt_v6(skb, cp->dest, &cp->daddr.in6, NULL,
-				      ipvsh, 0,
+	local = __ip_vs_get_out_rt_v6(cp->af, skb, cp->dest, &cp->daddr.in6,
+				      NULL, ipvsh, 0,
 				      IP_VS_RT_MODE_LOCAL |
 				      IP_VS_RT_MODE_NON_LOCAL);
 	if (local < 0)
@@ -1128,7 +1128,8 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
 		  IP_VS_RT_MODE_LOCAL | IP_VS_RT_MODE_NON_LOCAL |
 		  IP_VS_RT_MODE_RDR : IP_VS_RT_MODE_NON_LOCAL;
 	rcu_read_lock();
-	local = __ip_vs_get_out_rt(skb, cp->dest, cp->daddr.ip, rt_mode, NULL);
+	local = __ip_vs_get_out_rt(cp->af, skb, cp->dest, cp->daddr.ip, rt_mode,
+				   NULL);
 	if (local < 0)
 		goto tx_error;
 	rt = skb_rtable(skb);
@@ -1219,8 +1220,8 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
 		  IP_VS_RT_MODE_LOCAL | IP_VS_RT_MODE_NON_LOCAL |
 		  IP_VS_RT_MODE_RDR : IP_VS_RT_MODE_NON_LOCAL;
 	rcu_read_lock();
-	local = __ip_vs_get_out_rt_v6(skb, cp->dest, &cp->daddr.in6, NULL,
-				      ipvsh, 0, rt_mode);
+	local = __ip_vs_get_out_rt_v6(cp->af, skb, cp->dest, &cp->daddr.in6,
+				      NULL, ipvsh, 0, rt_mode);
 	if (local < 0)
 		goto tx_error;
 	rt = (struct rt6_info *) skb_dst(skb);
Signature · 1 line
1.8.1
#6 lore raw

PATCH v2 6/18 ipvs: Pull out crosses_local_route_boundary logic

In reply to Alex Gartrell

This logic is repeated in both out_rt functions so it was redundant. Additionally, we'll need to be able to do checks to route v4 to v6 and vice versa in order to deal with heterogeneous pools.

---
 net/netfilter/ipvs/ip_vs_xmit.c | 105 +++++++++++++++++++++-------------------
 1 file changed, 54 insertions(+), 51 deletions(-)
net/netfilter/ipvs/ip_vs_xmit.c +54 -51
index 94c7466..b348347 100644
@@ -157,6 +157,49 @@ retry:
 	return rt;
 }
 
+#ifdef CONFIG_IP_VS_IPV6
+static inline int __ip_vs_is_local_route6(struct rt6_info *rt)
+{
+	return rt->dst.dev && rt->dst.dev->flags & IFF_LOOPBACK;
+}
+#endif
+
+static inline bool crosses_local_route_boundary(int skb_af, struct sk_buff *skb,
+						int rt_mode, bool new_rt_is_local)
+{
+	bool rt_mode_allow_local = !!(rt_mode & IP_VS_RT_MODE_LOCAL);
+	bool rt_mode_allow_non_local = !!(rt_mode & IP_VS_RT_MODE_LOCAL);
+	bool rt_mode_allow_redirect = !!(rt_mode & IP_VS_RT_MODE_RDR);
+	bool source_is_loopback;
+	bool old_rt_is_local;
+
+#ifdef CONFIG_IP_VS_IPV6
+	if (skb_af == AF_INET6) {
+		source_is_loopback = (!skb->dev || skb->dev->flags & IFF_LOOPBACK) &&
+			(ipv6_addr_type(&ipv6_hdr(skb)->saddr) & IPV6_ADDR_LOOPBACK);
+		old_rt_is_local = __ip_vs_is_local_route6(
+			(struct rt6_info *) skb_dst(skb));
+	} else
+#endif
+	{
+		source_is_loopback = ipv4_is_loopback(ip_hdr(skb)->saddr);
+		old_rt_is_local = skb_rtable(skb)->rt_flags & RTCF_LOCAL;
+	}
+
+	if (unlikely(new_rt_is_local)) {
+		if (!rt_mode_allow_local)
+			return true;
+		if (!rt_mode_allow_redirect && old_rt_is_local)
+			return true;
+	} else {
+		if (!rt_mode_allow_non_local)
+			return true;
+		if (source_is_loopback)
+			return true;
+	}
+	return false;
+}
+
 /* Get route to destination or remote server */
 static int
 __ip_vs_get_out_rt(int skb_af, struct sk_buff *skb, struct ip_vs_dest *dest,
@@ -218,30 +261,14 @@ __ip_vs_get_out_rt(int skb_af, struct sk_buff *skb, struct ip_vs_dest *dest,
 	}
 
 	local = (rt->rt_flags & RTCF_LOCAL) ? 1 : 0;
-	if (!((local ? IP_VS_RT_MODE_LOCAL : IP_VS_RT_MODE_NON_LOCAL) &
-	      rt_mode)) {
-		IP_VS_DBG_RL("Stopping traffic to %s address, dest: %pI4\n",
-			     (rt->rt_flags & RTCF_LOCAL) ?
-			     "local":"non-local", &daddr);
+	if (unlikely(crosses_local_route_boundary(skb_af, skb, rt_mode,
+						  local))) {
+		IP_VS_DBG_RL("We are crossing local and non-local addresses\n");
 		goto err_put;
 	}
 	iph = ip_hdr(skb);
-	if (likely(!local)) {
-		if (unlikely(ipv4_is_loopback(iph->saddr))) {
-			IP_VS_DBG_RL("Stopping traffic from loopback address "
-				     "%pI4 to non-local address, dest: %pI4\n",
-				     &iph->saddr, &daddr);
-			goto err_put;
-		}
-	} else {
-		ort = skb_rtable(skb);
-		if (!(rt_mode & IP_VS_RT_MODE_RDR) &&
-		    !(ort->rt_flags & RTCF_LOCAL)) {
-			IP_VS_DBG_RL("Redirect from non-local address %pI4 to "
-				     "local requires NAT method, dest: %pI4\n",
-				     &iph->daddr, &daddr);
-			goto err_put;
-		}
+
+	if (unlikely(local)) {
 		/* skb to local stack, preserve old route */
 		if (!noref)
 			ip_rt_put(rt);
@@ -295,12 +322,6 @@ err_unreach:
 }
 
 #ifdef CONFIG_IP_VS_IPV6
-
-static inline int __ip_vs_is_local_route6(struct rt6_info *rt)
-{
-	return rt->dst.dev && rt->dst.dev->flags & IFF_LOOPBACK;
-}
-
 static struct dst_entry *
 __ip_vs_route_output_v6(struct net *net, struct in6_addr *daddr,
 			struct in6_addr *ret_saddr, int do_xfrm)
@@ -393,32 +414,14 @@ __ip_vs_get_out_rt_v6(int skb_af, struct sk_buff *skb, struct ip_vs_dest *dest,
 	}
 
 	local = __ip_vs_is_local_route6(rt);
-	if (!((local ? IP_VS_RT_MODE_LOCAL : IP_VS_RT_MODE_NON_LOCAL) &
-	      rt_mode)) {
-		IP_VS_DBG_RL("Stopping traffic to %s address, dest: %pI6c\n",
-			     local ? "local":"non-local", daddr);
+
+	if (unlikely(crosses_local_route_boundary(skb_af, skb, rt_mode,
+						  local))) {
+		IP_VS_DBG_RL("We are crossing local and non-local addresses\n");
 		goto err_put;
 	}
-	if (likely(!local)) {
-		if (unlikely((!skb->dev || skb->dev->flags & IFF_LOOPBACK) &&
-			     ipv6_addr_type(&ipv6_hdr(skb)->saddr) &
-					    IPV6_ADDR_LOOPBACK)) {
-			IP_VS_DBG_RL("Stopping traffic from loopback address "
-				     "%pI6c to non-local address, "
-				     "dest: %pI6c\n",
-				     &ipv6_hdr(skb)->saddr, daddr);
-			goto err_put;
-		}
-	} else {
-		ort = (struct rt6_info *) skb_dst(skb);
-		if (!(rt_mode & IP_VS_RT_MODE_RDR) &&
-		    !__ip_vs_is_local_route6(ort)) {
-			IP_VS_DBG_RL("Redirect from non-local address %pI6c "
-				     "to local requires NAT method, "
-				     "dest: %pI6c\n",
-				     &ipv6_hdr(skb)->daddr, daddr);
-			goto err_put;
-		}
+
+	if (unlikely(local)) {
 		/* skb to local stack, preserve old route */
 		if (!noref)
 			dst_release(&rt->dst);
Signature · 1 line
1.8.1
#7 lore raw

PATCH v2 7/18 ipvs: Pull out update_pmtu code

In reply to Alex Gartrell

Another step toward heterogeneous pools, this removes another piece of functionality currently specific to each address family type.

---
 net/netfilter/ipvs/ip_vs_xmit.c | 33 +++++++++++++++++++++------------
 1 file changed, 21 insertions(+), 12 deletions(-)
net/netfilter/ipvs/ip_vs_xmit.c +20 -8
index b348347..193ad01 100644
@@ -200,6 +200,25 @@ static inline bool crosses_local_route_boundary(int skb_af, struct sk_buff *skb,
 	return false;
 }
 
+static inline void maybe_update_pmtu(int skb_af, struct sk_buff *skb, int mtu)
+{
+	struct sock *sk = skb->sk;
+
+#ifdef CONFIG_IP_VS_IPV6
+	if (skb_af == AF_INET6) {
+		struct rt6_info *ort = (struct rt6_info *) skb_dst(skb);
+		if (!skb->dev && sk && sk->sk_state != TCP_TIME_WAIT)
+			ort->dst.ops->update_pmtu(&ort->dst, sk, NULL, mtu);
+
+	} else
+#endif
+	{
+		struct rtable *ort = skb_rtable(skb);
+		if (!skb->dev && sk && sk->sk_state != TCP_TIME_WAIT)
+			ort->dst.ops->update_pmtu(&ort->dst, sk, NULL, mtu);
+	}
+}
+
 /* Get route to destination or remote server */
 static int
 __ip_vs_get_out_rt(int skb_af, struct sk_buff *skb, struct ip_vs_dest *dest,
@@ -209,7 +228,6 @@ __ip_vs_get_out_rt(int skb_af, struct sk_buff *skb, struct ip_vs_dest *dest,
 	struct netns_ipvs *ipvs = net_ipvs(net);
 	struct ip_vs_dest_dst *dest_dst;
 	struct rtable *rt;			/* Route to the other host */
-	struct rtable *ort;			/* Original route */
 	struct iphdr *iph;
 	__be16 df;
 	int mtu;
@@ -279,16 +297,12 @@ __ip_vs_get_out_rt(int skb_af, struct sk_buff *skb, struct ip_vs_dest *dest,
 		mtu = dst_mtu(&rt->dst);
 		df = iph->frag_off & htons(IP_DF);
 	} else {
-		struct sock *sk = skb->sk;
-
 		mtu = dst_mtu(&rt->dst) - sizeof(struct iphdr);
 		if (mtu < 68) {
 			IP_VS_DBG_RL("%s(): mtu less than 68\n", __func__);
 			goto err_put;
 		}
-		ort = skb_rtable(skb);
-		if (!skb->dev && sk && sk->sk_state != TCP_TIME_WAIT)
-			ort->dst.ops->update_pmtu(&ort->dst, sk, NULL, mtu);
+		maybe_update_pmtu(skb_af, skb, mtu);
 		/* MTU check allowed? */
 		df = sysctl_pmtu_disc(ipvs) ? iph->frag_off & htons(IP_DF) : 0;
 	}
@@ -367,7 +381,6 @@ __ip_vs_get_out_rt_v6(int skb_af, struct sk_buff *skb, struct ip_vs_dest *dest,
 	struct net *net = dev_net(skb_dst(skb)->dev);
 	struct ip_vs_dest_dst *dest_dst;
 	struct rt6_info *rt;			/* Route to the other host */
-	struct rt6_info *ort;			/* Original route */
 	struct dst_entry *dst;
 	int mtu;
 	int local, noref = 1;
@@ -432,17 +445,13 @@ __ip_vs_get_out_rt_v6(int skb_af, struct sk_buff *skb, struct ip_vs_dest *dest,
 	if (likely(!(rt_mode & IP_VS_RT_MODE_TUNNEL)))
 		mtu = dst_mtu(&rt->dst);
 	else {
-		struct sock *sk = skb->sk;
#8 lore raw

PATCH v2 8/18 ipvs: Only do ip_hdr operations in *out_rt when skb_af is AF_INET

In reply to Alex Gartrell

We can no longer count on always being able to access a v4 ip header, so just drop the local variable and use ip_hdr only when skb_af is AF_INET.

---
 net/netfilter/ipvs/ip_vs_xmit.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
net/netfilter/ipvs/ip_vs_xmit.c +6 -6
index 193ad01..7990641 100644
@@ -228,8 +228,7 @@ __ip_vs_get_out_rt(int skb_af, struct sk_buff *skb, struct ip_vs_dest *dest,
 	struct netns_ipvs *ipvs = net_ipvs(net);
 	struct ip_vs_dest_dst *dest_dst;
 	struct rtable *rt;			/* Route to the other host */
-	struct iphdr *iph;
-	__be16 df;
+	__be16 df = 0;
 	int mtu;
 	int local, noref = 1;
 
@@ -284,7 +283,6 @@ __ip_vs_get_out_rt(int skb_af, struct sk_buff *skb, struct ip_vs_dest *dest,
 		IP_VS_DBG_RL("We are crossing local and non-local addresses\n");
 		goto err_put;
 	}
-	iph = ip_hdr(skb);
 
 	if (unlikely(local)) {
 		/* skb to local stack, preserve old route */
@@ -295,7 +293,8 @@ __ip_vs_get_out_rt(int skb_af, struct sk_buff *skb, struct ip_vs_dest *dest,
 
 	if (likely(!(rt_mode & IP_VS_RT_MODE_TUNNEL))) {
 		mtu = dst_mtu(&rt->dst);
-		df = iph->frag_off & htons(IP_DF);
+		if (skb_af == AF_INET)
+			df = ip_hdr(skb)->frag_off & htons(IP_DF);
 	} else {
 		mtu = dst_mtu(&rt->dst) - sizeof(struct iphdr);
 		if (mtu < 68) {
@@ -304,13 +303,14 @@ __ip_vs_get_out_rt(int skb_af, struct sk_buff *skb, struct ip_vs_dest *dest,
 		}
 		maybe_update_pmtu(skb_af, skb, mtu);
 		/* MTU check allowed? */
-		df = sysctl_pmtu_disc(ipvs) ? iph->frag_off & htons(IP_DF) : 0;
+		if (skb_af == AF_INET && sysctl_pmtu_disc(ipvs))
+			df = ip_hdr(skb)->frag_off & htons(IP_DF);
 	}
 
 	/* MTU checking */
 	if (unlikely(df && skb->len > mtu && !skb_is_gso(skb))) {
 		icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, htonl(mtu));
-		IP_VS_DBG(1, "frag needed for %pI4\n", &iph->saddr);
+		IP_VS_DBG(1, "frag needed for %pI4\n", &ip_hdr(skb)->saddr);
 		goto err_put;
 	}
 
Signature · 1 line
1.8.1
#9 lore raw

PATCH v2 9/18 ipvs: support ipv4 in ipv6 and ipv6 in ipv4 tunnel forwarding

In reply to Alex Gartrell

Pull the common logic for preparing an skb to prepend the header into a single function and then set fields such that they can be used in either case (generalize tos and tclass to dscp, hop_limit and ttl to ttl, etc)

---
 net/netfilter/ipvs/ip_vs_conn.c |  12 +++-
 net/netfilter/ipvs/ip_vs_xmit.c | 146 +++++++++++++++++++++++++++++-----------
 2 files changed, 116 insertions(+), 42 deletions(-)
net/netfilter/ipvs/ip_vs_conn.c +10 -2
index fdb4880..13e9cee 100644
@@ -488,7 +488,12 @@ static inline void ip_vs_bind_xmit(struct ip_vs_conn *cp)
 		break;
 
 	case IP_VS_CONN_F_TUNNEL:
-		cp->packet_xmit = ip_vs_tunnel_xmit;
+#ifdef CONFIG_IP_VS_IPV6
+		if (cp->daf == AF_INET6)
+			cp->packet_xmit = ip_vs_tunnel_xmit_v6;
+		else
+#endif
+			cp->packet_xmit = ip_vs_tunnel_xmit;
 		break;
 
 	case IP_VS_CONN_F_DROUTE:
@@ -514,7 +519,10 @@ static inline void ip_vs_bind_xmit_v6(struct ip_vs_conn *cp)
 		break;
 
 	case IP_VS_CONN_F_TUNNEL:
-		cp->packet_xmit = ip_vs_tunnel_xmit_v6;
+		if (cp->daf == AF_INET6)
+			cp->packet_xmit = ip_vs_tunnel_xmit_v6;
+		else
+			cp->packet_xmit = ip_vs_tunnel_xmit;
 		break;
 
 	case IP_VS_CONN_F_DROUTE:
net/netfilter/ipvs/ip_vs_xmit.c +106 -40

204 lines not on this page · raw message

Signature · 1 line
1.8.1
#10 lore raw

PATCH v2 10/18 ipvs: address family of LBLC entry depends on svc family

In reply to Alex Gartrell

From: Julian Anastasov <[email protected]>

The LBLC entries should use svc->af, not dest->af. Needed to support svc->af != dest->af.

---
 net/netfilter/ipvs/ip_vs_lblc.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
net/netfilter/ipvs/ip_vs_lblc.c +6 -6
index 547ff33..127f140 100644
@@ -199,11 +199,11 @@ ip_vs_lblc_get(int af, struct ip_vs_lblc_table *tbl,
  */
 static inline struct ip_vs_lblc_entry *
 ip_vs_lblc_new(struct ip_vs_lblc_table *tbl, const union nf_inet_addr *daddr,
-	       struct ip_vs_dest *dest)
+	       u16 af, struct ip_vs_dest *dest)
 {
 	struct ip_vs_lblc_entry *en;
 
-	en = ip_vs_lblc_get(dest->af, tbl, daddr);
+	en = ip_vs_lblc_get(af, tbl, daddr);
 	if (en) {
 		if (en->dest == dest)
 			return en;
@@ -213,8 +213,8 @@ ip_vs_lblc_new(struct ip_vs_lblc_table *tbl, const union nf_inet_addr *daddr,
 	if (!en)
 		return NULL;
 
-	en->af = dest->af;
-	ip_vs_addr_copy(dest->af, &en->addr, daddr);
+	en->af = af;
+	ip_vs_addr_copy(af, &en->addr, daddr);
 	en->lastuse = jiffies;
 
 	ip_vs_dest_hold(dest);
@@ -521,13 +521,13 @@ ip_vs_lblc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,
 	/* If we fail to create a cache entry, we'll just use the valid dest */
 	spin_lock_bh(&svc->sched_lock);
 	if (!tbl->dead)
-		ip_vs_lblc_new(tbl, &iph->daddr, dest);
+		ip_vs_lblc_new(tbl, &iph->daddr, svc->af, dest);
 	spin_unlock_bh(&svc->sched_lock);
 
 out:
 	IP_VS_DBG_BUF(6, "LBLC: destination IP address %s --> server %s:%d\n",
 		      IP_VS_DBG_ADDR(svc->af, &iph->daddr),
-		      IP_VS_DBG_ADDR(svc->af, &dest->addr), ntohs(dest->port));
+		      IP_VS_DBG_ADDR(dest->af, &dest->addr), ntohs(dest->port));
 
 	return dest;
 }
Signature · 1 line
1.8.1
#11 lore raw

PATCH v2 11/18 ipvs: address family of LBLCR entry depends on svc family

In reply to Alex Gartrell

From: Julian Anastasov <[email protected]>

The LBLCR entries should use svc->af, not dest->af. Needed to support svc->af != dest->af.

---
 net/netfilter/ipvs/ip_vs_lblcr.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
net/netfilter/ipvs/ip_vs_lblcr.c +6 -6
index 3f21a2f..2229d2d 100644
@@ -362,18 +362,18 @@ ip_vs_lblcr_get(int af, struct ip_vs_lblcr_table *tbl,
  */
 static inline struct ip_vs_lblcr_entry *
 ip_vs_lblcr_new(struct ip_vs_lblcr_table *tbl, const union nf_inet_addr *daddr,
-		struct ip_vs_dest *dest)
+		u16 af, struct ip_vs_dest *dest)
 {
 	struct ip_vs_lblcr_entry *en;
 
-	en = ip_vs_lblcr_get(dest->af, tbl, daddr);
+	en = ip_vs_lblcr_get(af, tbl, daddr);
 	if (!en) {
 		en = kmalloc(sizeof(*en), GFP_ATOMIC);
 		if (!en)
 			return NULL;
 
-		en->af = dest->af;
-		ip_vs_addr_copy(dest->af, &en->addr, daddr);
+		en->af = af;
+		ip_vs_addr_copy(af, &en->addr, daddr);
 		en->lastuse = jiffies;
 
 		/* initialize its dest set */
@@ -706,13 +706,13 @@ ip_vs_lblcr_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,
 	/* If we fail to create a cache entry, we'll just use the valid dest */
 	spin_lock_bh(&svc->sched_lock);
 	if (!tbl->dead)
-		ip_vs_lblcr_new(tbl, &iph->daddr, dest);
+		ip_vs_lblcr_new(tbl, &iph->daddr, svc->af, dest);
 	spin_unlock_bh(&svc->sched_lock);
 
 out:
 	IP_VS_DBG_BUF(6, "LBLCR: destination IP address %s --> server %s:%d\n",
 		      IP_VS_DBG_ADDR(svc->af, &iph->daddr),
-		      IP_VS_DBG_ADDR(svc->af, &dest->addr), ntohs(dest->port));
+		      IP_VS_DBG_ADDR(dest->af, &dest->addr), ntohs(dest->port));
 
 	return dest;
 }
Signature · 1 line
1.8.1
#12 lore raw

PATCH v2 12/18 ipvs: use correct address family in DH logs

In reply to Alex Gartrell

From: Julian Anastasov <[email protected]>

Needed to support svc->af != dest->af.

---
 net/netfilter/ipvs/ip_vs_dh.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/ipvs/ip_vs_dh.c +1 -1
index c3b8454..6be5c53 100644
@@ -234,7 +234,7 @@ ip_vs_dh_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,
 
 	IP_VS_DBG_BUF(6, "DH: destination IP address %s --> server %s:%d\n",
 		      IP_VS_DBG_ADDR(svc->af, &iph->daddr),
-		      IP_VS_DBG_ADDR(svc->af, &dest->addr),
+		      IP_VS_DBG_ADDR(dest->af, &dest->addr),
 		      ntohs(dest->port));
 
 	return dest;
Signature · 1 line
1.8.1
#13 lore raw

PATCH v2 13/18 ipvs: use correct address family in LC logs

In reply to Alex Gartrell

From: Julian Anastasov <[email protected]>

Needed to support svc->af != dest->af.

---
 net/netfilter/ipvs/ip_vs_lc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/ipvs/ip_vs_lc.c +1 -1
index 2bdcb1c..19a0769 100644
@@ -59,7 +59,7 @@ ip_vs_lc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,
 	else
 		IP_VS_DBG_BUF(6, "LC: server %s:%u activeconns %d "
 			      "inactconns %d\n",
-			      IP_VS_DBG_ADDR(svc->af, &least->addr),
+			      IP_VS_DBG_ADDR(least->af, &least->addr),
 			      ntohs(least->port),
 			      atomic_read(&least->activeconns),
 			      atomic_read(&least->inactconns));
Signature · 1 line
1.8.1
#14 lore raw

PATCH v2 14/18 ipvs: use correct address family in NQ logs

In reply to Alex Gartrell

From: Julian Anastasov <[email protected]>

Needed to support svc->af != dest->af.

---
 net/netfilter/ipvs/ip_vs_nq.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/netfilter/ipvs/ip_vs_nq.c +2 -1
index 961a6de..a8b6340 100644
@@ -107,7 +107,8 @@ ip_vs_nq_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,
   out:
 	IP_VS_DBG_BUF(6, "NQ: server %s:%u "
 		      "activeconns %d refcnt %d weight %d overhead %d\n",
-		      IP_VS_DBG_ADDR(svc->af, &least->addr), ntohs(least->port),
+		      IP_VS_DBG_ADDR(least->af, &least->addr),
+		      ntohs(least->port),
 		      atomic_read(&least->activeconns),
 		      atomic_read(&least->refcnt),
 		      atomic_read(&least->weight), loh);
Signature · 1 line
1.8.1
#15 lore raw

PATCH v2 15/18 ipvs: use correct address family in RR logs

In reply to Alex Gartrell

From: Julian Anastasov <[email protected]>

Needed to support svc->af != dest->af.

---
 net/netfilter/ipvs/ip_vs_rr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/ipvs/ip_vs_rr.c +1 -1
index 176b87c..58bacfc 100644
@@ -95,7 +95,7 @@ stop:
 	spin_unlock_bh(&svc->sched_lock);
 	IP_VS_DBG_BUF(6, "RR: server %s:%u "
 		      "activeconns %d refcnt %d weight %d\n",
-		      IP_VS_DBG_ADDR(svc->af, &dest->addr), ntohs(dest->port),
+		      IP_VS_DBG_ADDR(dest->af, &dest->addr), ntohs(dest->port),
 		      atomic_read(&dest->activeconns),
 		      atomic_read(&dest->refcnt), atomic_read(&dest->weight));
 
Signature · 1 line
1.8.1
#16 lore raw

PATCH v2 16/18 ipvs: use correct address family in SED logs

In reply to Alex Gartrell

From: Julian Anastasov <[email protected]>

Needed to support svc->af != dest->af.

---
 net/netfilter/ipvs/ip_vs_sed.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/netfilter/ipvs/ip_vs_sed.c +2 -1
index e446b9f..f8e2d00 100644
@@ -108,7 +108,8 @@ ip_vs_sed_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,
 
 	IP_VS_DBG_BUF(6, "SED: server %s:%u "
 		      "activeconns %d refcnt %d weight %d overhead %d\n",
-		      IP_VS_DBG_ADDR(svc->af, &least->addr), ntohs(least->port),
+		      IP_VS_DBG_ADDR(least->af, &least->addr),
+		      ntohs(least->port),
 		      atomic_read(&least->activeconns),
 		      atomic_read(&least->refcnt),
 		      atomic_read(&least->weight), loh);
Signature · 1 line
1.8.1
#17 lore raw

PATCH v2 17/18 ipvs: use correct address family in SH logs

In reply to Alex Gartrell

From: Julian Anastasov <[email protected]>

Needed to support svc->af != dest->af.

---
 net/netfilter/ipvs/ip_vs_sh.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
net/netfilter/ipvs/ip_vs_sh.c +4 -4
index cc65b2f..98a1343 100644
@@ -138,7 +138,7 @@ ip_vs_sh_get_fallback(struct ip_vs_service *svc, struct ip_vs_sh_state *s,
 		return dest;
 
 	IP_VS_DBG_BUF(6, "SH: selected unavailable server %s:%d, reselecting",
-		      IP_VS_DBG_ADDR(svc->af, &dest->addr), ntohs(dest->port));
+		      IP_VS_DBG_ADDR(dest->af, &dest->addr), ntohs(dest->port));
 
 	/* if the original dest is unavailable, loop around the table
 	 * starting from ihash to find a new dest
@@ -153,7 +153,7 @@ ip_vs_sh_get_fallback(struct ip_vs_service *svc, struct ip_vs_sh_state *s,
 			return dest;
 		IP_VS_DBG_BUF(6, "SH: selected unavailable "
 			      "server %s:%d (offset %d), reselecting",
-			      IP_VS_DBG_ADDR(svc->af, &dest->addr),
+			      IP_VS_DBG_ADDR(dest->af, &dest->addr),
 			      ntohs(dest->port), roffset);
 	}
 
@@ -192,7 +192,7 @@ ip_vs_sh_reassign(struct ip_vs_sh_state *s, struct ip_vs_service *svc)
 			RCU_INIT_POINTER(b->dest, dest);
 
 			IP_VS_DBG_BUF(6, "assigned i: %d dest: %s weight: %d\n",
-				      i, IP_VS_DBG_ADDR(svc->af, &dest->addr),
+				      i, IP_VS_DBG_ADDR(dest->af, &dest->addr),
 				      atomic_read(&dest->weight));
 
 			/* Don't move to next dest until filling weight */
@@ -342,7 +342,7 @@ ip_vs_sh_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,
 
 	IP_VS_DBG_BUF(6, "SH: source IP address %s --> server %s:%d\n",
 		      IP_VS_DBG_ADDR(svc->af, &iph->saddr),
-		      IP_VS_DBG_ADDR(svc->af, &dest->addr),
+		      IP_VS_DBG_ADDR(dest->af, &dest->addr),
 		      ntohs(dest->port));
 
 	return dest;
Signature · 1 line
1.8.1
#18 lore raw

PATCH v2 18/18 ipvs: use correct address family in WLC logs

In reply to Alex Gartrell

From: Julian Anastasov <[email protected]>

Needed to support svc->af != dest->af.

---
 net/netfilter/ipvs/ip_vs_wlc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/netfilter/ipvs/ip_vs_wlc.c +2 -1
index b5b4650..6b366fd 100644
@@ -80,7 +80,8 @@ ip_vs_wlc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,
 
 	IP_VS_DBG_BUF(6, "WLC: server %s:%u "
 		      "activeconns %d refcnt %d weight %d overhead %d\n",
-		      IP_VS_DBG_ADDR(svc->af, &least->addr), ntohs(least->port),
+		      IP_VS_DBG_ADDR(least->af, &least->addr),
+		      ntohs(least->port),
 		      atomic_read(&least->activeconns),
 		      atomic_read(&least->refcnt),
 		      atomic_read(&least->weight), loh);
Signature · 1 line
1.8.1
maintainer
#19 lore raw
In reply to Alex Gartrell

Hello,

Quoted 36 lines · Alex Gartrell

At Facebook we use ipip forwarding to deliver packets from our layer 4 ipvs load balancers to our layer 7 proxies. Today these layer 7 proxies are all dual stacked, so we can simply send v4 over v4 and v6 over v6. In the future, we're going to have v6-only layer 7 load balancers (no internal v4 address). To deal with this, we'll forward v4 packets in v6 tunnels. This patchset introduces the necessary functionality into ipvs.

The noteworthy limitation of this is that it is not compatible with state synchronization, so great care is taken to keep these things mutually exclusive.

This patchset includes changes that add an additional netlink attribute to destinations and changes that plumb the destination address family through parts of the code where it was assumed that it was the same as the service. Finally, there's a change that updates the transmit functions for tunneling to share common code and support v4 in v6 and vice versa.

Changes for v2:

Introduced crosses_local_route_boundary and update_pmtu functions and conditionally do the ip_hdr operations. The latter means that df will be effectively zero when we forward an ipv6 packet over an ipv4 tunnel.

Additionally, I addressed Julian's other statements.

Alex Gartrell (9):
ipvs: Pass destination address family to ip_vs_trash_get_dest
ipvs: Supply destination address family to ip_vs_conn_new
ipvs: maintain a mixed_address_family_dest count
ipvs: prevent mixing heterogeneous pools and synchronization
ipvs: Supply skb_af to out_rt* functions
ipvs: Pull out crosses_local_route_boundary logic
ipvs: Pull out update_pmtu code
ipvs: Only do ip_hdr operations in *out_rt when skb_af is AF_INET
ipvs: support ipv4 in ipv6 and ipv6 in ipv4 tunnel forwarding

Quoted 10 lines

Julian Anastasov (9):
ipvs: address family of LBLC entry depends on svc family
ipvs: address family of LBLCR entry depends on svc family
ipvs: use correct address family in DH logs
ipvs: use correct address family in LC logs
ipvs: use correct address family in NQ logs
ipvs: use correct address family in RR logs
ipvs: use correct address family in SED logs
ipvs: use correct address family in SH logs
ipvs: use correct address family in WLC logs

Great, here are some comments from me:

- as some patches are missing I'm not sure if some of my notes for cp->af usage are addressed, eg. in set_tcp_state.

Patch 1:
- I guess this patch depends on patch 1 and 2 from v1, they are now missing. This patch looks like a fixed patch 3 from v1.

Patch 2:
- looks ok

Patch 3:
- old_af and new_af are not needed anymore

Patch 4:
- it would be logically correct to take out the
/* Temporary for consistency */ check and the IP_VS_CONN_F_TUNNEL check after
/* Which connection types do we support? */ into another patch, not part of this patch. May be it can follow this patch or even it should be the last patch in this patchset. As result, current patch will include only the restriction for sync protocol and the last patch will enable the new feature.

Patch 5:
- it is not very good to just add unused args to funcs, may be we should mix patch 5 and 6?

Patch 6:
- scripts/checkpatch.pl warnings, may be renaming source_is_loopback to local_src can help. Make sure we do not exceed 80 columns.

- in crosses_local_route_boundary() the check for old_rt_is_local should be inverted, it should be:

if (!rt_mode_allow_redirect && !old_rt_is_local)

- In the "We are crossing local and non-local addresses" message we can safely print the daddr because the family is constant for the function. We will not do it for source address because it is more complex (depends on skb family).

Patch 7:
- I think, it should be safe to call skb_dst(skb)->ops->update_pmtu(skb_dst(skb), sk, NULL, mtu); in maybe_update_pmtu(), without any family checks.

- scripts/checkpatch.pl warnings

Patch 8:
- it looks like now icmp_send* calls should depend on skb_af, not on dest af. It means both __ip_vs_get_out_rt and __ip_vs_get_out_rt_v6 should use some new common function that will do "frag needed" checks for AF_INET skbs. It will also include the __mtu_check_toobig_v6 call, the IPv6 specific part. Then we have to provide 'ipvsh' as arg to __ip_vs_get_out_rt, it is already provided to __ip_vs_get_out_rt_v6.

- "frag needed for %pI4" looks correct because df is set only for IPv4.

Patch 9:
- we can use skb_af instead of version, right?

- using of out_skb in ip_vs_prepare_tunneled_skb leads to errors (example: IPv6), better to use new_skb and to work only with skb.

- ERR_PTR(ENOMEM) should be ERR_PTR(-ENOMEM)

- the old iptunnel_handle_offloads call still remains in ip_vs_tunnel_xmit_v6, should be removed

- __tun_gso_type_mask: only encaps_af should be used/checked? Or may be:
if (encaps_af == AF_INET) {
if (orig_af == AF_INET)
return SKB_GSO_IPIP;

#ifdef CONFIG_IP_VS_IPV6
			if (orig_af == AF_INET6)
				return SKB_GSO_SIT;
#endif
		}
		...
		return 0;

	- iph->payload_len = ntohs(payload_len);
	should be iph->payload_len = htons(payload_len);

	- scripts/checkpatch.pl warnings

Regards

--
Julian Anastasov <[email protected]>

#20 lore raw

Hey,

Thanks again for your fantastic review, Julian. As you mentioned, I omitted the first two patches. I'll include them in v3 and be more careful in the future.

Additionally, I've done an interactive rebase wherein I exec make -j && ./scripts/checkpatch.pl $(git format-patch) between every pick, so hopefully this will be less sloppy. The only warnings were related to splitting string literals across lines, which is done elsewhere in the file.

I've implemented the requested changes and will do the functional tests.
If all goes well I will mail v3 this evening.

On 8/15/14 3:42 PM, Alex Gartrell wrote:> On Fri, 15 Aug 2014 15:53:49 +0300

Quoted 57 lines
Quoted 55 lines · Julian Anastasov

Hello,

Quoted 49 lines · Alex Gartrell

At Facebook we use ipip forwarding to deliver packets from our layer 4 ipvs load balancers to our layer 7 proxies. Today these layer 7 proxies are all dual stacked, so we can simply send v4 over v4 and v6 over v6. In the future, we're going to have v6-only layer 7 load balancers (no internal v4 address). To deal with this, we'll forward v4 packets in v6 tunnels. This patchset introduces the necessary functionality into ipvs.

The noteworthy limitation of this is that it is not compatible with state synchronization, so great care is taken to keep these things mutually exclusive.

This patchset includes changes that add an additional netlink attribute to destinations and changes that plumb the destination address family through parts of the code where it was assumed that it was the same as the service. Finally, there's a change that updates the transmit functions for tunneling to share common code and support v4 in v6 and vice versa.

Changes for v2:

Introduced crosses_local_route_boundary and update_pmtu functions and conditionally do the ip_hdr operations. The latter means that df will be effectively zero when we forward an ipv6 packet over an ipv4 tunnel.

Additionally, I addressed Julian's other statements.

Alex Gartrell (9):
ipvs: Pass destination address family to ip_vs_trash_get_dest
ipvs: Supply destination address family to ip_vs_conn_new
ipvs: maintain a mixed_address_family_dest count
ipvs: prevent mixing heterogeneous pools and synchronization
ipvs: Supply skb_af to out_rt* functions
ipvs: Pull out crosses_local_route_boundary logic
ipvs: Pull out update_pmtu code
ipvs: Only do ip_hdr operations in *out_rt when skb_af is AF_INET
ipvs: support ipv4 in ipv6 and ipv6 in ipv4 tunnel forwarding

Julian Anastasov (9):
ipvs: address family of LBLC entry depends on svc family
ipvs: address family of LBLCR entry depends on svc family
ipvs: use correct address family in DH logs
ipvs: use correct address family in LC logs
ipvs: use correct address family in NQ logs
ipvs: use correct address family in RR logs
ipvs: use correct address family in SED logs
ipvs: use correct address family in SH logs
ipvs: use correct address family in WLC logs

Quoted 5 lines
Quoted 5 lines

Great, here are some comments from me:

- as some patches are missing I'm not sure if some of my notes for cp->af usage are addressed, eg. in set_tcp_state.

Yes you are right. I forgot the first two patches. Will include them in v3

Quoted 4 lines
Quoted 4 lines

Patch 1:
- I guess this patch depends on patch 1 and 2 from v1, they
are now missing. This patch looks like a fixed patch 3 from v1.

Yeah that's right

Quoted 6 lines
Quoted 6 lines

Patch 2:
- looks ok

Patch 3:
- old_af and new_af are not needed anymore

Duh, thanks

Quoted 10 lines
Quoted 10 lines

Patch 4:
- it would be logically correct to take out the /* Temporary for consistency */ check and the IP_VS_CONN_F_TUNNEL check after
/* Which connection types do we support? */ into another patch, not part of this patch. May be it can follow this patch or even it should be the last patch in this
patchset. As result, current patch will include only the restriction
for sync protocol and the last patch will enable the new feature.

I'll split this up and put it at the end.

Quoted 3 lines
Quoted 3 lines

Patch 5:
- it is not very good to just add unused args to funcs, may be we should mix patch 5 and 6?

Yeah, I was kind of afraid that it'd be confusing for people, but I think that the code is separate enough that it won't be.

Quoted 4 lines
Quoted 4 lines

Patch 6:
- scripts/checkpatch.pl warnings, may be renaming source_is_loopback to local_src can help. Make sure we do not exceed 80 columns.

Most embarrassing screw up :(

But yeah, these are just really unpleasantly long identifiers. I'll either need to break the lines in weird ways or shorten identifiers or both.

Quoted 5 lines
Quoted 5 lines

- in crosses_local_route_boundary() the check for old_rt_is_local should be inverted, it should be:

if (!rt_mode_allow_redirect && !old_rt_is_local)

That's scary. Good catch.

Quoted 4 lines
Quoted 4 lines

- In the "We are crossing local and non-local addresses"
message we can safely print the daddr because the family is constant for the function. We will not do it for source address because
it is more complex (depends on skb family).

I'll add "daddr=" to each

Quoted 5 lines
Quoted 5 lines

Patch 7:
- I think, it should be safe to call skb_dst(skb)->ops->update_pmtu(skb_dst(skb), sk, NULL, mtu); in maybe_update_pmtu(), without any family checks.

Yeah, both route types have dst in the same place and I imagine that's by design.

Quoted 11 lines
Quoted 11 lines

- scripts/checkpatch.pl warnings

Patch 8:
- it looks like now icmp_send* calls should depend on skb_af, not on dest af. It means both __ip_vs_get_out_rt and __ip_vs_get_out_rt_v6 should use some new common function that will do "frag needed" checks for AF_INET skbs. It will also include the __mtu_check_toobig_v6 call, the IPv6 specific
part. Then we have to provide 'ipvsh' as arg to __ip_vs_get_out_rt,
it is already provided to __ip_vs_get_out_rt_v6.

Yeah I was able to pull this out.

Quoted 5 lines
Quoted 5 lines

- "frag needed for %pI4" looks correct because df is set only for IPv4.

Patch 9:
- we can use skb_af instead of version, right?

Yeah, I remembered fixing this but must have done this elsewhere.

Quoted 4 lines
Quoted 4 lines

- using of out_skb in ip_vs_prepare_tunneled_skb leads to errors (example: IPv6), better to use new_skb and to work only with skb.

Yeah that's fair. I was concerned about not attempting to kfree_skb skb which is why I made the change, but the fact that it made me miss something else convinces me that it's problematic.

Quoted 2 lines
Quoted 2 lines

- ERR_PTR(ENOMEM) should be ERR_PTR(-ENOMEM)

Ah, that makes sense. Thanks

Quoted 4 lines
Quoted 4 lines

- the old iptunnel_handle_offloads call still remains in ip_vs_tunnel_xmit_v6, should be removed

*facepalm*

Quoted 9 lines
Quoted 9 lines
	- __tun_gso_type_mask: only encaps_af should be used/checked?
	Or may be:
		if (encaps_af == AF_INET) {
			if (orig_af == AF_INET)
				return SKB_GSO_IPIP;
#ifdef CONFIG_IP_VS_IPV6
			if (orig_af == AF_INET6)
				return SKB_GSO_SIT;

#endif

Can this just be else to spare the #ifdef lines?

Quoted 7 lines
Quoted 7 lines
		}
		...
		return 0;

	- iph->payload_len = ntohs(payload_len);
	should be iph->payload_len = htons(payload_len);

+1

Quoted 7 lines
Quoted 6 lines

- scripts/checkpatch.pl warnings

Regards

--
Julian Anastasov <[email protected]>