Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1797655pxb; Fri, 25 Mar 2022 05:59:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyALG3jisfD+HilIWhHRXUgPhxYi3sdCxb4ITIXOcB46QSkJAcr2BpheVmM2GMu6dlDKf3y X-Received: by 2002:a17:902:e202:b0:154:35cf:a029 with SMTP id u2-20020a170902e20200b0015435cfa029mr11581635plb.70.1648213144417; Fri, 25 Mar 2022 05:59:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648213144; cv=none; d=google.com; s=arc-20160816; b=hJFJ2KO5qfMKCmYZ51KvDPpmcyRflk05E9XcrtPwSRx2LAVXXcCXEgZqJb/Uzs+R9h LO0/MmGXHDXCwcaOrWGREOaba+zlXrj4geanDSTFywfveOttTzo25NHM6BfYGsYUF/0m BBA/bNwKGN3Pr9ZIgb8YfcUpkmBf/0arADwPmjYaQwx5lumkC+3fQKYHlgVUgJ3ugLq7 OwdLVAVMVf8VphDWi19zT8OiJ6R8Nh/qzW87vmeMD02x/0vyjCYGKdKUVJ+9D1HW+ZWu rYdm3dkSJlZNPPXmtI9oZylaNiLMRzAmuEuxvUpC2vasKfeRKgmnIK3dA3/huDmm2vIu spdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :hmm_source_type:hmm_attache_num:hmm_source_ip; bh=Bt2e59MoVDuGAX9sO2qXXVtiVhaj5emJcF0YVA9GUF4=; b=qis9Scf9ISlSgogT8bywpAxXaYvAMox9PXlK9oylTf6+PnDEommjwzSMUC2LwwhUt1 JaROPUu3W4YQ0tPN0squ4cmvEiPzz6eEBdmS5mmd9aUfCo/NFjnopZQQZrvXOErFr7nJ uCTX3SohEXnecRXleV7bdx13QWLdAahBUMhq19CDmPAaTc06yTGutEDI1cKCi58vNJnw Fcg71K7SCLMwaiNzHUplmPiHIQ6e1nqUKQidgyJ2ubm81g5m3RJIb8yS6Noq0JKmAWP/ /jxiRSwltFxoD6+Di0RsBTYfviGrO7w0nIk6JZPfP/UqgzsP+paWoTpdoSRGeGzpwjeU mF8g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x193-20020a6286ca000000b004fa3a8e007fsi2310623pfd.310.2022.03.25.05.58.49; Fri, 25 Mar 2022 05:59:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242505AbiCWMMJ (ORCPT + 99 others); Wed, 23 Mar 2022 08:12:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242989AbiCWMME (ORCPT ); Wed, 23 Mar 2022 08:12:04 -0400 Received: from chinatelecom.cn (prt-mail.chinatelecom.cn [42.123.76.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0EE043E5E1; Wed, 23 Mar 2022 05:10:33 -0700 (PDT) HMM_SOURCE_IP: 172.18.0.48:39292.1744386625 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-202.80.192.38 (unknown [172.18.0.48]) by chinatelecom.cn (HERMES) with SMTP id 125AB280099; Wed, 23 Mar 2022 20:10:28 +0800 (CST) X-189-SAVE-TO-SEND: +sunshouxin@chinatelecom.cn Received: from ([172.18.0.48]) by app0024 with ESMTP id ccaaf357fcfc45afb99e515e79688f1d for j.vosburgh@gmail.com; Wed, 23 Mar 2022 20:10:32 CST X-Transaction-ID: ccaaf357fcfc45afb99e515e79688f1d X-Real-From: sunshouxin@chinatelecom.cn X-Receive-IP: 172.18.0.48 X-MEDUSA-Status: 0 Sender: sunshouxin@chinatelecom.cn From: Sun Shouxin To: j.vosburgh@gmail.com, vfalico@gmail.com, andy@greyhouse.net, davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, yoshfuji@linux-ipv6.org, dsahern@kernel.org, oliver@neukum.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, huyd12@chinatelecom.cn, sunshouxin@chinatelecom.cn Subject: [PATCH v6 2/4] net:ipv6:Refactor ndisc_send_na to support sending na by slave directly Date: Wed, 23 Mar 2022 08:09:04 -0400 Message-Id: <20220323120906.42692-3-sunshouxin@chinatelecom.cn> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220323120906.42692-1-sunshouxin@chinatelecom.cn> References: <20220323120906.42692-1-sunshouxin@chinatelecom.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Refactor ndisc_send_na to support sending na by slave directly. Signed-off-by: Sun Shouxin --- include/net/ndisc.h | 6 +++++ net/ipv6/ndisc.c | 55 +++++++++++++++++++++++++++++++++------------ 2 files changed, 47 insertions(+), 14 deletions(-) diff --git a/include/net/ndisc.h b/include/net/ndisc.h index 24cf6e92fecc..e71702a44a3d 100644 --- a/include/net/ndisc.h +++ b/include/net/ndisc.h @@ -107,6 +107,12 @@ struct nd_opt_hdr { __u8 nd_opt_len; } __packed; +struct nd_sendinfo { + __u16 vlanid; + void *mac_dst; + const void *mac_src; +}; + /* ND options */ struct ndisc_options { struct nd_opt_hdr *nd_opt_array[__ND_OPT_ARRAY_MAX]; diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index f7bd7082abb4..47875aab86e5 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -526,22 +526,29 @@ void ndisc_send_na(struct net_device *dev, const struct in6_addr *daddr, struct inet6_ifaddr *ifp; const struct in6_addr *src_addr; struct nd_msg *msg; + struct nd_sendinfo *sendinfo = data; + struct net *net = dev_net(dev); + struct sock *sk = net->ipv6.ndisc_sk; int optlen = 0; - /* for anycast or proxy, solicited_addr != src_addr */ - ifp = ipv6_get_ifaddr(dev_net(dev), solicited_addr, dev, 1); - if (ifp) { - src_addr = solicited_addr; - if (ifp->flags & IFA_F_OPTIMISTIC) - override = false; - inc_opt |= ifp->idev->cnf.force_tllao; - in6_ifa_put(ifp); + if (!sendinfo) { + /* for anycast or proxy, solicited_addr != src_addr */ + ifp = ipv6_get_ifaddr(dev_net(dev), solicited_addr, dev, 1); + if (ifp) { + src_addr = solicited_addr; + if (ifp->flags & IFA_F_OPTIMISTIC) + override = false; + inc_opt |= ifp->idev->cnf.force_tllao; + in6_ifa_put(ifp); + } else { + if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr, + inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs, + &tmpaddr)) + return; + src_addr = &tmpaddr; + } } else { - if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr, - inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs, - &tmpaddr)) - return; - src_addr = &tmpaddr; + src_addr = solicited_addr; } if (!dev->addr_len) @@ -569,8 +576,28 @@ void ndisc_send_na(struct net_device *dev, const struct in6_addr *daddr, ndisc_fill_addr_option(skb, ND_OPT_TARGET_LL_ADDR, dev->dev_addr, NDISC_NEIGHBOUR_ADVERTISEMENT); + if (!sendinfo) { + ndisc_send_skb(skb, daddr, src_addr); + } else { + if (sendinfo->vlanid) + __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), + sendinfo->vlanid); + + msg->icmph.icmp6_cksum = csum_ipv6_magic(src_addr, daddr, skb->len, + IPPROTO_ICMPV6, + csum_partial(&msg->icmph, + skb->len, 0)); - ndisc_send_skb(skb, daddr, src_addr); + ip6_nd_hdr(skb, src_addr, daddr, inet6_sk(sk)->hop_limit, skb->len); + + skb->protocol = htons(ETH_P_IPV6); + skb->dev = dev; + if (dev_hard_header(skb, dev, ETH_P_IPV6, sendinfo->mac_dst, + sendinfo->mac_src, skb->len) < 0) + return; + + dev_queue_xmit(skb); + } } static void ndisc_send_unsol_na(struct net_device *dev) -- 2.27.0