Skip to contentSkip to conversation

Support v6 real servers in v4 pools and vice versa

PATCH Superseded Alex Gartrell 2 participants 11 messages Jul 30, 2014 – Jul 31, 2014

Subsystems (4)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

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.

Alex Gartrell (7):
ipvs: Add destination address family to netlink interface
ipvs: Supply destination addr family to ip_vs_{lookup_dest,find_dest}
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: support ipv4 in ipv6 and ipv6 in ipv4 tunnel forwarding

 include/net/ip_vs.h             |  14 ++++-
 include/uapi/linux/ip_vs.h      |   3 +
 net/netfilter/ipvs/ip_vs_conn.c |  23 +++++--
 net/netfilter/ipvs/ip_vs_core.c |   9 +--
 net/netfilter/ipvs/ip_vs_ctl.c  | 109 +++++++++++++++++++++++++-------
 net/netfilter/ipvs/ip_vs_sync.c |  14 +++--
 net/netfilter/ipvs/ip_vs_xmit.c | 135 ++++++++++++++++++++++++++--------------
 7 files changed, 222 insertions(+), 85 deletions(-)
Signature · 1 line
1.8.1
#1 lore raw

PATCH 1/7 ipvs: Add destination address family to netlink interface

This is necessary to support heterogeneous pools. For example, if you have an ipv6 addressed network, you'll want to be able to forward ipv4 traffic into it.

This patch enforces that destination address family is the same as service family, as none of the forwarding mechanisms support anything else.

For the old setsockopt mechanism, we simply set the dest address family to AF_INET as we do with the service.

---
 include/net/ip_vs.h            |  3 +++
 include/uapi/linux/ip_vs.h     |  3 +++
 net/netfilter/ipvs/ip_vs_ctl.c | 37 ++++++++++++++++++++++++++++++-------
 3 files changed, 36 insertions(+), 7 deletions(-)
include/net/ip_vs.h +3 -0
index 624a8a5..b7e2b62 100644
@@ -648,6 +648,9 @@ struct ip_vs_dest_user_kern {
 	/* thresholds for active connections */
 	u32			u_threshold;	/* upper threshold */
 	u32			l_threshold;	/* lower threshold */
+
+	/* Address family of addr */
+	u16			af;
 };
 
 
include/uapi/linux/ip_vs.h +3 -0
index fbcffe8..cabe95d 100644
@@ -384,6 +384,9 @@ enum {
 	IPVS_DEST_ATTR_PERSIST_CONNS,	/* persistent connections */
 
 	IPVS_DEST_ATTR_STATS,		/* nested attribute for dest stats */
+
+	IPVS_DEST_ATTR_ADDR_FAMILY,	/* Address family of address */
+
 	__IPVS_DEST_ATTR_MAX,
 };
 
net/netfilter/ipvs/ip_vs_ctl.c +30 -7
index 581a658..63a6c2e 100644
@@ -816,6 +816,8 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
 	dest->u_threshold = udest->u_threshold;
 	dest->l_threshold = udest->l_threshold;
 
+	dest->af = udest.af;
+
 	spin_lock_bh(&dest->dst_lock);
 	__ip_vs_dst_cache_reset(dest);
 	spin_unlock_bh(&dest->dst_lock);
@@ -846,8 +848,12 @@ 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 (svc->af == AF_INET6) {
+	if (udest->af == AF_INET6) {
 		atype = ipv6_addr_type(&udest->addr.in6);
 		if ((!(atype & IPV6_ADDR_UNICAST) ||
 			atype & IPV6_ADDR_LINKLOCAL) &&
@@ -875,12 +881,12 @@ ip_vs_new_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest,
 		u64_stats_init(&ip_vs_dest_stats->syncp);
 	}
 
-	dest->af = svc->af;
+	dest->af = udest->af;
 	dest->protocol = svc->protocol;
 	dest->vaddr = svc->addr;
 	dest->vport = svc->port;
 	dest->vfwmark = svc->fwmark;
-	ip_vs_addr_copy(svc->af, &dest->addr, &udest->addr);
+	ip_vs_addr_copy(udest->af, &dest->addr, &udest->addr);
 	dest->port = udest->port;
 
 	atomic_set(&dest->activeconns, 0);
@@ -928,7 +934,7 @@ ip_vs_add_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
 		return -ERANGE;
 	}
 
-	ip_vs_addr_copy(svc->af, &daddr, &udest->addr);
+	ip_vs_addr_copy(udest->af, &daddr, &udest->addr);
 
 	/* We use function that requires RCU lock */
 	rcu_read_lock();
@@ -949,7 +955,7 @@ ip_vs_add_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
 	if (dest != NULL) {
 		IP_VS_DBG_BUF(3, "Get destination %s:%u from trash, "
 			      "dest->refcnt=%d, service %u/%s:%u\n",
-			      IP_VS_DBG_ADDR(svc->af, &daddr), ntohs(dport),
+			      IP_VS_DBG_ADDR(udest->af, &daddr), ntohs(dport),
 			      atomic_read(&dest->refcnt),
 			      dest->vfwmark,
 			      IP_VS_DBG_ADDR(svc->af, &dest->vaddr),
@@ -992,7 +998,7 @@ ip_vs_edit_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
 		return -ERANGE;
 	}
 
-	ip_vs_addr_copy(svc->af, &daddr, &udest->addr);
+	ip_vs_addr_copy(udest->af, &daddr, &udest->addr);
 
 	/* We use function that requires RCU lock */
 	rcu_read_lock();
@@ -2318,6 +2324,7 @@ static void ip_vs_copy_udest_compat(struct ip_vs_dest_user_kern *udest,
 	udest->weight		= udest_compat->weight;
 	udest->u_threshold	= udest_compat->u_threshold;
 	udest->l_threshold	= udest_compat->l_threshold;
+	udest->af		= AF_INET;
 }
 
 static int
@@ -2863,6 +2870,7 @@ static const struct nla_policy ip_vs_dest_policy[IPVS_DEST_ATTR_MAX + 1] = {
 	[IPVS_DEST_ATTR_INACT_CONNS]	= { .type = NLA_U32 },
 	[IPVS_DEST_ATTR_PERSIST_CONNS]	= { .type = NLA_U32 },
 	[IPVS_DEST_ATTR_STATS]		= { .type = NLA_NESTED },
+	[IPVS_DEST_ATTR_ADDR_FAMILY]	= { .type = NLA_U16 },
 };
 
 static int ip_vs_genl_fill_stats(struct sk_buff *skb, int container_type,
@@ -3118,7 +3126,8 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
 	    nla_put_u32(skb, IPVS_DEST_ATTR_INACT_CONNS,
 			atomic_read(&dest->inactconns)) ||
 	    nla_put_u32(skb, IPVS_DEST_ATTR_PERSIST_CONNS,
-			atomic_read(&dest->persistconns)))
+			atomic_read(&dest->persistconns)) ||
+	    nla_put_u16(skb, IPVS_DEST_ATTR_ADDR_FAMILY, dest->af))
 		goto nla_put_failure;
 	if (ip_vs_genl_fill_stats(skb, IPVS_DEST_ATTR_STATS, &dest->stats))
 		goto nla_put_failure;
@@ -3199,6 +3208,7 @@ static int ip_vs_genl_parse_dest(struct ip_vs_dest_user_kern *udest,
 {
 	struct nlattr *attrs[IPVS_DEST_ATTR_MAX + 1];
 	struct nlattr *nla_addr, *nla_port;
+	struct nlattr *nla_addr_family;
 
 	/* Parse mandatory identifying destination fields first */
 	if (nla == NULL ||
@@ -3207,6 +3217,7 @@ static int ip_vs_genl_parse_dest(struct ip_vs_dest_user_kern *udest,
 
 	nla_addr	= attrs[IPVS_DEST_ATTR_ADDR];
 	nla_port	= attrs[IPVS_DEST_ATTR_PORT];
+	nla_addr_family	= attrs[IPVS_DEST_ATTR_ADDR_FAMILY];
 
 	if (!(nla_addr && nla_port))
 		return -EINVAL;
@@ -3216,6 +3227,11 @@ static int ip_vs_genl_parse_dest(struct ip_vs_dest_user_kern *udest,
 	nla_memcpy(&udest->addr, nla_addr, sizeof(udest->addr));
 	udest->port = nla_get_be16(nla_port);
 
+	if (nla_addr_family)
+		udest->af = nla_get_u16(nla_addr_family);
+	else
+		udest->af = 0;
+
 	/* If a full entry was requested, check for the additional fields */
 	if (full_entry) {
 		struct nlattr *nla_fwd, *nla_weight, *nla_u_thresh,
@@ -3443,6 +3459,13 @@ static int ip_vs_genl_set_cmd(struct sk_buff *skb, struct genl_info *info)
 					    need_full_dest);
 		if (ret)
 			goto out;
+
+		/* Old protocols did not allow the user to specify address family,
+		 * so we set it to zero instead.  We also didn't allow
+		 * heterogeneous pools in the old code, so it's safe to assume that
+		 * this will have the same address family as the service. */
+		if (udest.af == 0)
+			udest.af = svc->af;
 	}
 
 	switch (cmd) {
Signature · 1 line
1.8.1
#2 lore raw

PATCH 2/7 ipvs: Supply destination addr family to ip_vs_{lookup_dest,find_dest}

In reply to Alex Gartrell

We need to remove the assumption that virtual address family is the same as real address family in order to support heterogeneous services (that is, services with v4 vips and v6 backends or the opposite).

---
 include/net/ip_vs.h             |  5 +++--
 net/netfilter/ipvs/ip_vs_conn.c |  7 ++++++-
 net/netfilter/ipvs/ip_vs_ctl.c  | 24 ++++++++++++------------
 net/netfilter/ipvs/ip_vs_sync.c |  9 +++++++--
 4 files changed, 28 insertions(+), 17 deletions(-)
include/net/ip_vs.h +3 -2
index b7e2b62..2fa1155 100644
@@ -1399,8 +1399,9 @@ void ip_vs_unregister_nl_ioctl(void);
 int ip_vs_control_init(void);
 void ip_vs_control_cleanup(void);
 struct ip_vs_dest *
-ip_vs_find_dest(struct net *net, int af, const union nf_inet_addr *daddr,
-		__be16 dport, const union nf_inet_addr *vaddr, __be16 vport,
+ip_vs_find_dest(struct net *net, int svc_af, int dest_af,
+		const union nf_inet_addr *daddr, __be16 dport,
+		const union nf_inet_addr *vaddr, __be16 vport,
 		__u16 protocol, __u32 fwmark, __u32 flags);
 void ip_vs_try_bind_dest(struct ip_vs_conn *cp);
 
net/netfilter/ipvs/ip_vs_conn.c +6 -1
index 610e19c..2a59564 100644
@@ -616,7 +616,12 @@ void ip_vs_try_bind_dest(struct ip_vs_conn *cp)
 	struct ip_vs_dest *dest;
 
 	rcu_read_lock();
-	dest = ip_vs_find_dest(ip_vs_conn_net(cp), cp->af, &cp->daddr,
+
+	/* This function is only invoked by the synchronization code. We do
+	 * not currently support heterogeneous pools with synchronization,
+	 * so we can make the assumption that the svc_af is the same as the
+	 * dest_af */
+	dest = ip_vs_find_dest(ip_vs_conn_net(cp), cp->af, cp->af, &cp->daddr,
 			       cp->dport, &cp->vaddr, cp->vport,
 			       cp->protocol, cp->fwmark, cp->flags);
 	if (dest) {
net/netfilter/ipvs/ip_vs_ctl.c +12 -12
index 63a6c2e..72d8add 100644
@@ -574,8 +574,8 @@ bool ip_vs_has_real_service(struct net *net, int af, __u16 protocol,
  * Called under RCU lock.
  */
 static struct ip_vs_dest *
-ip_vs_lookup_dest(struct ip_vs_service *svc, const union nf_inet_addr *daddr,
-		  __be16 dport)
+ip_vs_lookup_dest(struct ip_vs_service *svc, int dest_af,
+		  const union nf_inet_addr *daddr, __be16 dport)
 {
 	struct ip_vs_dest *dest;
 
@@ -583,8 +583,8 @@ ip_vs_lookup_dest(struct ip_vs_service *svc, const union nf_inet_addr *daddr,
 	 * Find the destination for the given service
 	 */
 	list_for_each_entry_rcu(dest, &svc->destinations, n_list) {
-		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)) {
 			/* HIT */
 			return dest;
@@ -602,7 +602,7 @@ ip_vs_lookup_dest(struct ip_vs_service *svc, const union nf_inet_addr *daddr,
  * on the backup.
  * Called under RCU lock, no refcnt is returned.
  */
-struct ip_vs_dest *ip_vs_find_dest(struct net  *net, int af,
+struct ip_vs_dest *ip_vs_find_dest(struct net  *net, int svc_af, int dest_af,
 				   const union nf_inet_addr *daddr,
 				   __be16 dport,
 				   const union nf_inet_addr *vaddr,
@@ -613,14 +613,14 @@ struct ip_vs_dest *ip_vs_find_dest(struct net  *net, int af,
 	struct ip_vs_service *svc;
 	__be16 port = dport;
 
-	svc = ip_vs_service_find(net, af, fwmark, protocol, vaddr, vport);
+	svc = ip_vs_service_find(net, svc_af, fwmark, protocol, vaddr, vport);
 	if (!svc)
 		return NULL;
 	if (fwmark && (flags & IP_VS_CONN_F_FWD_MASK) != IP_VS_CONN_F_MASQ)
 		port = 0;
-	dest = ip_vs_lookup_dest(svc, daddr, port);
+	dest = ip_vs_lookup_dest(svc, dest_af, daddr, port);
 	if (!dest)
-		dest = ip_vs_lookup_dest(svc, daddr, port ^ dport);
+		dest = ip_vs_lookup_dest(svc, dest_af, daddr, port ^ dport);
 	return dest;
 }
 
@@ -816,7 +816,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
 	dest->u_threshold = udest->u_threshold;
 	dest->l_threshold = udest->l_threshold;
 
-	dest->af = udest.af;
+	dest->af = udest->af;
 
 	spin_lock_bh(&dest->dst_lock);
 	__ip_vs_dst_cache_reset(dest);
@@ -938,7 +938,7 @@ ip_vs_add_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
 
 	/* We use function that requires RCU lock */
 	rcu_read_lock();
-	dest = ip_vs_lookup_dest(svc, &daddr, dport);
+	dest = ip_vs_lookup_dest(svc, udest->af, &daddr, dport);
 	rcu_read_unlock();
 
 	if (dest != NULL) {
@@ -1002,7 +1002,7 @@ ip_vs_edit_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
 
 	/* We use function that requires RCU lock */
 	rcu_read_lock();
-	dest = ip_vs_lookup_dest(svc, &daddr, dport);
+	dest = ip_vs_lookup_dest(svc, udest->af, &daddr, dport);
 	rcu_read_unlock();
 
 	if (dest == NULL) {
@@ -1084,7 +1084,7 @@ ip_vs_del_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
 
 	/* We use function that requires RCU lock */
 	rcu_read_lock();
-	dest = ip_vs_lookup_dest(svc, &udest->addr, dport);
+	dest = ip_vs_lookup_dest(svc, udest->af, &udest->addr, dport);
 	rcu_read_unlock();
 
 	if (dest == NULL) {
net/netfilter/ipvs/ip_vs_sync.c +7 -2
index db80126..392f687 100644
@@ -880,8 +880,13 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
 		 * but still handled.
 		 */
 		rcu_read_lock();
-		dest = ip_vs_find_dest(net, type, daddr, dport, param->vaddr,
-				       param->vport, protocol, fwmark, flags);
+		/* This function is only invoked by the synchronization
+		 * code. We do not currently support heterogeneous pools
+		 * with synchronization, so we can make the assumption that
+		 * the svc_af is the same as the dest_af */
+		dest = ip_vs_find_dest(net, type, type, daddr, dport,
+				       param->vaddr, param->vport, protocol,
+				       fwmark, flags);
 
 		cp = ip_vs_conn_new(param, daddr, dport, flags, dest, fwmark);
 		rcu_read_unlock();
Signature · 1 line
1.8.1
#3 lore raw

PATCH 3/7 ipvs: Pass destination address family to ip_vs_trash_get_dest

In reply to Alex Gartrell

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 72d8add..6702cf8 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
#4 lore raw

PATCH 4/7 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             | 2 +-
 net/netfilter/ipvs/ip_vs_conn.c | 4 ++--
 net/netfilter/ipvs/ip_vs_core.c | 9 +++++----
 net/netfilter/ipvs/ip_vs_sync.c | 3 ++-
 4 files changed, 10 insertions(+), 8 deletions(-)
include/net/ip_vs.h +1 -1
index 2fa1155..72698b1 100644
@@ -1213,7 +1213,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 +2 -2
index 2a59564..22c72da 100644
@@ -853,7 +853,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)
 {
@@ -879,7 +879,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(dest_af, &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_sync.c +2 -1
index 392f687..9b1c936 100644
@@ -888,7 +888,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
#5 lore raw

PATCH 5/7 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 | 42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)
include/net/ip_vs.h +4 -0
index 72698b1..69d8722 100644
@@ -989,6 +989,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 +42 -0

66 lines not on this page · raw message

Signature · 1 line
1.8.1
#6 lore raw

PATCH 6/7 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 | 4 ----
 1 file changed, 4 deletions(-)
net/netfilter/ipvs/ip_vs_ctl.c +0 -3
index 1c0621b..498510b 100644
@@ -863,10 +863,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;
#7 lore raw

PATCH 7/7 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 | 135 ++++++++++++++++++++++++++--------------
 2 files changed, 100 insertions(+), 47 deletions(-)
net/netfilter/ipvs/ip_vs_conn.c +10 -2
index 22c72da..86ecb14 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->dest->af == 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->dest->af == 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 +90 -45

191 lines not on this page · raw message

Signature · 1 line
1.8.1
maintainer
#8 lore raw
In reply to Alex Gartrell

Hello,

Quoted 17 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.

Quoted 8 lines

Alex Gartrell (7):
ipvs: Add destination address family to netlink interface
ipvs: Supply destination addr family to ip_vs_{lookup_dest,find_dest}
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: support ipv4 in ipv6 and ipv6 in ipv4 tunnel forwarding

This feature looks good to me.

Such change should go first in net-next tree, after the change
for skb->encapsulation (net tree). So, probably, after some -rc we can add this patchset.

So, to summarize our plan:

- we have sockopt and netlink interface

- IPv6 is supported only on netlink interface

- the sockopt structs can not be changed, eg. struct ip_vs_dest_user in include/uapi/linux/ip_vs.h.

- ipvsadm should allow different family (svc and dest) only for TUN method

- we can also encode somehow the tunnel mode in sync message, eg. around the STYPE_F_INET6 value. May be this octet can become tunnel/header type. This can be done later in another patchset.

Comments for your patchset:

Patch 1:
- please fix the dest->af = udest.af in __ip_vs_update_dest(), so that this patch can compile and as result this fix will disappear from patch 2:
- dest->af = udest.af;
+ dest->af = udest->af;

- __ip_vs_get_dest_entries() needs to skip dests with dest->af != svc->af, we can not exports such dests to sockopt users

- too long comments, use scripts/checkpatch.pl --strict /tmp/p1.diff

- everything else looks ok

Patch 2:
- avoid error from patch 1 in __ip_vs_update_dest

- errors from scripts/checkpatch.pl --strict /tmp/p2.diff

Patch 3:

	- in the "Destination %u/%s:%u still in trash, " message
	we should use dest->af, not dest_af.

Patch 4:
- we have to introduce u16 cp->daf, just below cp->protocol

- as result, cp->af is for caddr and vaddr, cp->daf is for cp->daddr, this is needed because sync protocol can create connections with cp->dest = NULL, cp binds to dest later

- ip_vs_ftp.c uses ip_vs_conn_new, now it does not compile

- Another file net/netfilter/xt_ipvs.c depends on IPVS definitions but I think this patchset does not break it

Patch 5:
- note that dest address can not be changed, so if you see reason this patch to exist the check in __ip_vs_update_dest should be: if (add && udest->af != svc->af)

- errors from scripts/checkpatch.pl --strict /tmp/p5.diff

Patch 6:
- comment and code do not match

Patch 7:
- patch looks based on skb_checksum_help patch, the plan is to base it after the offload change we are about to send soon

- ip_vs_bind_xmit*: sync protocol does not guarantee that cp->dest exists in all cases, we can not use cp->dest->af because cp->dest can be NULL, we have to use cp->daf (from patch 4)

- for ip_vs_prepare_tunneled_skb():
- usage of 'version' can be changed to 'af'

- __ip_vs_get_out_rt_v6 and __ip_vs_get_out_rt should be changed to account header from both families for MTU check, these checks happen for IP_VS_RT_MODE_TUNNEL

- errors from scripts/checkpatch.pl --strict /tmp/p7.diff

- looking at cp, set_tcp_state() can not know what family is used for

	cp->daddr, we have to use cp->daf. We have to check the
	cp->af usage everywhere.

- I didn't fixed ip_vs_core.c logs yet

I'm attaching some patches for your patchset. If it is
difficult for you to maintain them in the patchset, we can post them later after your patchset, as separate patchset. For now you can use them as reference. Or may be they should be inserted at some point in your patchset, so that your patchset looks correct if applied up to some patch.

Let me know if you plan ipvsadm changes based on the
ipvsadm tree:

git://git.kernel.org/pub/scm/utils/kernel/ipvsadm/ipvsadm.git

I can do it, if needed.

Regards

--
Julian Anastasov <[email protected]>

#9 lore raw

Thanks for your review!

I've made most of the changes that you've asked for, just a couple quick questions before I submit v2.

Quoted 6 lines

This feature looks good to me.

Such change should go first in net-next tree, after the change
for skb->encapsulation (net tree). So, probably, after some -rc we can add this patchset.

SGTM

Quoted 16 lines

So, to summarize our plan:

- we have sockopt and netlink interface

- IPv6 is supported only on netlink interface

- the sockopt structs can not be changed, eg. struct ip_vs_dest_user in include/uapi/linux/ip_vs.h.

- ipvsadm should allow different family (svc and dest) only for TUN method

- we can also encode somehow the tunnel mode in sync message, eg. around the STYPE_F_INET6 value. May be this octet can become tunnel/header type. This can be done later in another patchset.

Quoted 8 lines

Comments for your patchset:

Patch 1:
- please fix the dest->af = udest.af in __ip_vs_update_dest(), so that this patch can compile and as result this fix will disappear from patch 2:
- dest->af = udest.af;
+ dest->af = udest->af;

Ah, embarrassing. I thought I checked that this all compiled. Will do.

Quoted 3 lines
	- __ip_vs_get_dest_entries() needs to skip dests with
	dest->af != svc->af, we can not exports such dests to
	sockopt users

Yeah seems reasonable, I'll include a short comment as well

Quoted 2 lines

- too long comments, use scripts/checkpatch.pl
--strict /tmp/p1.diff

Another amateur move. Thanks for the epointer

Quoted 5 lines

- everything else looks ok

Patch 2:
- avoid error from patch 1 in __ip_vs_update_dest

Quoted 8 lines

- errors from scripts/checkpatch.pl --strict /tmp/p2.diff

Patch 3:

	- in the "Destination %u/%s:%u still in trash, " message
	we should use dest->af, not dest_af.

Patch 4:
- we have to introduce u16 cp->daf, just below cp->protocol

yeah makes sense

Quoted 3 lines

- as result, cp->af is for caddr and vaddr, cp->daf is for
cp->daddr, this is needed because sync protocol can create connections

	with cp->dest = NULL, cp binds to dest later

Agree that we should just create daf, but if we keep heterogeneous pools and sync distinct can we still run into this? (Just curious)

Quoted 1 line

- ip_vs_ftp.c uses ip_vs_conn_new, now it does not compile

It appears that these are all IPv4 only, so I'll just use AF_INET and add a comment.

Quoted 3 lines

- Another file net/netfilter/xt_ipvs.c depends on IPVS definitions but I think this patchset does not break it

Yeah, this still builds

Quoted 5 lines

Patch 5:
- note that dest address can not be changed, so if you see reason this patch to exist the check in __ip_vs_update_dest should be: if (add && udest->af != svc->af)

Well that definitely simplifies things. My plan is to add a BUG_ON(!add && udest->af != dest->af) -- more as documentation than anything.

Quoted 4 lines

- errors from scripts/checkpatch.pl --strict /tmp/p5.diff

Patch 6:
- comment and code do not match

What do you mean? This just removes a temporary "return -EINVAL" to keep the code sane.

Quoted 5 lines

Patch 7:
- patch looks based on skb_checksum_help patch, the plan is to base it after the offload change we are about to send soon

Yeah, nothing significant about that, I was planning to rebase it the patch when it lands.

Quoted 4 lines
	- ip_vs_bind_xmit*: sync protocol does not guarantee that
	cp->dest exists in all cases, we can not use cp->dest->af
	because cp->dest can be NULL, we have to use cp->daf (from
	patch 4)

Fixed this

Quoted 3 lines

- for ip_vs_prepare_tunneled_skb():
- usage of 'version' can be changed to 'af'

I'm a little bit confused by this. In this case, we aren't passing in af. Since the caller doesn't really know (or care) what the type of the packet is it made sense to figure it out from the ipheader version. Do you mean that there's another function I should use to grab the address family from the skb or is it possible to get it from somewhere else?

Quoted 4 lines

- __ip_vs_get_out_rt_v6 and __ip_vs_get_out_rt should be changed to account header from both families for MTU check, these checks happen for IP_VS_RT_MODE_TUNNEL

Yes this looks fairly significant. Unless you'll object I'll introduce this as a separate patch.

Quoted 6 lines

- errors from scripts/checkpatch.pl --strict /tmp/p7.diff

- looking at cp, set_tcp_state() can not know what family is used for

	cp->daddr, we have to use cp->daf. We have to check the
	cp->af usage everywhere.
Quoted 8 lines

- I didn't fixed ip_vs_core.c logs yet

I'm attaching some patches for your patchset. If it is
difficult for you to maintain them in the patchset, we can post them later after your patchset, as separate patchset. For now you can use them as reference. Or may be they should be inserted at some point in your patchset, so that your patchset looks correct if applied up to some patch.

I'll add them to my patch set. Thank you for doing them!

Quoted 3 lines

Let me know if you plan ipvsadm changes based on the
ipvsadm tree:

I have made the appropriate changes for this. It's a relatively straightforward patch. I can submit it at any time.

Signature · 1 line
Alex
maintainer
#10 lore raw

Hello,

Quoted 67 lines · Alex Gartrell

Thanks for your review!

I've made most of the changes that you've asked for, just a couple quick questions before I submit v2.

Quoted 6 lines

This feature looks good to me.

Such change should go first in net-next tree, after the change
for skb->encapsulation (net tree). So, probably, after some -rc we can add this patchset.

SGTM

Quoted 16 lines

So, to summarize our plan:

- we have sockopt and netlink interface

- IPv6 is supported only on netlink interface

- the sockopt structs can not be changed, eg. struct ip_vs_dest_user in include/uapi/linux/ip_vs.h.

- ipvsadm should allow different family (svc and dest) only for TUN method

- we can also encode somehow the tunnel mode in sync message, eg. around the STYPE_F_INET6 value. May be this octet can become tunnel/header type. This can be done later in another patchset.

Quoted 8 lines

Comments for your patchset:

Patch 1:
- please fix the dest->af = udest.af in __ip_vs_update_dest(), so that this patch can compile and as result this fix will disappear from patch 2:
- dest->af = udest.af;
+ dest->af = udest->af;

Ah, embarrassing. I thought I checked that this all compiled. Will do.

Quoted 3 lines
	- __ip_vs_get_dest_entries() needs to skip dests with
	dest->af != svc->af, we can not exports such dests to
	sockopt users

Yeah seems reasonable, I'll include a short comment as well

Quoted 2 lines

- too long comments, use scripts/checkpatch.pl
--strict /tmp/p1.diff

Another amateur move. Thanks for the epointer

Quoted 5 lines

- everything else looks ok

Patch 2:
- avoid error from patch 1 in __ip_vs_update_dest

Quoted 8 lines

- errors from scripts/checkpatch.pl --strict /tmp/p2.diff

Patch 3:

	- in the "Destination %u/%s:%u still in trash, " message
	we should use dest->af, not dest_af.

Patch 4:
- we have to introduce u16 cp->daf, just below cp->protocol

Quoted 8 lines

yeah makes sense

Quoted 3 lines

- as result, cp->af is for caddr and vaddr, cp->daf is for
cp->daddr, this is needed because sync protocol can create connections

	with cp->dest = NULL, cp binds to dest later

Agree that we should just create daf, but if we keep heterogeneous pools and sync distinct can we still run into this? (Just curious)

I think, in patch 7 ip_vs_bind_xmit and ip_vs_bind_xmit_v6
will simply crash when sync is used, without heterogeneous pools, due to cp->dest dereference. So, it happens for synced conns.

Quoted 4 lines
Quoted 1 line

- ip_vs_ftp.c uses ip_vs_conn_new, now it does not compile

It appears that these are all IPv4 only, so I'll just use AF_INET and add a comment.

Yes, ip_vs_ftp still supports v4 only.

Quoted 12 lines
Quoted 3 lines

- Another file net/netfilter/xt_ipvs.c depends on IPVS definitions but I think this patchset does not break it

Yeah, this still builds

Quoted 5 lines

Patch 5:
- note that dest address can not be changed, so if you see reason this patch to exist the check in __ip_vs_update_dest should be: if (add && udest->af != svc->af)

Quoted 3 lines

Well that definitely simplifies things. My plan is to add a BUG_ON(!add && udest->af != dest->af) -- more as documentation than anything.

The af,addr,port are the key we use to search dest,
it is silly to duplicate them as parameters just to support such dest change, I think it can not happen.

Quoted 7 lines
Quoted 4 lines

- errors from scripts/checkpatch.pl --strict /tmp/p5.diff

Patch 6:
- comment and code do not match

What do you mean? This just removes a temporary "return -EINVAL" to keep the code sane.

This patch (6) changes only ip_vs_new_dest() but talks
about "sync" and "switch statement" ...

Quoted 7 lines
Quoted 4 lines

Patch 7:
- patch looks based on skb_checksum_help patch, the plan is to base it after the offload change we are about to send soon

Yeah, nothing significant about that, I was planning to rebase it the patch when it lands.

I'll wait for comments about GSO for 1-2 days and will send
official patch.

Quoted 8 lines
Quoted 4 lines
	- ip_vs_bind_xmit*: sync protocol does not guarantee that
	cp->dest exists in all cases, we can not use cp->dest->af
	because cp->dest can be NULL, we have to use cp->daf (from
	patch 4)

Fixed this

Quoted 1 line
Quoted 8 lines
Quoted 2 lines

- for ip_vs_prepare_tunneled_skb():
- usage of 'version' can be changed to 'af'

I'm a little bit confused by this. In this case, we aren't passing in af. Since the caller doesn't really know (or care) what the type of the packet is it made sense to figure it out from the ipheader version. Do you mean that there's another function I should use to grab the address family from the skb or is it possible to get it from somewhere else?

	We can use cp->af, cp->dest can be NULL (synced conn)
Quoted 7 lines
Quoted 4 lines

- __ip_vs_get_out_rt_v6 and __ip_vs_get_out_rt should be changed to account header from both families for MTU check, these checks happen for IP_VS_RT_MODE_TUNNEL

Yes this looks fairly significant. Unless you'll object I'll introduce this as a separate patch.

But in the same patchset, right?

Quoted 8 lines
Quoted 8 lines

- errors from scripts/checkpatch.pl --strict /tmp/p7.diff

- looking at cp, set_tcp_state() can not know what family is used for

	cp->daddr, we have to use cp->daf. We have to check the
	cp->af usage everywhere.

- I didn't fixed ip_vs_core.c logs yet

Quoted 8 lines
Quoted 6 lines

I'm attaching some patches for your patchset. If it is
difficult for you to maintain them in the patchset, we can post them later after your patchset, as separate patchset. For now you can use them as reference. Or may be they should be inserted at some point in your patchset, so that your patchset looks correct if applied up to some patch.

I'll add them to my patch set. Thank you for doing them!

Ok, thanks!

Quoted 6 lines
Quoted 3 lines

Let me know if you plan ipvsadm changes based on the
ipvsadm tree:

I have made the appropriate changes for this. It's a relatively straightforward patch. I can submit it at any time.

ok

Regards

--
Julian Anastasov <[email protected]>