From patchwork Sun Oct 6 06:56:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 13823693 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 11E7A166F1B; Sun, 6 Oct 2024 06:57:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728197847; cv=none; b=gLEP48Yy1t8SC99KfoHd6xbc1AnQD+uCnTqUbHUWa9I82SNJjs+3REcNJnCx4nmYwn4Dk+kQQDreYHISEtZrbyoelZp4E9snWhQjYctowSpo7OD6MzmTiCZN0TJGkAiTIpAbyreaFi3l4GVlq0qyT/VcvciUUfXMD3pgzbZdccc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728197847; c=relaxed/simple; bh=0ZgJtJ+TjXiHcGPlxVYxhjDteuWSfgfQg0cBummbs2g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=b/EsL4XOyT2fc64IfgEWYLAQYgXjMB7KZdG+POyegsu2dCYyh0LIYwDAXumTUny7NTg3Mq+hqkpccY5tGhoa5t6So2VPYJsLykDsodrV3kL9Dia1zOnvvlxTpW5RFa2qqotsl8aFV/64ONFz+Ityq2SepLeX7+yLurudnY9pkFU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=UcbczpAx; arc=none smtp.client-ip=209.85.214.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UcbczpAx" Received: by mail-pl1-f194.google.com with SMTP id d9443c01a7336-20b0b2528d8so39461045ad.2; Sat, 05 Oct 2024 23:57:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728197845; x=1728802645; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zDoqXpsFl8RNldAVAwpbrbVadRrwiVLnsOpDQV2p6FU=; b=UcbczpAxX7h++a1Y++ehiPj4iSPHdadeN3kR+yEW3MgPEoDlZSHAKgmeOZEkDowyfN kNd8agm5o5gEMBBU5pDItdIZfLJ4HYfQCP9gWhBWhNno64BNtRCMs4rnqGlkpXEOBr/P /47V5FvfDZmaFl/ZJoQtTdaDp4W3fXFvHlqC7u0vjH9jbyVQf+MCunHaWu2A1KEXPzvx pW5YyOncGWEW5a8S/Tebr7YvEso4LIRX36BDYJkn3XSpS5BG7IMqaAvO8qkmuLqNo+JR 3Dq2prrQenzGgA2eqRsCwfSD74BXRk1mnRtN1rQZb+R6GaXMdaKi+TU34Dk9Nx9biJqg 6oDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728197845; x=1728802645; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zDoqXpsFl8RNldAVAwpbrbVadRrwiVLnsOpDQV2p6FU=; b=D7XxehJYZr+S9KVn9+Gmx/lqLi1nY4To0n8VbSCHjQzgMZZE77ceUEJBdbmsErJsDw hLZ1iXWr7hBqVty4qcF5HoOZByHSS+drBE0ucm96s7QUdR5GI/M5ZI7iMX/deVIs4sA5 0xiQj/PcnloFCo7jjGH6FraGtvSC5mMnn+jCrnfZire3HOhuha4JHo0zOMUmn7PzyZXw 1QI3tEb+rNgTm442DDAc0aBF9Q93imQgC7wqI9za9x5cXW7GhTqKWt3egyU0pRloCgqT vGCRetdbIepHB5a+1bFHFGLvilZ4/BEDxwvCEBpuhNw8UNKxRRhBTXW0+sUDvOrnt+g2 ycQA== X-Forwarded-Encrypted: i=1; AJvYcCU/JfIvi4LJ9NzGpJWAceXXXWlaQqDaBVMV6ScfzEGWap7lqpZrQ9yHbxcVjaiR3Ld5J9RXA145GN6uJ14=@vger.kernel.org, AJvYcCUfXBMKUENNEUAC86c+/gINbetqKRY46tvcsetsdguLHLXN75hKJ8SZ9wdmNThU+da/wH61ehoP@vger.kernel.org X-Gm-Message-State: AOJu0YyNqvWRj0JrJARE0Jg1l6Cz2wxtjrNtop3ryD6KNtQz5BSfId6D /yYycetei0uLpM0GK73GjCoEy0aE++TEFKFab8eeu5DOP0S+e7Mi X-Google-Smtp-Source: AGHT+IG2aloFo9TpQS72Qo/YAtPA2QYlWX24x6YVnSYqMWNLXgVKxuGK1VO0K+nG7GW82+cG1ehC0A== X-Received: by 2002:a17:902:d4ca:b0:1fa:9c04:946a with SMTP id d9443c01a7336-20bfdf64fcfmr117512235ad.1.1728197845380; Sat, 05 Oct 2024 23:57:25 -0700 (PDT) Received: from localhost.localdomain ([43.129.25.208]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20c138af813sm21749865ad.9.2024.10.05.23.57.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Oct 2024 23:57:24 -0700 (PDT) From: Menglong Dong X-Google-Original-From: Menglong Dong To: idosch@nvidia.com, kuba@kernel.org, aleksander.lobakin@intel.com, horms@kernel.org Cc: davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, dsahern@kernel.org, dongml2@chinatelecom.cn, amcohen@nvidia.com, gnault@redhat.com, bpoirier@nvidia.com, b.galvani@gmail.com, razor@blackwall.org, petrm@nvidia.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next v5 06/12] net: vxlan: make vxlan_snoop() return drop reasons Date: Sun, 6 Oct 2024 14:56:10 +0800 Message-Id: <20241006065616.2563243-7-dongml2@chinatelecom.cn> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241006065616.2563243-1-dongml2@chinatelecom.cn> References: <20241006065616.2563243-1-dongml2@chinatelecom.cn> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Change the return type of vxlan_snoop() from bool to enum skb_drop_reason. In this commit, two drop reasons are introduced: SKB_DROP_REASON_MAC_INVALID_SOURCE SKB_DROP_REASON_VXLAN_ENTRY_EXISTS Signed-off-by: Menglong Dong Reviewed-by: Simon Horman --- v5: - rename SKB_DROP_REASON_VXLAN_INVALID_SMAC to SKB_DROP_REASON_MAC_INVALID_SOURCE in the commit log v4: - rename SKB_DROP_REASON_VXLAN_INVALID_SMAC to SKB_DROP_REASON_MAC_INVALID_SOURCE --- drivers/net/vxlan/vxlan_core.c | 17 +++++++++-------- include/net/dropreason-core.h | 9 +++++++++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c index 34b44755f663..1a81a3957327 100644 --- a/drivers/net/vxlan/vxlan_core.c +++ b/drivers/net/vxlan/vxlan_core.c @@ -1437,9 +1437,10 @@ static int vxlan_fdb_get(struct sk_buff *skb, * and Tunnel endpoint. * Return true if packet is bogus and should be dropped. */ -static bool vxlan_snoop(struct net_device *dev, - union vxlan_addr *src_ip, const u8 *src_mac, - u32 src_ifindex, __be32 vni) +static enum skb_drop_reason vxlan_snoop(struct net_device *dev, + union vxlan_addr *src_ip, + const u8 *src_mac, u32 src_ifindex, + __be32 vni) { struct vxlan_dev *vxlan = netdev_priv(dev); struct vxlan_fdb *f; @@ -1447,7 +1448,7 @@ static bool vxlan_snoop(struct net_device *dev, /* Ignore packets from invalid src-address */ if (!is_valid_ether_addr(src_mac)) - return true; + return SKB_DROP_REASON_MAC_INVALID_SOURCE; #if IS_ENABLED(CONFIG_IPV6) if (src_ip->sa.sa_family == AF_INET6 && @@ -1461,15 +1462,15 @@ static bool vxlan_snoop(struct net_device *dev, if (likely(vxlan_addr_equal(&rdst->remote_ip, src_ip) && rdst->remote_ifindex == ifindex)) - return false; + return SKB_NOT_DROPPED_YET; /* Don't migrate static entries, drop packets */ if (f->state & (NUD_PERMANENT | NUD_NOARP)) - return true; + return SKB_DROP_REASON_VXLAN_ENTRY_EXISTS; /* Don't override an fdb with nexthop with a learnt entry */ if (rcu_access_pointer(f->nh)) - return true; + return SKB_DROP_REASON_VXLAN_ENTRY_EXISTS; if (net_ratelimit()) netdev_info(dev, @@ -1497,7 +1498,7 @@ static bool vxlan_snoop(struct net_device *dev, spin_unlock(&vxlan->hash_lock[hash_index]); } - return false; + return SKB_NOT_DROPPED_YET; } static bool __vxlan_sock_release_prep(struct vxlan_sock *vs) diff --git a/include/net/dropreason-core.h b/include/net/dropreason-core.h index 98259d2b3e92..1cb8d7c953be 100644 --- a/include/net/dropreason-core.h +++ b/include/net/dropreason-core.h @@ -94,6 +94,8 @@ FN(TC_RECLASSIFY_LOOP) \ FN(VXLAN_INVALID_HDR) \ FN(VXLAN_VNI_NOT_FOUND) \ + FN(MAC_INVALID_SOURCE) \ + FN(VXLAN_ENTRY_EXISTS) \ FN(IP_TUNNEL_ECN) \ FNe(MAX) @@ -429,6 +431,13 @@ enum skb_drop_reason { SKB_DROP_REASON_VXLAN_INVALID_HDR, /** @SKB_DROP_REASON_VXLAN_VNI_NOT_FOUND: no VXLAN device found for VNI */ SKB_DROP_REASON_VXLAN_VNI_NOT_FOUND, + /** @SKB_DROP_REASON_MAC_INVALID_SOURCE: source mac is invalid */ + SKB_DROP_REASON_MAC_INVALID_SOURCE, + /** + * @SKB_DROP_REASON_VXLAN_ENTRY_EXISTS: trying to migrate a static + * entry or an entry pointing to a nexthop. + */ + SKB_DROP_REASON_VXLAN_ENTRY_EXISTS, /** * @SKB_DROP_REASON_IP_TUNNEL_ECN: skb is dropped according to * RFC 6040 4.2, see __INET_ECN_decapsulate() for detail.