Received: by 2002:ac0:950e:0:0:0:0:0 with SMTP id f14csp323167imc; Sat, 16 Mar 2019 02:07:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqxqldRUz5xiW+jX1KV1DHdhnJ9/OFlc2qGSoYDl2jden0w70J/frRTJDTiZlqNZzNEerobA X-Received: by 2002:a63:9752:: with SMTP id d18mr7822777pgo.0.1552727272561; Sat, 16 Mar 2019 02:07:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552727272; cv=none; d=google.com; s=arc-20160816; b=oAIayw1li5UKVsjQG4WQEHsOwgoejyF6BD5ro7qs1eyYQGDlSofdvLB0SA72u60ygJ DoGZVxMcGvSdziaJKLnz9NISt62n6yNgTCauD5aqVzi8/+cpsLcLqDXhpFc2acr26Puf VLgrJeMaXXD0sxIp+ldF4H6gyCOZLq7BBkiUi1YSMGjt93G37sYcTMTnH5ovS2mmm/+c KVQRxlpVPJPjnvDXlwJdntrdHWHR1sL8Fkf+WVkKV0lVrw8ttsq5bVOTx/GXyaxxJwUp 5ObgXoyL03ajnRzcZm5VfkJdC91BEqoaF0GwZKIXAB5uQEdnQUtdTPLPs5JWmrt3a5Fn yOug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=1CekbLKhQPFI5/wptDLk+NcoE10cHlTXYa1nu/y3EPw=; b=uzmPMXMKDawKEr3vjdMOI2WmLjYdLxlHveIUjvjK2yEza6L6q/mOkxIIXPOcgbIywT 5ADTRcIGvdt821OUM1cLCKfA50H/kVy1Hmkv6IcOM0O4QS/KtVbQDQgjV/P9w4bFIHHc WcqAH2NAE8n1/uJ4xLdAt/GfJBtfN8qYLoIT7ediVt9yzUulf/zaa6p8V90Zur/ZBBAs i+XXvVP7QjZSsto9Whc7xvbKbGmWc3XphRHArseMHSojmjkSWJqmKUizSW/XjgimajiL mmwVoFFCZ+WY1XGIyunmf7r+dnTexgwPMAqMVYvrusnCeJ2HhQqL6HbjrmyN46qgbQ1I ARTA== 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 j9si3835153pgk.323.2019.03.16.02.07.36; Sat, 16 Mar 2019 02:07:52 -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 S1726767AbfCPJG4 (ORCPT + 99 others); Sat, 16 Mar 2019 05:06:56 -0400 Received: from mail.us.es ([193.147.175.20]:37056 "EHLO mail.us.es" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726499AbfCPJG4 (ORCPT ); Sat, 16 Mar 2019 05:06:56 -0400 Received: from antivirus1-rhel7.int (unknown [192.168.2.11]) by mail.us.es (Postfix) with ESMTP id 6EAF0DA8A3 for ; Sat, 16 Mar 2019 10:06:53 +0100 (CET) Received: from antivirus1-rhel7.int (localhost [127.0.0.1]) by antivirus1-rhel7.int (Postfix) with ESMTP id 5CCF1DA846 for ; Sat, 16 Mar 2019 10:06:53 +0100 (CET) Received: by antivirus1-rhel7.int (Postfix, from userid 99) id 51F44DA844; Sat, 16 Mar 2019 10:06:53 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on antivirus1-rhel7.int X-Spam-Level: X-Spam-Status: No, score=-108.2 required=7.5 tests=ALL_TRUSTED,BAYES_50, SMTPAUTH_US2,USER_IN_WHITELIST autolearn=disabled version=3.4.1 Received: from antivirus1-rhel7.int (localhost [127.0.0.1]) by antivirus1-rhel7.int (Postfix) with ESMTP id 1BE75DA846; Sat, 16 Mar 2019 10:06:50 +0100 (CET) Received: from 192.168.1.97 (192.168.1.97) by antivirus1-rhel7.int (F-Secure/fsigk_smtp/550/antivirus1-rhel7.int); Sat, 16 Mar 2019 10:06:50 +0100 (CET) X-Virus-Status: clean(F-Secure/fsigk_smtp/550/antivirus1-rhel7.int) Received: from us.es (sys.soleta.eu [212.170.55.40]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: 1984lsi) by entrada.int (Postfix) with ESMTPSA id D59134265A4E; Sat, 16 Mar 2019 10:06:49 +0100 (CET) Date: Sat, 16 Mar 2019 10:06:49 +0100 X-SMTPAUTHUS: auth mail.us.es From: Pablo Neira Ayuso To: Jacky Hu Cc: jacky.hu@walmart.com, jason.niesz@walmart.com, Wensong Zhang , Simon Horman , Julian Anastasov , "David S. Miller" , Alexey Kuznetsov , Hideaki YOSHIFUJI , Jozsef Kadlecsik , Florian Westphal , 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 v3] ipvs: allow tunneling with gue encapsulation Message-ID: <20190316090649.mm7fskvzx5hzp672@salvia> References: <20190316072009.2247-1-hengqing.hu@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190316072009.2247-1-hengqing.hu@gmail.com> User-Agent: NeoMutt/20170113 (1.7.2) X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Mar 16, 2019 at 03:20:07PM +0800, 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 > --- What did it change from v2 to v3? A quick report here would help us to follow track of your updates. Thanks! > include/net/ip_vs.h | 5 ++ > include/uapi/linux/ip_vs.h | 17 ++++++ > net/netfilter/ipvs/ip_vs_ctl.c | 20 ++++++- > net/netfilter/ipvs/ip_vs_xmit.c | 93 +++++++++++++++++++++++++++++++-- > 4 files changed, 130 insertions(+), 5 deletions(-) > > diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h > index a0d2e0bb9a94..56c1770b00fe 100644 > --- a/include/net/ip_vs.h > +++ b/include/net/ip_vs.h > @@ -603,6 +603,9 @@ struct ip_vs_dest_user_kern { > > /* Address family of addr */ > u16 af; > + > + u16 tun_type; /* tunnel type */ > + __be16 tun_port; /* tunnel port */ > }; > > > @@ -663,6 +666,8 @@ struct ip_vs_dest { > atomic_t conn_flags; /* flags to copy to conn */ > atomic_t weight; /* server weight */ > atomic_t last_weight; /* server latest weight */ > + atomic_t tun_type; /* tunnel type */ > + atomic_t tun_port; /* tunnel port */ > > refcount_t refcnt; /* reference counter */ > struct ip_vs_stats stats; /* statistics */ > diff --git a/include/uapi/linux/ip_vs.h b/include/uapi/linux/ip_vs.h > index 1c916b2f89dc..b43297691337 100644 > --- a/include/uapi/linux/ip_vs.h > +++ b/include/uapi/linux/ip_vs.h > @@ -124,6 +124,13 @@ > > #define IP_VS_PEDATA_MAXLEN 255 > > +/* Tunnel types */ > +enum { > + IP_VS_CONN_F_TUNNEL_TYPE_IPIP = 0, /* IPIP */ > + IP_VS_CONN_F_TUNNEL_TYPE_GUE, /* GUE */ > + IP_VS_CONN_F_TUNNEL_TYPE_MAX, > +}; > + > /* > * The struct ip_vs_service_user and struct ip_vs_dest_user are > * used to set IPVS rules through setsockopt. > @@ -155,6 +162,9 @@ struct ip_vs_dest_user { > /* thresholds for active connections */ > __u32 u_threshold; /* upper threshold */ > __u32 l_threshold; /* lower threshold */ > + > + __u16 tun_type; /* tunnel type */ > + __be16 tun_port; /* tunnel port */ > }; > > > @@ -220,6 +230,9 @@ struct ip_vs_dest_entry { > __u32 u_threshold; /* upper threshold */ > __u32 l_threshold; /* lower threshold */ > > + __u16 tun_type; /* tunnel type */ > + __be16 tun_port; /* tunnel port */ > + > __u32 activeconns; /* active connections */ > __u32 inactconns; /* inactive connections */ > __u32 persistconns; /* persistent connections */ > @@ -392,6 +405,10 @@ enum { > > IPVS_DEST_ATTR_STATS64, /* nested attribute for dest stats */ > > + IPVS_DEST_ATTR_TUN_TYPE, /* tunnel type */ > + > + IPVS_DEST_ATTR_TUN_PORT, /* tunnel port */ > + > __IPVS_DEST_ATTR_MAX, > }; > > diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c > index 432141f04af3..48509b03a5ea 100644 > --- a/net/netfilter/ipvs/ip_vs_ctl.c > +++ b/net/netfilter/ipvs/ip_vs_ctl.c > @@ -830,6 +830,10 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest, > conn_flags = udest->conn_flags & IP_VS_CONN_F_DEST_MASK; > conn_flags |= IP_VS_CONN_F_INACTIVE; > > + /* set the tunnel info */ > + atomic_set(&dest->tun_type, udest->tun_type); > + atomic_set(&dest->tun_port, udest->tun_port); > + > /* set the IP_VS_CONN_F_NOOUTPUT flag if not masquerading/NAT */ > if ((conn_flags & IP_VS_CONN_F_FWD_MASK) != IP_VS_CONN_F_MASQ) { > conn_flags |= IP_VS_CONN_F_NOOUTPUT; > @@ -2869,6 +2873,8 @@ static const struct nla_policy ip_vs_dest_policy[IPVS_DEST_ATTR_MAX + 1] = { > [IPVS_DEST_ATTR_PERSIST_CONNS] = { .type = NLA_U32 }, > [IPVS_DEST_ATTR_STATS] = { .type = NLA_NESTED }, > [IPVS_DEST_ATTR_ADDR_FAMILY] = { .type = NLA_U16 }, > + [IPVS_DEST_ATTR_TUN_TYPE] = { .type = NLA_U8 }, > + [IPVS_DEST_ATTR_TUN_PORT] = { .type = NLA_U16 }, > }; > > static int ip_vs_genl_fill_stats(struct sk_buff *skb, int container_type, > @@ -3172,6 +3178,10 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest) > IP_VS_CONN_F_FWD_MASK)) || > nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT, > atomic_read(&dest->weight)) || > + nla_put_u8(skb, IPVS_DEST_ATTR_TUN_TYPE, > + atomic_read(&dest->tun_type)) || > + nla_put_u16(skb, IPVS_DEST_ATTR_TUN_PORT, > + atomic_read(&dest->tun_port)) || > nla_put_u32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold) || > nla_put_u32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold) || > nla_put_u32(skb, IPVS_DEST_ATTR_ACTIVE_CONNS, > @@ -3294,12 +3304,14 @@ static int ip_vs_genl_parse_dest(struct ip_vs_dest_user_kern *udest, > /* If a full entry was requested, check for the additional fields */ > if (full_entry) { > struct nlattr *nla_fwd, *nla_weight, *nla_u_thresh, > - *nla_l_thresh; > + *nla_l_thresh, *nla_tun_type, *nla_tun_port; > > nla_fwd = attrs[IPVS_DEST_ATTR_FWD_METHOD]; > nla_weight = attrs[IPVS_DEST_ATTR_WEIGHT]; > nla_u_thresh = attrs[IPVS_DEST_ATTR_U_THRESH]; > nla_l_thresh = attrs[IPVS_DEST_ATTR_L_THRESH]; > + nla_tun_type = attrs[IPVS_DEST_ATTR_TUN_TYPE]; > + nla_tun_port = attrs[IPVS_DEST_ATTR_TUN_PORT]; > > if (!(nla_fwd && nla_weight && nla_u_thresh && nla_l_thresh)) > return -EINVAL; > @@ -3309,6 +3321,12 @@ static int ip_vs_genl_parse_dest(struct ip_vs_dest_user_kern *udest, > 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); > + > + if (nla_tun_type) > + udest->tun_type = nla_get_u8(nla_tun_type); > + > + if (nla_tun_port) > + udest->tun_port = nla_get_u16(nla_tun_port); > } > > return 0; > diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c > index 473cce2a5231..e748c5605b04 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(atomic_read(&cp->dest->tun_port)); > + 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,7 @@ 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; > + int tun_type, gso_type; > > EnterFunction(10); > > @@ -1033,7 +1071,7 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, > IP_VS_RT_MODE_NON_LOCAL | > IP_VS_RT_MODE_CONNECT | > IP_VS_RT_MODE_TUNNEL, &saddr, ipvsh); > - if (local < 0) > + if (!cp->dest || local < 0) > goto tx_error; > if (local) > return ip_vs_send_or_cont(NFPROTO_IPV4, skb, cp, 1); > @@ -1046,6 +1084,14 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, > */ > max_headroom = LL_RESERVED_SPACE(tdev) + sizeof(struct iphdr); > > + tun_type = atomic_read(&cp->dest->tun_type); > + > + switch (tun_type) { > + case IP_VS_CONN_F_TUNNEL_TYPE_GUE: > + max_headroom += sizeof(struct udphdr) + sizeof(struct guehdr); > + break; > + } > + > /* 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 +1100,26 @@ 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))) > + switch (tun_type) { > + case IP_VS_CONN_F_TUNNEL_TYPE_GUE: > + gso_type = SKB_GSO_UDP_TUNNEL; > + break; > + default: > + gso_type = __tun_gso_type_mask(AF_INET, cp->af); > + break; > + } > + > + if (iptunnel_handle_offloads(skb, gso_type)) > goto tx_error; > > skb->transport_header = skb->network_header; > > + switch (tun_type) { > + case IP_VS_CONN_F_TUNNEL_TYPE_GUE: > + __build_gue_header(dev_net(tdev), skb, cp, &next_protocol); > + break; > + } > + > skb_push(skb, sizeof(struct iphdr)); > skb_reset_network_header(skb); > memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt)); > @@ -1112,6 +1173,7 @@ 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; > + int tun_type, gso_type; > > EnterFunction(10); > > @@ -1121,7 +1183,7 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, > IP_VS_RT_MODE_LOCAL | > IP_VS_RT_MODE_NON_LOCAL | > IP_VS_RT_MODE_TUNNEL); > - if (local < 0) > + if (!cp->dest || local < 0) > goto tx_error; > if (local) > return ip_vs_send_or_cont(NFPROTO_IPV6, skb, cp, 1); > @@ -1134,17 +1196,40 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, > */ > max_headroom = LL_RESERVED_SPACE(tdev) + sizeof(struct ipv6hdr); > > + tun_type = atomic_read(&cp->dest->tun_type); > + > + switch (tun_type) { > + case IP_VS_CONN_F_TUNNEL_TYPE_GUE: > + max_headroom += sizeof(struct udphdr) + sizeof(struct guehdr); > + break; > + } > + > 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))) > + switch (tun_type) { > + case IP_VS_CONN_F_TUNNEL_TYPE_GUE: > + gso_type = SKB_GSO_UDP_TUNNEL; > + break; > + default: > + gso_type = __tun_gso_type_mask(AF_INET, cp->af); > + break; > + } > + > + if (iptunnel_handle_offloads(skb, gso_type)) > goto tx_error; > > skb->transport_header = skb->network_header; > > + switch (tun_type) { > + case IP_VS_CONN_F_TUNNEL_TYPE_GUE: > + __build_gue_header(dev_net(tdev), skb, cp, &next_protocol); > + break; > + } > + > skb_push(skb, sizeof(struct ipv6hdr)); > skb_reset_network_header(skb); > memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt)); > -- > 2.21.0 >