Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4169437ybi; Mon, 29 Jul 2019 20:47:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqzlT76Y7/eH+RcZX4+4zpL9IhvKowyu8Qr6C49IUCwNGoItDftyJnYG7Q3TMiOHGm8u9qAv X-Received: by 2002:a65:46cf:: with SMTP id n15mr13203408pgr.267.1564458421477; Mon, 29 Jul 2019 20:47:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564458421; cv=none; d=google.com; s=arc-20160816; b=IigGYD7y9r11cMjoXbx/eyIzb9iitTEbRgZAF5Ssd2Y3PRZ+XdEqBysBQN4Sew4oJj z0A9qj3a6Bj0Ytm2AcALsqWjPPK5s7/n1EmQuBTnvQinwDmCjhpDZQ9lLKEUeDPaNM6V icz1XKipBLHEbo+RdWVJ5mJSZQ6N/UpJpWhlNUe3nn/1DGT6miFDKPnTAUoy1+lbQo8V PfP0rAkW6ZdNQNJcxupP4UEOgqX6aM2md5i/t24gaHIyWingCj/4elw/LJKgBC8JPzZh 8F5v1ybOWMaLlIw6e+s7EbBstZ7OZrf3/20MdjvhnCKq9u2qwrZTWhdr3JKuvpK8D86H SgEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=SDS/oRbp3ndQD48erCJR8LYHts1U4WFu/TkobcIYFLU=; b=jXbPKAWPchZmte8dhcdn4ZlZQsnzXeYNuyiXEaDOBraH5ljSf7Py5F5hlyLka/okN3 ycI57cNVrOMuYaDocyj9rtaIq3lL9Zb0n+/Ogj05ghnw9quiVxZx1/orvAETUlyQvYo2 WPqdprZnWAyLISbrlWoGqSQzXPIo1XFmTekemLkZe0Hww1PjFFn1oSMry4c7gb8kY078 DFLOVoj1It+xTBTDDIgVyMxHzSBesiBLM3r2qTkPLBkL3GWnLrPdgZpXN9I2mYmIlXjV EBNGEYY3PrnXZxjOC8gz7VuL+PjbM87t8xj2nRWklXfSJcP38V7nsyKp0blXm9XO0sPG Zniw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=K7Px++Gy; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 97si28055875ple.161.2019.07.29.20.46.46; Mon, 29 Jul 2019 20:47: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=@gmail.com header.s=20161025 header.b=K7Px++Gy; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729783AbfG3AXd (ORCPT + 99 others); Mon, 29 Jul 2019 20:23:33 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:45794 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727723AbfG3AXd (ORCPT ); Mon, 29 Jul 2019 20:23:33 -0400 Received: by mail-pg1-f194.google.com with SMTP id o13so29057375pgp.12; Mon, 29 Jul 2019 17:23:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=SDS/oRbp3ndQD48erCJR8LYHts1U4WFu/TkobcIYFLU=; b=K7Px++GyUB3IKchznHVKlpORjcHhnjcdO6Lw067w6ofIzdRXflKRgfr3ZFCzzGfrLp xXxVa9do5SNUJCaGd5yUkgiUOXV45J8S6jDKMNVw8AXl0TMfRzsgP5+eEKITgCezoBKn DGrDJETdxGJEUcMwZL4HgYXgSX9/zspKvJ66ODuUYM5SCxwKhfPMQXupCrw9CKehZdWI uxlY9PrDQR9tc5cb63vDo23DQ+1Cf0KseuXbMjfHC5VomKrUXiJglEzfZ6sBGDNLc5Gg 8f2lFSMjnks1nFi4Y2rmokYXB9qpyPPgEDKaI0VSN2BESinSKo8N0Jv3z1TfkGjz/k80 PiFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=SDS/oRbp3ndQD48erCJR8LYHts1U4WFu/TkobcIYFLU=; b=uhix5wd26pemwhdrlBMQihdLBpwuIvt04TlaStN9seftHbP2S4vHR03RjqJaWzOnN9 OXQRpXU9DMmxyEgcNk3HwC+mjP5LLxzzwH+uiwIziesQzbTmn8eLKOsWR9EzuLZmgeRf mfU2uQ81EXTu4cN4nD/yLsDMfbL/sGXEuCGMBWMx5Fz3v3YAoYxhSPdLkT6/62/L08pr aug4kZMp780VUr2qANx3SgL0vb5oTdK4sntmw0i5yFPb2NjXnTvZ3BwGQTdfCIpkDPhf lwn+e4Rqg/TWQloFyHPwBomRuPe+zyS/e7PqKY6Vn0TNRzWtToGNtBv7dAx/o2Yg9bGC z/pQ== X-Gm-Message-State: APjAAAWJz03/0ybQM9Gyaub4BMV9XYni4lRTv4v8TOAr1Kg3cYifS3pP O1ULw4mABEIfCDZLtTKuVJhULKvO X-Received: by 2002:a17:90a:36a7:: with SMTP id t36mr112276735pjb.34.1564446211820; Mon, 29 Jul 2019 17:23:31 -0700 (PDT) Received: from [172.27.227.219] ([216.129.126.118]) by smtp.googlemail.com with ESMTPSA id v126sm251489pgb.23.2019.07.29.17.23.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Jul 2019 17:23:30 -0700 (PDT) Subject: Re: [PATCH net] net: ipv6: Fix a bug in ndisc_send_ns when netdev only has a global address To: Su Yanjun , davem@davemloft.net, kuznet@ms2.inr.ac.ru, yoshfuji@linux-ipv6.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org References: <1564368591-42301-1-git-send-email-suyj.fnst@cn.fujitsu.com> From: David Ahern Message-ID: <4889aab0-5d79-bbba-1286-91d89c55fc1e@gmail.com> Date: Mon, 29 Jul 2019 18:23:28 -0600 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <1564368591-42301-1-git-send-email-suyj.fnst@cn.fujitsu.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/28/19 8:49 PM, Su Yanjun wrote: > When we send mpls packets and the interface only has a > manual global ipv6 address, then the two hosts cant communicate. > I find that in ndisc_send_ns it only tries to get a ll address. > In my case, the executive path is as below. > ip6_output > ->ip6_finish_output > ->lwtunnel_xmit > ->mpls_xmit > ->neigh_resolve_output > ->neigh_probe > ->ndisc_solicit > ->ndisc_send_ns for the archives, this is not an MPLS problem but a general IPv6 forwarding problem when the egress interface does not have a link local address. > > In RFC4861, 7.2.2 says > "If the source address of the packet prompting the solicitation is the > same as one of the addresses assigned to the outgoing interface, that > address SHOULD be placed in the IP Source Address of the outgoing > solicitation. Otherwise, any one of the addresses assigned to the > interface should be used." > > In this patch we try get a global address if we get ll address failed. > > Signed-off-by: Su Yanjun > --- > include/net/addrconf.h | 4 ++++ > net/ipv6/addrconf.c | 34 ++++++++++++++++++++++++++++++++++ > net/ipv6/ndisc.c | 8 ++++++-- > 3 files changed, 44 insertions(+), 2 deletions(-) > > diff --git a/include/net/addrconf.h b/include/net/addrconf.h > index becdad5..006db8e 100644 > --- a/include/net/addrconf.h > +++ b/include/net/addrconf.h > @@ -107,6 +107,10 @@ int __ipv6_get_lladdr(struct inet6_dev *idev, struct in6_addr *addr, > u32 banned_flags); > int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr, > u32 banned_flags); > +int __ipv6_get_addr(struct inet6_dev *idev, struct in6_addr *addr, > + u32 banned_flags); no reason to export __ipv6_get_addr. I suspect you copied __ipv6_get_lladdr but it has an external (to addrconf.c) user. In this case only ipv6_get_addr needs to be exported. > +int ipv6_get_addr(struct net_device *dev, struct in6_addr *addr, > + u32 banned_flags); > bool inet_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2, > bool match_wildcard); > bool inet_rcv_saddr_any(const struct sock *sk); > diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c > index 521e320..4c0a43f 100644 > --- a/net/ipv6/addrconf.c > +++ b/net/ipv6/addrconf.c > @@ -1870,6 +1870,40 @@ int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr, > return err; > } > > +int __ipv6_get_addr(struct inet6_dev *idev, struct in6_addr *addr, > + u32 banned_flags) > +{ > + struct inet6_ifaddr *ifp; > + int err = -EADDRNOTAVAIL; > + > + list_for_each_entry_reverse(ifp, &idev->addr_list, if_list) { Addresses are ordered by scope. __ipv6_get_lladdr uses list_for_each_entry_reverse because the LLA's are after the globals. Since this is falling back to 'give an address' from this interface, I think you can just use list_for_each_entry. > + if (ifp->scope == 0 && > + !(ifp->flags & banned_flags)) { > + *addr = ifp->addr; > + err = 0; > + break; > + } > + } > + return err; > +} > + > +int ipv6_get_addr(struct net_device *dev, struct in6_addr *addr, > + u32 banned_flags) > +{ > + struct inet6_dev *idev; > + int err = -EADDRNOTAVAIL; > + > + rcu_read_lock(); > + idev = __in6_dev_get(dev); > + if (idev) { > + read_lock_bh(&idev->lock); > + err = __ipv6_get_addr(idev, addr, banned_flags); > + read_unlock_bh(&idev->lock); > + } > + rcu_read_unlock(); > + return err; > +} > + > static int ipv6_count_addresses(const struct inet6_dev *idev) > { > const struct inet6_ifaddr *ifp; > diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c > index 083cc1c..18ac2fb 100644 > --- a/net/ipv6/ndisc.c > +++ b/net/ipv6/ndisc.c > @@ -606,8 +606,12 @@ void ndisc_send_ns(struct net_device *dev, const struct in6_addr *solicit, > > if (!saddr) { And since you are going to do a v2, another nit - define a local banned flags and use it for both lookups just to make it clear. u32 banned_flags = IFA_F_TENTATIVE | IFA_F_OPTIMISTIC; > if (ipv6_get_lladdr(dev, &addr_buf, > - (IFA_F_TENTATIVE|IFA_F_OPTIMISTIC))) > - return; > + (IFA_F_TENTATIVE | IFA_F_OPTIMISTIC))) { > + /* try global address */ > + if (ipv6_get_addr(dev, &addr_buf, > + (IFA_F_TENTATIVE | IFA_F_OPTIMISTIC))) > + return; > + } > saddr = &addr_buf; > } > >