From patchwork Sat Apr 27 13:14:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Suryaputra X-Patchwork-Id: 1091984 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="b/Pnuvv0"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44rrzq35zbz9sN6 for ; Sat, 27 Apr 2019 23:16:55 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726628AbfD0NQx (ORCPT ); Sat, 27 Apr 2019 09:16:53 -0400 Received: from mail-yw1-f65.google.com ([209.85.161.65]:34233 "EHLO mail-yw1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725942AbfD0NQw (ORCPT ); Sat, 27 Apr 2019 09:16:52 -0400 Received: by mail-yw1-f65.google.com with SMTP id u14so2171627ywe.1 for ; Sat, 27 Apr 2019 06:16:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=Q8H4EwneQ8k+4D99FngoBRJVESCwOQ3UfUerhaCUhLA=; b=b/Pnuvv092gsZrhuwAgikO03fXvFqfIxTILlncOALweRPXSug7+ZFuyAmVGK055RwV 4TpfycpsvA2dlRmlRpvoxReq+kc13u19uCMqyAyK5YrXYZpkucaynCETWUugLYqZ8z2U 1Hio+C75cT+t552y0hTbOYrN6HB/bL9tOElT4yU26h+CpuqfD8w4AKVTixUMKbR29mWw R1luhCbDmTJCMbEajLHLKM4GQIXiDqZXe+PG2Sgm2AJgWwCmzDMPtFEARxDIAMygsI6E ytlLFAwk7uaesoi2g0UwhyqbWp5SVnG1TusYDijL2xRMQnuxT+kvvVmHo52V/0HdCZeL lsEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Q8H4EwneQ8k+4D99FngoBRJVESCwOQ3UfUerhaCUhLA=; b=OsvfvdpcixggoN+yMQEeCrl4BBrqIHH7LIlmRKZKBygz8HJk0etnnee7PYWsj8z+nP TQk4SV7dmMo959t8CZ1zQwqMdYIsIZ0axCsti+ycBK6gFsVq/gcSeuu03BBRjWCVARVH FgJ39XDftNkHGtTvvOuLfa5ov7yuScSGSCVsRZBgl3WSc6iHunsGarFsjWs0nNVZojPZ dMPHPFHxEZnIb58YZv+J7AVBwXJJiZ9cktoFl70pydln7lcoRVTS9tP6ATZWWgf6QGXR J1UH351/M9Y8KKttLod44cXQ+72wsW422oc3W8Cs6nQFE4Acop0kxmjYUgcy/+y6DlO+ 1iKw== X-Gm-Message-State: APjAAAWbf6qZHCpqBjx0HI3sSlGqSBPisPEWyrQ3C0pTLYN2OIA5Ne/T I95tjdom3k/V8cxNbU/7LPZ+oRs= X-Google-Smtp-Source: APXvYqxObKibYXObovlb2X8t7R99fBGfIxW6wqAvc0ft5YP90FZmt7iOpD9jQGdgbf2/n47HxqzQ7Q== X-Received: by 2002:a81:140a:: with SMTP id 10mr42910142ywu.340.1556371011418; Sat, 27 Apr 2019 06:16:51 -0700 (PDT) Received: from localhost.localdomain (99-149-127-125.lightspeed.rlghnc.sbcglobal.net. [99.149.127.125]) by smtp.gmail.com with ESMTPSA id g133sm11342019ywg.84.2019.04.27.06.16.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 27 Apr 2019 06:16:50 -0700 (PDT) From: Stephen Suryaputra To: netdev@vger.kernel.org Cc: Stephen Suryaputra Subject: [PATCH net, v3] vrf: Use orig netdev to count Ip6InNoRoutes and a fresh route lookup when sending dest unreach Date: Sat, 27 Apr 2019 09:14:33 -0400 Message-Id: <20190427131433.4082-1-ssuryaextr@gmail.com> X-Mailer: git-send-email 2.17.1 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org When there is no route to an IPv6 dest addr, skb_dst(skb) points to loopback dev in the case of that the IP6CB(skb)->iif is enslaved to a vrf. This causes Ip6InNoRoutes to be incremented on the loopback dev. This also causes the lookup to fail on icmpv6_send() and the dest unreachable to not sent and Ip6OutNoRoutes gets incremented on the loopback dev. To reproduce: * Gateway configuration: ip link add dev vrf_258 type vrf table 258 ip link set dev enp0s9 master vrf_258 ip addr add 66:1/64 dev enp0s9 ip -6 route add unreachable default metric 8192 table 258 sysctl -w net.ipv6.conf.all.forwarding=1 sysctl -w net.ipv6.conf.enp0s9.forwarding=1 * Sender configuration: ip addr add 66::2/64 dev enp0s9 ip -6 route add default via 66::1 and ping 67::1 for example from the sender. Fix this by counting on the original netdev and reset the skb dst to force a fresh lookup. v2: Fix typo of destination address in the repro steps. v3: Simplify the loopback check (per David Ahern) and use reverse Christmas tree format (per David Miller). Signed-off-by: Stephen Suryaputra Reviewed-by: David Ahern Tested-by: David Ahern Reviewed-by: David Ahern --- net/ipv6/route.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 7178e32eb15d..b4899f0de0d0 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -3668,23 +3668,34 @@ int ipv6_route_ioctl(struct net *net, unsigned int cmd, void __user *arg) static int ip6_pkt_drop(struct sk_buff *skb, u8 code, int ipstats_mib_noroutes) { - int type; struct dst_entry *dst = skb_dst(skb); + struct net *net = dev_net(dst->dev); + struct inet6_dev *idev; + int type; + + if (netif_is_l3_master(skb->dev) && + dst->dev == net->loopback_dev) + idev = __in6_dev_get_safely(dev_get_by_index_rcu(net, IP6CB(skb)->iif)); + else + idev = ip6_dst_idev(dst); + switch (ipstats_mib_noroutes) { case IPSTATS_MIB_INNOROUTES: type = ipv6_addr_type(&ipv6_hdr(skb)->daddr); if (type == IPV6_ADDR_ANY) { - IP6_INC_STATS(dev_net(dst->dev), - __in6_dev_get_safely(skb->dev), - IPSTATS_MIB_INADDRERRORS); + IP6_INC_STATS(net, idev, IPSTATS_MIB_INADDRERRORS); break; } /* FALLTHROUGH */ case IPSTATS_MIB_OUTNOROUTES: - IP6_INC_STATS(dev_net(dst->dev), ip6_dst_idev(dst), - ipstats_mib_noroutes); + IP6_INC_STATS(net, idev, ipstats_mib_noroutes); break; } + + /* Start over by dropping the dst for l3mdev case */ + if (netif_is_l3_master(skb->dev)) + skb_dst_drop(skb); + icmpv6_send(skb, ICMPV6_DEST_UNREACH, code, 0); kfree_skb(skb); return 0;