From patchwork Mon Jan 13 14:37:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Liang X-Patchwork-Id: 857076 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 BA2DE2397BF; Mon, 13 Jan 2025 14:37:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736779069; cv=none; b=R9FdYnIMc3pQEOCITKlPXXBhYQR24P+6MWk8iyqa5WndYRoXfmEXYixG9p2UsxYbVBO5EtyZr2lFHndTShGN9XCLD5bCmSgwqyE+p8bECrj9zHFVVS1iEGWWm19PldK7RJnUZ5pZfulB7tx/bMouJ8tWYrnOOwSM3XSjL+SI0a4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736779069; c=relaxed/simple; bh=1RoOlxGJ2Sn6kgEHCY+FxkXtwcVhSAPqVZyj9KxB0EE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RwwTQZp0CGMdVaMEiUgAlGgdGe7pyUWH0T3+Rjwr7g1zrTz72zu1chA5mcsm9xax6v/chsiMICWYP3c4aYIrENPifDgteP4PYmGuu1Xmd+PIjLSedIjpTrE7mIG+3hdgDssmKWDavjaQxheqPROeMI0klhAmentjXkytqWso04c= 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=kixnE4u7; arc=none smtp.client-ip=209.85.214.177 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="kixnE4u7" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-2165cb60719so77851745ad.0; Mon, 13 Jan 2025 06:37:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736779066; x=1737383866; 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=aStnhmnU+u9WzYJvS9wSRsKutCltWxiDBFKzpdLaN7A=; b=kixnE4u7j4CxKmHe38ncW1VAPwhl9JI40my+hvEntMKz/Cm4clDrwcRWQAOYkYMSs1 jalfniK1aiHmM2Te+vM2A0koEXd+BugmA8FAys62oRgJ4E+wGerQ0DyHeA03yPNvPmBn Byl8B1ozIr8U/9Ltp5mcjZQh5QqxcMFZvnE0JDc9J92QH1DZyqhKFQc9ZvF4DVXVVqd1 lqn+F3d01Er4JIsLl+DZH/19tIJJb6Mls4kRW47md21WK4fTon76/4jwHXIRU3vez+eK LPACa80/Yep3eGSIGL3eeBA/05/aAhsSGQ5Re88sEYV2SBFFWHN641vB4zVCfmlsTwpd 3DeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736779066; x=1737383866; 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=aStnhmnU+u9WzYJvS9wSRsKutCltWxiDBFKzpdLaN7A=; b=qL9VuZNdkhOKzg0NvvNX7ac302963UxtOzv5nnENPLe8bTXv5bX7GO7vZr6HVSsPuQ pgZl4vFMVkZivShBrrwVZqdN34xGWWqenpJeBQCjpZUm7aZNp2GE0uEube+RgqxlM2ie k9yxPCQcamzy5EJzhtJdsI/pi/oWTPNUtZXg3Z7SYx+Fnu9XlXKA/6uYkTyiJwZHWLbG 5y1eRLzbQQMiX5h3rPyT8JMcdjO+GwuJ8HcaRIVxNGKOPPuXLGR/5Llu/jMYxnVshdyY LJMjT4x87UNFppTZnYxL5QD2GufsWilKTPrcvfcsXZGI4rhBbzQJGXl0guNYyhKs+yO1 hzLQ== X-Forwarded-Encrypted: i=1; AJvYcCU0wRAGsDry2pZT2YrphN9gGrfqTaF7MPWyiYTo+vulK5AkjwNT9H+kv9N2Y2s3VqywEriwAzKhjj/P@vger.kernel.org, AJvYcCUKb0wo+tvKXgb3uI0l2Wz09TU5d3AdOj6fSvKyYEikt9J5Q+DgnBo7leS3lROL7i3u4pfdHcERhV9ZU1z6fAkb@vger.kernel.org, AJvYcCUZ6IFBAac+R3bM8V9pERNBqHyVB83gPvIzKc1GYOVmQChskE5+DLai5OAm1qGbt7RsdXbEubgoZboP5y74Uls=@vger.kernel.org, AJvYcCV+adA/qdbX+P1jlLOj6eMmLiweIRweTZc+WgOeq4lOiiFxfhDFUmhkeXnLaMpQIIH+fyrpzEIdj3d4DKDv@vger.kernel.org, AJvYcCVPhcX5xcNl2GgxXmGE1lrd1BIwSSs8XPM3FdO+53WAiXnGBbgyo5cer6/32LrlZ1T27LE/57//vn3/@vger.kernel.org, AJvYcCVcH5AX0wNe3852401/JfpM0E8mdfDYalbWWUtDZKGGtMMeeuwfFpmWkXSVpHdUCA3IyA4VTXbXd8cYUg==@vger.kernel.org, AJvYcCXXIFOanl1R0GnVgHeBRNOa0O/Wtxt5gEtHF7lT+75GdcIzh1VRywMxBYC6cHVwdGYQ1Oo=@vger.kernel.org, AJvYcCXY/uSxWP7uaLsuEwlz+w1NXWBYp0wL/RenwO2t/CVEI3PnW6wAoIkaHi66rFHa86FjHOlK9jSEkFbqzg==@vger.kernel.org X-Gm-Message-State: AOJu0YzSbjOPc0QBJ9pRF4pE2eeNavmtHNWqrfgGzh1xrSED8nwwKrLX rRpggr5uFkQ4Kq7/pJGO7X5dZEzO60VrAkEf2+/leb29qGH8FJbmwTe9SGwBIpw= X-Gm-Gg: ASbGncuKttoRMBd8lRpINXdxGv4kd2lFplRhs6Ggp91IHcaADqeRq1+RRdUQPCelUR/ HhmKfxtOSwCyrxb0Y1NzcFlu9bsWV/fpHtFBb1TvNm0pism3y7iaMahZqZTKmBr0TaS2jV/vnCE ifTo/LZbd21XojGd3tjIq/wl23aA2IsvYqobRde9DNig/kdAmp7KCQugjMQb4AwHZm0RBcNE0xT WIDYZteUyWmXMKlo51/WNartOitcVozWIguLGdvd26J3/4= X-Google-Smtp-Source: AGHT+IEEIzRcAyOPsqmoPyg3LqUO10MpSinA1zy4f8+lVawQb15WuSETw63Trl8RPwnuvmvDM8k1Dw== X-Received: by 2002:a17:902:e74e:b0:215:aee1:7e3e with SMTP id d9443c01a7336-21a83f36d48mr318259495ad.5.1736779066532; Mon, 13 Jan 2025 06:37:46 -0800 (PST) Received: from ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f155e00sm54328715ad.103.2025.01.13.06.37.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 06:37: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 , Andrew Lunn , Simon Horman , Shuah Khan , Donald Hunter , Alexander Aring , Stefan Schmidt , Miquel Raynal , Steffen Klassert , Herbert Xu , linux-rdma@vger.kernel.org, linux-can@vger.kernel.org, osmocom-net-gprs@lists.osmocom.org, bpf@vger.kernel.org, linux-ppp@vger.kernel.org, wireguard@lists.zx2c4.com, linux-wireless@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org, bridge@lists.linux.dev, linux-wpan@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v8 01/11] rtnetlink: Lookup device in target netns when creating link Date: Mon, 13 Jan 2025 22:37:09 +0800 Message-ID: <20250113143719.7948-2-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250113143719.7948-1-shaw.leon@gmail.com> References: <20250113143719.7948-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 1f4d4b5570ab..ec98349b9620 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -3861,20 +3861,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 Mon Jan 13 14:37:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Liang X-Patchwork-Id: 857075 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.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 13DE124633B; Mon, 13 Jan 2025 14:38:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736779088; cv=none; b=YtyXWrCAyyW9UPsGhveXIXFT7g8ta7m/OIy4vx5jZ1DDxEWj+fl53ABGPnPtfz5Ers9/f4jvglqC6laaVg5S/IVdMAhJ0K7t2dDIN0vRxsrdnCN6GlxhKS3xtfZAWebP8XkcIJtriy9hz9jOIz39cjTYwH4wdEsHp8iGcFaa/K0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736779088; c=relaxed/simple; bh=yVXZazNTD2EBAWknl/LWkjWGKnNjfNLy9fPEJ6+d1rc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Om4MinTlDxz3G0E7SzffK/e839bMHdsTzRzuO3vdhIssooQDfRs87NGGlMXjyP3C6Hk3TV5X4bxWeZWw2tj4lLUGLNRH0U+5eDDBHFiEUykV1IBRgv9GGPHX8GMhqJtzk5bbatPHrNt9umPnO/w5Gb55xRzKNFbQMWRwzs9UywA= 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=WXaf42pl; arc=none smtp.client-ip=209.85.214.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="WXaf42pl" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-2163b0c09afso78914825ad.0; Mon, 13 Jan 2025 06:38:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736779084; x=1737383884; 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=LZBCyw57IE7Zso6/WsMTOb7GBu1vP4ikeykgITmoGTY=; b=WXaf42pliAXm7S2hpDW6Y50VJZyXP3nvAsohzdfG/FQwrTQQNC6qhuBc2DK5nLJpBt aST/j5jIhKYoMnt2Br4UIFHJYdLE8Q9r8BYPAUovI4j4EN1K0EB3aep/tFajE5n1Nhjm HLuNicT/DFMcw5W22vgkSCp4YB0s9pfZLThlQdsOPUrA3UUFq7b7i/ILZPpmUxCBrXmY +hQF01Dd4CGE32IbGWWGFxgKNIFahlVsVAS36x1hNUbB6fvikc+PvhxtH2I+kxaV+Ndm OA3AWchpBvOb1u8GUM6NS/KhrLSlov3wrpLhc4rd5PJbpyRiacwt6U6pdpmheiW/1r/+ OJbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736779084; x=1737383884; 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=LZBCyw57IE7Zso6/WsMTOb7GBu1vP4ikeykgITmoGTY=; b=ezZpZFe6rJ009dvDMl2+AINVfA/THqMF9yZSqw6tdtcm8l0+OZ1mQGLBI/R7CGJ1w3 RhDBSv3kuodFNNkcpj/3tNcwu3UkfRLTx/T9HPn2aF/eAU5GJziyMFEJxJW2/6A1+K7A QPqdQchNQaYY7U2oEYQNAbsuGpOHxo30+kZwBPe63YhhmpYS1vhML/8yt6rrp3NKXX4f ++h9zgGPdWTfWSeSRP5wlTnYd9gwO0nmmTHLZqGHlmBEQMIFker4HYMxZOlDEz1oz519 EwLLxkojsIfUymAPRgU7GRgtqoQjJNmlXx7JT/gezwMzUJem+MkoQp0GtfiLGBPC+Kyd 3eXQ== X-Forwarded-Encrypted: i=1; AJvYcCUDrD4Oix9RrrIxxidzHG0vYDg1S/iS/hdvBp0QhmVaoxUuM4oM1Xwq9ANtzO59L/5BJVqtI8qxGf6OYoM5r4RF@vger.kernel.org, AJvYcCUqd+cCn/MzZu4gciqOA9KaDg8kA6JOWMaVVAtJQwzTbPjMe/OqiWxnxG4WX8K4IwVYoERK0m+lUg6J@vger.kernel.org, AJvYcCVBU+D/J6dMuNMHX81KXaRiy68XcLCQWRoL1URptgfbP3+Nlxj8fJJ5Z6M9kdYgdG1MnzQ=@vger.kernel.org, AJvYcCVQAyqTntfopVU8owlO4Vpwl2MYUKbZcuoMmlTScygEAslQDrzUbomF0y9KhobljvUpBfQiDJ2HfWYK@vger.kernel.org, AJvYcCVmpp65t6x+HXGgeZzHTFFw4CD5n5JkiAjxharKd3GTsut/sdzvlDFaJLj4QMsSBgvAMcfQLsFOYeR8QVuA@vger.kernel.org, AJvYcCVoVA7mUaJ9eN7vthXp5aYC9Tg1J7keRNzcodoQ4SAB5fxD03iVpMHE1Hr0oDpyEyRPsClhsd44IPgInQ==@vger.kernel.org, AJvYcCWGT6SnKvdojOPbFrwcZ+3SCRQhfArNyGZFOOwmSnxPpUzxUxgeDxTqXWSJo39oS8Z1S2M8wdJRbNwKvg==@vger.kernel.org, AJvYcCWnOLOfHoClGKsRI9FaVj6EFEg+K0zyJO5V5KePVlgyofn2cPwJIfnWBkyRPk7L9Cvn6xHTd290fmPhKTUxvtc=@vger.kernel.org X-Gm-Message-State: AOJu0YxeU/4C+ATvrglbabxKJNL9fj5ONv9LPiEK+OqHttPLW7h9TMgU xxP6uZWBuOsEB8/394g6m69dJ+dx4+SIArAMrRhdOkkexKe0lo5ggh3GkoikL6k= X-Gm-Gg: ASbGncviWypHVfx51Ts138AHQFDkyQX0o21diRdjXm4xA+AvwTxoM6HryJfY2RDg3YX 1p9rPQ2rqkKqBW/GDpN4sX3ccskqubbDJFFyjj47uB7GpdsBZ3nDvMmWqj5AOHhrLh9lXXM743c V8mKPg3wPkbysaJlY//447Hmd37zmBObTuKI1VoJxjNa/7XSgUBmJTShcQJOGE+sNCoO69Ltz7d 5cMovbHNlsQRSDrEuaLX/WK00sch9kDgHxtRoGxnp8EAvU= X-Google-Smtp-Source: AGHT+IE+8qVbma2Qb/CZO5qK/8pf/aA+GET4Kf+ksPfd0XQFxcjbmABnzOsLzbZBSWi1j8h4JBn4Hg== X-Received: by 2002:a17:903:32ce:b0:215:b8c6:338a with SMTP id d9443c01a7336-21a83f338a5mr322037415ad.4.1736779084410; Mon, 13 Jan 2025 06:38:04 -0800 (PST) Received: from ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f155e00sm54328715ad.103.2025.01.13.06.37.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 06:38:03 -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 , Andrew Lunn , Simon Horman , Shuah Khan , Donald Hunter , Alexander Aring , Stefan Schmidt , Miquel Raynal , Steffen Klassert , Herbert Xu , linux-rdma@vger.kernel.org, linux-can@vger.kernel.org, osmocom-net-gprs@lists.osmocom.org, bpf@vger.kernel.org, linux-ppp@vger.kernel.org, wireguard@lists.zx2c4.com, linux-wireless@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org, bridge@lists.linux.dev, linux-wpan@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v8 03/11] net: Use link netns in newlink() of rtnl_link_ops Date: Mon, 13 Jan 2025 22:37:11 +0800 Message-ID: <20250113143719.7948-4-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250113143719.7948-1-shaw.leon@gmail.com> References: <20250113143719.7948-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 These netdevice drivers already uses netns parameter in newlink() callback. Convert them to use rtnl_newlink_link_net() or rtnl_newlink_peer_net() for clarity and deprecate params->net. Signed-off-by: Xiao Liang --- drivers/infiniband/ulp/ipoib/ipoib_netlink.c | 4 ++-- drivers/net/amt.c | 6 +++--- drivers/net/bareudp.c | 4 ++-- drivers/net/can/vxcan.c | 2 +- drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c | 4 ++-- drivers/net/geneve.c | 4 ++-- drivers/net/gtp.c | 4 ++-- drivers/net/ipvlan/ipvlan_main.c | 4 ++-- drivers/net/macsec.c | 4 ++-- drivers/net/macvlan.c | 4 ++-- drivers/net/macvtap.c | 4 ++-- drivers/net/netkit.c | 2 +- drivers/net/pfcp.c | 4 ++-- drivers/net/ppp/ppp_generic.c | 4 ++-- drivers/net/veth.c | 2 +- drivers/net/vxlan/vxlan_core.c | 4 ++-- drivers/net/wireguard/device.c | 4 ++-- drivers/net/wireless/virtual/virt_wifi.c | 4 ++-- drivers/net/wwan/wwan_core.c | 2 +- net/8021q/vlan_netlink.c | 4 ++-- net/hsr/hsr_netlink.c | 8 ++++---- 21 files changed, 41 insertions(+), 41 deletions(-) diff --git a/drivers/infiniband/ulp/ipoib/ipoib_netlink.c b/drivers/infiniband/ulp/ipoib/ipoib_netlink.c index 16cb8ced9f35..53db7c8191e3 100644 --- a/drivers/infiniband/ulp/ipoib/ipoib_netlink.c +++ b/drivers/infiniband/ulp/ipoib/ipoib_netlink.c @@ -101,8 +101,8 @@ static int ipoib_new_child_link(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + struct net *link_net = rtnl_newlink_link_net(params); struct nlattr **data = params->data; - struct net *src_net = params->net; struct nlattr **tb = params->tb; struct net_device *pdev; struct ipoib_dev_priv *ppriv; @@ -112,7 +112,7 @@ static int ipoib_new_child_link(struct net_device *dev, if (!tb[IFLA_LINK]) return -EINVAL; - pdev = __dev_get_by_index(src_net, nla_get_u32(tb[IFLA_LINK])); + pdev = __dev_get_by_index(link_net, nla_get_u32(tb[IFLA_LINK])); if (!pdev || pdev->type != ARPHRD_INFINIBAND) return -ENODEV; diff --git a/drivers/net/amt.c b/drivers/net/amt.c index 96b7ec9a2c13..53899b70fae1 100644 --- a/drivers/net/amt.c +++ b/drivers/net/amt.c @@ -3165,13 +3165,13 @@ static int amt_newlink(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + struct net *link_net = rtnl_newlink_link_net(params); struct amt_dev *amt = netdev_priv(dev); struct nlattr **data = params->data; struct nlattr **tb = params->tb; - struct net *net = params->net; int err = -EINVAL; - amt->net = net; + amt->net = link_net; amt->mode = nla_get_u32(data[IFLA_AMT_MODE]); if (data[IFLA_AMT_MAX_TUNNELS] && @@ -3186,7 +3186,7 @@ static int amt_newlink(struct net_device *dev, amt->hash_buckets = AMT_HSIZE; amt->nr_tunnels = 0; get_random_bytes(&amt->hash_seed, sizeof(amt->hash_seed)); - amt->stream_dev = dev_get_by_index(net, + amt->stream_dev = dev_get_by_index(link_net, nla_get_u32(data[IFLA_AMT_LINK])); if (!amt->stream_dev) { NL_SET_ERR_MSG_ATTR(extack, tb[IFLA_AMT_LINK], diff --git a/drivers/net/bareudp.c b/drivers/net/bareudp.c index fc21dcfb4848..d1473c5f8eef 100644 --- a/drivers/net/bareudp.c +++ b/drivers/net/bareudp.c @@ -702,9 +702,9 @@ static int bareudp_newlink(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + struct net *link_net = rtnl_newlink_link_net(params); struct nlattr **data = params->data; struct nlattr **tb = params->tb; - struct net *net = params->net; struct bareudp_conf conf; int err; @@ -712,7 +712,7 @@ static int bareudp_newlink(struct net_device *dev, if (err) return err; - err = bareudp_configure(net, dev, &conf, extack); + err = bareudp_configure(link_net, dev, &conf, extack); if (err) return err; diff --git a/drivers/net/can/vxcan.c b/drivers/net/can/vxcan.c index 6f8ebb1cfd7b..99a78a757167 100644 --- a/drivers/net/can/vxcan.c +++ b/drivers/net/can/vxcan.c @@ -176,8 +176,8 @@ static int vxcan_newlink(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + struct net *peer_net = rtnl_newlink_peer_net(params); struct nlattr **data = params->data; - struct net *peer_net = params->net; struct nlattr **tb = params->tb; struct vxcan_priv *priv; struct net_device *peer; diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c index 8151e91395e2..ab7e5b6649b2 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c @@ -122,8 +122,8 @@ static int rmnet_newlink(struct net_device *dev, struct netlink_ext_ack *extack) { u32 data_format = RMNET_FLAGS_INGRESS_DEAGGREGATION; + struct net *link_net = rtnl_newlink_link_net(params); struct nlattr **data = params->data; - struct net *src_net = params->net; struct nlattr **tb = params->tb; struct net_device *real_dev; int mode = RMNET_EPMODE_VND; @@ -137,7 +137,7 @@ static int rmnet_newlink(struct net_device *dev, return -EINVAL; } - real_dev = __dev_get_by_index(src_net, nla_get_u32(tb[IFLA_LINK])); + real_dev = __dev_get_by_index(link_net, nla_get_u32(tb[IFLA_LINK])); if (!real_dev) { NL_SET_ERR_MSG_MOD(extack, "link does not exist"); return -ENODEV; diff --git a/drivers/net/geneve.c b/drivers/net/geneve.c index d373a851930c..c7700deefb00 100644 --- a/drivers/net/geneve.c +++ b/drivers/net/geneve.c @@ -1618,9 +1618,9 @@ static int geneve_newlink(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + struct net *link_net = rtnl_newlink_link_net(params); struct nlattr **data = params->data; struct nlattr **tb = params->tb; - struct net *net = params->net; struct geneve_config cfg = { .df = GENEVE_DF_UNSET, .use_udp6_rx_checksums = false, @@ -1634,7 +1634,7 @@ static int geneve_newlink(struct net_device *dev, if (err) return err; - err = geneve_configure(net, dev, extack, &cfg); + err = geneve_configure(link_net, dev, extack, &cfg); if (err) return err; diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c index 80ad618ba423..646d0fdd42f4 100644 --- a/drivers/net/gtp.c +++ b/drivers/net/gtp.c @@ -1464,8 +1464,8 @@ static int gtp_newlink(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + struct net *link_net = rtnl_newlink_link_net(params); struct nlattr **data = params->data; - struct net *src_net = params->net; unsigned int role = GTP_ROLE_GGSN; struct gtp_dev *gtp; struct gtp_net *gn; @@ -1496,7 +1496,7 @@ static int gtp_newlink(struct net_device *dev, gtp->restart_count = nla_get_u8_default(data[IFLA_GTP_RESTART_COUNT], 0); - gtp->net = src_net; + gtp->net = link_net; err = gtp_hashtable_new(gtp, hashsize); if (err < 0) diff --git a/drivers/net/ipvlan/ipvlan_main.c b/drivers/net/ipvlan/ipvlan_main.c index 19ce19ca7e32..b56144ca2fde 100644 --- a/drivers/net/ipvlan/ipvlan_main.c +++ b/drivers/net/ipvlan/ipvlan_main.c @@ -535,9 +535,9 @@ static int ipvlan_nl_fillinfo(struct sk_buff *skb, int ipvlan_link_new(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + struct net *link_net = rtnl_newlink_link_net(params); struct ipvl_dev *ipvlan = netdev_priv(dev); struct nlattr **data = params->data; - struct net *src_net = params->net; struct nlattr **tb = params->tb; struct ipvl_port *port; struct net_device *phy_dev; @@ -547,7 +547,7 @@ int ipvlan_link_new(struct net_device *dev, struct rtnl_newlink_params *params, if (!tb[IFLA_LINK]) return -EINVAL; - phy_dev = __dev_get_by_index(src_net, nla_get_u32(tb[IFLA_LINK])); + phy_dev = __dev_get_by_index(link_net, nla_get_u32(tb[IFLA_LINK])); if (!phy_dev) return -ENODEV; diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c index 1869b0513f57..4de5d63fd577 100644 --- a/drivers/net/macsec.c +++ b/drivers/net/macsec.c @@ -4145,10 +4145,10 @@ static int macsec_newlink(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + struct net *link_net = rtnl_newlink_link_net(params); struct macsec_dev *macsec = macsec_priv(dev); struct nlattr **data = params->data; struct nlattr **tb = params->tb; - struct net *net = params->net; rx_handler_func_t *rx_handler; u8 icv_len = MACSEC_DEFAULT_ICV_LEN; struct net_device *real_dev; @@ -4157,7 +4157,7 @@ static int macsec_newlink(struct net_device *dev, if (!tb[IFLA_LINK]) return -EINVAL; - real_dev = __dev_get_by_index(net, nla_get_u32(tb[IFLA_LINK])); + real_dev = __dev_get_by_index(link_net, nla_get_u32(tb[IFLA_LINK])); if (!real_dev) return -ENODEV; if (real_dev->type != ARPHRD_ETHER) diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c index 0c496aa1f706..689759bbd159 100644 --- a/drivers/net/macvlan.c +++ b/drivers/net/macvlan.c @@ -1569,8 +1569,8 @@ static int macvlan_newlink(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { - return macvlan_common_newlink(params->net, dev, params->tb, - params->data, extack); + return macvlan_common_newlink(rtnl_newlink_link_net(params), dev, + params->tb, params->data, extack); } void macvlan_dellink(struct net_device *dev, struct list_head *head) diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c index 6dbfeeac5c99..ee1bfd4298c2 100644 --- a/drivers/net/macvtap.c +++ b/drivers/net/macvtap.c @@ -105,8 +105,8 @@ static int macvtap_newlink(struct net_device *dev, /* Don't put anything that may fail after macvlan_common_newlink * because we can't undo what it does. */ - err = macvlan_common_newlink(params->net, dev, params->tb, params->data, - extack); + err = macvlan_common_newlink(rtnl_newlink_link_net(params), dev, + params->tb, params->data, extack); if (err) { netdev_rx_handler_unregister(dev); return err; diff --git a/drivers/net/netkit.c b/drivers/net/netkit.c index 1e9eadc77da2..d278d7697cee 100644 --- a/drivers/net/netkit.c +++ b/drivers/net/netkit.c @@ -331,8 +331,8 @@ static int netkit_new_link(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + struct net *peer_net = rtnl_newlink_peer_net(params); struct nlattr **data = params->data; - struct net *peer_net = params->net; struct nlattr **tb = params->tb; struct nlattr *peer_tb[IFLA_MAX + 1], **tbp = tb, *attr; enum netkit_action policy_prim = NETKIT_PASS; diff --git a/drivers/net/pfcp.c b/drivers/net/pfcp.c index d9e4b5185c51..33eaded152ce 100644 --- a/drivers/net/pfcp.c +++ b/drivers/net/pfcp.c @@ -188,12 +188,12 @@ static int pfcp_newlink(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + struct net *link_net = rtnl_newlink_link_net(params); struct pfcp_dev *pfcp = netdev_priv(dev); - struct net *net = params->net; struct pfcp_net *pn; int err; - pfcp->net = net; + pfcp->net = link_net; err = pfcp_add_sock(pfcp); if (err) { diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c index b3340f8a6149..6220866258fc 100644 --- a/drivers/net/ppp/ppp_generic.c +++ b/drivers/net/ppp/ppp_generic.c @@ -1307,8 +1307,8 @@ static int ppp_nl_newlink(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + struct net *link_net = rtnl_newlink_link_net(params); struct nlattr **data = params->data; - struct net *src_net = params->net; struct nlattr **tb = params->tb; struct ppp_config conf = { .unit = -1, @@ -1346,7 +1346,7 @@ static int ppp_nl_newlink(struct net_device *dev, if (!tb[IFLA_IFNAME] || !nla_len(tb[IFLA_IFNAME]) || !*(char *)nla_data(tb[IFLA_IFNAME])) conf.ifname_is_set = false; - err = ppp_dev_configure(src_net, dev, &conf); + err = ppp_dev_configure(link_net, dev, &conf); out_unlock: mutex_unlock(&ppp_mutex); diff --git a/drivers/net/veth.c b/drivers/net/veth.c index 7dfda89f072f..ba3ae2d8092f 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -1769,8 +1769,8 @@ static int veth_newlink(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + struct net *peer_net = rtnl_newlink_peer_net(params); struct nlattr **data = params->data; - struct net *peer_net = params->net; struct nlattr **tb = params->tb; int err; struct net_device *peer; diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c index 86c620b4c26f..cd0964823864 100644 --- a/drivers/net/vxlan/vxlan_core.c +++ b/drivers/net/vxlan/vxlan_core.c @@ -4397,8 +4397,8 @@ static int vxlan_newlink(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + struct net *link_net = rtnl_newlink_link_net(params); struct nlattr **data = params->data; - struct net *src_net = params->net; struct nlattr **tb = params->tb; struct vxlan_config conf; int err; @@ -4407,7 +4407,7 @@ static int vxlan_newlink(struct net_device *dev, if (err) return err; - return __vxlan_dev_create(src_net, dev, &conf, extack); + return __vxlan_dev_create(link_net, dev, &conf, extack); } static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[], diff --git a/drivers/net/wireguard/device.c b/drivers/net/wireguard/device.c index 404cf05bd72b..c496d35b266d 100644 --- a/drivers/net/wireguard/device.c +++ b/drivers/net/wireguard/device.c @@ -311,11 +311,11 @@ static int wg_newlink(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + struct net *link_net = rtnl_newlink_link_net(params); struct wg_device *wg = netdev_priv(dev); - struct net *src_net = params->net; int ret = -ENOMEM; - rcu_assign_pointer(wg->creating_net, src_net); + rcu_assign_pointer(wg->creating_net, link_net); init_rwsem(&wg->static_identity.lock); mutex_init(&wg->socket_update_lock); mutex_init(&wg->device_update_lock); diff --git a/drivers/net/wireless/virtual/virt_wifi.c b/drivers/net/wireless/virtual/virt_wifi.c index 26905b2b3ba3..f9d11a023313 100644 --- a/drivers/net/wireless/virtual/virt_wifi.c +++ b/drivers/net/wireless/virtual/virt_wifi.c @@ -524,7 +524,7 @@ static int virt_wifi_newlink(struct net_device *dev, struct netlink_ext_ack *extack) { struct virt_wifi_netdev_priv *priv = netdev_priv(dev); - struct net *src_net = params->net; + struct net *link_net = rtnl_newlink_link_net(params); struct nlattr **tb = params->tb; int err; @@ -534,7 +534,7 @@ static int virt_wifi_newlink(struct net_device *dev, netif_carrier_off(dev); priv->upperdev = dev; - priv->lowerdev = __dev_get_by_index(src_net, + priv->lowerdev = __dev_get_by_index(link_net, nla_get_u32(tb[IFLA_LINK])); if (!priv->lowerdev) diff --git a/drivers/net/wwan/wwan_core.c b/drivers/net/wwan/wwan_core.c index 53a6c437ff79..34e34bc3ae94 100644 --- a/drivers/net/wwan/wwan_core.c +++ b/drivers/net/wwan/wwan_core.c @@ -1068,7 +1068,7 @@ static void wwan_create_default_link(struct wwan_device *wwandev, struct nlmsghdr *nlh; struct sk_buff *msg; struct rtnl_newlink_params params = { - .net = &init_net, + .src_net = &init_net, .tb = tb, .data = data, }; diff --git a/net/8021q/vlan_netlink.c b/net/8021q/vlan_netlink.c index 91df0f96e32a..a000b1ef0520 100644 --- a/net/8021q/vlan_netlink.c +++ b/net/8021q/vlan_netlink.c @@ -139,9 +139,9 @@ static int vlan_newlink(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + struct net *link_net = rtnl_newlink_link_net(params); struct vlan_dev_priv *vlan = vlan_dev_priv(dev); struct nlattr **data = params->data; - struct net *src_net = params->net; struct nlattr **tb = params->tb; struct net_device *real_dev; unsigned int max_mtu; @@ -158,7 +158,7 @@ static int vlan_newlink(struct net_device *dev, return -EINVAL; } - real_dev = __dev_get_by_index(src_net, nla_get_u32(tb[IFLA_LINK])); + real_dev = __dev_get_by_index(link_net, nla_get_u32(tb[IFLA_LINK])); if (!real_dev) { NL_SET_ERR_MSG_MOD(extack, "link does not exist"); return -ENODEV; diff --git a/net/hsr/hsr_netlink.c b/net/hsr/hsr_netlink.c index 39add538ba99..b120470246cc 100644 --- a/net/hsr/hsr_netlink.c +++ b/net/hsr/hsr_netlink.c @@ -33,8 +33,8 @@ static int hsr_newlink(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + struct net *link_net = rtnl_newlink_link_net(params); struct nlattr **data = params->data; - struct net *src_net = params->net; enum hsr_version proto_version; unsigned char multicast_spec; u8 proto = HSR_PROTOCOL_HSR; @@ -48,7 +48,7 @@ static int hsr_newlink(struct net_device *dev, NL_SET_ERR_MSG_MOD(extack, "Slave1 device not specified"); return -EINVAL; } - link[0] = __dev_get_by_index(src_net, + link[0] = __dev_get_by_index(link_net, nla_get_u32(data[IFLA_HSR_SLAVE1])); if (!link[0]) { NL_SET_ERR_MSG_MOD(extack, "Slave1 does not exist"); @@ -58,7 +58,7 @@ static int hsr_newlink(struct net_device *dev, NL_SET_ERR_MSG_MOD(extack, "Slave2 device not specified"); return -EINVAL; } - link[1] = __dev_get_by_index(src_net, + link[1] = __dev_get_by_index(link_net, nla_get_u32(data[IFLA_HSR_SLAVE2])); if (!link[1]) { NL_SET_ERR_MSG_MOD(extack, "Slave2 does not exist"); @@ -71,7 +71,7 @@ static int hsr_newlink(struct net_device *dev, } if (data[IFLA_HSR_INTERLINK]) - interlink = __dev_get_by_index(src_net, + interlink = __dev_get_by_index(link_net, nla_get_u32(data[IFLA_HSR_INTERLINK])); if (interlink && interlink == link[0]) { From patchwork Mon Jan 13 14:37:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Liang X-Patchwork-Id: 857074 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 C24C3246355; Mon, 13 Jan 2025 14:38:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736779104; cv=none; b=OGAJUkd6YCuoVYtsvE+wNoDs+p0CPYAT7Hxek9520tqirhy6/dZpqxXg+Eugjj6WmmiUq2zxXz1Yjv1aRna7yS+H2PMaOIw1qe30rMcqvLp/3Nq6Jno8YGmgbwwBHJSbiP/S/AMln+EyO9iFIARJ9y07KKHS6A87g8KFMtBCbPg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736779104; c=relaxed/simple; bh=4+uj3n3qzLmPEBfggnLAVLnO/V0f9mUleOD9sy+kwQs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BpaBH6K1KHBBhrr6mYhcGI6pc6e9wsN1dhOqQWyBmts0m3p6pdpqXn7ZwlacAqKDcOCv3b8OKeGptQQxo6qD7WoR79s6UbQZY324h2pMzdZ8c4tX/Juzs0UAi6V3c5MybSbHf2XzpDGM26mVX40q3BV+knqi/SIATV+RXJGhaM4= 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=bfnzCE6R; arc=none smtp.client-ip=209.85.214.179 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="bfnzCE6R" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-215770613dbso52931945ad.2; Mon, 13 Jan 2025 06:38:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736779102; x=1737383902; 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=v2hr3iCsVwpwP1Nzlez7XTECQN7gMZZquvojvDybmoY=; b=bfnzCE6RhkR3mH6HdaywSfC0r2ONa7vLfi4KQ1j0U7zFOFANx1MxyxXEY8+b2v365A N0Jflc1WZJ5hmV7pxrVA+h0Wc3B4SvJg+eRTLCydrRuH166XGrbqi/pIdCLtOu6S6KBZ ukFrNEKme98YWNM0ZwwDxD5uYt7GANZN9cP+XYsbH/yq+pumW00j97fQuU21W6ApcDVx pDviWZ7nTyPyJqiDLf3D4T66TsI+ilZ18QXzZEQwwM4RFcEDf4zQ4LIukp81s7bJBvrv hjoLBcrpiKKgYSjHFa9+VEwcSCj49kOIFpYtjAQDuoA7PXYZRJJ4AKNqB7kGngmJN5Yh ZrsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736779102; x=1737383902; 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=v2hr3iCsVwpwP1Nzlez7XTECQN7gMZZquvojvDybmoY=; b=ZGb7oeutrBpcI3FsMnm/H0p9pilZfifLWSJzgwr/OuNQzcyGNJMdCLMAxB710a1pnC 9L356jOPMPxkLZwADFG1psCXKb3IbqCJq9HHjdqxn/Qe1KyGgEifFcF5AXel8wUXG4SU OhymppWKWLDTdS90vUPkSxLk+5zAPqgbs/48mW+/1l93C7vc8eFAA9bNp5GjKXXCDmgO kxJi+9+1L4wEpaqGo20b3+3vf+3sL+M2Fi3EKIRBKrpb8bOpr/ojFWKfGblv5Gis217P 6fBy0poCaUmQgPFcwGLzmS0AC83LRn8SL2NCInhWJQiL4J541Ac/h3tIifY9oybqZgD2 cJ/g== X-Forwarded-Encrypted: i=1; AJvYcCUUkcKgY0Jt9rEXZvt//Aw/Ch8Fw+B7Vy8gTHkhUZ3OzRGkCi4oAMEarH49gJ8YKrdAKauCUmsCioViHySJgElm@vger.kernel.org, AJvYcCUZfygCc3aQo5/TJ3hzGaR7PLbe443xngGTMBz19+Rg8o9zANOHwl6450BZxbKSAx3OIKc=@vger.kernel.org, AJvYcCVAheS3YNo1fhOK1dYOX8rjrPuEvjV7RRkctcgEMFR+t1wAie96d1iZJJey0A0pWxjsP4LPKMX7nvBcHg==@vger.kernel.org, AJvYcCVQ04dilNbo0YfI/FoBBiDoqowcx80Wanqj5MomQP7o6ZS560NmVqvp0d7SBIFFOZGUUolPQwFjHZqz@vger.kernel.org, AJvYcCVikUMBBw8TEmlKxsfNJz7spR89TBbG/y8SFRvv9hwhJAp5utqE12Q/NjVWLmYXzbDnZ+SM/t6MT6G8besHKQU=@vger.kernel.org, AJvYcCWYqpM1we9bZr7ImhMd3jGNr/i6HmKDqc19gtsY8mOhUT6WzMqAEInsyZqvQgi/kd8t4BrB6R8NEkRR@vger.kernel.org, AJvYcCWn40lY4Mp0J1FkGEQTuczwuTQ03xTw5dw3Q94tvYeGjkcUa9lc22XVY8gSJoobh9FG/R5OYbIdgUBDnQ==@vger.kernel.org, AJvYcCXwKgKUFtbKx9gIwMYW8VUdzVEN0Qx/uHLQKD7G2lSZN0VV7ke4WU0i2jhqb6WhR3h8s2nJIa/V5fsa2mJZ@vger.kernel.org X-Gm-Message-State: AOJu0YxBvfjf6k+w4tDwlDXknTMQGdIT9ZknNLLIcxUzb2ICeWgdvMxm FU+57/D5559/niDPMOQvKyYEcoT9VJyLJejg6kUlEm5XAM12PrIIUy+hLNF5VUQ= X-Gm-Gg: ASbGnctQvqa46xG5wbMDI2KXyG2NPSF3+8As7mSu9u3XhI6X4atEBA6NHV2owX1JusW h+Fe5t2rV2H37qTG1Ult7+/2boJanPYv7zPsMtwg4WWRa24gWw6JJua/3se39Qf1yOCkmCU1xqy sVASfHPm1DkNKez12Q1VCCjKK6kwS3JFHFvyjFVynoIyIARb/LsQ3RAsUKdnYav3swBxCnqJS3R lLNKb1Ek/BACPXsJ+MXP0u4VEGmpE7B30g9INyfiVt9i54= X-Google-Smtp-Source: AGHT+IGv14RrhPbpKFC9/J2BufZTu7MOaWM0c1rsX2Y4WR5iS1cGRY2j7eRCHAjKSVADaNJCQQybTw== X-Received: by 2002:a17:902:f685:b0:215:b473:1dc9 with SMTP id d9443c01a7336-21a83fdf10fmr312977815ad.46.1736779101666; Mon, 13 Jan 2025 06:38:21 -0800 (PST) Received: from ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f155e00sm54328715ad.103.2025.01.13.06.38.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 06:38:21 -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 , Andrew Lunn , Simon Horman , Shuah Khan , Donald Hunter , Alexander Aring , Stefan Schmidt , Miquel Raynal , Steffen Klassert , Herbert Xu , linux-rdma@vger.kernel.org, linux-can@vger.kernel.org, osmocom-net-gprs@lists.osmocom.org, bpf@vger.kernel.org, linux-ppp@vger.kernel.org, wireguard@lists.zx2c4.com, linux-wireless@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org, bridge@lists.linux.dev, linux-wpan@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v8 05/11] net: ip_tunnel: Use link netns in newlink() of rtnl_link_ops Date: Mon, 13 Jan 2025 22:37:13 +0800 Message-ID: <20250113143719.7948-6-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250113143719.7948-1-shaw.leon@gmail.com> References: <20250113143719.7948-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 link_net is set, use it as link netns instead of dev_net(). This prepares for rtnetlink core to create device in target netns directly, in which case the two namespaces may be different. Convert common ip_tunnel_newlink() to accept an extra link netns argument. Don't overwrite ip_tunnel.net in ip_tunnel_init(). Signed-off-by: Xiao Liang --- include/net/ip_tunnels.h | 5 +++-- net/ipv4/ip_gre.c | 8 +++++--- net/ipv4/ip_tunnel.c | 10 ++++++---- net/ipv4/ip_vti.c | 3 ++- net/ipv4/ipip.c | 3 ++- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h index 1aa31bdb2b31..ae1f2dda4533 100644 --- a/include/net/ip_tunnels.h +++ b/include/net/ip_tunnels.h @@ -406,8 +406,9 @@ int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb, bool log_ecn_error); 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(struct net *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_gre.c b/net/ipv4/ip_gre.c index 4e8c310769ad..51113e981229 100644 --- a/net/ipv4/ip_gre.c +++ b/net/ipv4/ip_gre.c @@ -1409,7 +1409,8 @@ static int ipgre_newlink(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(params->link_net ? : dev_net(dev), dev, tb, &p, + fwmark); } static int erspan_newlink(struct net_device *dev, @@ -1429,7 +1430,8 @@ static int erspan_newlink(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(params->link_net ? : dev_net(dev), dev, tb, &p, + fwmark); } static int ipgre_changelink(struct net_device *dev, struct nlattr *tb[], @@ -1703,7 +1705,7 @@ struct net_device *gretap_fb_dev_create(struct net *net, const char *name, struct ip_tunnel *t; int err; struct rtnl_newlink_params params = { - .net = net, + .src_net = net, .tb = tb, }; diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c index 09b73acf037a..618a50d5c0c2 100644 --- a/net/ipv4/ip_tunnel.c +++ b/net/ipv4/ip_tunnel.c @@ -1213,11 +1213,11 @@ 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(struct net *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; @@ -1326,7 +1326,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; diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c index b901bee03e6d..159b4473290e 100644 --- a/net/ipv4/ip_vti.c +++ b/net/ipv4/ip_vti.c @@ -585,7 +585,8 @@ static int vti_newlink(struct net_device *dev, __u32 fwmark = 0; vti_netlink_parms(data, &parms, &fwmark); - return ip_tunnel_newlink(dev, tb, &parms, fwmark); + return ip_tunnel_newlink(params->link_net ? : dev_net(dev), dev, tb, + &parms, fwmark); } static int vti_changelink(struct net_device *dev, struct nlattr *tb[], diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c index a8b844bcfc64..bab0bf90c908 100644 --- a/net/ipv4/ipip.c +++ b/net/ipv4/ipip.c @@ -455,7 +455,8 @@ static int ipip_newlink(struct net_device *dev, } ipip_netlink_parms(data, &p, &t->collect_md, &fwmark); - return ip_tunnel_newlink(dev, tb, &p, fwmark); + return ip_tunnel_newlink(params->link_net ? : dev_net(dev), dev, tb, &p, + fwmark); } static int ipip_changelink(struct net_device *dev, struct nlattr *tb[], From patchwork Mon Jan 13 14:37:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Liang X-Patchwork-Id: 857073 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 018542297E4; Mon, 13 Jan 2025 14:38:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736779121; cv=none; b=hcWNhBJ50+b793ORx1yvkQ8P3lUHohk6XKkt31kq+fXFkwXFA5pGOd5rpUt0//P3SkYS2uCnzH9GcWpURp4w+xfvPYaCP3SAWS9Edf09pdHh+IGPA3lwqW+DgwvirVWoPYZy3T6ImW76mlBjpDMvB7qcFJ/VbfztRARCZn3BLjA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736779121; c=relaxed/simple; bh=pUkeHC9Duzkf0b0cEfL+7VFfzV63XchEu8lpcFtp5IM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VWHRq0QpzV7O04Ual9WFIS/PoNAveX6eEVNKpZc+ri4inhzE/NykvC5rSvWl64bM3ffwihFnncgxphM4j/Xahla/+32oRBP/z4RXkCuUlsOGZ2UsL3kS9OMRGjFO82ohpluSqzClRXzF84DtZKuwtHMkySKrjRI/ex06wNOLeoY= 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=VaSxtuw4; arc=none smtp.client-ip=209.85.214.181 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="VaSxtuw4" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-2163b0c09afso78936185ad.0; Mon, 13 Jan 2025 06:38:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736779119; x=1737383919; 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=n79rk6b+8xqMmWjuAyko0er+FR6QjAQIxOU32J9enis=; b=VaSxtuw4+z5YRbznyJGw57orxt8BaN3nxucZFYOcb+Y3/QVE0tI8u/ZJQGfq8p+Sr2 PS0okpJa55NqGwhL0nlZRUFM3OGX3R/u706zsyz2pyMEE9gI+6TB6bRFmybILuwmbLfv O4O5jtdANwtUPEyu1Mc/X4x0h8eOCK8uALgITZ6VPz38p//1XmOziXZktyCNiQhLsX7n a2jEopYN71A/0VotmmAaqjJ20NMlKIGAYhbJhIKMiNdiJgsGTcN/yX/8f4MaclrpudCz IFMkBNCtzCUc0B6Cct+mIrfMZ+/JXzCmr0kDNHKYi1GSP5gGOA/CMB2STSXumj4W4Fl5 QPpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736779119; x=1737383919; 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=n79rk6b+8xqMmWjuAyko0er+FR6QjAQIxOU32J9enis=; b=GAtxwVagYJhdu5NQJptnnl8JWYwtUB3JuayEKl/5K3QHZLMz8g2UngkIaQUAjwjwBV XK22HPE0k9RHaXBaIFqs5xt3JTRde7l1Cl9xJ3LhkLfD0AFIXxmZ3E87iZlJknRWQu2F lJaMMMeApkpxDKwE3WHlM/6Xb+ooyoyRzgs2yIHi5xAhe4vbqm0tj1v2Kik+i/0VAuHf LOy2UOgE7vAutn/fp55fmy7A7GwJiFgfcDEjwxxYWsDGhaC7sW/oBUPSd0SUC89pcHsI B1QFDYCjB4ibalYex5w/nATeKCSKyuzUk8+RfErt18+GitqgiOD1ZNyQtCv6JNPPy9Ym ld+w== X-Forwarded-Encrypted: i=1; AJvYcCUCbUiyI3cH9cq4Cixx6+sqBlbMSIbycN+fdQrTzyM0ooKI3gIclMrn6H07XbZ52yvJO84QLMS1s6So@vger.kernel.org, AJvYcCV4pmqQiRPJCnhqXviQsPnuJZ+GvbgqCUJF7x9r6GRq0t5P2LOP8udeB0+c7vxxg+FKZqMG+Fz9S64K7i/V@vger.kernel.org, AJvYcCVS5jvkhKBCwnAls71IPTfGysYXt/x/rN4MFBjPqqyo/UAyt+0D3dHqLzfwQLJkr/rj/bc=@vger.kernel.org, AJvYcCVVOxQ4BcD4ntjNICscuQTeVlp+IzLCtUosyGfSCo2czcQQRbbh9VFaLjWEseIP0KxD1NMGrOI5hZXoHA==@vger.kernel.org, AJvYcCVjcXD1+RteH69G6E2RW2D9NZGRSpZpzf6Y/Ui9OY5AJH6EP7v0S8olQ06fx6dyBKf/ORTLtHF3SDqQXUYPEFM=@vger.kernel.org, AJvYcCWO/vteSDdRT/Cosz2r63xXrey1auG3PyL0486xWn5fjOfml1p86umoVOcx5UEfp75fAc7f3pPF3Usx2g==@vger.kernel.org, AJvYcCXWCeC6y7B0vNC1et/d7HHuiNam1aJvImFRAbDYb50IXWfqo5H49tDJbfky0VLhPTdu/yoUkrdI2Vq2@vger.kernel.org, AJvYcCXgURTHVA4jcLrra0TqDsmFD/XidEFxjkGh+XE6X2ZlimrE5J3Jrlah/LOdukzkIz/zlxjp+xqR7/zVI7TT3hy4@vger.kernel.org X-Gm-Message-State: AOJu0YxsaPijT23PtLu0DtlB2NIXrDYLmVGqUWKbrcY1jIdGGg1tUpMV lnmedXOkBgOF9bC5ddUMNuxeiTKETmQkgitJpqPdVArUrI+a6kZikN22ZifdmcE= X-Gm-Gg: ASbGnctRMkCw3yARvgvAdAGN21gClc6EnQo2pkY44L9WyOoJ6NapuAW7seen1ydpgkF eKI5cy5qEz1VdddKAceE3eVytxshK8SmUBmOsVaEy+WzPr3rzUwQ800jrsm/bdn83HsDYlmKlWV Vr9fua2wVG2Pe54r1vLHcWhZoEAAUaN54wCoE9CAfZocKoDcTumarYaqIdklqrhuAZz32Gb5T8m a5VAQ8ahIc13yxuTXYy8X0DSWxKjJqhKev953uaQ24qfLg= X-Google-Smtp-Source: AGHT+IGazeu03SiYco1yjo+DeQUEtizAzSGgMZznFsd/ItXTJBGhLqoPfMkABloEPy5ZTJeLHULJqw== X-Received: by 2002:a17:902:cecd:b0:215:6995:1ef3 with SMTP id d9443c01a7336-21a83f3469cmr286693405ad.3.1736779118671; Mon, 13 Jan 2025 06:38:38 -0800 (PST) Received: from ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f155e00sm54328715ad.103.2025.01.13.06.38.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 06:38:38 -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 , Andrew Lunn , Simon Horman , Shuah Khan , Donald Hunter , Alexander Aring , Stefan Schmidt , Miquel Raynal , Steffen Klassert , Herbert Xu , linux-rdma@vger.kernel.org, linux-can@vger.kernel.org, osmocom-net-gprs@lists.osmocom.org, bpf@vger.kernel.org, linux-ppp@vger.kernel.org, wireguard@lists.zx2c4.com, linux-wireless@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org, bridge@lists.linux.dev, linux-wpan@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v8 07/11] net: xfrm: Use link netns in newlink() of rtnl_link_ops Date: Mon, 13 Jan 2025 22:37:15 +0800 Message-ID: <20250113143719.7948-8-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250113143719.7948-1-shaw.leon@gmail.com> References: <20250113143719.7948-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 link_net is set, use it as link netns instead of dev_net(). This prepares for rtnetlink core to create device in target netns directly, in which case the two namespaces may be different. Signed-off-by: Xiao Liang --- net/xfrm/xfrm_interface_core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/net/xfrm/xfrm_interface_core.c b/net/xfrm/xfrm_interface_core.c index b7ac558025d5..b87a5c950833 100644 --- a/net/xfrm/xfrm_interface_core.c +++ b/net/xfrm/xfrm_interface_core.c @@ -242,10 +242,9 @@ static void xfrmi_dev_free(struct net_device *dev) gro_cells_destroy(&xi->gro_cells); } -static int xfrmi_create(struct net_device *dev) +static int xfrmi_create(struct net *net, struct net_device *dev) { struct xfrm_if *xi = netdev_priv(dev); - struct net *net = dev_net(dev); struct xfrmi_net *xfrmn = net_generic(net, xfrmi_net_id); int err; @@ -819,11 +818,12 @@ static int xfrmi_newlink(struct net_device *dev, struct netlink_ext_ack *extack) { struct nlattr **data = params->data; - struct net *net = dev_net(dev); struct xfrm_if_parms p = {}; struct xfrm_if *xi; + struct net *net; int err; + net = params->link_net ? : dev_net(dev); xfrmi_netlink_parms(data, &p); if (p.collect_md) { struct xfrmi_net *xfrmn = net_generic(net, xfrmi_net_id); @@ -852,7 +852,7 @@ static int xfrmi_newlink(struct net_device *dev, xi->net = net; xi->dev = dev; - err = xfrmi_create(dev); + err = xfrmi_create(net, dev); return err; } From patchwork Mon Jan 13 14:37:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Liang X-Patchwork-Id: 857072 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 E0AE922DFBB; Mon, 13 Jan 2025 14:38:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736779138; cv=none; b=ADzK7oEC8EknPnFYpxqKP5YTAiQrfzA1BPRr6Ue/D968sOZ4Vc/Lb73dcuMTbNSOPYyDBkvgZMWJ2eoBl/OY+lMm+g2o87RsWCja+xrQyyBTDgkUJy+H5UrstjVTk9Gz+yJwaKDOYo0RR/fXomuILTp1FZgPGekzNNOcP5e58bw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736779138; c=relaxed/simple; bh=HRgkD5FKjFgLgWVxBNT3gyl1M0RycbLvrFOZUB35tkQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Td++9PxjjmlCjNRnktdJ9PfYP/ec198sa5tkhTbe8w9BPY5oLGstcX4JhPK+qYlI8EijRt5M9140EzXgObwhg/h1H98fHdVHe5UwIn88vnhK6JLep0huV5iDyxsajXDePUi9wcp0Wz5g2wkN+Z0F3piQCYPYOb0HkuKVDEUCJvM= 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=TCymOuVN; arc=none smtp.client-ip=209.85.214.181 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="TCymOuVN" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-2164b662090so72494875ad.1; Mon, 13 Jan 2025 06:38:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736779136; x=1737383936; 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=3RwrUezkHV4Bxso8Lan3H8PNeHkallTCdG4JVNGo1S0=; b=TCymOuVNtub+RoSE/q4/jI7nJDy2ZTafd4gGusYP1GD4bB0XE8b5fqgX4mjn3nUp+P vtvKnWDy/FTUsILLdgeCGUcRTGnbuJ79Qw3e2HEXwMi5cXXcPU6v7UPLZ6OuxyU+BnC0 5CEailZ12Ufq3Y4PjnQQ4ccHc5Lh7JzpwX/98C3tYSiDR/NdzGdKlhcmEgPWhChFBPj9 YrfAWUl9nWlspKF08eJaTz1QLwUFnfTDdNmm4L0D/VlkgZJfns7P8x6hhNMnPJolM+/e +ARHlADeagomj5phE8nsBLzr/a/Xg0HJ2+ZR41EWOqAiow9Ja4gCdHe9cNGclldV3pwJ aLEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736779136; x=1737383936; 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=3RwrUezkHV4Bxso8Lan3H8PNeHkallTCdG4JVNGo1S0=; b=WnviK/ZcJIFKatA1O4q/t0C0s52kmuVHnHCsY8u+AODeXEGIW2tu8FLBiESJ80BumF gW/TNUFgW4HlbuJoyhmq0c4unehs7dBucZiZ6mIHL3iitt9rGkScHwY9yYv4LDIRn7t6 6E5bU0cabahRTR/vKHhLWKhit0tKQ5QXqJGegbaCqeUlAWpJ0IhEWAnKu9iNGw1x6yLo fJUtJTFX9EA9GIkmT2vIVyFjdf1SlQ2cxUL1T3SgiNWusevcxCpKFwZGlg9IdWdHVjuy v5TWeJha7lTlGBGmY5x2f8HD6fUL5/sNBuE7VxFUNjnM0jbQwNXqYMx1wVQZVnfSTNoq nakg== X-Forwarded-Encrypted: i=1; AJvYcCU3kPIFp32L68EAjgtaZ82+hHKbwN8Bc/g0T39e5/loGLgNSa4imobz41uqdH5O2JiTHYaF6F7tJ+Ke@vger.kernel.org, AJvYcCU97xC8iLU9PbPoqk5nZXyXjtjr5Ruv2VkRBfj5LhjhJWhdORCrAuPl5rKZJ+Qt2trpSUjcS57iSSlJ@vger.kernel.org, AJvYcCUXgPW1rjteQ7WOIGWs9R1PVlCXYUXF4p7/3tuihuUHKr5zd84Sj0l0C70c54Inzjp5KW+4NAXBo6PXopZ/PTA=@vger.kernel.org, AJvYcCWXfSjICMyvOKRjSGgmK6sup0SRjrxwAN/l2EJ58rRokct2GPZRg/3zdYz58GUU9Un9pCE3+CvU09DHIw==@vger.kernel.org, AJvYcCWac8ybgMS3OkRLE56avFYqOuW3/O4+VtD2DcScckmVo5pbfk6gjQrO69h9TqFt5EGm/Qo=@vger.kernel.org, AJvYcCWxBKoabvtBkqs/KHwhYwzTrALQlw0x7+m4Zvi5ONOlg1UZEI6YB/rbcIc7ibp3q3xmbO7BnJkP6h8dTA==@vger.kernel.org, AJvYcCX1l2+pgVaXvtEaCcoPKstIQPpMSkbwGAtPSnayailoNW5rNd3+7f84M92jZyVZCCYvqCcCDbEOkhSuzBcE@vger.kernel.org, AJvYcCXj9zMBVBs6IZOrfdyNuavH5zO4qOTtK/cq+3jQYUIpIZ6e0OH+R9EHQ7+wD+MTzMN1q994oZD9zKDOHLYpgdC2@vger.kernel.org X-Gm-Message-State: AOJu0YzhLtCiD4ayWXm+QiQs1uZYiG/4hC4crhh46QdpoyQDgiVWgg/L zCIS41OOAQUhSytwE6U+5aic0BSeHMcJwqKobeyP3D1s8eaP9DNoQFnrSIyst3Q= X-Gm-Gg: ASbGncsmZuvyHUSquy6otKQY8/7Od6oxNvHHnfeA/c4h9KGtqrLeN5ijlV3oZQEf5yu t22GLf7IvwM84dH8KQVKWA5DZy1SaVjUmdQCn7PJrsHiz6DTE+MsycRJwDD15zm19rAz3ssVPNb lcXaGpQKvtNMTkngDyXKHE8KrR8B6EYKNAUoibvzcx0osquVlMDDxO5Vsd8rYQp1YKduUYcYlFh qVOcxHhvAYZ0lIk7hnGQm50TQHcfMi6IKjZaXHCnYCUarU= X-Google-Smtp-Source: AGHT+IHt1nCTDh10fBQS9NHgK/oOky2VtiRHLWbePcQNxSAsFYQfmLDkyg61R0c+C95BGg+IP2F6xw== X-Received: by 2002:a17:903:18a:b0:216:4a06:e87a with SMTP id d9443c01a7336-21a83fc7640mr358427785ad.40.1736779135888; Mon, 13 Jan 2025 06:38:55 -0800 (PST) Received: from ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f155e00sm54328715ad.103.2025.01.13.06.38.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 06:38:55 -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 , Andrew Lunn , Simon Horman , Shuah Khan , Donald Hunter , Alexander Aring , Stefan Schmidt , Miquel Raynal , Steffen Klassert , Herbert Xu , linux-rdma@vger.kernel.org, linux-can@vger.kernel.org, osmocom-net-gprs@lists.osmocom.org, bpf@vger.kernel.org, linux-ppp@vger.kernel.org, wireguard@lists.zx2c4.com, linux-wireless@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org, bridge@lists.linux.dev, linux-wpan@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v8 09/11] rtnetlink: Create link directly in target net namespace Date: Mon, 13 Jan 2025 22:37:17 +0800 Message-ID: <20250113143719.7948-10-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250113143719.7948-1-shaw.leon@gmail.com> References: <20250113143719.7948-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 Make rtnl_newlink_create() create device in target namespace directly. Avoid extra netns change when link netns is provided. Device drivers has been converted to be aware of link netns, that is not assuming device netns is and link netns is the same when ops->newlink() is called. Signed-off-by: Xiao Liang --- net/core/rtnetlink.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index cce5bcd1f257..65f09ab616b5 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -3784,8 +3784,8 @@ 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(tgt_net, ifname, name_assign_type, ops, tb, + extack); if (IS_ERR(dev)) { err = PTR_ERR(dev); goto out; @@ -3805,11 +3805,6 @@ 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) { - err = dev_change_net_namespace(dev, tgt_net, ifname); - if (err < 0) - goto out_unregister; - } if (tb[IFLA_MASTER]) { err = do_set_master(dev, nla_get_u32(tb[IFLA_MASTER]), extack); if (err) From patchwork Mon Jan 13 14:37:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Liang X-Patchwork-Id: 857071 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 7C44622DFB1; Mon, 13 Jan 2025 14:39:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736779156; cv=none; b=sBNJGu8C+OFoEtVvyJ7hsQ0etH12VvX+5ykHpHNvcjxqQK4ceJhkBHYtwR4LbLHqWUBpQKQ9nxtwWMvMWMZwBm49UwFj8Vwwe6y1EfH9WKtxjrCW6eWZXOAcz53D2Ctv9NdiNvCgJDjQ6V0/5iCM4Vh1y/0tW3cC+n4mpPwwe54= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736779156; c=relaxed/simple; bh=0G+WJHelzbbjtgv/Zbgactw+yzF4V+X8MJldF12Uf7A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BOLWsJS5luNWaQ+/zuM/zTvfqBrZuPwxp5NB/Lrr4Ayks0T6L4MlWQh8bm1D7YCaxHP/MEem8HuToVskqs/rUEsWUg7gYFFaepO9cKzGReRsFE2Yz7nGG9HZxnm41LZAmdmmecRefsJqxIDcEcp966o6LFN93uCL3HJCUbu/VP4= 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=mdhV9hqD; arc=none smtp.client-ip=209.85.214.181 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="mdhV9hqD" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-21644aca3a0so95936325ad.3; Mon, 13 Jan 2025 06:39:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736779153; x=1737383953; 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=R0TVXDX/Oq9IB0mhgmi61TXIFVtPNPu1PWKjPd5bzuM=; b=mdhV9hqDkGVkVHMv0B5JnL14GjXjp3LSB6fFUzLsJUGCasBB8mLgesFEOKv28jfDQd Dzv9tytKyUQmeNmr0+wcbcXOgQNMFfYqZUI5zSj9chuix98ydumZFVItYR7h3Smk8JY6 qy9WYM4CWnIklxZUKa2JhV5aXokm3Al7xOQSm7mWYdVmiVV+1TJqPaoICAo+SL/hCtu0 CxxPKId7EHV4QmxfhygiXApf3kS57jsAH/+Sd0XgB2iliWc223bWim26um12wtE/LfMD w+VpxgfWK0BuRYPqQC8P0mCE8sevD/v8WCBPHiUMxbyMtMZNi945f2zAWPCU0dClTA+z 5OkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736779153; x=1737383953; 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=R0TVXDX/Oq9IB0mhgmi61TXIFVtPNPu1PWKjPd5bzuM=; b=WiuFY5ERx4fZpmkVLLqT3P0vHJpVZTD4HhV2mAT1D0QBAnwulvqAvaNRcn64O5blyc hDj4RpT+Plp04Pu7UlmXy4MjtAGn2kNUQ61hmsC/OCSzVaA4s5Ze1zVwqwn5qvfsgWpr Pfr78T+22PAEgiES06BHBq9kn31SQTsW7eVc8hshLjM0qcpJDgoGEu6NpGdTdFMpU5Zz D7MVUMDRqz63KPY1fgKYHlrduGQiLzSYH08AUovaad12NMUc7EQcHF2plZ0ltC3c+d0v 5p7Nz9b1ZICM4g6+cjkFfwU/c+izLfUAGhSLB8/1nqZV7jB5nwJx0ya24+p9abalJ2d0 HuNA== X-Forwarded-Encrypted: i=1; AJvYcCUFLHbYOydfU9es94NceemO6MeaBLSuau8MGS8Q5YQESD11JXXOC6rSc+YvLCR3Sm/AtRsdSlk2ET7xLVFg@vger.kernel.org, AJvYcCUH1F2mkybZW4CxDUuGB3TjgjLWxQydaIAE9tOJaQOi7MkoP/SfNHUdxjdW4qpAQUVoGNoa+FGzyN/GUKDUC/4D@vger.kernel.org, AJvYcCWTd2MAO6ANCPBs8qvzHuKtQr7/4ogS81msGHChhwaaOHylmBnmZEfpzWj/C2B3Wto1KaHxpg6R1mv90w==@vger.kernel.org, AJvYcCWjqDRNJI/jmkdmeioMn0CMfVjTK0VRKBw6M//Z3e7KCOGNSoK7rJiRJvIhJLX+FS4hekz2ZHpKtPMf+Q==@vger.kernel.org, AJvYcCWtBh8hPHYqbJoqQIYIihjXOAyYSagAbJi018tUytgJ7p/OowWk5/IwCB84dXwLc0vdo7Aw1uGolxVcuC44rE4=@vger.kernel.org, AJvYcCX/B+yT7GmPsoczL3aqi1Ex3PWFXFf2fwhq0bQr9Ju83Cme6A1xfCrGJsjdfbl4JhOGr4U67PP41/T+@vger.kernel.org, AJvYcCXGoICj+Ow8nY1RV5ZEW8Ggph/NaOfyzM7/vU//PECyYsVQnZIZ/FLkNup8ASnFgz7cdPCzfdCMSLy/@vger.kernel.org, AJvYcCXHOCpOX4LkVkZd5kinYzLin1oVXQ0qV5luP8ZG8OoSBCU0QLSE5VkZEBxMETIKIrOTGOU=@vger.kernel.org X-Gm-Message-State: AOJu0YxfpaCXHld9uVlEVWr3bQ3IJQ4VPT89um+69Bp60rvdb1FGnt1J A/LqcgXWNaulD7HtHYQnzs/aYAYG83MQONpWAhkwBKdmTun6Ax1ojdA0tyVvWqw= X-Gm-Gg: ASbGncuuf7feJL582A2xBsiBfUhssO5EqfS1JSB43mvXNmmx5ZE2+FugdrD+meMcQy0 33I/DELTcM7BVkf37+aQxv9+BqRj2JU3OJUY6JhCzGjyfDWPvV8irsFxYCT60fQmyU+E8bDA9ra vlNzm+eqjvcN7it1Hxz9q53DPLxrfNgFSWfJvXCLf9PCehp/DfP3Mw5peDu/iWVk0CTkhJDix8V kotEJlHrksrYu7h3Sa+jyQNyZBqRrI7UO0oddpCDHCTBzg= X-Google-Smtp-Source: AGHT+IFt4cEJz+p42bYm31EfJt3Zb0JLb+qW+6vXHsT58zE4AWUF4ed/u79zsBlznytyW2KBQMyVfw== X-Received: by 2002:a17:902:d511:b0:215:6489:cfbf with SMTP id d9443c01a7336-21a83f48cc0mr313835205ad.11.1736779153175; Mon, 13 Jan 2025 06:39:13 -0800 (PST) Received: from ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f155e00sm54328715ad.103.2025.01.13.06.39.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 06:39:12 -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 , Andrew Lunn , Simon Horman , Shuah Khan , Donald Hunter , Alexander Aring , Stefan Schmidt , Miquel Raynal , Steffen Klassert , Herbert Xu , linux-rdma@vger.kernel.org, linux-can@vger.kernel.org, osmocom-net-gprs@lists.osmocom.org, bpf@vger.kernel.org, linux-ppp@vger.kernel.org, wireguard@lists.zx2c4.com, linux-wireless@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org, bridge@lists.linux.dev, linux-wpan@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v8 11/11] selftests: net: Add test cases for link and peer netns Date: Mon, 13 Jan 2025 22:37:19 +0800 Message-ID: <20250113143719.7948-12-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250113143719.7948-1-shaw.leon@gmail.com> References: <20250113143719.7948-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 to verify that link is created in target netns directly - no link new/del events should be generated in link netns or current netns. - Add test cases to verify that link-netns is set as expected for various drivers and combination of namespace-related parameters. Signed-off-by: Xiao Liang --- tools/testing/selftests/net/Makefile | 1 + tools/testing/selftests/net/config | 5 + tools/testing/selftests/net/link_netns.py | 141 ++++++++++++++++++++++ tools/testing/selftests/net/netns-name.sh | 10 ++ 4 files changed, 157 insertions(+) create mode 100755 tools/testing/selftests/net/link_netns.py diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile index 73ee88d6b043..df07a38f884f 100644 --- a/tools/testing/selftests/net/Makefile +++ b/tools/testing/selftests/net/Makefile @@ -35,6 +35,7 @@ TEST_PROGS += cmsg_so_mark.sh TEST_PROGS += cmsg_so_priority.sh TEST_PROGS += cmsg_time.sh cmsg_ipv6.sh TEST_PROGS += netns-name.sh +TEST_PROGS += link_netns.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/config b/tools/testing/selftests/net/config index 5b9baf708950..ab55270669ec 100644 --- a/tools/testing/selftests/net/config +++ b/tools/testing/selftests/net/config @@ -107,3 +107,8 @@ CONFIG_XFRM_INTERFACE=m CONFIG_XFRM_USER=m CONFIG_IP_NF_MATCH_RPFILTER=m CONFIG_IP6_NF_MATCH_RPFILTER=m +CONFIG_IPVLAN=m +CONFIG_CAN=m +CONFIG_CAN_DEV=m +CONFIG_CAN_VXCAN=m +CONFIG_NETKIT=y diff --git a/tools/testing/selftests/net/link_netns.py b/tools/testing/selftests/net/link_netns.py new file mode 100755 index 000000000000..aab043c59d69 --- /dev/null +++ b/tools/testing/selftests/net/link_netns.py @@ -0,0 +1,141 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +import time + +from lib.py import ksft_run, ksft_exit, ksft_true +from lib.py import ip +from lib.py import NetNS, NetNSEnter +from lib.py import RtnlFamily + + +LINK_NETNSID = 100 + + +def test_event() -> None: + with NetNS() as ns1, NetNS() as ns2: + with NetNSEnter(str(ns2)): + rtnl = RtnlFamily() + + rtnl.ntf_subscribe("rtnlgrp-link") + + ip(f"netns set {ns2} {LINK_NETNSID}", ns=str(ns1)) + ip(f"link add netns {ns1} link-netnsid {LINK_NETNSID} dummy1 type dummy") + ip(f"link add netns {ns1} dummy2 type dummy", ns=str(ns2)) + + ip("link del dummy1", ns=str(ns1)) + ip("link del dummy2", ns=str(ns1)) + + time.sleep(1) + rtnl.check_ntf() + ksft_true(rtnl.async_msg_queue.empty(), + "Received unexpected link notification") + + +def validate_link_netns(netns, ifname, link_netnsid) -> bool: + link_info = ip(f"-d link show dev {ifname}", ns=netns, json=True) + if not link_info: + return False + return link_info[0].get("link_netnsid") == link_netnsid + + +def test_link_net() -> None: + configs = [ + # type, common args, type args, fallback to dev_net + ("ipvlan", "link dummy1", "", False), + ("macsec", "link dummy1", "", False), + ("macvlan", "link dummy1", "", False), + ("macvtap", "link dummy1", "", False), + ("vlan", "link dummy1", "id 100", False), + ("gre", "", "local 192.0.2.1", True), + ("vti", "", "local 192.0.2.1", True), + ("ipip", "", "local 192.0.2.1", True), + ("ip6gre", "", "local 2001:db8::1", True), + ("ip6tnl", "", "local 2001:db8::1", True), + ("vti6", "", "local 2001:db8::1", True), + ("sit", "", "local 192.0.2.1", True), + ("xfrm", "", "if_id 1", True), + ] + + with NetNS() as ns1, NetNS() as ns2, NetNS() as ns3: + net1, net2, net3 = str(ns1), str(ns2), str(ns3) + + # prepare link netnsid and a dummy link needed by certain drivers + ip(f"netns set {net3} {LINK_NETNSID}", ns=str(net2)) + ip("link add dummy1 type dummy", ns=net3) + + cases = [ + # source, "netns", "link-netns", expected link-netns + (net3, None, None, None, None), + (net3, net2, None, None, LINK_NETNSID), + (net2, None, net3, LINK_NETNSID, LINK_NETNSID), + (net1, net2, net3, LINK_NETNSID, LINK_NETNSID), + ] + + for src_net, netns, link_netns, exp1, exp2 in cases: + tgt_net = netns or src_net + for typ, cargs, targs, fb_dev_net in configs: + cmd = "link add" + if netns: + cmd += f" netns {netns}" + if link_netns: + cmd += f" link-netns {link_netns}" + cmd += f" {cargs} foo type {typ} {targs}" + ip(cmd, ns=src_net) + if fb_dev_net: + ksft_true(validate_link_netns(tgt_net, "foo", exp1), + f"{typ} link_netns validation failed") + else: + ksft_true(validate_link_netns(tgt_net, "foo", exp2), + f"{typ} link_netns validation failed") + ip(f"link del foo", ns=tgt_net) + + +def test_peer_net() -> None: + types = [ + "vxcan", + "netkit", + "veth", + ] + + with NetNS() as ns1, NetNS() as ns2, NetNS() as ns3, NetNS() as ns4: + net1, net2, net3, net4 = str(ns1), str(ns2), str(ns3), str(ns4) + + ip(f"netns set {net3} {LINK_NETNSID}", ns=str(net2)) + + cases = [ + # source, "netns", "link-netns", "peer netns", expected + (net1, None, None, None, None), + (net1, net2, None, None, None), + (net2, None, net3, None, LINK_NETNSID), + (net1, net2, net3, None, None), + (net2, None, None, net3, LINK_NETNSID), + (net1, net2, None, net3, LINK_NETNSID), + (net2, None, net2, net3, LINK_NETNSID), + (net1, net2, net4, net3, LINK_NETNSID), + ] + + for src_net, netns, link_netns, peer_netns, exp in cases: + tgt_net = netns or src_net + for typ in types: + cmd = "link add" + if netns: + cmd += f" netns {netns}" + if link_netns: + cmd += f" link-netns {link_netns}" + cmd += f" foo type {typ}" + if peer_netns: + cmd += f" peer netns {peer_netns}" + ip(cmd, ns=src_net) + ksft_true(validate_link_netns(tgt_net, "foo", exp), + f"{typ} peer_netns validation failed") + ip(f"link del foo", ns=tgt_net) + + +def main() -> None: + ksft_run([test_event, test_link_net, test_peer_net]) + ksft_exit() + + +if __name__ == "__main__": + main() 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 ]"