Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp906687pxp; Wed, 16 Mar 2022 20:52:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxScnbw3je1B0ESEj3v0fvpR1ApO2hO03AJjWGee5oifNLvxzfPwJep6fmvRI4oZcv6Rh9+ X-Received: by 2002:a17:90b:1e47:b0:1bf:6d79:b1fd with SMTP id pi7-20020a17090b1e4700b001bf6d79b1fdmr13791229pjb.49.1647489139012; Wed, 16 Mar 2022 20:52:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647489139; cv=none; d=google.com; s=arc-20160816; b=DHIM4jagdcSqg62kgGJCw6rsZBMr5p+i8mvUCwL3e4iKP63P+OvKKRXgLsnRYCNpTE TcG9r4bNZP3bHAMhTSEV887kXmJzsFtO2CapCvcuuuKejtfPaNEDkkhaQWbEmDFfPfZC 8hDWTBNp7flCt7m1IToN1rHj15g27bGTYerWhSp8oQlzvyZ5nKTdyCRDoYL4yyvA9qpx cQk/6yLsI9KKf5yernSKOP2fZ8jSVi2O3aq89rCEIEhxHDNcDWLeVYHiVjMHvsq+eskZ LfueUSQHVglRC1U8kyT93yTDWYlYblpgRj41j/0uC86YTZcCstyK5hWY2WqhY0RUu2zs 0szA== 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=1QC1mCYRnwXtX/5xMNbrNNS7JnJW9wp8vy/lWeSrr8w=; b=eyHbo+Rll/gXd3VT6AoZAJcO0tisgcBjvEaDloJPy9OZscsMdakG5m+4zCRVZFKJkq C8aMVHbsG9hx2t3Szc1VP2lwcFMqTMYMhiadGkVSoYxnTgUVY7dO3NlYuaeE2ThSqvAr TFoJdAadt7Je4wMaxw4ykhsVpmNC1ekrowxg/MhoNJ0g3w7WsVIFXPAzXMM7GRFf2KQD V3D68SNcsDrbG6OwqgKf73OtWvnHDDPd7lzXKuQIkIEYLX/vZhTKEHy4PCv1dw0lnsvC 8oFOIvhSw/kHL9sYdCGIbDC7sAStsR0m4y3gZwFib77Q7GdsMJS4XniQSf0yBxsl/9GD 82yA== 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:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id k3-20020a63ba03000000b003816043ef08si1013946pgf.253.2022.03.16.20.52.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 20:52:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A707A7DA87; Wed, 16 Mar 2022 20:40:24 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354661AbiCPIxD (ORCPT + 99 others); Wed, 16 Mar 2022 04:53:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233129AbiCPIxC (ORCPT ); Wed, 16 Mar 2022 04:53:02 -0400 Received: from chinatelecom.cn (prt-mail.chinatelecom.cn [42.123.76.222]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D010F64BF4; Wed, 16 Mar 2022 01:51:48 -0700 (PDT) HMM_SOURCE_IP: 172.18.0.188:37546.597671551 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-202.80.192.39 (unknown [172.18.0.188]) by chinatelecom.cn (HERMES) with SMTP id 18EFC2800ED; Wed, 16 Mar 2022 16:51:42 +0800 (CST) X-189-SAVE-TO-SEND: +sunshouxin@chinatelecom.cn Received: from ([172.18.0.188]) by app0023 with ESMTP id aad3f8a1d9eb46ce9f50b380442d6553 for j.vosburgh@gmail.com; Wed, 16 Mar 2022 16:51:47 CST X-Transaction-ID: aad3f8a1d9eb46ce9f50b380442d6553 X-Real-From: sunshouxin@chinatelecom.cn X-Receive-IP: 172.18.0.188 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, 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 v3 1/4] net:ipv6:Refactor ndisc_send_na to support sending na by slave directly Date: Wed, 16 Mar 2022 04:49:55 -0400 Message-Id: <20220316084958.21169-2-sunshouxin@chinatelecom.cn> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220316084958.21169-1-sunshouxin@chinatelecom.cn> References: <20220316084958.21169-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, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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. Suggested-by: Hu Yadi Signed-off-by: Sun Shouxin --- changelog: v1-->v2: remove ndisc_bond_send_na and refactor ndisc_send_na v2-->v3: don't export ndisc_send_na --- include/net/ipv6_stubs.h | 3 +- include/net/ndisc.h | 9 +++++- net/ipv6/ndisc.c | 64 +++++++++++++++++++++++++++++----------- 3 files changed, 56 insertions(+), 20 deletions(-) diff --git a/include/net/ipv6_stubs.h b/include/net/ipv6_stubs.h index 45e0339be6fa..2b64ea6590b6 100644 --- a/include/net/ipv6_stubs.h +++ b/include/net/ipv6_stubs.h @@ -56,7 +56,8 @@ struct ipv6_stub { void (*udpv6_encap_enable)(void); void (*ndisc_send_na)(struct net_device *dev, const struct in6_addr *daddr, const struct in6_addr *solicited_addr, - bool router, bool solicited, bool override, bool inc_opt); + bool router, bool solicited, bool override, + bool inc_opt, void *data); #if IS_ENABLED(CONFIG_XFRM) void (*xfrm6_local_rxpmtu)(struct sk_buff *skb, u32 mtu); int (*xfrm6_udp_encap_rcv)(struct sock *sk, struct sk_buff *skb); diff --git a/include/net/ndisc.h b/include/net/ndisc.h index da7eec8669ec..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]; @@ -460,7 +466,8 @@ void ndisc_send_rs(struct net_device *dev, const struct in6_addr *saddr, const struct in6_addr *daddr); void ndisc_send_na(struct net_device *dev, const struct in6_addr *daddr, const struct in6_addr *solicited_addr, - bool router, bool solicited, bool override, bool inc_opt); + bool router, bool solicited, bool override, bool inc_opt, + void *data); void ndisc_send_redirect(struct sk_buff *skb, const struct in6_addr *target); diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index fcb288b0ae13..47875aab86e5 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -518,29 +518,37 @@ EXPORT_SYMBOL(ndisc_send_skb); void ndisc_send_na(struct net_device *dev, const struct in6_addr *daddr, const struct in6_addr *solicited_addr, - bool router, bool solicited, bool override, bool inc_opt) + bool router, bool solicited, bool override, bool inc_opt, + void *data) { struct sk_buff *skb; struct in6_addr tmpaddr; 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) @@ -568,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) @@ -591,7 +619,7 @@ static void ndisc_send_unsol_na(struct net_device *dev) ndisc_send_na(dev, &in6addr_linklocal_allnodes, &ifa->addr, /*router=*/ !!idev->cnf.forwarding, /*solicited=*/ false, /*override=*/ true, - /*inc_opt=*/ true); + /*inc_opt=*/ true, NULL); } read_unlock_bh(&idev->lock); @@ -932,7 +960,7 @@ static void ndisc_recv_ns(struct sk_buff *skb) if (dad) { ndisc_send_na(dev, &in6addr_linklocal_allnodes, &msg->target, - !!is_router, false, (ifp != NULL), true); + !!is_router, false, ifp, true, NULL); goto out; } @@ -954,7 +982,7 @@ static void ndisc_recv_ns(struct sk_buff *skb) NDISC_NEIGHBOUR_SOLICITATION, &ndopts); if (neigh || !dev->header_ops) { ndisc_send_na(dev, saddr, &msg->target, !!is_router, - true, (ifp != NULL && inc), inc); + true, (ifp && inc), inc, NULL); if (neigh) neigh_release(neigh); } -- 2.27.0