From patchwork Thu Nov 7 13:29:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Liang X-Patchwork-Id: 13866478 Received: from mail-oa1-f44.google.com (mail-oa1-f44.google.com [209.85.160.44]) (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 2D9081EE019; Thu, 7 Nov 2024 13:30:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730986228; cv=none; b=Z/LXtL1ZfIqVkvGraEevKR52CU2mGVzD03dqWllqRUmyI4QmrXImOGPMcq+6XxteR5guw/EolxukyM5mGfOFaupFlfmajSshuDaRP3YgUuq8Kc4uRIRe7Y6zaIP00UeZjvZkB2uOANA30zXjYhSYRZl58reKqkcaxCooIwhqnnQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730986228; c=relaxed/simple; bh=iw/SM9Psp33X0c2Lv+k4yRqInuKG2rlsgifBPqJLhmQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BOgWxFX4Kt80znulxzjDIUL7NUy9jc78rPsAS7hy78EH4pInGiWUUdTkO0u7VTjczaiooAQOuh5RwF6Owp5Oy4kuF12ryf/6L2l7WYUNVHzue2t3JhPDvIqWNs4NvZ5EEL1Fm3ZXr6ZfpONhIreZIRQX1T+epoCce4055KsD/I4= 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=GkjP5DAo; arc=none smtp.client-ip=209.85.160.44 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="GkjP5DAo" Received: by mail-oa1-f44.google.com with SMTP id 586e51a60fabf-2884a6b897cso510236fac.3; Thu, 07 Nov 2024 05:30:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730986225; x=1731591025; 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=OcQAk/hItgTSgG59VLwLZXQpYC3MmRXj2uoY0G4TpWw=; b=GkjP5DAoC+HPPt/lilPLHB9QlT1ut4FO/CL4VQHh2ECDI4g7khicn6pUjetRouoMBy mnkGKW5iuZO57CWaFWRg7JJHD4xr1WNbYJOHyBQHxP8hxdeMyUZLnog6KmC4QXewzd12 TkXOyUUEEZ6xDplP7uLPP1gAeMZkm9zgaVM03NDpRoA/EWRjZmKDSn+RJjo5f28S065C C1vbQ6/AL3OkCZelk440rA50LhkExcxWtGPmAc7o24TCo0vMg9iN9k6FHHLrU6kXCFhb 8uHXkSzqcDGHOVK2aFyolvlyjTwjaJk/nnX2sdYdBrtltzcu6WBQGa8oYKHYphTYaymU ueOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730986225; x=1731591025; 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=OcQAk/hItgTSgG59VLwLZXQpYC3MmRXj2uoY0G4TpWw=; b=hoo+W0Q3duU2ziBsBDGqiKBGMbu/M7EKSgzOY3UuUCJnrYaEbURnn1KcQ4bqXn7ZLW CS0Nzjkt74b8ThOx/vTx1OsyaY2SpxStmbkbJXevtje1YKcKQs2SMzlLZGbJszCXYnxv TpnQmgwhLwkWG0ZweCwZPO0GBm5/KB2UI+K+Pa7+IkL6Y/4n06ejYV80rJyYWWO0qz7L VjZxR/TaNRg8ARc4dNVMnWp/cj5HiBPlw1HHVyaQ6Nt9bsMM9jMOj/GHwD6/G4apOMT8 5CmCmxJ5quIjs2ePmmE/KnOQ9QqhlTWIEtFUUvi+F+hWbULFUyU932B0gMk+kNs8Z5UO uLJw== X-Forwarded-Encrypted: i=1; AJvYcCVVefhginyussyyt4YwFwUssLfuW79bxKwzEllx+XKg/h8OvFtSJoVpAfAiZuZKMcudX26O+EbfYkSJX4wAgTk=@vger.kernel.org X-Gm-Message-State: AOJu0YyohfzcPzWUEI8KeIm2OXFFhDn5GG2sV6lPmjbOFg5dtuwV/u4m fI2U2aXsRSEPEzIV9SiBldPR4Y7xOjf3hqHsbspEstUlsyAv/Jv2nmmK9Q0j4LE= X-Google-Smtp-Source: AGHT+IGYtGTmiIvy/cHSxBYa5kuiJKBz68ystxKTgA/zLNlQOrr/HoyXfzazbNJgEL8sE3fRt9dAeQ== X-Received: by 2002:a05:6870:a40b:b0:287:a973:2c66 with SMTP id 586e51a60fabf-29051c830f8mr39192512fac.28.1730986225349; Thu, 07 Nov 2024 05:30:25 -0800 (PST) Received: from nova-ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7f41f65b5afsm1359303a12.76.2024.11.07.05.30.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 05:30:24 -0800 (PST) From: Xiao Liang To: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Kuniyuki Iwashima , Jakub Kicinski Cc: "David S. Miller" , David Ahern , Eric Dumazet , Paolo Abeni , Ido Schimmel , Andrew Lunn , Simon Horman , Donald Hunter , Shuah Khan , Jiri Pirko , Hangbin Liu Subject: [PATCH net-next v2 1/8] rtnetlink: Lookup device in target netns when creating link Date: Thu, 7 Nov 2024 21:29:56 +0800 Message-ID: <20241107133004.7469-2-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241107133004.7469-1-shaw.leon@gmail.com> References: <20241107133004.7469-1-shaw.leon@gmail.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When creating link, lookup for existing device in target net namespace instead of current one. For example, two links created by: # ip link add dummy1 type dummy # ip link add netns ns1 dummy1 type dummy should have no conflict since they are in different namespaces. Signed-off-by: Xiao Liang --- net/core/rtnetlink.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 3b33810d92a8..8119f4ad9e5f 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -3744,20 +3744,26 @@ static int __rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh, { struct nlattr ** const tb = tbs->tb; struct net *net = sock_net(skb->sk); + struct net *device_net; struct net_device *dev; struct ifinfomsg *ifm; bool link_specified; + /* When creating, lookup for existing device in target net namespace */ + device_net = (nlh->nlmsg_flags & NLM_F_CREATE) && + (nlh->nlmsg_flags & NLM_F_EXCL) ? + tgt_net : net; + ifm = nlmsg_data(nlh); if (ifm->ifi_index > 0) { link_specified = true; - dev = __dev_get_by_index(net, ifm->ifi_index); + dev = __dev_get_by_index(device_net, ifm->ifi_index); } else if (ifm->ifi_index < 0) { NL_SET_ERR_MSG(extack, "ifindex can't be negative"); return -EINVAL; } else if (tb[IFLA_IFNAME] || tb[IFLA_ALT_IFNAME]) { link_specified = true; - dev = rtnl_dev_get(net, tb); + dev = rtnl_dev_get(device_net, tb); } else { link_specified = false; dev = NULL; From patchwork Thu Nov 7 13:29:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Liang X-Patchwork-Id: 13866479 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (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 4ADA3212169; Thu, 7 Nov 2024 13:30:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730986234; cv=none; b=ZazzXxKv9cT8Zm3YJeo8WqtGWE6OlImBQ5obr6g0qW7Li7ohY5Xm5mlZdjivGc9wuyqn9FNFRdVV2Bsw42oNwEaI/XBOMCDjZbu1b7Lq4+77EPDX8dWaPfFNzXy2gZ6Qxv3I9KeRnpipOusb1sqCSs+r2v0NBIqdPhdVEYSe6sE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730986234; c=relaxed/simple; bh=520bY/0sRcY76U5JvV7+YiGmAQmexLctQ/6aOXCbZL4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gTSNbL9DQSf/2bo/8wra699Gq2CtsHSVjsc0M6CSPYVSG7oryAqPt1kPQkY1aPvvh9Uxt6bd5p5TxdWlqjqpZGrt7gFgIqz9XyKSXCClGayEn1LjYLqegalQgEE+jGlAHJZW5/r7XLWYthfEcRMs/LkJ//iImizsr6dIifrHn9U= 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=arF1gN7Y; arc=none smtp.client-ip=209.85.210.175 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="arF1gN7Y" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-71e681bc315so733739b3a.0; Thu, 07 Nov 2024 05:30:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730986232; x=1731591032; 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=N+eXRMVMKQHzq/AF94296l6CIgMBceDx8WLjFZJpjK0=; b=arF1gN7Ydv+vekmSbux6C0CXBIVnS6FO36GX+eiHlH+5bUzn69m8/J1V81x8JIE+rn NzFml4RD9EqQeU7PAQaKuSqQ3JEzCTVswKac1pUnt4BVPEQR0Cqqdr1wM2Xif7vph5Pz 4Gx9OrllZxvxjqW5TTVmzFt0orAnVNXKu5VEZSKDVJVJnuyZ5GvEVbwOhhrxF2/wgsfF ZcmQsPEzGKWjQlD6u1ikfKNsu8nIvtLRBk1uxR12fTJlDPiaKjHr8xgBMFqmgCQt0Qvt Kq+OocqK9udbg9awlWVEk2S+4R0vyXAUcjna/iElnBSyk1okss+xqzWgeQ2WbzC8tapb cyOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730986232; x=1731591032; 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=N+eXRMVMKQHzq/AF94296l6CIgMBceDx8WLjFZJpjK0=; b=LngZjta9xciuO+rGXPLtd6aLp0/OpJPeZWU21pSJieYAXJD9MHlhlR+WzCfSLBzeE2 aSQw3p+cM4TJEUYbcD6B6WQJVtr4K85mIupFbO3nOTnTYFAjAiKgJC8KJKXUrvdrA4EB Gila5HeyXjw7QQuQB/MQKXFID/+rfZEMiMv56RNoyYjvq8jAkTXsNbrIwhsUrkypibdY 46ox272QtbFbT+SBFIBrg/KTbZRGD6lAPbW3z3ayZEpj1KtgLyPXOzvD6R2SVHSS9i8r yKEr4Rjk3RplUdtxI3orf61QEOpSlr3pj8rmDglVV4DCD5AGQQYso41SdljpbNGxZS3W dBmw== X-Forwarded-Encrypted: i=1; AJvYcCWUEFzxyS74lEuTpETDW46nZA3yhpdoiACoQFkMk2cesRUjS80EZp8eOOGZ1tbi01ZMx0Kc7xo2R6/mEqox9SQ=@vger.kernel.org X-Gm-Message-State: AOJu0YyL4CcmKoTblbZMNQv1NeGd90DdMXZ3THXkBJ8Xw9oYORMd5l6p DfBIyAA3JaHP24BT5jpOV2MHEfUQHaiKfeTj39mR66Afm13L4g0OGav2xiHf4lA= X-Google-Smtp-Source: AGHT+IHgbzYKY4bYk17LRWp95QI+OGcqsTdZmhi9h9N4vnyexBNReFmxgROSUY8O9vFH/PXJmsD/kg== X-Received: by 2002:a05:6a00:194a:b0:71e:4dc5:259a with SMTP id d2e1a72fcca58-72410d18c9emr5644b3a.7.1730986230418; Thu, 07 Nov 2024 05:30:30 -0800 (PST) Received: from nova-ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7f41f65b5afsm1359303a12.76.2024.11.07.05.30.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 05:30:29 -0800 (PST) From: Xiao Liang To: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Kuniyuki Iwashima , Jakub Kicinski Cc: "David S. Miller" , David Ahern , Eric Dumazet , Paolo Abeni , Ido Schimmel , Andrew Lunn , Simon Horman , Donald Hunter , Shuah Khan , Jiri Pirko , Hangbin Liu Subject: [PATCH net-next v2 2/8] rtnetlink: Add netns_atomic flag in rtnl_link_ops Date: Thu, 7 Nov 2024 21:29:57 +0800 Message-ID: <20241107133004.7469-3-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241107133004.7469-1-shaw.leon@gmail.com> References: <20241107133004.7469-1-shaw.leon@gmail.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Currently these two steps are needed to create a net device with IFLA_LINK_NETNSID attr: 1. create and setup the netdev in the link netns with rtnl_create_link() 2. move it to the target netns with dev_change_net_namespace() This has some side effects, including extra ifindex allocation, ifname validation and link notifications in link netns. Add a netns_atomic flag, that if set to true, devices will be created in the target netns directly. Signed-off-by: Xiao Liang --- include/net/rtnetlink.h | 3 +++ net/core/rtnetlink.c | 7 ++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h index b260c0cc9671..7e78f3952774 100644 --- a/include/net/rtnetlink.h +++ b/include/net/rtnetlink.h @@ -75,6 +75,8 @@ static inline int rtnl_msg_family(const struct nlmsghdr *nlh) * @srcu: Used internally * @kind: Identifier * @netns_refund: Physical device, move to init_net on netns exit + * @netns_atomic: Device can be created in target netns even when + * link-netns is different, avoiding netns change. * @maxtype: Highest device specific netlink attribute number * @policy: Netlink policy for device specific attribute validation * @validate: Optional validation function for netlink/changelink parameters @@ -116,6 +118,7 @@ struct rtnl_link_ops { void (*setup)(struct net_device *dev); bool netns_refund; + bool netns_atomic; unsigned int maxtype; const struct nla_policy *policy; int (*validate)(struct nlattr *tb[], diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 8119f4ad9e5f..b0d1cbb44a03 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -3690,8 +3690,9 @@ static int rtnl_newlink_create(struct sk_buff *skb, struct ifinfomsg *ifm, name_assign_type = NET_NAME_ENUM; } - dev = rtnl_create_link(link_net ? : tgt_net, ifname, - name_assign_type, ops, tb, extack); + dev = rtnl_create_link(!link_net || ops->netns_atomic ? + tgt_net : link_net, ifname, name_assign_type, + ops, tb, extack); if (IS_ERR(dev)) { err = PTR_ERR(dev); goto out; @@ -3711,7 +3712,7 @@ static int rtnl_newlink_create(struct sk_buff *skb, struct ifinfomsg *ifm, err = rtnl_configure_link(dev, ifm, portid, nlh); if (err < 0) goto out_unregister; - if (link_net) { + if (link_net && !ops->netns_atomic) { err = dev_change_net_namespace(dev, tgt_net, ifname); if (err < 0) goto out_unregister; From patchwork Thu Nov 7 13:29:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Liang X-Patchwork-Id: 13866480 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (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 D5D9B21263B; Thu, 7 Nov 2024 13:30:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730986238; cv=none; b=tvgtZfz16YP3FXsajrPQ8OhJCOot3rxtjJ0oNmRiXyZycsELTo+w35DvlcF0seAl2vFliVSK+/g5jyaVqWtblSUiyBOdzSjVv3CjPtjBswp/TwGcERhdu6jWuS0D1LvV9S6xdmyelW3nw8H0MdrMrskwlLhYwl3IoME0WWcGIn8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730986238; c=relaxed/simple; bh=R2okbkGGv03EaZoNX3EjievQR0H31mw0HCvCROIPr9g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pnEBbXW4qqzlbnJSEkoDbtUVbXBk8AHw69FjApuaYixn6cQkluxWr1JsbLVEs76oHkQp9yeMCTP4QzaFOvMfsCAzVZ0SHm5sB0GRbnugBdpnUbg1QU7zKcUxE0BbH58GLffoDie8YV2osfYjYgZUygCfsydwDCWYCsONvtL+KyE= 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=Yf5FeYMY; arc=none smtp.client-ip=209.85.210.180 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="Yf5FeYMY" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-720be27db27so680799b3a.2; Thu, 07 Nov 2024 05:30:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730986236; x=1731591036; 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=IrCaarQptqoPnVIGF6Rw6t9hI+Rf9ZxQVNSlbFD1HYQ=; b=Yf5FeYMYQxI308x5eaSPyx09G+e6uuWYcMXQ/BvrKDeqIIkxVvh+lo/knkw51+nMyJ XKCZasF5924W1aOc/DoLYsN2P9mavy8Jytsm0FMpzXhvqP+FNWBl+yOwyFM9fmNU8f6s 75kfcwztH+ZWFy71qlulwWbJd4hWUZXKZLPD8S5/xdewpJY7amKEwzbUPwDioR0RIYQZ 3dS2T7bIui3YJxq7ZxFu+yh9qqeiImt3pX44NbYQJMhe6q//bnlW52ohH309i8IPaJfP JCUZEoqFXH4QmYiJy5wa3OoOdeG++EOqKCT2J1PVnHEWT7I2G/BlLzvDhTG424a2W4Jg yoZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730986236; x=1731591036; 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=IrCaarQptqoPnVIGF6Rw6t9hI+Rf9ZxQVNSlbFD1HYQ=; b=C0ClhW5RISihVWzrIJuRoAIsWJQR2me+sJ15iz/t1vcASUyJCa3iOX0R4UmDY3zWl+ nQzZHRmifiPvS5NLOxatwUGLhlzF3JW+jJj74PEmIXPhbeW2cu+QaIDY2UD3euhxxSrX Dw0IWrKt5MHy3RZG4BYlyw/uparcXjahcKn8esL5C1hfKmrfe/iUNw0jwnVOGwjxMPs9 ouKgEDwwuU6wmE8DUVFg85fMudJjtkn9m15wOI4x/kGDh2tf3DmreRve6FP/1ez78dT5 +/7rsa7M8ffqKJmLSzyKzs4D1f35OajGf6T7H/zIwuXXPLCjlyPGasBxjwtf/QqrK/jq 8IVw== X-Forwarded-Encrypted: i=1; AJvYcCUOtWwdP64jaOcv93/aRv5P8DTiFLctHY6oZLe3wHRzE/KWtdkFC6NYLf3sJW2iCY3NHYwDKn176FqUM9DHYzE=@vger.kernel.org X-Gm-Message-State: AOJu0Yyh5efDmgEeVgqfDL7fiKOkh2LolGmvy3F56v5Zds4RM3arAvhS 8FnzZDtYDOuxHbXz+K8OZ9ULCPggcCOryIFZTE04+5OkrPIMeLUkkIanV01MZ7k= X-Google-Smtp-Source: AGHT+IFze7XtSUQRU9pWJyYFcIBTOxHAQhW46NXV/DKBG1Xjom3lV7mRNygSAOr8WJWkoEMTPfHvpw== X-Received: by 2002:aa7:88d4:0:b0:71e:6bf1:158f with SMTP id d2e1a72fcca58-7240cfaa137mr972045b3a.21.1730986235784; Thu, 07 Nov 2024 05:30:35 -0800 (PST) Received: from nova-ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7f41f65b5afsm1359303a12.76.2024.11.07.05.30.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 05:30:35 -0800 (PST) From: Xiao Liang To: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Kuniyuki Iwashima , Jakub Kicinski Cc: "David S. Miller" , David Ahern , Eric Dumazet , Paolo Abeni , Ido Schimmel , Andrew Lunn , Simon Horman , Donald Hunter , Shuah Khan , Jiri Pirko , Hangbin Liu Subject: [PATCH net-next v2 3/8] net: ip_tunnel: Build flow in underlay net namespace Date: Thu, 7 Nov 2024 21:29:58 +0800 Message-ID: <20241107133004.7469-4-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241107133004.7469-1-shaw.leon@gmail.com> References: <20241107133004.7469-1-shaw.leon@gmail.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Build IPv4 flow in underlay net namespace, where encapsulated packets are routed. Signed-off-by: Xiao Liang --- net/ipv4/ip_tunnel.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c index 25505f9b724c..09b73acf037a 100644 --- a/net/ipv4/ip_tunnel.c +++ b/net/ipv4/ip_tunnel.c @@ -294,7 +294,7 @@ static int ip_tunnel_bind_dev(struct net_device *dev) ip_tunnel_init_flow(&fl4, iph->protocol, iph->daddr, iph->saddr, tunnel->parms.o_key, - iph->tos & INET_DSCP_MASK, dev_net(dev), + iph->tos & INET_DSCP_MASK, tunnel->net, tunnel->parms.link, tunnel->fwmark, 0, 0); rt = ip_route_output_key(tunnel->net, &fl4); @@ -611,7 +611,7 @@ void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev, } ip_tunnel_init_flow(&fl4, proto, key->u.ipv4.dst, key->u.ipv4.src, tunnel_id_to_key32(key->tun_id), - tos & INET_DSCP_MASK, dev_net(dev), 0, skb->mark, + tos & INET_DSCP_MASK, tunnel->net, 0, skb->mark, skb_get_hash(skb), key->flow_flags); if (!tunnel_hlen) @@ -774,7 +774,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev, ip_tunnel_init_flow(&fl4, protocol, dst, tnl_params->saddr, tunnel->parms.o_key, tos & INET_DSCP_MASK, - dev_net(dev), READ_ONCE(tunnel->parms.link), + tunnel->net, READ_ONCE(tunnel->parms.link), tunnel->fwmark, skb_get_hash(skb), 0); if (ip_tunnel_encap(skb, &tunnel->encap, &protocol, &fl4) < 0) From patchwork Thu Nov 7 13:29:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Liang X-Patchwork-Id: 13866481 Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) (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 27FD621263B; Thu, 7 Nov 2024 13:30:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730986243; cv=none; b=cnEXVQIE8rVVArPkgN/6brTwj5b/fpBaRKRtpMUPHAQt47irR4yIWOOtpRzPJ7E1UaBPMuBIBFckGTtq6J6LhZAiPdOuq45P5G5FfaJnFsM94Frb+rNhdTJBim+nmq0HySj4/0MULX6iqZGhhr4YD1UVOfMuwRNIdQGWrAUPoPY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730986243; c=relaxed/simple; bh=RIeIldQmMdDgDbqz3W4hOhKKpSmk1DSKS+AB23VYQvI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=chN69wB67o88F6LXUZ2tVY17FYmiehea+D8FS/O35JgV5V5AUdF9sRuoYAPPHZB8j5ApYHGZSRLRM7x7q3afNXLm5gX0b7bEZPp4rWS8TgWTaTPLsGBxVR4TSEGOW5bl5AGDfx2EwrEDXqGatz7LsZiKVFGoJ+8S5tJ91laY8tU= 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=QnFvcIp+; arc=none smtp.client-ip=209.85.215.178 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="QnFvcIp+" Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-7e6d04f74faso722843a12.1; Thu, 07 Nov 2024 05:30:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730986241; x=1731591041; 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=edUof7QbXp59vbL8hGVThiWd9steq8vHUUDXnAQJbcI=; b=QnFvcIp+edCnx9X2zTrQFBevIcbtSKmsuiv4g4qp5JRZwk/m8aqlLzyIINoFbab4aB o+a6Rdj/0XGrEKKsI+OkIJpHHrMHk6BbaQuMHEE0zeLhgr+aT+uP0maaSQw+jkuVes2l UY8SDND2x5aRe01dTsBfvjAP5t1SCYcZv+0QxB0VKnO+HQbtEjq5Dk7u67ktl1akMjuu pJZN5aKlHqOUt7YRm6fLS1o24Px6wdGH3i61PqUSkmW484gaCg8orNJhGrmq7iamtom8 hNKzZG2tTAOiJSfxW4xkyoMxwoSTab0ZdlKap6kJSUu9v87wsm9gVE+HeurzWHbFmgZC M2Nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730986241; x=1731591041; 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=edUof7QbXp59vbL8hGVThiWd9steq8vHUUDXnAQJbcI=; b=biCtsh/121yQ6B7vbRSptGMzS5RHEazYst2yXZG9vggUK9G34ZdbyGH3R3bQwUBCvO AY0WnL8Kfhqkiq3OoeESDmGdUd9m3jIrfLUgvvT0YlunztOiP4ZLUh6xIruwOd9M3Gcz AsX4WsI3FkEMzKC+3H7yZhPpLFtswF5pjq0eMoadvqNpp4FfMHLyUbY8+3ep+xZXra1L QgrWq9WVbzqzEY/QgRpKuynD4hkkplLQ0dRfR0KcMV4kUWZkL3UuU5pM/tXL7qjhQNQR Exi0/HrvBWWIUcY8x6bvdxddrgkKyxzQlffXqwGK18vbf9GmW2Kj8TtK+w8fUm4A1Vmq LT5g== X-Forwarded-Encrypted: i=1; AJvYcCVzA9BSUZxFo6WZRchEFTPXxEdeHUDm/Vhf1Nrkn7uymcvk5i6TW2UAmdmyAU5alY0pMGkbe18CvtRBemLFd3M=@vger.kernel.org X-Gm-Message-State: AOJu0YyIsso0TXyO1xW6OklcNI+GYhuOTM03UbyYllNHy2zUAaJtWYbQ 0NnVY4gPpyr0UmifLE98pgZcO1nUasgJbaRiZpjRQb5a/myjPHPtB8C/VI1yJBw= X-Google-Smtp-Source: AGHT+IFKqI6A60S+72Sq4xBo0OBSVo/LClDbkWd02Q8TYGnP5n41wmBzinwzBIQPB+v2rfG7zIGCYQ== X-Received: by 2002:a05:6a20:918c:b0:1d7:1288:8338 with SMTP id adf61e73a8af0-1dc18849479mr1779747637.8.1730986241107; Thu, 07 Nov 2024 05:30:41 -0800 (PST) Received: from nova-ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7f41f65b5afsm1359303a12.76.2024.11.07.05.30.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 05:30:40 -0800 (PST) From: Xiao Liang To: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Kuniyuki Iwashima , Jakub Kicinski Cc: "David S. Miller" , David Ahern , Eric Dumazet , Paolo Abeni , Ido Schimmel , Andrew Lunn , Simon Horman , Donald Hunter , Shuah Khan , Jiri Pirko , Hangbin Liu Subject: [PATCH net-next v2 4/8] net: ip_tunnel: Add source netns support for newlink Date: Thu, 7 Nov 2024 21:29:59 +0800 Message-ID: <20241107133004.7469-5-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241107133004.7469-1-shaw.leon@gmail.com> References: <20241107133004.7469-1-shaw.leon@gmail.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add ip_tunnel_newlink_net() that accepts src_net parameter, which is passed from newlink() of RTNL ops, and use it as tunnel source netns. Signed-off-by: Xiao Liang --- include/net/ip_tunnels.h | 3 +++ net/ipv4/ip_tunnel.c | 21 +++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h index 1aa31bdb2b31..e7cabc93902b 100644 --- a/include/net/ip_tunnels.h +++ b/include/net/ip_tunnels.h @@ -408,6 +408,9 @@ int ip_tunnel_changelink(struct net_device *dev, struct nlattr *tb[], struct ip_tunnel_parm_kern *p, __u32 fwmark); int ip_tunnel_newlink(struct net_device *dev, struct nlattr *tb[], struct ip_tunnel_parm_kern *p, __u32 fwmark); +int ip_tunnel_newlink_net(struct net *src_net, struct net_device *dev, + struct nlattr *tb[], struct ip_tunnel_parm_kern *p, + __u32 fwmark); void ip_tunnel_setup(struct net_device *dev, unsigned int net_id); bool ip_tunnel_netlink_encap_parms(struct nlattr *data[], diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c index 09b73acf037a..bbb2fbb90bd2 100644 --- a/net/ipv4/ip_tunnel.c +++ b/net/ipv4/ip_tunnel.c @@ -1213,17 +1213,17 @@ void ip_tunnel_delete_nets(struct list_head *net_list, unsigned int id, } EXPORT_SYMBOL_GPL(ip_tunnel_delete_nets); -int ip_tunnel_newlink(struct net_device *dev, struct nlattr *tb[], - struct ip_tunnel_parm_kern *p, __u32 fwmark) +int ip_tunnel_newlink_net(struct net *src_net, struct net_device *dev, + struct nlattr *tb[], struct ip_tunnel_parm_kern *p, + __u32 fwmark) { struct ip_tunnel *nt; - struct net *net = dev_net(dev); struct ip_tunnel_net *itn; int mtu; int err; nt = netdev_priv(dev); - itn = net_generic(net, nt->ip_tnl_net_id); + itn = net_generic(src_net, nt->ip_tnl_net_id); if (nt->collect_md) { if (rtnl_dereference(itn->collect_md_tun)) @@ -1233,7 +1233,7 @@ int ip_tunnel_newlink(struct net_device *dev, struct nlattr *tb[], return -EEXIST; } - nt->net = net; + nt->net = src_net; nt->parms = *p; nt->fwmark = fwmark; err = register_netdevice(dev); @@ -1265,6 +1265,13 @@ int ip_tunnel_newlink(struct net_device *dev, struct nlattr *tb[], err_register_netdevice: return err; } +EXPORT_SYMBOL_GPL(ip_tunnel_newlink_net); + +int ip_tunnel_newlink(struct net_device *dev, struct nlattr *tb[], + struct ip_tunnel_parm_kern *p, __u32 fwmark) +{ + return ip_tunnel_newlink_net(dev_net(dev), dev, tb, p, fwmark); +} EXPORT_SYMBOL_GPL(ip_tunnel_newlink); int ip_tunnel_changelink(struct net_device *dev, struct nlattr *tb[], @@ -1326,7 +1333,9 @@ int ip_tunnel_init(struct net_device *dev) } tunnel->dev = dev; - tunnel->net = dev_net(dev); + if (!tunnel->net) + tunnel->net = dev_net(dev); + strscpy(tunnel->parms.name, dev->name); iph->version = 4; iph->ihl = 5; From patchwork Thu Nov 7 13:30:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Liang X-Patchwork-Id: 13866482 Received: from mail-oa1-f54.google.com (mail-oa1-f54.google.com [209.85.160.54]) (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 E305F21263B; Thu, 7 Nov 2024 13:30:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730986249; cv=none; b=W6I9VRg53a8yRwWaAZLTnVITE4YlBKkFoAKPIFJRXlJfU44IKAN853Rm031TWBqfDtWxgEk26scbBN020obu7IEDPEaA6aQ+rRO7d42IzzH14u3HGcRQkCXOqpL4jA5lQKYaNRDc6lPKQO2tawvEuM36EM89ZGAnHeuW/rqH/OA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730986249; c=relaxed/simple; bh=DP+FtCvuMIZd6/BnGy3YHcmGQRT1aA22G7G7QoSQE1o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W9ZXhBVyh2NyEKl7m2dUaB4gqc5oTKkBUkN3/9CZOoaNCxp4udgXajsxmZerLYG7T1XzcRjjOwOT8Bhhni0bMqikRW/Y/jd0UnZ4ImJv2pkYWHgjZOztEl1dMqd0ePgq1EhF2EMCjK3m8B5eZVwd/XpxP1ppRhzcYN/rC3YqR+I= 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=c+Gaf29e; arc=none smtp.client-ip=209.85.160.54 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="c+Gaf29e" Received: by mail-oa1-f54.google.com with SMTP id 586e51a60fabf-288661760d3so482439fac.3; Thu, 07 Nov 2024 05:30:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730986247; x=1731591047; 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=gClAoFe1h5U+0NiA7Nj6o2YtRc1W3/sr4TmNeojvSXo=; b=c+Gaf29ex4ZwF77HWo4rIq9/wJY+94BgG9HyPQTAvRp0vKqYOaIz+0WUnZCircZ8Pm LqFh5D4TCY6Vx3EDbRK5qiwXa2lKYpxBWc55/VBFe8kKJKcTWzMg+0g5RHkvD8GPPuEn qpjtjc3uzS1Y3ScSt6WPqt6aNw2SPkhdrSO5Aweb+GoGY9iGA+uWD1CWtANgkizZsP91 BDzJ9++1ye/m2oMMCo1cbynCR59KpPDlJDsCl/a70pxE9GbFd2mPYriwIrLq1kcW7bLu d0iQx6Sgis05OurP3FZMazu3xz5BmV1XM4YnACK2nPww3fX4p8IZiVHm1DGkYauH6MKw LLvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730986247; x=1731591047; 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=gClAoFe1h5U+0NiA7Nj6o2YtRc1W3/sr4TmNeojvSXo=; b=MRIhk27TR0V7goyivZjVAV+SFpE/RtPy7vRvgByAKIhKkEjxYhxrW0xsqXDD6f5/TR AU5t7qOMKvYFKf0xdknnxfYztm9NxnPTjDQkCdOIbHIKdG4JrjzPhtOCEg4w9EzfOPsQ vtQXeTBlnW/XsGuw2xMCdPxA/WeuoDLBUo3DGkfaQ+4nMXK0CAroZqe8H30TWftbXQvc legD2O+J+TtLizfynTlwuRZnTr9l6tqeauLY/9w9/7uEa+UE2G9cwlfDeQu+XEKmWzx5 hzeA+58ht756DUgIBQ1QYUCCvYenB/n91xehcf9k3XFPqkiiY2oRnN5T5rq8nUliLCjt Bg2A== X-Forwarded-Encrypted: i=1; AJvYcCW66S4ctjpIO8RDWo1WeE6nHaqr+tTeh+9G1veIOV5nvanbOyJTavWT5f6G3TcM8CNdydYe6wx4i/QyUogA0E0=@vger.kernel.org X-Gm-Message-State: AOJu0YwkYkQVRM0QOd9uBzG/DULJh5ZSHVBEA9JH/StofkbieGI/EmE+ Yl+P3+NHX2DLL64oP6mTGMQ4QXz9H0wsxQnp7JSiunnMtVurgib+0KdBwnJXYRE= X-Google-Smtp-Source: AGHT+IG3t8hX31pJw8ubYbA4z3BcyxT+HBjVplQdqc1Kz+fLlnndA1qcsnroO+cgg7mJOqee6zSr5A== X-Received: by 2002:a05:6870:3310:b0:255:2e14:3d9d with SMTP id 586e51a60fabf-29051adb328mr38968240fac.5.1730986246492; Thu, 07 Nov 2024 05:30:46 -0800 (PST) Received: from nova-ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7f41f65b5afsm1359303a12.76.2024.11.07.05.30.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 05:30:46 -0800 (PST) From: Xiao Liang To: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Kuniyuki Iwashima , Jakub Kicinski Cc: "David S. Miller" , David Ahern , Eric Dumazet , Paolo Abeni , Ido Schimmel , Andrew Lunn , Simon Horman , Donald Hunter , Shuah Khan , Jiri Pirko , Hangbin Liu Subject: [PATCH net-next v2 5/8] net: ip_gre: Add netns_atomic module parameter Date: Thu, 7 Nov 2024 21:30:00 +0800 Message-ID: <20241107133004.7469-6-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241107133004.7469-1-shaw.leon@gmail.com> References: <20241107133004.7469-1-shaw.leon@gmail.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 If set to true, create device in target netns (when different from link-netns) without netns change, and use current netns as link-netns if not specified explicitly. Signed-off-by: Xiao Liang --- net/ipv4/ip_gre.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c index f1f31ebfc793..6ef7e98e4620 100644 --- a/net/ipv4/ip_gre.c +++ b/net/ipv4/ip_gre.c @@ -107,6 +107,11 @@ static bool log_ecn_error = true; module_param(log_ecn_error, bool, 0644); MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN"); +static bool netns_atomic; +module_param(netns_atomic, bool, 0444); +MODULE_PARM_DESC(netns_atomic, + "Create tunnel in target net namespace directly and use current net namespace as link-netns by default"); + static struct rtnl_link_ops ipgre_link_ops __read_mostly; static const struct header_ops ipgre_header_ops; @@ -1393,6 +1398,7 @@ static int ipgre_newlink(struct net *src_net, struct net_device *dev, struct nlattr *tb[], struct nlattr *data[], struct netlink_ext_ack *extack) { + struct net *link_net = netns_atomic ? src_net : dev_net(dev); struct ip_tunnel_parm_kern p; __u32 fwmark = 0; int err; @@ -1404,13 +1410,14 @@ static int ipgre_newlink(struct net *src_net, struct net_device *dev, err = ipgre_netlink_parms(dev, data, tb, &p, &fwmark); if (err < 0) return err; - return ip_tunnel_newlink(dev, tb, &p, fwmark); + return ip_tunnel_newlink_net(link_net, dev, tb, &p, fwmark); } static int erspan_newlink(struct net *src_net, struct net_device *dev, struct nlattr *tb[], struct nlattr *data[], struct netlink_ext_ack *extack) { + struct net *link_net = netns_atomic ? src_net : dev_net(dev); struct ip_tunnel_parm_kern p; __u32 fwmark = 0; int err; @@ -1422,7 +1429,7 @@ static int erspan_newlink(struct net *src_net, struct net_device *dev, err = erspan_netlink_parms(dev, data, tb, &p, &fwmark); if (err) return err; - return ip_tunnel_newlink(dev, tb, &p, fwmark); + return ip_tunnel_newlink_net(link_net, dev, tb, &p, fwmark); } static int ipgre_changelink(struct net_device *dev, struct nlattr *tb[], @@ -1777,6 +1784,10 @@ static int __init ipgre_init(void) pr_info("GRE over IPv4 tunneling driver\n"); + ipgre_link_ops.netns_atomic = netns_atomic; + ipgre_tap_ops.netns_atomic = netns_atomic; + erspan_link_ops.netns_atomic = netns_atomic; + err = register_pernet_device(&ipgre_net_ops); if (err < 0) return err; From patchwork Thu Nov 7 13:30:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Liang X-Patchwork-Id: 13866483 Received: from mail-il1-f170.google.com (mail-il1-f170.google.com [209.85.166.170]) (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 C89BC212D0D; Thu, 7 Nov 2024 13:30:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730986255; cv=none; b=hf6SHUVqA6phABxSTUHLgYzBt4YX3oQYX6UDJxxP6p7vXMkkZSrj2LHwvZLbYX35U6dJ6+NUUeQWD/timYjwqDMtiYp6bvjdaCK+gmnZfXshNQKFaw7BAIINrbJ4YeOcmuqkern+hIEuG5HeUbCwRubG9z7oPlq3xXnwLLXLjCM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730986255; c=relaxed/simple; bh=HP/T98jq8ZVtbRkR8ymskxcaIrygIxP03M2Tey2Ql7c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jgt90EMQXGqmZYEbs0snYX4oeRTeXL9zUd2GLdZLi6pDG13MmqYuZD1aosAV5SUlMweSQQ3eJunAMQT4/Pf5wBxDFwQwuzuN99urx852kzBlSS/h1cYn7lCSGx5/8quETvGv2dBLpSR2rFTYXqefJ4HBLvPEU1YSgdo5yQfFfTw= 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=QFxtja6f; arc=none smtp.client-ip=209.85.166.170 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="QFxtja6f" Received: by mail-il1-f170.google.com with SMTP id e9e14a558f8ab-3a3b8b34be9so3393125ab.2; Thu, 07 Nov 2024 05:30:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730986252; x=1731591052; 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=QUs9BWOu32L2gGfBENh+erfoCLDyT1PmV3IMsurFVA8=; b=QFxtja6fETJqAP2OjKQNj+8hXAkth/QPZUQ32Gs8MZ49fSuznct77gK6y/69GkerX1 37KQmvUL3nIuhHxDSaJwgIP/ZhukLEFQAtzXSGJciXv5u+Wa8/AL37JSy3Fzv0ewAFFD SXUdqlX2EC+ihY+a8g5WTvBw4lUpVzvcfCcSzukKj85j779C5QQXSZYYAqZT0j+Xss6J ESkle3ooDQIqOLQm6253aVioVuHjyCpUinxkapBVky4i+MBe5mgKkGiawZFqdpCgWafF i/pOsog/inU0mzteKveTytQbchqmwgu9+nJmTL7706K8vwS5/cb6dGXkMv2y/ltftV+L q9/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730986252; x=1731591052; 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=QUs9BWOu32L2gGfBENh+erfoCLDyT1PmV3IMsurFVA8=; b=XxfMTE4C2VErTJPaadLmOgzCcnfQ0I10VJY4TlB0pB5Xsu2dk6DlTJqqVWIeb+TCCe XDWps52kcd7wEa2uswdsumtWlKhCPxDlY21muXdwc3zYSc/ceYpJf9lWPrcEBhgGZyIE k7MBvBwYKYNaKThJq+Ra75VD2k1zI5Ena69ylcrpeuAadWM1gK27ueudw0h6CB7qUWPV J5ePHULDzCMu1Scy40ah1ZB77Hh/b+PHxqKdfcb0b8kflLgrf3VrWlMC59Mjrqa59IDn fijPYxu51w2vesDUAN1kClL5I2146RK54aNdvRB0Vqnt1PXZ6Rm8UPzCeHdi4L7JmjDX 1HYg== X-Forwarded-Encrypted: i=1; AJvYcCXJG0mOgf+dO/6F9xErTY5ORZrDAP2R7rSGGZsVrrcqJXXUKj62xjByxg1tO2Z3k9bMqFRiE2UzR56OG9IiibA=@vger.kernel.org X-Gm-Message-State: AOJu0YwYLh0LRq7Fi+yboNb41QtW+K9Aq0YmgbPiuoIyjLSQbkCL2aNU rZ/e9XEnww+TQc/wfjABFX/JoYYP0ynZwFW0fhVrajFArrl7jng/3qsxiatOz3o= X-Google-Smtp-Source: AGHT+IHGKUmmx0POT4xmxjZoMd4NM+GzQvAiR8OFD0CMQp+8DnJsg/ZtDJybFx1AONbQK2LxQ7Js5w== X-Received: by 2002:a05:6e02:1a8b:b0:3a4:e8cc:2aa6 with SMTP id e9e14a558f8ab-3a6b02612ffmr271633295ab.8.1730986251843; Thu, 07 Nov 2024 05:30:51 -0800 (PST) Received: from nova-ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7f41f65b5afsm1359303a12.76.2024.11.07.05.30.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 05:30:51 -0800 (PST) From: Xiao Liang To: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Kuniyuki Iwashima , Jakub Kicinski Cc: "David S. Miller" , David Ahern , Eric Dumazet , Paolo Abeni , Ido Schimmel , Andrew Lunn , Simon Horman , Donald Hunter , Shuah Khan , Jiri Pirko , Hangbin Liu Subject: [PATCH net-next v2 6/8] net: dummy: Set netns_atomic in rtnl ops for testing Date: Thu, 7 Nov 2024 21:30:01 +0800 Message-ID: <20241107133004.7469-7-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241107133004.7469-1-shaw.leon@gmail.com> References: <20241107133004.7469-1-shaw.leon@gmail.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Set netns_atomic flag in rtnl ops. For testing purpose only, since link-netns is not used for dummy interfaces in practice. Signed-off-by: Xiao Liang --- drivers/net/dummy.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/dummy.c b/drivers/net/dummy.c index e9c5e1e11fa0..38d79f543998 100644 --- a/drivers/net/dummy.c +++ b/drivers/net/dummy.c @@ -138,6 +138,7 @@ static struct rtnl_link_ops dummy_link_ops __read_mostly = { .kind = DRV_NAME, .setup = dummy_setup, .validate = dummy_validate, + .netns_atomic = true, }; /* Number of dummy devices to be set up by this module. */ From patchwork Thu Nov 7 13:30:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Liang X-Patchwork-Id: 13866484 Received: from mail-oa1-f46.google.com (mail-oa1-f46.google.com [209.85.160.46]) (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 8A60F210188; Thu, 7 Nov 2024 13:30:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730986260; cv=none; b=cBVH9wCxmQfQKdIGpNIozlv+goZKraQg+Q56hkYuES8vRijCl97bcrM4shV0FSxVTJrWU8CpJP6dhpyGKO+F8mkRo6fV2vN/nq/f+x/yhzBckuCpXeijxJraZKJOvmimPuFP3XhS4r0NTrnSc/MLCx4/ZzKGF+8SKOZsa9dGgKw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730986260; c=relaxed/simple; bh=lksVcw2gq5LR6jEmpI4cHWB5J25IFrGgoWPkr++Yw/g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Hcs3PZhd1S3CZYDis7NzF1+qT9Ljczl8J/BLpaQ4eYGNpC35WkARSGETWN4M0wdZikCZrwcyM9EUcppsC+j1Ft2KdhB8A1Ppx8YZuXihekbMs/1/lSyETr6ic9P5is2/9JfxHvuSz6u7WHRB7ERL9D1YUiWHNbkyWyAHEyL4++k= 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=lgHsPeCS; arc=none smtp.client-ip=209.85.160.46 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="lgHsPeCS" Received: by mail-oa1-f46.google.com with SMTP id 586e51a60fabf-2951f3af3ceso591199fac.1; Thu, 07 Nov 2024 05:30:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730986257; x=1731591057; 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=v/sPiX4msaWzkl3dC5zUiLMAXLFRKVpxYb5+istaczI=; b=lgHsPeCSOmcSPIhXl4P2G3P6TfI+Tvwe9+xQaaZ//uubt7nvT0DuJldnddEbiOve+c czlmQihzaLOSsZpfte8Fbw6pw//mBXZbZX8udxgYVUz+I43tqtcz6Vu+2H8iCjeIBbAp qVLHHsBWg71rVd/9Q0D28cc80Q9g70DOgKjfjMcqMRrL7N4uuuENKbWLCPSQ/93NncK4 nIaMhq1v0QfddPXdr1U+7av4HN54Bs144U8VSvwtv1lEA+O4Xc2NYoXK/NVjJmmKiA57 6lkBA64kPILMbv61t2rNOLM9O4FHYKocp0uObqvNbzItYOp/pwspeYQBntpTo8Kd4vM4 Ae7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730986257; x=1731591057; 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=v/sPiX4msaWzkl3dC5zUiLMAXLFRKVpxYb5+istaczI=; b=AsAhs01fhepb6/csTRrG7DDHT/kLg687mTDNZripnwxAXggatAPQJLAgx5R9MzuO4v iMnbwByfTay9MQaTDjwXubP5mTsDozkqPQoJPVl56y9QO+OLoAFHpsznU8+jmrzD4dJr A/sM1ocTCvrtBJPeJXgc5Rpk8GaQk9cx0UA4lK0XsOA/s+S5w2grf/DRcGOcrAeKlQKs DzYeX/JfxYYHKR+KuHzrYI0Q32hWQNsKp+Lzi+t7XhFC5ZZ0/tbKkQXhzUFXQn2f4qO+ HfNkXUU07bUM/dj6zsITl5kGcDaqbVrQwtZS1frInNfAxDSq8SNPJWIgkEiYNTDOZqjV 1Xiw== X-Forwarded-Encrypted: i=1; AJvYcCVRJU3WEG6g8N/tts2JdOnmprF2BLHzuJfFj3/3RVlSJyw1h1ywUmDmPWNnylpmXmJACybVK4LveTN+b+tD6iw=@vger.kernel.org X-Gm-Message-State: AOJu0YxLDkwW4fj0ubHj1L+TNk0wk5ox/OKPF3/SOBjZngOmUUPKVddy 8iZ+9CY1fVEhpkYwOxdbnmAq+4PEC6ze2kKodJCsdo9jgkOAxnla3zDH3k5AQpo= X-Google-Smtp-Source: AGHT+IFRMc2iwIo5lsI6Tk3LdxarpcBShY9iMipSXsnnSJgSUBkktGhIsVkOAdRsmLaTWGO3LAHpNA== X-Received: by 2002:a05:6870:3648:b0:25e:e6d:5247 with SMTP id 586e51a60fabf-2949ed975c5mr20120367fac.14.1730986257211; Thu, 07 Nov 2024 05:30:57 -0800 (PST) Received: from nova-ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7f41f65b5afsm1359303a12.76.2024.11.07.05.30.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 05:30:56 -0800 (PST) From: Xiao Liang To: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Kuniyuki Iwashima , Jakub Kicinski Cc: "David S. Miller" , David Ahern , Eric Dumazet , Paolo Abeni , Ido Schimmel , Andrew Lunn , Simon Horman , Donald Hunter , Shuah Khan , Jiri Pirko , Hangbin Liu Subject: [PATCH net-next v2 7/8] tools/net/ynl: Add retry limit for async notification Date: Thu, 7 Nov 2024 21:30:02 +0800 Message-ID: <20241107133004.7469-8-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241107133004.7469-1-shaw.leon@gmail.com> References: <20241107133004.7469-1-shaw.leon@gmail.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Since commit 1bf70e6c3a53 ("tools/net/ynl: improve async notification handling"), check_ntf() would block indefinitely if there's no messages. In some cases we want to set a limit on waiting time. This patch adds max_reties parameter check_ntf(), and makes it stop when no message is recievied in that number of consecutive retries. Signed-off-by: Xiao Liang --- tools/net/ynl/lib/ynl.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py index 92f85698c50e..dff5166a4650 100644 --- a/tools/net/ynl/lib/ynl.py +++ b/tools/net/ynl/lib/ynl.py @@ -907,7 +907,8 @@ class YnlFamily(SpecFamily): msg['msg'] = attrs self.async_msg_queue.put(msg) - def check_ntf(self, interval=0.1): + def check_ntf(self, interval=0.1, max_retries=None): + retry = 0 while True: try: reply = self.sock.recv(self._recv_size, socket.MSG_DONTWAIT) @@ -933,7 +934,11 @@ class YnlFamily(SpecFamily): try: yield self.async_msg_queue.get_nowait() + retry = 0 except queue.Empty: + retry += 1 + if max_retries is not None and retry > max_retries: + return try: time.sleep(interval) except KeyboardInterrupt: From patchwork Thu Nov 7 13:30:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Liang X-Patchwork-Id: 13866485 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (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 3FB6B210188; Thu, 7 Nov 2024 13:31:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730986265; cv=none; b=P+IvhnwoyuH3G4/2BdTa4+Eu/Jw5/bgpiEDm4z7L7WdSqmMwSzI/rvvwVTRhl6h3iSuDYPWedbTNYCelYTqNVyZS1reQPR3+snShgm4OVNzc56kN28wv1nKTbtJQyXa73kGGsR8pXdrlMjn6rxpOnDFphocXwvxRNjVNBXYBuA0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730986265; c=relaxed/simple; bh=TTAXzMoR6prbPDyHf3K7ryf5DxLLy+uLbXyIgHqvYrE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QLkxohko2FyQqEhvsrXUZVI18Q0oCKfkY3BWFPEg5r1c6lmCvHYd1eijLOfql2CJ35d4tyjkZtdAwX/nIV8Kpt2/AFTq/rY1XdSiir64ZDZs2MlSacdUE42DHKtEiiF8VtPktZh3qmEDKFSmNuat96Ya2NK7GC28ZOpXsadf+ck= 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=UdTIQt93; arc=none smtp.client-ip=209.85.210.174 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="UdTIQt93" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-7240d93fffdso230052b3a.2; Thu, 07 Nov 2024 05:31:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730986262; x=1731591062; 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=ZIZzWn+nKvXmxLmxcEunwkkL//l0GlmBJ8eEaT50DUs=; b=UdTIQt93WGI1xTqJfS2i9v3514ImNEokfhvhdOhSHi6tCq4IUF/hZUctxhkp9yk4t7 yfVTaaWWrBZ5UfKsSO4pVED0v5vTqTadHsl08Px3mQyZGQA2KheohLFCB2EE7tVpoi6p 48yEB3/QpJl6cOUUYi8Dy0e4VkQi/4SuJtI6qUAQ6CofhNDuujfjRX0aLmENynNzlzPZ O/ZLTeqJJmZ8df6Rjv9IZs2h/C5iUT5t49Qsot9QO9m9InFqZvJWigNoPmzvP0SreSqA xCULtOBj43aTScb9TEtU/WrF8exTacRucDy23lYKfKe7ksLvio3auBvwYDgjjFUU8f6Y A1bQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730986262; x=1731591062; 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=ZIZzWn+nKvXmxLmxcEunwkkL//l0GlmBJ8eEaT50DUs=; b=PcEBz4R18+GhcEL7EZvo+1mY8EfDIxh8hJ6P5bNYdtiKc9F62YpnEyw4j/hKkLNJ8D tZ94CcdW2SuWHDAxZ7BouVkc9aXKyi0YWJ4M0t+EuU3pHRMuRyfKomNIxK+qVjTSutyr Ukjg0nzJuTFf5d0KOqTEFBF8DFhJ7admRsf8lsHyBa8+SlQIlYv+qqwhwxK5AEk9yyvz Uc4sZ9cEoiv/2YkfcZoxEi3sw2QQuTuaeum3X3t86eHKPk2PoT2hXIJx/Aah6yKmuxPq CjBU8WLfnfz4DhjNCNjjlDh3iAmdt3i3VTs4wbJqge1gJBsfNuvVtinZXX7Cyp3T+hUy cuyg== X-Forwarded-Encrypted: i=1; AJvYcCUYsnmQRDxeURr5iG2ntGVxCz+RyxCFTldlCi/Eao7lfxxjTiouWsqgLnjJLUqtJo8Aq7HEeRpGTPs9/h8gKXo=@vger.kernel.org X-Gm-Message-State: AOJu0YxIg8uuoOP4X7rX55S0b62VDl2KRFe3dbjoKUTqBX0ZkvcYkBdr HrwFvzngVtnogg8hq4l9YB+sxNzipkr5azBf2/6RzRcPSwqUEt1d6cePknHqjd8= X-Google-Smtp-Source: AGHT+IEh95nMdBX1+0rzwUpHOxUQK7Py9U7CAHY31MA+MJvL+BeTAvewl50HEbJcORXsi9Sf9tRzIg== X-Received: by 2002:a05:6a21:8985:b0:1dc:154a:81fb with SMTP id adf61e73a8af0-1dc17c4f723mr1075230637.44.1730986262550; Thu, 07 Nov 2024 05:31:02 -0800 (PST) Received: from nova-ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7f41f65b5afsm1359303a12.76.2024.11.07.05.30.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 05:31:02 -0800 (PST) From: Xiao Liang To: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Kuniyuki Iwashima , Jakub Kicinski Cc: "David S. Miller" , David Ahern , Eric Dumazet , Paolo Abeni , Ido Schimmel , Andrew Lunn , Simon Horman , Donald Hunter , Shuah Khan , Jiri Pirko , Hangbin Liu Subject: [PATCH net-next v2 8/8] selftests: net: Add two test cases for link netns Date: Thu, 7 Nov 2024 21:30:03 +0800 Message-ID: <20241107133004.7469-9-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241107133004.7469-1-shaw.leon@gmail.com> References: <20241107133004.7469-1-shaw.leon@gmail.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 - Add test for creating link in another netns when a link of the same name and ifindex exists in current netns. - Add test for netns_atomic - create link directly in target netns, and no notifications should be generated in current netns. Signed-off-by: Xiao Liang --- tools/testing/selftests/net/Makefile | 1 + tools/testing/selftests/net/netns-name.sh | 10 ++++ tools/testing/selftests/net/netns_atomic.py | 54 +++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100755 tools/testing/selftests/net/netns_atomic.py diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile index 26a4883a65c9..ba1a486f93dc 100644 --- a/tools/testing/selftests/net/Makefile +++ b/tools/testing/selftests/net/Makefile @@ -34,6 +34,7 @@ TEST_PROGS += gre_gso.sh TEST_PROGS += cmsg_so_mark.sh TEST_PROGS += cmsg_time.sh cmsg_ipv6.sh TEST_PROGS += netns-name.sh +TEST_PROGS += netns_atomic.py TEST_PROGS += nl_netdev.py TEST_PROGS += srv6_end_dt46_l3vpn_test.sh TEST_PROGS += srv6_end_dt4_l3vpn_test.sh diff --git a/tools/testing/selftests/net/netns-name.sh b/tools/testing/selftests/net/netns-name.sh index 6974474c26f3..0be1905d1f2f 100755 --- a/tools/testing/selftests/net/netns-name.sh +++ b/tools/testing/selftests/net/netns-name.sh @@ -78,6 +78,16 @@ ip -netns $NS link show dev $ALT_NAME 2> /dev/null && fail "Can still find alt-name after move" ip -netns $test_ns link del $DEV || fail +# +# Test no conflict of the same name/ifindex in different netns +# +ip -netns $NS link add name $DEV index 100 type dummy || fail +ip -netns $NS link add netns $test_ns name $DEV index 100 type dummy || + fail "Can create in netns without moving" +ip -netns $test_ns link show dev $DEV >> /dev/null || fail "Device not found" +ip -netns $NS link del $DEV || fail +ip -netns $test_ns link del $DEV || fail + echo -ne "$(basename $0) \t\t\t\t" if [ $RET_CODE -eq 0 ]; then echo "[ OK ]" diff --git a/tools/testing/selftests/net/netns_atomic.py b/tools/testing/selftests/net/netns_atomic.py new file mode 100755 index 000000000000..0a3864e22b8b --- /dev/null +++ b/tools/testing/selftests/net/netns_atomic.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +import ctypes + +from lib.py import ksft_run, ksft_exit, ksft_true +from lib.py import ip +from lib.py import NetNS +from lib.py import RtnlFamily + +libc = ctypes.cdll.LoadLibrary('libc.so.6') + + +class NSEnter: + def __init__(self, ns_name): + self.ns_path = f"/run/netns/{ns_name}" + + def __enter__(self): + self.saved = open("/proc/thread-self/ns/net") + with open(self.ns_path) as ns_file: + libc.setns(ns_file.fileno(), 0) + + def __exit__(self, exc_type, exc_value, traceback): + libc.setns(self.saved.fileno(), 0) + self.saved.close() + + +def test_event(ns1, ns2) -> None: + with NSEnter(str(ns1)): + rtnl = RtnlFamily() + + rtnl.ntf_subscribe("rtnlgrp-link") + + ip(f"netns set {ns1} 0", ns=str(ns2)) + + ip(f"link add netns {ns2} link-netnsid 0 dummy1 type dummy") + ip(f"link add netns {ns2} dummy2 type dummy", ns=str(ns1)) + + ip("link del dummy1", ns=str(ns2)) + ip("link del dummy2", ns=str(ns2)) + + # Should receive no link events in ns1. Wait 5*0.1 seconds. + ksft_true(next(rtnl.check_ntf(max_retries=5), None) is None, + "Received unexpected link notification") + + +def main() -> None: + with NetNS() as ns1, NetNS() as ns2: + ksft_run([test_event], args=(ns1, ns2)) + ksft_exit() + + +if __name__ == "__main__": + main()