Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp3242726imc; Wed, 13 Mar 2019 12:31:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqzJjJbPtw4+2LinehYESPvUVIcYwPT6XMV1UO9FIiDOU5OpSZvtBJ51/0DN+6iYRtDaN4Af X-Received: by 2002:a63:2bcd:: with SMTP id r196mr40829315pgr.355.1552505496541; Wed, 13 Mar 2019 12:31:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552505496; cv=none; d=google.com; s=arc-20160816; b=Sj+vRwc3AKwREDrbujKjBqgd8t56e8k1Njl7gqWbMvE8pWPoANz/7OVYc2PWcV14WI 7gPdotfw7s8lmyl9HUgVQaRChZVXVyW9B02TNNm2lz+1TMH9pRp2/grsL7l/Kxlejw0N QtqotQd3N5wd3YAZg6BogQhKBmfvXBYD5p50fJHsBvfKpJVc1DunQaClwG7wN4P3eePU th1B2NYHMwgYDzFxnH7bIe1FXoxavTJqaQyzIizBqpYe3ErPsC7aYqmeYWB7ffCD8j61 TO9PcLG3dMKtA2VmGaAALgk1rcLCkfIXRHlQz2oQh7pvrHmwjESu9oltSFxwPMTiKt5L a6Yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=5m0iW34Qwkm3DgLLSEDb57iYerpZOutgKKrk9czuPu4=; b=b+QrwAjKJSWPp0e4JyJdM6E9jbJvBz3ijnd3NyvHkDfnrwwII/S8tPsyKF70E7NeBR iv8l5sdah54PZ7RKvZuMkUQGI+ftB5U92RKjtgPSoZ0dvpYEpUc4NuF7lXcJ5aUC7zDl NRSPHand5O1Te2Xfhoi7Oo+VNIot8ktY7EFYt4XoLv7hvLGuqMHeE38VyCmK4ChhsGIn JoRogjEKDaGP+yoSqsacVFxN4/EH7M50+cr3gWqNhTqm07xK3dUXBMlFTNsFOwc6A4aZ Bbv3aNtvL6fg0TGuQXHHuptrnMWNm6Au7l3827sfQugkyhbSgKcGFh7+pyozVDWIUDfK YPaQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w3si11652160plq.169.2019.03.13.12.31.19; Wed, 13 Mar 2019 12:31:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728048AbfCMTaJ (ORCPT + 99 others); Wed, 13 Mar 2019 15:30:09 -0400 Received: from ja.ssi.bg ([178.16.129.10]:33558 "EHLO ja.ssi.bg" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1727892AbfCMTaH (ORCPT ); Wed, 13 Mar 2019 15:30:07 -0400 X-Greylist: delayed 586 seconds by postgrey-1.27 at vger.kernel.org; Wed, 13 Mar 2019 15:30:06 EDT Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by ja.ssi.bg (8.15.2/8.15.2) with ESMTP id x2DJJcZb003076; Wed, 13 Mar 2019 21:19:38 +0200 Date: Wed, 13 Mar 2019 21:19:38 +0200 (EET) From: Julian Anastasov To: Jacky Hu cc: jacky.hu@walmart.com, jason.niesz@walmart.com, Wensong Zhang , Simon Horman , Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , "David S. Miller" , netdev@vger.kernel.org, lvs-devel@vger.kernel.org, linux-kernel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org Subject: Re: [PATCH] ipvs: allow tunneling with gue encapsulation In-Reply-To: <20190312071218.21905-1-hengqing.hu@gmail.com> Message-ID: References: <20190312071218.21905-1-hengqing.hu@gmail.com> User-Agent: Alpine 2.21 (LFD 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, On Tue, 12 Mar 2019, Jacky Hu wrote: > ipip packets are blocked in some public cloud environments, this patch > allows gue encapsulation with the tunneling method, which would make > tunneling working in those environments. > > Signed-off-by: Jacky Hu > --- > include/uapi/linux/ip_vs.h | 17 +++++++- > net/netfilter/ipvs/ip_vs_ctl.c | 4 +- > net/netfilter/ipvs/ip_vs_xmit.c | 71 ++++++++++++++++++++++++++++++++- > 3 files changed, 87 insertions(+), 5 deletions(-) > > diff --git a/include/uapi/linux/ip_vs.h b/include/uapi/linux/ip_vs.h > index 1c916b2f89dc..6637e45b93f4 100644 > --- a/include/uapi/linux/ip_vs.h > +++ b/include/uapi/linux/ip_vs.h > @@ -96,13 +96,25 @@ > #define IP_VS_CONN_F_TEMPLATE 0x1000 /* template, not connection */ > #define IP_VS_CONN_F_ONE_PACKET 0x2000 /* forward only one packet */ > > +/* tunneling with gue */ > +#define IP_VS_CONN_F_GUE 0x0008 > + > +/* gue destination port bit 0 */ > +#define IP_VS_CONN_F_GUE_PORT_LSB 0x4000 > + > +/* gue destination port bit 1-15 */ > +#define IP_VS_CONN_F_GUE_PORT_MSB 0xFFFFE0000 > + > /* Initial bits allowed in backup server */ > #define IP_VS_CONN_F_BACKUP_MASK (IP_VS_CONN_F_FWD_MASK | \ > IP_VS_CONN_F_NOOUTPUT | \ > IP_VS_CONN_F_INACTIVE | \ > IP_VS_CONN_F_SEQ_MASK | \ > IP_VS_CONN_F_NO_CPORT | \ > - IP_VS_CONN_F_TEMPLATE \ > + IP_VS_CONN_F_TEMPLATE | \ > + IP_VS_CONN_F_GUE | \ > + IP_VS_CONN_F_GUE_PORT_MSB | \ > + IP_VS_CONN_F_GUE_PORT_LSB \ > ) > > /* Bits allowed to update in backup server */ > @@ -116,6 +128,9 @@ > #define IP_VS_CONN_F_DEST_MASK (IP_VS_CONN_F_FWD_MASK | \ > IP_VS_CONN_F_ONE_PACKET | \ > IP_VS_CONN_F_NFCT | \ > + IP_VS_CONN_F_GUE | \ > + IP_VS_CONN_F_GUE_PORT_MSB | \ > + IP_VS_CONN_F_GUE_PORT_LSB | \ > 0) It would be better to not touch these flags. The backup sync server simply ignores the forwarding method by applying the IP_VS_CONN_F_BACKUP_UPD_MASK mask. The real server is found only by daddr+dport. It would be enough to provide any new non-default parameters as optional IPVS_DEST_ATTR_xxx attributes. By this way, we can later add more tunneling methods. > #define IP_VS_SCHEDNAME_MAXLEN 16 > diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c > index 432141f04af3..cecfb52cdea4 100644 > --- a/net/netfilter/ipvs/ip_vs_ctl.c > +++ b/net/netfilter/ipvs/ip_vs_ctl.c > @@ -3169,7 +3169,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest) > nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) || > nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD, > (atomic_read(&dest->conn_flags) & > - IP_VS_CONN_F_FWD_MASK)) || > + IP_VS_CONN_F_DEST_MASK)) || > nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT, > atomic_read(&dest->weight)) || > nla_put_u32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold) || We can add the new attributes in this function. > @@ -3305,7 +3305,7 @@ static int ip_vs_genl_parse_dest(struct ip_vs_dest_user_kern *udest, > return -EINVAL; > > udest->conn_flags = nla_get_u32(nla_fwd) > - & IP_VS_CONN_F_FWD_MASK; > + & IP_VS_CONN_F_DEST_MASK; > udest->weight = nla_get_u32(nla_weight); > udest->u_threshold = nla_get_u32(nla_u_thresh); > udest->l_threshold = nla_get_u32(nla_l_thresh); Here too. Also, note that __ip_vs_update_dest() can update the forwarding methods, so we should be able to switch them between any method. > diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c > index 473cce2a5231..2667b587b91d 100644 > --- a/net/netfilter/ipvs/ip_vs_xmit.c > +++ b/net/netfilter/ipvs/ip_vs_xmit.c > @@ -32,6 +32,7 @@ > #include > #include /* for tcphdr */ > #include > +#include > #include /* for csum_tcpudp_magic */ > #include > #include /* for icmp_send */ > @@ -989,6 +990,42 @@ static inline int __tun_gso_type_mask(int encaps_af, int orig_af) > } > } > > +static int > +__build_gue_header(struct net *net, struct sk_buff *skb, > + struct ip_vs_conn *cp, __u8 *next_protocol) > +{ > + __be16 dport; > + __be16 sport; > + struct udphdr *udph; /* Our new UDP header */ > + struct guehdr *gueh; /* Our new GUE header */ > + > + skb_push(skb, sizeof(struct guehdr)); > + > + gueh = (struct guehdr *)skb->data; > + > + gueh->control = 0; > + gueh->version = 0; > + gueh->hlen = 0; > + gueh->flags = 0; > + gueh->proto_ctype = *next_protocol; > + > + skb_push(skb, sizeof(struct udphdr)); > + skb_reset_transport_header(skb); > + > + udph = udp_hdr(skb); > + > + dport = htons(((cp->flags >> 16) & 0xFFFE) | ((cp->flags >> 14) & 1)); > + sport = udp_flow_src_port(net, skb, 0, 0, false); > + udph->dest = dport; > + udph->source = sport; > + udph->len = htons(skb->len); > + udph->check = 0; > + > + *next_protocol = IPPROTO_UDP; > + > + return 0; > +} > + > /* > * IP Tunneling transmitter > * > @@ -1025,6 +1062,8 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, > struct iphdr *iph; /* Our new IP header */ > unsigned int max_headroom; /* The extra header space needed */ > int ret, local; > + bool gue = false; > + int type; > > EnterFunction(10); > > @@ -1041,11 +1080,16 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, > rt = skb_rtable(skb); > tdev = rt->dst.dev; > Then, in this func we should drop traffic when cp->dest is NULL because we will not know the actual tunneling method. But it can happen only on misconfigured backup servers, so this is not a big problem. Now, the parameters should be available in cp->dest. > + gue = (bool)(cp->flags & IP_VS_CONN_F_GUE); > + > /* > * Okay, now see if we can stuff it in the buffer as-is. > */ > max_headroom = LL_RESERVED_SPACE(tdev) + sizeof(struct iphdr); > > + if (gue) > + max_headroom += sizeof(struct udphdr) + sizeof(struct guehdr); > + > /* We only care about the df field if sysctl_pmtu_disc(ipvs) is set */ > dfp = sysctl_pmtu_disc(ipvs) ? &df : NULL; > skb = ip_vs_prepare_tunneled_skb(skb, cp->af, max_headroom, > @@ -1054,11 +1098,19 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, > if (IS_ERR(skb)) > goto tx_error; > > - if (iptunnel_handle_offloads(skb, __tun_gso_type_mask(AF_INET, cp->af))) > + if (gue) > + type = SKB_GSO_UDP_TUNNEL; > + else > + type = __tun_gso_type_mask(AF_INET, cp->af); > + > + if (iptunnel_handle_offloads(skb, type)) > goto tx_error; > > skb->transport_header = skb->network_header; > > + if (gue) > + __build_gue_header(dev_net(tdev), skb, cp, &next_protocol); > + > skb_push(skb, sizeof(struct iphdr)); > skb_reset_network_header(skb); > memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt)); > @@ -1112,6 +1164,8 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, > struct ipv6hdr *iph; /* Our new IP header */ > unsigned int max_headroom; /* The extra header space needed */ > int ret, local; > + bool gue = false; > + int type; > > EnterFunction(10); > > @@ -1129,22 +1183,35 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, > rt = (struct rt6_info *) skb_dst(skb); > tdev = rt->dst.dev; > > + gue = (bool)(cp->flags & IP_VS_CONN_F_GUE); > + > /* > * Okay, now see if we can stuff it in the buffer as-is. > */ > max_headroom = LL_RESERVED_SPACE(tdev) + sizeof(struct ipv6hdr); > > + if (gue) > + max_headroom += sizeof(struct udphdr) + sizeof(struct guehdr); > + > skb = ip_vs_prepare_tunneled_skb(skb, cp->af, max_headroom, > &next_protocol, &payload_len, > &dsfield, &ttl, NULL); > if (IS_ERR(skb)) > goto tx_error; > > - if (iptunnel_handle_offloads(skb, __tun_gso_type_mask(AF_INET6, cp->af))) > + if (gue) > + type = SKB_GSO_UDP_TUNNEL; > + else > + type = __tun_gso_type_mask(AF_INET6, cp->af); > + > + if (iptunnel_handle_offloads(skb, type)) > goto tx_error; > > skb->transport_header = skb->network_header; > > + if (gue) > + __build_gue_header(dev_net(tdev), skb, cp, &next_protocol); > + > skb_push(skb, sizeof(struct ipv6hdr)); > skb_reset_network_header(skb); > memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt)); > -- > 2.21.0 Regards -- Julian Anastasov