Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp1497119ybc; Tue, 12 Nov 2019 22:58:01 -0800 (PST) X-Google-Smtp-Source: APXvYqzBR1KIkpUdG/KyhsQXvoZvyhDc3TO4qGO21JniLSUtK6dAk/ZXFUnjQp74XuxjQ1zDM2w6 X-Received: by 2002:a50:da4b:: with SMTP id a11mr1863468edk.17.1573628281650; Tue, 12 Nov 2019 22:58:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573628281; cv=none; d=google.com; s=arc-20160816; b=lM3qP6rGhe5KCN5f2Zt455uCYtGNuWRvJWU4iwzJ2z8v6hdM7kB89ME/Jxq0ObPuTh jv/yY/JrnbsIwSf+bOlc5Ke25f+cuAfDjnYCE7UguFK730CCnOo/3X7Swdlv7MHcIZcq VstDHm39RuPGpI00YKc4SjBcRJa7lKKoQujs3xjP3T6qOs0Se/o+nrivVKmLAaTGwWhI PJCxsyR2gPqWbb5E95eEYy0OCJE2P9/4pnZEA1HZmmxVqdK1KRwMc/zLptkcmQizC6mG kFwFXGkn781LfhMKEaY5o8IGHgjESxSjxZdYv2iYxSokQTVtQp1YK2Plt66Kt/bPDmo0 ej9w== 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:dkim-signature; bh=4DsUGnKqjy0+txZT/fzFV5OBdOrHS8RfuCy5beGf3m8=; b=mO0AzD0I0AB+nWNOrmRY6oa9QOrwBtCRvmJkAvVmB3ekLV3mKA9POJokIRMyC8zqmZ e9PHMXgfVWOR/Zr02wCBYhIiUPsE3dctv4vUTfitiS6NYUhvMTJ16GrE1lgfNng4u7QL zOhNiEN3mYIWTp81oaWd/B+gjQyKqEPQ11R/a2wwkhDL7QdqQExGL4KNsaspN7K7hcvJ 0aDRcqBQCQu0aqd4R1Ro5UoWP2uAQ3ofoIcFjeqtNqB/nxbfpzv4KvyjmDTSYqb4n/CA v5wkKVAUaO/qvjYZTaYak4rPKzXPa77vcClG+OgwFfJi0jkkx91iDDnF1o7LQMMrF0i7 L2Nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@netronome-com.20150623.gappssmtp.com header.s=20150623 header.b=XkYn73Sm; 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 q8si588056ejt.321.2019.11.12.22.57.36; Tue, 12 Nov 2019 22:58:01 -0800 (PST) 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; dkim=pass header.i=@netronome-com.20150623.gappssmtp.com header.s=20150623 header.b=XkYn73Sm; 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 S1726190AbfKMG5G (ORCPT + 99 others); Wed, 13 Nov 2019 01:57:06 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:44455 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725866AbfKMG5F (ORCPT ); Wed, 13 Nov 2019 01:57:05 -0500 Received: by mail-wr1-f66.google.com with SMTP id f2so952234wrs.11 for ; Tue, 12 Nov 2019 22:57:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=4DsUGnKqjy0+txZT/fzFV5OBdOrHS8RfuCy5beGf3m8=; b=XkYn73SmZx1XM56MaLKx411vKh7Ufy9yYQS/T96JXUgx6wzXEvz9qOXG/LsrdPRoSz 1C2tTaQEE9VGrS1/Pc4A/hAp4rAT7DgJT63LiGY2FyxMCyn9VSMcENvzJHhTcoZ0opm1 d67IG4Y/aUXhYWJnJh+tERBtbVugGxYuxM/ZWP3ujr86yJcNPMc4JGHVNhZ66EoV9w53 8/SzpiK/3F313nP9rajTAX8DDg/tveCFsdhgxrEOAqW1Kkx9700GSKBGhe+dvMsxCEVE cJ8hXR+4V/EMY3nQI2x+5uW3rhlNWYU0qFCosbapn6sPY1D1j9JauMjOZ6g7s0x2zrZm 5jnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=4DsUGnKqjy0+txZT/fzFV5OBdOrHS8RfuCy5beGf3m8=; b=lV6yS3iapGwnA0XJavLOFdouYX9k1qShTP0505suDCNTE3T9bKVTJFooo44PaEbprp T1sUstqP7KFMklzOEhWI0oRj9JhFbrP/qfADdB4FWwJSaTpuZmM5myAtWwvJkwb/hKTP /rjEN2KoszmSbu5H+JxZD6Gv3AqAZjk/qgB4796Epbqp/JOfjTTHlARDoKbCb9QfXONG LN9Au4Tu4zdcSHzX2nihdwFm+NcvPh9er7Drkq2yO1fLb1F4D7RKmzkzN3091yD+fNGR iesnZdIU9cCco1fOi9szTXTkUnBFwikbgPXt7Nq2xjsSd+5/j1EYvoSN1EXSmj4uqJ3q 5t2g== X-Gm-Message-State: APjAAAVEyEMvB6UyGSIx1op47PMCR1ISHbV0RMjBbBcapLFm2nK+tLkD AIa+bftMB5W6isF3ciYwptNpdw== X-Received: by 2002:adf:e80d:: with SMTP id o13mr143146wrm.73.1573628223450; Tue, 12 Nov 2019 22:57:03 -0800 (PST) Received: from netronome.com ([2001:982:756:703:d63d:7eff:fe99:ac9d]) by smtp.gmail.com with ESMTPSA id a186sm603876wmc.48.2019.11.12.22.57.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Nov 2019 22:57:02 -0800 (PST) Date: Wed, 13 Nov 2019 07:57:02 +0100 From: Simon Horman To: Matteo Croce Cc: netdev , dev@openvswitch.org, LKML , Pravin B Shelar , "David S. Miller" , Bindiya Kurle Subject: Re: [PATCH net-next] openvswitch: add TTL decrement action Message-ID: <20191113065701.f76pe4drfixdm6ci@netronome.com> References: <20191112102518.4406-1-mcroce@redhat.com> <20191112150046.2aehmeoq7ri6duwo@netronome.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 12, 2019 at 04:46:12PM +0100, Matteo Croce wrote: > On Tue, Nov 12, 2019 at 4:00 PM Simon Horman wrote: > > > > On Tue, Nov 12, 2019 at 11:25:18AM +0100, Matteo Croce wrote: > > > New action to decrement TTL instead of setting it to a fixed value. > > > This action will decrement the TTL and, in case of expired TTL, send the > > > packet to userspace via output_userspace() to take care of it. > > > > > > Supports both IPv4 and IPv6 via the ttl and hop_limit fields, respectively. > > > > > > > Usually OVS achieves this behaviour by matching on the TTL and > > setting it to the desired value, pre-calculated as TTL -1. > > With that in mind could you explain the motivation for this > > change? > > > > Hi, > > the problem is that OVS creates a flow for each ttl it see. I can let > vswitchd create 255 flows with like this: > > $ for i in {2..255}; do ping 192.168.0.2 -t $i -c1 -w1 &>/dev/null & done > $ ovs-dpctl dump-flows |fgrep -c 'set(ipv4(ttl' > 255 Hi, so the motivation is to reduce the number of megaflows in the case where flows otherwise match but the TTL differs. I think this makes sense and the absence of this feature may date back to designs made before megaflow support was added - just guessing. I think this is a reasonable feature but I think it would be good to explain the motivation in the changelog. > > > @@ -1174,6 +1174,43 @@ static int execute_check_pkt_len(struct datapath *dp, struct sk_buff *skb, > > > nla_len(actions), last, clone_flow_key); > > > } > > > > > > +static int execute_dec_ttl(struct sk_buff *skb, struct sw_flow_key *key) > > > +{ > > > + int err; > > > + > > > + if (skb->protocol == htons(ETH_P_IPV6)) { > > > + struct ipv6hdr *nh = ipv6_hdr(skb); > > > + > > > + err = skb_ensure_writable(skb, skb_network_offset(skb) + > > > + sizeof(*nh)); > > > + if (unlikely(err)) > > > + return err; > > > + > > > + if (nh->hop_limit <= 1) > > > + return -EHOSTUNREACH; > > > + > > > + key->ip.ttl = --nh->hop_limit; > > > + } else { > > > + struct iphdr *nh = ip_hdr(skb); > > > + u8 old_ttl; > > > + > > > + err = skb_ensure_writable(skb, skb_network_offset(skb) + > > > + sizeof(*nh)); > > > + if (unlikely(err)) > > > + return err; > > > + > > > + if (nh->ttl <= 1) > > > + return -EHOSTUNREACH; > > > + > > > + old_ttl = nh->ttl--; > > > + csum_replace2(&nh->check, htons(old_ttl << 8), > > > + htons(nh->ttl << 8)); > > > + key->ip.ttl = nh->ttl; > > > + } > > > > The above may send packets with TTL = 0, is that desired? > > > > If TTL is 1 or 0, execute_dec_ttl() returns -EHOSTUNREACH, and the > caller will just send the packet to userspace and then free it. > I think this is enough, am I missing something? No, you are not. I was missing something. I now think this logic is fine.