Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp1971789ima; Thu, 25 Oct 2018 07:46:01 -0700 (PDT) X-Google-Smtp-Source: AJdET5eCF5+kn2yqYilUceY8DkOcKoR/wUwY1dzakxypdr/1YrrDUyaMqckm6k85ND7LLoKWcVkb X-Received: by 2002:a62:9f11:: with SMTP id g17-v6mr1843834pfe.144.1540478761529; Thu, 25 Oct 2018 07:46:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540478761; cv=none; d=google.com; s=arc-20160816; b=l7jW1ksbe9ilL0dnViewdVk54q8z8+aIU2w0+r3hz/GmbRQutUPFFXeRXivRVRgzbB EvxYD3/dhz6IXE3NmfFc0LjqZZjOYL2tNBTZeqtHwERPRE3kYaexHUvFW5GDy3iZ62qG 2WkBXp7nYdGUNewogfD+bmTQmxakUcF8mBNm2r5IQKRsc7lAKBxsP7pYcmz8kITYFp38 ++VXVzcpB3a6QHYmB4d4khH470O3zhoGMcXEXld0RvnC/WnOKRnTxjfXrpfINoBEFQAL yP9oOEh2fYS7CGMB1nZj+BsHsYwIcRBhqBG91QANMlDS3lk8afsFL34HUbMhBsd0WUF5 cayA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=vUNZuutASX/U1ZdwM9TuBksekqGjqmz4ATn6+OQroU4=; b=WyKj4KVmCu26J9gvbba5vEgi0vm+THM46Qq5JZXXHkH/U+g8gyojshBus4oi3CRjYu Afdfwmk6fh/4OKtdLcoRluIBhMiZJVClRSzgj/bfrp4zpWSayc9s6CqYIPixtJUP2U8f 1/AhcWxGwYxNJstkgBx72H2iNHfv+Pvjo+1sPpdeZhJiUZ+av+kAWxgWu7Dwhe3RZA9W 6JDdNtpjvKJ9OvrctNxtpru8fKEJkBTYuqkaf6SZgk1uoAARepuYhCql+2fk2TSTfwiT jGa6rvpkbM1ds9ogS57vOsZ0G2psa1p/s2GhR1YQAUAmBw+EFHA8oqy6BE6CvQaRNFuv cbCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=K2DkaAFE; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c191-v6si5654044pga.402.2018.10.25.07.45.42; Thu, 25 Oct 2018 07:46:01 -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; dkim=pass header.i=@kernel.org header.s=default header.b=K2DkaAFE; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728637AbeJYWrn (ORCPT + 99 others); Thu, 25 Oct 2018 18:47:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:55802 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728375AbeJYWrl (ORCPT ); Thu, 25 Oct 2018 18:47:41 -0400 Received: from sasha-vm.mshome.net (unknown [167.98.65.38]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EDE3720868; Thu, 25 Oct 2018 14:14:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1540476884; bh=Pxy9XmggyhrI5moCWecJTAZe0/NzbrCaDdTohbZ686w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K2DkaAFEDDwY4Pw0821PrMC/g3sxmh3MD4LGfj8vmPHZGjjGJDi7vYOcHZDlydVWi xyHyP6GVgV/5SDzSFWyyv6VDRqik4+GWiPwBKvXA3UtVx6CYsVgBqk9a/dO5W9o0kD 6nmrduuJkZkEna42T3EDFdOnxvhgo39tTxAbBmF0= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Xin Long , "David S . Miller" , Sasha Levin Subject: [PATCH AUTOSEL 4.9 12/98] ipv6: set rt6i_protocol properly in the route when it is installed Date: Thu, 25 Oct 2018 10:12:57 -0400 Message-Id: <20181025141423.213774-12-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025141423.213774-1-sashal@kernel.org> References: <20181025141423.213774-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xin Long [ Upstream commit b91d532928dff2141ea9c107c3e73104d9843767 ] After commit c2ed1880fd61 ("net: ipv6: check route protocol when deleting routes"), ipv6 route checks rt protocol when trying to remove a rt entry. It introduced a side effect causing 'ip -6 route flush cache' not to work well. When flushing caches with iproute, all route caches get dumped from kernel then removed one by one by sending DELROUTE requests to kernel for each cache. The thing is iproute sends the request with the cache whose proto is set with RTPROT_REDIRECT by rt6_fill_node() when kernel dumps it. But in kernel the rt_cache protocol is still 0, which causes the cache not to be matched and removed. So the real reason is rt6i_protocol in the route is not set when it is allocated. As David Ahern's suggestion, this patch is to set rt6i_protocol properly in the route when it is installed and remove the codes setting rtm_protocol according to rt6i_flags in rt6_fill_node. This is also an improvement to keep rt6i_protocol consistent with rtm_protocol. Fixes: c2ed1880fd61 ("net: ipv6: check route protocol when deleting routes") Reported-by: Jianlin Shi Suggested-by: David Ahern Signed-off-by: Xin Long Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/ipv6/route.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 70fa31e37360..4cc12eeca7ab 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -2289,6 +2289,7 @@ static void rt6_do_redirect(struct dst_entry *dst, struct sock *sk, struct sk_bu if (on_link) nrt->rt6i_flags &= ~RTF_GATEWAY; + nrt->rt6i_protocol = RTPROT_REDIRECT; nrt->rt6i_gateway = *(struct in6_addr *)neigh->primary_key; if (ip6_ins_rt(nrt)) @@ -2393,6 +2394,7 @@ static struct rt6_info *rt6_add_route_info(struct net *net, .fc_dst_len = prefixlen, .fc_flags = RTF_GATEWAY | RTF_ADDRCONF | RTF_ROUTEINFO | RTF_UP | RTF_PREF(pref), + .fc_protocol = RTPROT_RA, .fc_nlinfo.portid = 0, .fc_nlinfo.nlh = NULL, .fc_nlinfo.nl_net = net, @@ -2445,6 +2447,7 @@ struct rt6_info *rt6_add_dflt_router(const struct in6_addr *gwaddr, .fc_ifindex = dev->ifindex, .fc_flags = RTF_GATEWAY | RTF_ADDRCONF | RTF_DEFAULT | RTF_UP | RTF_EXPIRES | RTF_PREF(pref), + .fc_protocol = RTPROT_RA, .fc_nlinfo.portid = 0, .fc_nlinfo.nlh = NULL, .fc_nlinfo.nl_net = dev_net(dev), @@ -3241,14 +3244,6 @@ static int rt6_fill_node(struct net *net, } rtm->rtm_scope = RT_SCOPE_UNIVERSE; rtm->rtm_protocol = rt->rt6i_protocol; - if (rt->rt6i_flags & RTF_DYNAMIC) - rtm->rtm_protocol = RTPROT_REDIRECT; - else if (rt->rt6i_flags & RTF_ADDRCONF) { - if (rt->rt6i_flags & (RTF_DEFAULT | RTF_ROUTEINFO)) - rtm->rtm_protocol = RTPROT_RA; - else - rtm->rtm_protocol = RTPROT_KERNEL; - } if (rt->rt6i_flags & RTF_CACHE) rtm->rtm_flags |= RTM_F_CLONED; -- 2.17.1