Skip to contentSkip to conversation

move ipvs to PRE/POSTROUTING

PATCH In review Jason Stubbs 3 participants 17 messages Apr 15, 2008 – Apr 18, 2008

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover move ipvs to PRE/POSTROUTING

I'm a newbie at all of this so forgive me if I'm doing anything wrong. ;) I've attached the full patch here should anybody like to give it a try.

This patch set aims to separate LVS processing from netfilter processing in order to allow netfilter's capabilities to be fully utilized. The flow of traffic can visualized as:

incoming => de-lvs packets => netfilter => lvs packets => outgoing

The goal is for netfilter to only have to deal with CIP/VIP packets and for any translations netfilter might do of CIP to be transparent to LVS.

There are three main downfalls with this patch at present:
1) Having a VIP on a local interface causes the traffic to be delivered locally as VIP checks have been moved to the end of POST_ROUTING.
2) Localnode with address of 127.0.0.1 does not work as packets with a destination of 127.0.0.1 and a non-local source address are unconditionally dropped.
3) Firewall rules on existing installations will most likely break.

The first issue can probably be dealt with by The localnode issue could probably be dealt with by using a hook at the end of PREROUTING and the second issue could be handled like ipt_REDIRECT. I can't see a way to handle firewall rules though which implies that this needs to be optional and defaulting to off should it be considered for inclusion. I'd appreciate any suggestions on how that can be done elegantly.

Signature · 4 lines
Jason Stubbs <[email protected]>
LINKTHINK INC.
東京都渋谷区桜ヶ丘町22-14 N.E.S S棟 3F
TEL 03-5728-4772  FAX 03-5728-4773
include/net/ip_vs.h +0 -2
diff -urp linux.0.orig/include/net/ip_vs.h linux.6.localhooks/include/net/ip_vs.h
@@ -901,8 +901,6 @@ extern void ip_vs_zero_estimator(struct 
 /*
  *	Various IPVS packet transmitters (from ip_vs_xmit.c)
  */
-extern int ip_vs_null_xmit
-(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
 extern int ip_vs_bypass_xmit
 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
 extern int ip_vs_nat_xmit
net/ipv4/ipvs/ip_vs_conn.c +1 -4
diff -urp linux.0.orig/net/ipv4/ipvs/ip_vs_conn.c linux.6.localhooks/net/ipv4/ipvs/ip_vs_conn.c
@@ -350,6 +350,7 @@ static inline void ip_vs_bind_xmit(struc
 {
 	switch (IP_VS_FWD_METHOD(cp)) {
 	case IP_VS_CONN_F_MASQ:
+	case IP_VS_CONN_F_LOCALNODE:
 		cp->packet_xmit = ip_vs_nat_xmit;
 		break;
 
@@ -361,10 +362,6 @@ static inline void ip_vs_bind_xmit(struc
 		cp->packet_xmit = ip_vs_dr_xmit;
 		break;
 
-	case IP_VS_CONN_F_LOCALNODE:
-		cp->packet_xmit = ip_vs_null_xmit;
-		break;
-
 	case IP_VS_CONN_F_BYPASS:
 		cp->packet_xmit = ip_vs_bypass_xmit;
 		break;
net/ipv4/ipvs/ip_vs_core.c +41 -64

186 lines not on this page · raw message

net/ipv4/ipvs/ip_vs_proto_tcp.c +2 -1
diff -urp linux.0.orig/net/ipv4/ipvs/ip_vs_proto_tcp.c linux.6.localhooks/net/ipv4/ipvs/ip_vs_proto_tcp.c
@@ -535,7 +535,8 @@ tcp_app_conn_bind(struct ip_vs_conn *cp)
 	int result = 0;
 
 	/* Default binding: bind app only for NAT */
-	if (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ)
+	if (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ &&
+	    IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_LOCALNODE)
 		return 0;
 
 	/* Lookup application incarnations and bind the right one */
net/ipv4/ipvs/ip_vs_proto_udp.c +2 -1
diff -urp linux.0.orig/net/ipv4/ipvs/ip_vs_proto_udp.c linux.6.localhooks/net/ipv4/ipvs/ip_vs_proto_udp.c
@@ -329,7 +329,8 @@ static int udp_app_conn_bind(struct ip_v
 	int result = 0;
 
 	/* Default binding: bind app only for NAT */
-	if (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ)
+	if (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ &&
+	    IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_LOCALNODE)
 		return 0;
 
 	/* Lookup application incarnations and bind the right one */
net/ipv4/ipvs/ip_vs_xmit.c +9 -21
diff -urp linux.0.orig/net/ipv4/ipvs/ip_vs_xmit.c linux.6.localhooks/net/ipv4/ipvs/ip_vs_xmit.c
@@ -125,28 +125,15 @@ ip_vs_dst_reset(struct ip_vs_dest *dest)
 	dst_release(old_dst);
 }
 
-#define IP_VS_XMIT(skb, rt)				\
+#define IP_VS_XMIT(skb)				\
 do {							\
 	(skb)->ipvs_property = 1;			\
 	skb_forward_csum(skb);				\
-	NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, (skb), NULL,	\
-		(rt)->u.dst.dev, dst_output);		\
+	dst_output(skb);				\
 } while (0)
 
 
 /*
- *      NULL transmitter (do nothing except return NF_ACCEPT)
- */
-int
-ip_vs_null_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
-		struct ip_vs_protocol *pp)
-{
-	/* we do not touch skb and do not need pskb ptr */
-	return NF_ACCEPT;
-}
-
-
-/*
  *      Bypass transmitter
  *      Let packets bypass the destination when the destination is not
  *      available, it may be only used in transparent cache cluster.
@@ -202,7 +189,7 @@ ip_vs_bypass_xmit(struct sk_buff *skb, s
 	/* Another hack: avoid icmp_send in ip_fragment */
 	skb->local_df = 1;
 
-	IP_VS_XMIT(skb, rt);
+	IP_VS_XMIT(skb);
 
 	LeaveFunction(10);
 	return NF_STOLEN;
@@ -278,7 +265,7 @@ ip_vs_nat_xmit(struct sk_buff *skb, stru
 	/* Another hack: avoid icmp_send in ip_fragment */
 	skb->local_df = 1;
 
-	IP_VS_XMIT(skb, rt);
+	IP_VS_XMIT(skb);
 
 	LeaveFunction(10);
 	return NF_STOLEN;
@@ -413,7 +400,7 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, s
 	/* Another hack: avoid icmp_send in ip_fragment */
 	skb->local_df = 1;
 
-	IP_VS_XMIT(skb, rt);
+	IP_VS_XMIT(skb);
 
 	LeaveFunction(10);
 
@@ -471,7 +458,7 @@ ip_vs_dr_xmit(struct sk_buff *skb, struc
 	/* Another hack: avoid icmp_send in ip_fragment */
 	skb->local_df = 1;
 
-	IP_VS_XMIT(skb, rt);
+	IP_VS_XMIT(skb);
 
 	LeaveFunction(10);
 	return NF_STOLEN;
@@ -502,7 +489,8 @@ ip_vs_icmp_xmit(struct sk_buff *skb, str
 	/* The ICMP packet for VS/TUN, VS/DR and LOCALNODE will be
 	   forwarded directly here, because there is no need to
 	   translate address/port back */
-	if (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ) {
+	if (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ &&
+	    IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_LOCALNODE) {
 		if (cp->packet_xmit)
 			rc = cp->packet_xmit(skb, cp, pp);
 		else
@@ -544,7 +532,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, str
 	/* Another hack: avoid icmp_send in ip_fragment */
 	skb->local_df = 1;
 
-	IP_VS_XMIT(skb, rt);
+	IP_VS_XMIT(skb);
 
 	rc = NF_STOLEN;
 	goto out;
#1 lore raw

PATCH 1/6 move ipvs to PRE/POSTROUTING

This patch moves the handling of traffic to VIPs to the end of POSTROUTING and the handling of traffic from RIPs to the beginning of PREROUTING. It also drops the post routing hook that prevents LVS'd traffic from running through POSTROUTING as traffic no longer gets LVS'd until after POSTROUTING has finished.

Signature · 4 lines
Jason Stubbs <[email protected]>
LINKTHINK INC.
東京都渋谷区桜ヶ丘町22-14 N.E.S S棟 3F
TEL 03-5728-4772  FAX 03-5728-4773
net/ipv4/ipvs/ip_vs_core.c +7 -43
diff -urp linux.0.orig/net/ipv4/ipvs/ip_vs_core.c linux.1.rehook/net/ipv4/ipvs/ip_vs_core.c
@@ -480,25 +480,6 @@ int ip_vs_leave(struct ip_vs_service *sv
 }
 
 
-/*
- *      It is hooked before NF_IP_PRI_NAT_SRC at the NF_IP_POST_ROUTING
- *      chain, and is used for VS/NAT.
- *      It detects packets for VS/NAT connections and sends the packets
- *      immediately. This can avoid that iptable_nat mangles the packets
- *      for VS/NAT.
- */
-static unsigned int ip_vs_post_routing(unsigned int hooknum,
-				       struct sk_buff *skb,
-				       const struct net_device *in,
-				       const struct net_device *out,
-				       int (*okfn)(struct sk_buff *))
-{
-	if (!skb->ipvs_property)
-		return NF_ACCEPT;
-	/* The packet was sent from IPVS, exit this chain */
-	return NF_STOP;
-}
-
 __sum16 ip_vs_checksum_complete(struct sk_buff *skb, int offset)
 {
 	return csum_fold(skb_checksum(skb, offset, skb->len - offset, 0));
@@ -1032,8 +1013,8 @@ static struct nf_hook_ops ip_vs_in_ops =
 	.hook		= ip_vs_in,
 	.owner		= THIS_MODULE,
 	.pf		= PF_INET,
-	.hooknum        = NF_IP_LOCAL_IN,
-	.priority       = 100,
+	.hooknum        = NF_IP_POST_ROUTING,
+	.priority       = NF_IP_PRI_LAST,
 };
 
 /* After packet filtering, change source only for VS/NAT */
@@ -1041,8 +1022,8 @@ static struct nf_hook_ops ip_vs_out_ops 
 	.hook		= ip_vs_out,
 	.owner		= THIS_MODULE,
 	.pf		= PF_INET,
-	.hooknum        = NF_IP_FORWARD,
-	.priority       = 100,
+	.hooknum        = NF_IP_PRE_ROUTING,
+	.priority       = NF_IP_PRI_FIRST + 1,
 };
 
 /* After packet filtering (but before ip_vs_out_icmp), catch icmp
@@ -1051,17 +1032,8 @@ static struct nf_hook_ops ip_vs_forward_
 	.hook		= ip_vs_forward_icmp,
 	.owner		= THIS_MODULE,
 	.pf		= PF_INET,
-	.hooknum        = NF_IP_FORWARD,
-	.priority       = 99,
-};
-
-/* Before the netfilter connection tracking, exit from POST_ROUTING */
-static struct nf_hook_ops ip_vs_post_routing_ops = {
-	.hook		= ip_vs_post_routing,
-	.owner		= THIS_MODULE,
-	.pf		= PF_INET,
-	.hooknum        = NF_IP_POST_ROUTING,
-	.priority       = NF_IP_PRI_NAT_SRC-1,
+	.hooknum        = NF_IP_PRE_ROUTING,
+	.priority       = NF_IP_PRI_FIRST,
 };
 
 
@@ -1103,22 +1075,15 @@ static int __init ip_vs_init(void)
 		IP_VS_ERR("can't register out hook.\n");
 		goto cleanup_inops;
 	}
-	ret = nf_register_hook(&ip_vs_post_routing_ops);
-	if (ret < 0) {
-		IP_VS_ERR("can't register post_routing hook.\n");
-		goto cleanup_outops;
-	}
 	ret = nf_register_hook(&ip_vs_forward_icmp_ops);
 	if (ret < 0) {
 		IP_VS_ERR("can't register forward_icmp hook.\n");
-		goto cleanup_postroutingops;
+		goto cleanup_outops;
 	}
 
 	IP_VS_INFO("ipvs loaded.\n");
 	return ret;
 
-  cleanup_postroutingops:
-	nf_unregister_hook(&ip_vs_post_routing_ops);
   cleanup_outops:
 	nf_unregister_hook(&ip_vs_out_ops);
   cleanup_inops:
@@ -1137,7 +1102,6 @@ static int __init ip_vs_init(void)
 static void __exit ip_vs_cleanup(void)
 {
 	nf_unregister_hook(&ip_vs_forward_icmp_ops);
-	nf_unregister_hook(&ip_vs_post_routing_ops);
 	nf_unregister_hook(&ip_vs_out_ops);
 	nf_unregister_hook(&ip_vs_in_ops);
 	ip_vs_conn_cleanup();
#2 lore raw

PATCH 2/6 move ipvs to PRE/POSTROUTING

In reply to Jason Stubbs

Currently, LVS steals packets from the INPUT chain, processes them and then asks netfilter to run them through the OUTPUT chain and to run dst_output if the packet is accepted. With the previous patch, packets are now being stolen from the end of POSTROUTING. This patch makes processed packets sent straight to dst_output, which then recalculates routing information and sends the packet through POSTROUTING again.

I'm not completely certain on the conntrack behaviour for the second POSTROUTING run, but it is not causing any issues.

I am also not certain of how traffic control will handle this. This patch may be causing traffic to be accounted for twice depending on when tcp_output is actually run.

There is also the chance that the routing decision made based on sending to the VIP caused a packet to be fragmented when it didn't need to be. This could cause some performance issues.

Finally, as rt isn't being passed to IP_VS_XMIT any more, some of the operations with rt prior to IP_VS_XMIT may no longer be necessary. I've left them as is for the time being.

Signature · 4 lines
Jason Stubbs <[email protected]>
LINKTHINK INC.
東京都渋谷区桜ヶ丘町22-14 N.E.S S棟 3F
TEL 03-5728-4772  FAX 03-5728-4773
net/ipv4/ipvs/ip_vs_xmit.c +7 -8
diff -urp linux.1.rehook/net/ipv4/ipvs/ip_vs_xmit.c linux.2.xmit/net/ipv4/ipvs/ip_vs_xmit.c
@@ -125,12 +125,11 @@ ip_vs_dst_reset(struct ip_vs_dest *dest)
 	dst_release(old_dst);
 }
 
-#define IP_VS_XMIT(skb, rt)				\
+#define IP_VS_XMIT(skb)				\
 do {							\
 	(skb)->ipvs_property = 1;			\
 	skb_forward_csum(skb);				\
-	NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, (skb), NULL,	\
-		(rt)->u.dst.dev, dst_output);		\
+	dst_output(skb);				\
 } while (0)
 
 
@@ -202,7 +201,7 @@ ip_vs_bypass_xmit(struct sk_buff *skb, s
 	/* Another hack: avoid icmp_send in ip_fragment */
 	skb->local_df = 1;
 
-	IP_VS_XMIT(skb, rt);
+	IP_VS_XMIT(skb);
 
 	LeaveFunction(10);
 	return NF_STOLEN;
@@ -278,7 +277,7 @@ ip_vs_nat_xmit(struct sk_buff *skb, stru
 	/* Another hack: avoid icmp_send in ip_fragment */
 	skb->local_df = 1;
 
-	IP_VS_XMIT(skb, rt);
+	IP_VS_XMIT(skb);
 
 	LeaveFunction(10);
 	return NF_STOLEN;
@@ -413,7 +412,7 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, s
 	/* Another hack: avoid icmp_send in ip_fragment */
 	skb->local_df = 1;
 
-	IP_VS_XMIT(skb, rt);
+	IP_VS_XMIT(skb);
 
 	LeaveFunction(10);
 
@@ -471,7 +470,7 @@ ip_vs_dr_xmit(struct sk_buff *skb, struc
 	/* Another hack: avoid icmp_send in ip_fragment */
 	skb->local_df = 1;
 
-	IP_VS_XMIT(skb, rt);
+	IP_VS_XMIT(skb);
 
 	LeaveFunction(10);
 	return NF_STOLEN;
@@ -544,7 +543,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, str
 	/* Another hack: avoid icmp_send in ip_fragment */
 	skb->local_df = 1;
 
-	IP_VS_XMIT(skb, rt);
+	IP_VS_XMIT(skb);
 
 	rc = NF_STOLEN;
 	goto out;
#11 lore raw

PATCH 3/6 move ipvs to PRE/POSTROUTING

In reply to Jason Stubbs

I'm not entirely certain of what these two chunks are meant to do but they prevent things from working with my other changes. Please let me know if any of it may still be required.

Signature · 4 lines
Jason Stubbs <[email protected]>
LINKTHINK INC.
東京都渋谷区桜ヶ丘町22-14 N.E.S S棟 3F
TEL 03-5728-4772  FAX 03-5728-4773
net/ipv4/ipvs/ip_vs_core.c +0 -21
diff -urp linux.2.xmit/net/ipv4/ipvs/ip_vs_core.c linux.3.routing/net/ipv4/ipvs/ip_vs_core.c
@@ -748,15 +748,6 @@ ip_vs_out(unsigned int hooknum, struct s
 	ip_hdr(skb)->saddr = cp->vaddr;
 	ip_send_check(ip_hdr(skb));
 
-	/* For policy routing, packets originating from this
-	 * machine itself may be routed differently to packets
-	 * passing through.  We want this packet to be routed as
-	 * if it came from this machine itself.  So re-compute
-	 * the routing information.
-	 */
-	if (ip_route_me_harder(skb, RTN_LOCAL) != 0)
-		goto drop;
-
 	IP_VS_DBG_PKT(10, pp, skb, 0, "After SNAT");
 
 	ip_vs_out_stats(cp, skb);
@@ -886,19 +877,6 @@ ip_vs_in(unsigned int hooknum, struct sk
 	int ret, restart;
 	int ihl;
 
-	/*
-	 *	Big tappo: only PACKET_HOST (neither loopback nor mcasts)
-	 *	... don't know why 1st test DOES NOT include 2nd (?)
-	 */
-	if (unlikely(skb->pkt_type != PACKET_HOST
-		     || skb->dev->flags & IFF_LOOPBACK || skb->sk)) {
-		IP_VS_DBG(12, "packet type=%d proto=%d daddr=%d.%d.%d.%d ignored\n",
-			  skb->pkt_type,
-			  ip_hdr(skb)->protocol,
-			  NIPQUAD(ip_hdr(skb)->daddr));
-		return NF_ACCEPT;
-	}
#12 lore raw

PATCH 4/6 move ipvs to PRE/POSTROUTING

In reply to Jason Stubbs

Packets that have been processed by LVS are being sent out immediately meaning that there's no chance for looping in ip_vs_out so I removed the ipvs_property sets/checks from those paths. Packets that have been sent out first go through POSTROUTING (again) and aren't changed in the case of LVS-DR and LVS-TUN so I've used the flag to prevent an infinite loop in ip_vs_in.

Signature · 4 lines
Jason Stubbs <[email protected]>
LINKTHINK INC.
東京都渋谷区桜ヶ丘町22-14 N.E.S S棟 3F
TEL 03-5728-4772  FAX 03-5728-4773
net/ipv4/ipvs/ip_vs_core.c +0 -5
diff -urp linux.3.routing/net/ipv4/ipvs/ip_vs_core.c linux.4.recursion/net/ipv4/ipvs/ip_vs_core.c
@@ -640,7 +640,6 @@ static int ip_vs_out_icmp(struct sk_buff
 	/* do the statistics and put it back */
 	ip_vs_out_stats(cp, skb);
 
-	skb->ipvs_property = 1;
 	verdict = NF_ACCEPT;
 
   out:
@@ -676,9 +675,6 @@ ip_vs_out(unsigned int hooknum, struct s
 
 	EnterFunction(11);
 
-	if (skb->ipvs_property)
-		return NF_ACCEPT;
-
 	iph = ip_hdr(skb);
 	if (unlikely(iph->protocol == IPPROTO_ICMP)) {
 		int related, verdict = ip_vs_out_icmp(skb, &related);
@@ -754,8 +750,6 @@ ip_vs_out(unsigned int hooknum, struct s
 	ip_vs_set_state(cp, IP_VS_DIR_OUTPUT, skb, pp);
 	ip_vs_conn_put(cp);
 
-	skb->ipvs_property = 1;
#13 lore raw

PATCH 5/6 move ipvs to PRE/POSTROUTING

In reply to Jason Stubbs

Currently, VIPs are (usually) bound on local interfaces and LVS is handled in the INPUT chain. This means that local node traffic can simply be passed on. With VIPs not being on bound and LVS handled in POSTROUTING, packets need to be redirected to a local address. This patch essentially alises LOCALNODE to MASQ.

After dst_output and the second POSTROUTING, packets are then sent through PREROUTING and INPUT and finally handled locally.

Signature · 4 lines
Jason Stubbs <[email protected]>
LINKTHINK INC.
東京都渋谷区桜ヶ丘町22-14 N.E.S S棟 3F
TEL 03-5728-4772  FAX 03-5728-4773
include/net/ip_vs.h +0 -2
diff -urp linux.4.recursion/include/net/ip_vs.h linux.5.localmasq/include/net/ip_vs.h
@@ -901,8 +901,6 @@ extern void ip_vs_zero_estimator(struct 
 /*
  *	Various IPVS packet transmitters (from ip_vs_xmit.c)
  */
-extern int ip_vs_null_xmit
-(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
 extern int ip_vs_bypass_xmit
 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
 extern int ip_vs_nat_xmit
net/ipv4/ipvs/ip_vs_conn.c +1 -4
diff -urp linux.4.recursion/net/ipv4/ipvs/ip_vs_conn.c linux.5.localmasq/net/ipv4/ipvs/ip_vs_conn.c
@@ -350,6 +350,7 @@ static inline void ip_vs_bind_xmit(struc
 {
 	switch (IP_VS_FWD_METHOD(cp)) {
 	case IP_VS_CONN_F_MASQ:
+	case IP_VS_CONN_F_LOCALNODE:
 		cp->packet_xmit = ip_vs_nat_xmit;
 		break;
 
@@ -361,10 +362,6 @@ static inline void ip_vs_bind_xmit(struc
 		cp->packet_xmit = ip_vs_dr_xmit;
 		break;
 
-	case IP_VS_CONN_F_LOCALNODE:
-		cp->packet_xmit = ip_vs_null_xmit;
-		break;
-
 	case IP_VS_CONN_F_BYPASS:
 		cp->packet_xmit = ip_vs_bypass_xmit;
 		break;
net/ipv4/ipvs/ip_vs_proto_tcp.c +2 -1
diff -urp linux.4.recursion/net/ipv4/ipvs/ip_vs_proto_tcp.c linux.5.localmasq/net/ipv4/ipvs/ip_vs_proto_tcp.c
@@ -535,7 +535,8 @@ tcp_app_conn_bind(struct ip_vs_conn *cp)
 	int result = 0;
 
 	/* Default binding: bind app only for NAT */
-	if (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ)
+	if (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ &&
+	    IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_LOCALNODE)
 		return 0;
 
 	/* Lookup application incarnations and bind the right one */
net/ipv4/ipvs/ip_vs_proto_udp.c +2 -1
diff -urp linux.4.recursion/net/ipv4/ipvs/ip_vs_proto_udp.c linux.5.localmasq/net/ipv4/ipvs/ip_vs_proto_udp.c
@@ -329,7 +329,8 @@ static int udp_app_conn_bind(struct ip_v
 	int result = 0;
 
 	/* Default binding: bind app only for NAT */
-	if (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ)
+	if (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ &&
+	    IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_LOCALNODE)
 		return 0;
 
 	/* Lookup application incarnations and bind the right one */
net/ipv4/ipvs/ip_vs_xmit.c +0 -10
diff -urp linux.4.recursion/net/ipv4/ipvs/ip_vs_xmit.c linux.5.localmasq/net/ipv4/ipvs/ip_vs_xmit.c
@@ -134,18 +134,6 @@ do {							\
 
 
 /*
- *      NULL transmitter (do nothing except return NF_ACCEPT)
- */
-int
-ip_vs_null_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
-		struct ip_vs_protocol *pp)
-{
-	/* we do not touch skb and do not need pskb ptr */
-	return NF_ACCEPT;
-}
-
#14 lore raw

PATCH 6/6 move ipvs to PRE/POSTROUTING

In reply to Jason Stubbs

Aliasing LOCALNODE to MASQ means that traffic entering the OUTPUT chain may be replies for a LVS-NAT'd connection. This patch adds the same hooks that de-LVS packets at the start of PREROUTING to the start of OUTPUT too.

Signature · 4 lines
Jason Stubbs <[email protected]>
LINKTHINK INC.
東京都渋谷区桜ヶ丘町22-14 N.E.S S棟 3F
TEL 03-5728-4772  FAX 03-5728-4773
net/ipv4/ipvs/ip_vs_core.c +38 -0
diff -urp linux.5.localmasq/net/ipv4/ipvs/ip_vs_core.c linux.6.localhooks/net/ipv4/ipvs/ip_vs_core.c
@@ -1008,6 +1008,25 @@ static struct nf_hook_ops ip_vs_forward_
 	.owner		= THIS_MODULE,
 	.pf		= PF_INET,
 	.hooknum        = NF_IP_PRE_ROUTING,
+	.priority       = NF_IP_PRI_FIRST + 1,
+};
+
+/* After packet filtering, change source only for VS/NAT */
+static struct nf_hook_ops ip_vs_local_out_ops = {
+	.hook		= ip_vs_out,
+	.owner		= THIS_MODULE,
+	.pf		= PF_INET,
+	.hooknum        = NF_IP_LOCAL_OUT,
+	.priority       = NF_IP_PRI_FIRST,
+};
+
+/* After packet filtering (but before ip_vs_out_icmp), catch icmp
+   destined for 0.0.0.0/0, which is for incoming IPVS connections */
+static struct nf_hook_ops ip_vs_local_icmp_ops = {
+	.hook		= ip_vs_forward_icmp,
+	.owner		= THIS_MODULE,
+	.pf		= PF_INET,
+	.hooknum        = NF_IP_LOCAL_OUT,
 	.priority       = NF_IP_PRI_FIRST,
 };
 
@@ -1050,15 +1069,32 @@ static int __init ip_vs_init(void)
 		IP_VS_ERR("can't register out hook.\n");
 		goto cleanup_inops;
 	}
+
 	ret = nf_register_hook(&ip_vs_forward_icmp_ops);
 	if (ret < 0) {
 		IP_VS_ERR("can't register forward_icmp hook.\n");
 		goto cleanup_outops;
 	}
 
+	ret = nf_register_hook(&ip_vs_local_out_ops);
+	if (ret < 0) {
+		IP_VS_ERR("can't register local out hook.\n");
+		goto cleanup_icmpops;
+	}
+
+	ret = nf_register_hook(&ip_vs_local_icmp_ops);
+	if (ret < 0) {
+		IP_VS_ERR("can't register local icmp hook.\n");
+		goto cleanup_localout;
+	}
+
 	IP_VS_INFO("ipvs loaded.\n");
 	return ret;
 
+  cleanup_localout:
+    nf_unregister_hook(&ip_vs_local_out_ops);
+  cleanup_icmpops:
+    nf_unregister_hook(&ip_vs_forward_icmp_ops);
   cleanup_outops:
 	nf_unregister_hook(&ip_vs_out_ops);
   cleanup_inops:
@@ -1076,6 +1112,8 @@ static int __init ip_vs_init(void)
 
 static void __exit ip_vs_cleanup(void)
 {
+	nf_unregister_hook(&ip_vs_local_icmp_ops);
+	nf_unregister_hook(&ip_vs_local_out_ops);
 	nf_unregister_hook(&ip_vs_forward_icmp_ops);
 	nf_unregister_hook(&ip_vs_out_ops);
 	nf_unregister_hook(&ip_vs_in_ops);
#15 lore raw
In reply to Jason Stubbs
Quoted 1 line · Jason Stubbs

I'm a newbie at all of this so forgive me if I'm doing anything wrong. ;)

you're doing great.

Quoted 4 lines

incoming => de-lvs packets => netfilter => lvs packets => outgoing

The goal is for netfilter to only have to deal with CIP/VIP packets and for any translations netfilter might do of CIP to be transparent to LVS.

can you give me an example of a translation of the CIP (I can't think of anything, presumably the F5-SNAT will be done in outgoing).

Quoted 2 lines

There are three main downfalls with this patch at present:
1) Having a VIP on a local interface

I thought with the hooks in the new place that there'd be no VIP on the director anymore. The director would be acting as a router for dst_addr=VIP. Presumbly routing would handle sending packets for the VIP to the director (eg the director would proxy arp for the VIP).

Are you talking about a case where the director is misconfigured?

Quoted 6 lines

causes the traffic to be delivered
locally as VIP checks have been moved to the end of POST_ROUTING.
2) Localnode with address of 127.0.0.1 does not work as packets with a destination of 127.0.0.1 and a non-local source address are unconditionally dropped.
3) Firewall rules on existing installations will most likely break.

no problem. This is a new setup and will have new rules.

Quoted 1 line

The first issue can probably be dealt with by The localnode issue could probably be dealt with by using a hook at the end of PREROUTING and the second issue could be handled like ipt_REDIRECT.

I thought with netfilter, that REDIRECT delivers a packet that now has the wrong address for LVS.

Quoted 1 line

I can't see a way to handle firewall rules though

you haven't figured it out yet, or you've looked and there is no way of having firewall rules?

Joe

Signature · 4 lines
Joseph Mack NA3T EME(B,D), FM05lw North Carolina
jmack (at) wm7d (dot) net - azimuthal equidistant map
generator at http://www.wm7d.net/azproj.shtml
Homepage http://www.austintek.com/ It's GNU/Linux!
#16 lore raw
Quoted 4 lines · On Tuesday 15 April 2008 20:49:42 JST, Joseph Mack NA3T wrote:
Quoted 1 line · Jason Stubbs

I'm a newbie at all of this so forgive me if I'm doing anything wrong. ;)

you're doing great.

Cheers :)

Quoted 21 lines
Quoted 4 lines

incoming => de-lvs packets => netfilter => lvs packets => outgoing

The goal is for netfilter to only have to deal with CIP/VIP packets and for any translations netfilter might do of CIP to be transparent to LVS.

can you give me an example of a translation of the CIP (I can't think of anything, presumably the F5-SNAT will be done in outgoing).

Quoted 2 lines

There are three main downfalls with this patch at present:
1) Having a VIP on a local interface

I thought with the hooks in the new place that there'd be no VIP on the director anymore. The director would be acting as a router for dst_addr=VIP. Presumbly routing would handle sending packets for the VIP to the director (eg the director would proxy arp for the VIP).

Are you talking about a case where the director is misconfigured?

Quoted 8 lines
Quoted 6 lines

causes the traffic to be delivered
locally as VIP checks have been moved to the end of POST_ROUTING.
2) Localnode with address of 127.0.0.1 does not work as packets with a destination of 127.0.0.1 and a non-local source address are unconditionally dropped.
3) Firewall rules on existing installations will most likely break.

no problem. This is a new setup and will have new rules.

The above three points are issues that would need to be overcome before the changes could be merged. I can of course maintain it out of tree myself, but I'd rather try and overcome any obstacles against getting it merged.

You have highlighted another issue though. I've been assuming that the director is already in the routing path in which case arp replies for the VIP aren't necessary. I have no idea how arp advertisements should be handled.

Quoted 7 lines
Quoted 4 lines

The first issue can probably be dealt with by The localnode issue could probably be dealt with by using a hook at the end of PREROUTING and the second issue could be handled like ipt_REDIRECT.

I thought with netfilter, that REDIRECT delivers a packet that now has the wrong address for LVS.

REDIRECT is a special case of DNAT where the destination is changed to 127.0.0.1 for local generated traffic and the first IP on the first interface for any other traffic.

Quoted 4 lines
Quoted 1 line

I can't see a way to handle firewall rules though

you haven't figured it out yet, or you've looked and there is no way of having firewall rules?

All the firewall rules I've tested work fine. I'm referring to existing installations where, for example, FORWARD rules don't take into account LVS traffic. Moving LVS hooks around will invariably break these rules in different ways.

--
Jason Stubbs

#3 lore raw
In reply to Jason Stubbs

Having to reply to myself sucks.. :(

Quoted 3 lines · On Tuesday 15 April 2008 15:41:17 Jason Stubbs wrote:

I am also not certain of how traffic control will handle this. This patch may be causing traffic to be accounted for twice depending on when tcp_output is actually run.

I got confused between TCP congestion control and qdiscs here. Congestion control is before netfilter and thus unaffected. Qdiscs run directly on interfaces after netfilter has completed and so is also unaffected.

Signature · 4 lines
Jason Stubbs <[email protected]>
LINKTHINK INC.
東京都渋谷区桜ヶ丘町22-14 N.E.S S棟 3F
TEL 03-5728-4772  FAX 03-5728-4773
maintainer
#4 lore raw

Hello,

Quoted 8 lines · Jason Stubbs
Quoted 3 lines · On Tuesday 15 April 2008 15:41:17 Jason Stubbs wrote:

I am also not certain of how traffic control will handle this. This patch may be causing traffic to be accounted for twice depending on when tcp_output is actually run.

I got confused between TCP congestion control and qdiscs here. Congestion control is before netfilter and thus unaffected. Qdiscs run directly on interfaces after netfilter has completed and so is also unaffected.

Yes, QoS is before (ingress) and after (egress) any IP hooks.
No TCP and sockets (skb->sk) when playing with IPVS. When IPVS runs you should take care for such issues:

- do not play with packets accounted for sockets (skb->sk != NULL). There was check you removed. Please, reconsider.

- ability to throttle IPVS traffic with netfilter modules. How we can benefit from such modules, can they protect us, can we avoid IPVS scheduling on overload (such modules should work before IPVS conn scheduling, which should be true if you schedule in POST_ROUTING). Was true for LOCAL_IN scheduling.

- any work before input routing is dangerous (eg. PRE_ROUTING). There can be spoofed or looped traffic. For example, it is safer to work with replies, OTOH handling requests before input routing should be considered dangerous.

- one thing should be checked: what state is shown in Netfilter when UDP and TCP packets are scheduled. I see that at POST_ROUTING ipv4_confirm() is called, then __nf_conntrack_confirm() calls nf_ct_get() which should work with translated addresses (by IPVS). You should see that netfilter correctly marks traffic as confirmed. Also, you can confirm that states are properly set by applying NEW rules for requests and then only ESTABLISHED,RELATED in FORWARD. I think, you once tested it with -m state rules but make sure it works after recent (any new) changes because this is essential part. It is interesting what is -m state in Netfilter when no replies are forwarded for LVS-DR setups, replies go directly from real server to client. Are you sure long established connections do not timeout shorter due to bad state in netfilter? May be conntrack_tcp will be confused that only one direction works?

- when testing LVS-NAT make sure client does not see directly the internal hosts. This can happen when testing on LAN. It is possible something to work on LAN but not when client is out of LAN because sometimes packets do not flow as expected but client and real servers still talk successfully by avoiding IPVS box. No reply traffic passes IPVS box and nothing is REJECT-ed in FORWARD. But it should be noticed by broken TCP connections, I think.

- there are setups that use LVS-DR but replies come in IPVS box because it is gateway for the real servers. This is useful feature because VIP is preserved in packet allowing virtual hosts to work by IP. It means replies should be passed in IPVS box with the help from forward_shared patch.

- ICMP generation: when VIP is not configured as IP address icmp_send() currently will use some local address as source for the ICMP error sent to client. Even if this is not a big problem for clients out of LAN, on some setups when non-Linux clients are on LAN this can be confusing, there are expectations that multiple subnets share single LAN without a problem (clients know only the VIP subnet, for example). But this is more an icmp_send() problem.

Regards

--
Julian Anastasov <[email protected]>

#5 lore raw

(No need to CC me anymore, please)

Quoted 5 lines · On Wednesday 16 April 2008 18:10:52 Julian Anastasov wrote:

No TCP and sockets (skb->sk) when playing with IPVS. When IPVS runs you should take care for such issues:

- do not play with packets accounted for sockets (skb->sk != NULL). There was check you removed. Please, reconsider.

With this check restored, the director can't access the virtual server. I haven't found any solid documentation, but skb->sk seems to be the local socket that the packet is tied to? Is there some badness that can happen by allowing these packets to be LVS'd?

Quoted 5 lines

- ability to throttle IPVS traffic with netfilter modules. How we can benefit from such modules, can they protect us, can we avoid IPVS scheduling on overload (such modules should work before IPVS conn scheduling, which should be true if you schedule in POST_ROUTING). Was true for LOCAL_IN scheduling.

Are you referring to ipt_RECENT here? That module tested ok.

Quoted 4 lines

- any work before input routing is dangerous (eg. PRE_ROUTING). There can be spoofed or looped traffic. For example, it is safer to work with replies, OTOH handling requests before input routing should be considered dangerous.

I hadn't really considered this... I can't see anything that could be dangerous looking through ip_vs_out and ip_vs_out_icmp. With current LVS, rp_filter should prevent spoofed packets from getting through as the VIP is on a local interface. I guess with VIP-less director + LVS-NAT, spoofed packets would need to be be handled with a rule such as:

iptables -t raw -I PREROUTING -i ${EXT_DEV} -s ${VIP} -j DROP

Quoted 10 lines

- one thing should be checked: what state is shown in Netfilter when UDP and TCP packets are scheduled. I see that at POST_ROUTING ipv4_confirm() is called, then __nf_conntrack_confirm() calls nf_ct_get() which should work with translated addresses (by IPVS). You should see that netfilter correctly marks traffic as confirmed. Also, you can confirm that states are properly set by applying NEW rules for requests and then only ESTABLISHED,RELATED in FORWARD. I think, you once tested it with -m state rules but make sure it works after recent (any new) changes because this is essential part.

Yep, this all still works.

Quoted 5 lines

It is interesting what is -m state in Netfilter when
no replies are forwarded for LVS-DR setups, replies go directly from real server to client. Are you sure long established connections do not timeout shorter due to bad state in netfilter? May be conntrack_tcp will be confused that only one direction works?

This is currently working, but shouldn't be. When forwarding to a regular server via the LVS box, a conntrack entry in the SYN_SENT state is set up and no further traffic is allowed. When forwarding for a VIP, traffic is flowing through regardless of whether there's a conntrack entry or not. It must be something that ip_vs_out is doing so I'll look into it a little more and try to fix it.

Quoted 7 lines

- when testing LVS-NAT make sure client does not see directly the internal hosts. This can happen when testing on LAN. It is possible something to work on LAN but not when client is out of LAN because sometimes packets do not flow as expected but client and real servers still talk successfully by avoiding IPVS box. No reply traffic passes IPVS box and nothing is REJECT-ed in FORWARD. But it should be noticed by broken TCP connections, I think.

I've set net.ipv4.conf.all.send_redirects=0 and am using host routes to make sure the traffic is going where I intend it to. The client and real server are on two separate LANs connected by both a regular router and the LVS test box.

Quoted 5 lines

- there are setups that use LVS-DR but replies come in IPVS box because it is gateway for the real servers. This is useful feature because VIP is preserved in packet allowing virtual hosts to work by IP. It means replies should be passed in IPVS box with the help from forward_shared patch.

I can't say anything for sure until I've fixed the above bug, but conntrack _should_ work fine with LVS-DR when the director is also the gateway.

Quoted 7 lines

- ICMP generation: when VIP is not configured as IP address icmp_send() currently will use some local address as source for the ICMP error sent to client. Even if this is not a big problem for clients out of LAN, on some setups when non-Linux clients are on LAN this can be confusing, there are expectations that multiple subnets share single LAN without a problem (clients know only the VIP subnet, for example). But this is more an icmp_send() problem.

Yep, you're right. However, with my patch the director doesn't appear to be the virtual server (aka no arp replies) so clients should be expecting this possibility. For my patch to be useful in this case, I'd need to allow for the VIP being bound to a local interface.

Thanks for reviewing by the way. It's definitely giving me more confidence.

Signature · 4 lines
Jason Stubbs <[email protected]>
LINKTHINK INC.
東京都渋谷区桜ヶ丘町22-14 N.E.S S棟 3F
TEL 03-5728-4772  FAX 03-5728-4773
#6 lore raw
Quoted 7 lines · On Thursday 17 April 2008 12:25:54 Jason Stubbs wrote:
Quoted 5 lines · On Wednesday 16 April 2008 18:10:52 Julian Anastasov wrote:

It is interesting what is -m state in Netfilter when
no replies are forwarded for LVS-DR setups, replies go directly from real server to client. Are you sure long established connections do not timeout shorter due to bad state in netfilter? May be conntrack_tcp will be confused that only one direction works?

Quoted 6 lines

This is currently working, but shouldn't be. When forwarding to a regular server via the LVS box, a conntrack entry in the SYN_SENT state is set up and no further traffic is allowed. When forwarding for a VIP, traffic is flowing through regardless of whether there's a conntrack entry or not. It must be something that ip_vs_out is doing so I'll look into it a little more and try to fix it.

On further investigation, the behaviour is the same regardless of whether it is a VIP or a real host. When a SYN_SENT state exists traffic doesn't flow. However, if there is no state and an ACK (no SYN) packet arrives, an ESTABLISHED entry is created such as:

ipv4 2 tcp 6 431996 ESTABLISHED src=192.168.0.104 dst=192.168.1.3
sport=20001 dport=80 packets=1 bytes=54 [UNREPLIED] src=192.168.1.3 dst=192.168.0.104 sport=80 dport=20001 packets=0 bytes=0 mark=0 use=1

After this the connection can complete normally. I wonder if this is not a bug in conntrack handling? It doesn't seem right to me.

Signature · 4 lines
Jason Stubbs <[email protected]>
LINKTHINK INC.
東京都渋谷区桜ヶ丘町22-14 N.E.S S棟 3F
TEL 03-5728-4772  FAX 03-5728-4773
#7 lore raw
Quoted 11 lines · On Thursday 17 April 2008 15:59:47 Jason Stubbs wrote:

On further investigation, the behaviour is the same regardless of whether it is a VIP or a real host. When a SYN_SENT state exists traffic doesn't flow. However, if there is no state and an ACK (no SYN) packet arrives, an ESTABLISHED entry is created such as:

ipv4 2 tcp 6 431996 ESTABLISHED src=192.168.0.104 dst=192.168.1.3
sport=20001 dport=80 packets=1 bytes=54 [UNREPLIED] src=192.168.1.3 dst=192.168.0.104 sport=80 dport=20001 packets=0 bytes=0 mark=0 use=1

After this the connection can complete normally. I wonder if this is not a bug in conntrack handling? It doesn't seem right to me.

There's an undocumented (as far as I can tell) sysctl that controls this called net.netfilter.nf_conntrack_tcp_loose which defaults to 1. Turning it off gave the behaviour I expected.

Signature · 4 lines
Jason Stubbs <[email protected]>
LINKTHINK INC.
東京都渋谷区桜ヶ丘町22-14 N.E.S S棟 3F
TEL 03-5728-4772  FAX 03-5728-4773
maintainer
#8 lore raw
In reply to Jason Stubbs

Hello,

Quoted 4 lines · Jason Stubbs

On further investigation, the behaviour is the same regardless of whether it is a VIP or a real host. When a SYN_SENT state exists traffic doesn't flow. However, if there is no state and an ACK (no SYN) packet arrives, an ESTABLISHED entry is created such as:

This conntrack does not look good, dst=192.168.1.3 in
original direction is RIP instead of VIP.

Your fw rules are not strict enough, you are using:

iptables -t filter -A FORWARD -d 192.168.0.7 -i eth0 -j ACCEPT iptables -t filter -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT iptables -t filter -P FORWARD REJECT

Can you replace first rule to allow traffic to VIP:VPORT
only for NEW. Most users don't allow traffic to any port, they specify NEW for explicit ports, others are disabled. By this way we can see if conntrack has valid directions. I suspect conntracks are not properly confirmed which happens at POST_ROUTING:NF_IP_PRI_CONNTRACK_CONFIRM. For the original request we exit with NF_STOLEN and the forwarded request goes to POST_ROUTING via dst_output call. Somewhere original destination in conntrack is replaced (or wrongly set).

You can also see the NFCT patch, it plays with conntrack
in the hard way but you can see how IPVS tries to keep conntracks in good shape.

http://www.ssi.bg/~ja/nfct/
http://www.ssi.bg/~ja/nfct/ipvs-nfct-2.6.24-1.diff

Quoted 6 lines

ipv4 2 tcp 6 431996 ESTABLISHED src=192.168.0.104 dst=192.168.1.3
sport=20001 dport=80 packets=1 bytes=54 [UNREPLIED] src=192.168.1.3 dst=192.168.0.104 sport=80 dport=20001 packets=0 bytes=0 mark=0 use=1

After this the connection can complete normally. I wonder if this is not a bug in conntrack handling? It doesn't seem right to me.

loose flag has different prurpose:

/* If it is set to zero, we disable picking up already established
connections. */
static int nf_ct_tcp_loose __read_mostly = 1;

I hope conntracks are not created per-packet? You have to
check how the conntrack looks in the different cases when playing with nf_ct_tcp_loose. Addresses before [UNREPLIED] is the original direction and data for the reply direction is the second part of addresses. Also, tcp_conntracks[][][] looks valid for SS state in the original direction, it will not switch to sES for invalid senders (may be until tcp_loose is set?).

I remember that for NFCT patch tests some packets
were dropped due to TCP SEQ number problems after ip_vs_ftp mangled the IP addresses in FTP commands. Then I used

echo 1 > /proc/sys/net/ipv4/netfilter/ip_conntrack_tcp_be_liberal

to solve it because ip_vs_ftp and tcp conntrack do not work perfectly together.

Regards

--
Julian Anastasov <[email protected]>

maintainer
#10 lore raw
In reply to Jason Stubbs

Hello,

Quoted 7 lines · Jason Stubbs
Quoted 2 lines

- do not play with packets accounted for sockets (skb->sk != NULL). There was check you removed. Please, reconsider.

With this check restored, the director can't access the virtual server. I haven't found any solid documentation, but skb->sk seems to be the local socket that the packet is tied to? Is there some badness that can happen by allowing these packets to be LVS'd?

Hm, I didn't know that with your patch director can be client.
The problem was that IPVS didn't touched packets owned by sockets before, I remember that there are rules when such skbs should be modified, related to sharing and cloning, may be skbs should be copied if modified. But I assume now skb_make_writable() handles it properly.

Quoted 7 lines
Quoted 5 lines

- ability to throttle IPVS traffic with netfilter modules. How we can benefit from such modules, can they protect us, can we avoid IPVS scheduling on overload (such modules should work before IPVS conn scheduling, which should be true if you schedule in POST_ROUTING). Was true for LOCAL_IN scheduling.

Are you referring to ipt_RECENT here? That module tested ok.

Yes, for example, -m limit for SYN packets _BEFORE_
IPVS scheduling to protect IPVS from SYN floods. But this should be checked only for changes that move IPVS scheduling at PRE_ROUTING.

Regards

--
Julian Anastasov <[email protected]>

#9 lore raw
In reply to Julian Anastasov
Quoted 10 lines · On Friday 18 April 2008 16:14:29 Julian Anastasov wrote:

Hello,

Quoted 4 lines · Jason Stubbs

On further investigation, the behaviour is the same regardless of whether it is a VIP or a real host. When a SYN_SENT state exists traffic doesn't flow. However, if there is no state and an ACK (no SYN) packet arrives, an ESTABLISHED entry is created such as:

This conntrack does not look good, dst=192.168.1.3 in
original direction is RIP instead of VIP.

That is because this testing was done by accessing the host's IP directly.

Quoted 8 lines
Quoted 2 lines

After this the connection can complete normally. I wonder if this is not a bug in conntrack handling? It doesn't seem right to me.

loose flag has different prurpose:

/* If it is set to zero, we disable picking up already established
connections. */
static int nf_ct_tcp_loose __read_mostly = 1;

This is what I was testing. I wasn't aware of the flag until just a couple of hours ago. With outgoing packets leaving via a different gateway and connection tracking enabled and --state NEW rules in place, the following happens:

1. client sends SYN
2. director sets up SYN_SENT state and forwards SYN
3. server receives SYN
4. server sends SYN/ACK via other gateway
5. client receives SYN/ACK and sends ACK
6. director sees SYN_SENT entry without a SYN/ACK and blocks ACK (4-6 are repeated a few times as server assumes the SYN/ACK got lost)
7. SYN_SENT entry times out and is deleted on the director
8. server sends SYN/ACK via other gateway
9. client receives SYN/ACK and sends ACK
10. director assumes an active connection and creates an ESTABLISHED entry
11. traffic flows fine until the end of the connection

Not being aware of the tcp_loose setting, steps 8-11 were confusing to me which is why I was testing direct access to the server. Behaviour with a VIP is the same.

Conntrack entries with both LVS-NAT and LVS-DR (when the director is also the return gateway) look like this:

ipv4 2 tcp 6 431996 ESTABLISHED src=192.168.0.104 dst=192.168.0.7
sport=35235 dport=80 packets=3 bytes=176 src=192.168.0.7 dst=192.168.0.104 sport=80 dport=35235 packets=1 bytes=60 [ASSURED] mark=0 use=1

iptables rules are:

# iptables -A FORWARD -p tcp -d 192.168.0.7 --dport 80 \
                      -m state --state NEW -j ACCEPT
# iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
# iptables -P FORWARD DROP
Signature · 4 lines
Jason Stubbs <[email protected]>
LINKTHINK INC.
東京都渋谷区桜ヶ丘町22-14 N.E.S S棟 3F
TEL 03-5728-4772  FAX 03-5728-4773