From patchwork Thu Dec 3 07:53:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Stringer X-Patchwork-Id: 552061 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (unknown [IPv6:2600:3c00::f03c:91ff:fe6e:bdf7]) by ozlabs.org (Postfix) with ESMTP id 680ED1402E2 for ; Thu, 3 Dec 2015 18:55:09 +1100 (AEDT) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id D4D4B10B7C; Wed, 2 Dec 2015 23:54:31 -0800 (PST) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx3v3.cudamail.com (mx3.cudamail.com [64.34.241.5]) by archives.nicira.com (Postfix) with ESMTPS id D5C9C10B76 for ; Wed, 2 Dec 2015 23:54:30 -0800 (PST) Received: from bar4.cudamail.com (localhost [127.0.0.1]) by mx3v3.cudamail.com (Postfix) with ESMTPS id 62DC316153E for ; Thu, 3 Dec 2015 00:54:30 -0700 (MST) X-ASG-Debug-ID: 1449129270-03dc21603d82f650001-byXFYA Received: from mx3-pf2.cudamail.com ([192.168.14.1]) by bar4.cudamail.com with ESMTP id RPGVDPK1uarszEbR (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 03 Dec 2015 00:54:30 -0700 (MST) X-Barracuda-Envelope-From: joe@ovn.org X-Barracuda-RBL-Trusted-Forwarder: 192.168.14.1 Received: from unknown (HELO relay4-d.mail.gandi.net) (217.70.183.196) by mx3-pf2.cudamail.com with ESMTPS (DHE-RSA-AES256-SHA encrypted); 3 Dec 2015 07:54:29 -0000 Received-SPF: pass (mx3-pf2.cudamail.com: SPF record at ovn.org designates 217.70.183.196 as permitted sender) X-Barracuda-Apparent-Source-IP: 217.70.183.196 X-Barracuda-RBL-IP: 217.70.183.196 Received: from mfilter21-d.gandi.net (mfilter21-d.gandi.net [217.70.178.149]) by relay4-d.mail.gandi.net (Postfix) with ESMTP id 139A1172097; Thu, 3 Dec 2015 08:54:28 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mfilter21-d.gandi.net Received: from relay4-d.mail.gandi.net ([IPv6:::ffff:217.70.183.196]) by mfilter21-d.gandi.net (mfilter21-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id HSCR9aRRZUXY; Thu, 3 Dec 2015 08:54:26 +0100 (CET) X-Originating-IP: 208.91.1.34 Received: from localhost.localdomain (unknown [208.91.1.34]) (Authenticated sender: joe@ovn.org) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 43AC51720C3; Thu, 3 Dec 2015 08:54:25 +0100 (CET) X-CudaMail-Envelope-Sender: joe@ovn.org From: Joe Stringer To: dev@openvswitch.org X-CudaMail-Whitelist-To: dev@openvswitch.org X-CudaMail-MID: CM-V2-1202000770 X-CudaMail-DTE: 120315 X-CudaMail-Originating-IP: 217.70.183.196 Date: Wed, 2 Dec 2015 23:53:43 -0800 X-ASG-Orig-Subj: [##CM-V2-1202000770##][PATCHv2 07/20] compat: Backport ip_skb_dst_mtu(). Message-Id: <1449129236-5038-8-git-send-email-joe@ovn.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1449129236-5038-1-git-send-email-joe@ovn.org> References: <1449129236-5038-1-git-send-email-joe@ovn.org> X-Barracuda-Connect: UNKNOWN[192.168.14.1] X-Barracuda-Start-Time: 1449129270 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-ASG-Whitelist: Header =?UTF-8?B?eFwtY3VkYW1haWxcLXdoaXRlbGlzdFwtdG8=?= X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 Subject: [ovs-dev] [PATCHv2 07/20] compat: Backport ip_skb_dst_mtu(). X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" From: Joe Stringer From upstream f87c10a8aa1e ("ipv4: introduce ip_dst_mtu_maybe_forward and protect forwarding path against pmtu spoofing") Signed-off-by: Joe Stringer --- acinclude.m4 | 1 + datapath/linux/compat/include/net/ip.h | 39 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/acinclude.m4 b/acinclude.m4 index 5aaaa1081262..78da9402b2c0 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -348,6 +348,7 @@ AC_DEFUN([OVS_CHECK_LINUX_COMPAT], [ OVS_GREP_IFELSE([$KSRC/include/net/ip.h], [inet_get_local_port_range.*net], [OVS_DEFINE([HAVE_INET_GET_LOCAL_PORT_RANGE_USING_NET])]) OVS_GREP_IFELSE([$KSRC/include/net/ip.h], [ip_is_fragment]) + OVS_GREP_IFELSE([$KSRC/include/net/ip.h], [ip_skb_dst_mtu]) OVS_GREP_IFELSE([$KSRC/include/net/dst_metadata.h], [metadata_dst]) OVS_GREP_IFELSE([$KSRC/include/linux/net.h], [sock_create_kern.*net], diff --git a/datapath/linux/compat/include/net/ip.h b/datapath/linux/compat/include/net/ip.h index a9401a7f0e7c..ead6e2904ba7 100644 --- a/datapath/linux/compat/include/net/ip.h +++ b/datapath/linux/compat/include/net/ip.h @@ -22,4 +22,43 @@ static inline void rpl_inet_get_local_port_range(struct net *net, int *low, #endif +/* IPv4 datagram length is stored into 16bit field (tot_len) */ +#ifndef IP_MAX_MTU +#define IP_MAX_MTU 0xFFFFU +#endif + +#ifndef HAVE_IP_SKB_DST_MTU +static inline bool rpl_ip_sk_use_pmtu(const struct sock *sk) +{ + return inet_sk(sk)->pmtudisc < IP_PMTUDISC_PROBE; +} +#define ip_sk_use_pmtu rpl_ip_sk_use_pmtu + +static inline unsigned int ip_dst_mtu_maybe_forward(const struct dst_entry *dst, + bool forwarding) +{ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0) + struct net *net = dev_net(dst->dev); + + if (net->ipv4.sysctl_ip_fwd_use_pmtu || + dst_metric_locked(dst, RTAX_MTU) || + !forwarding) + return dst_mtu(dst); +#endif + + return min(dst->dev->mtu, IP_MAX_MTU); +} + +static inline unsigned int rpl_ip_skb_dst_mtu(const struct sk_buff *skb) +{ + if (!skb->sk || ip_sk_use_pmtu(skb->sk)) { + bool forwarding = IPCB(skb)->flags & IPSKB_FORWARDED; + return ip_dst_mtu_maybe_forward(skb_dst(skb), forwarding); + } else { + return min(skb_dst(skb)->dev->mtu, IP_MAX_MTU); + } +} +#define ip_skb_dst_mtu rpl_ip_skb_dst_mtu +#endif /* HAVE_IP_SKB_DST_MTU */ + #endif