From patchwork Wed Dec 18 13:08: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: 13913657 X-Patchwork-Delegate: johannes@sipsolutions.net Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.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 5B62A1BEF80; Wed, 18 Dec 2024 13:09:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734527375; cv=none; b=jQFzbKvQ846P/KxqEUF2ZGbn9bC0gF6j/nF6DAqZEmXG16/sXVTT7KaKvFU/3vWvphAn5AXLMCnraLA0j7Uc7rKgXB6ZMomLJfEU5CxVg1056hSaF3BWd3/g6+URx0287S7EQ7if6KKSCZkppfwt/vdS9zz7bwqGwGg93gT+qGM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734527375; c=relaxed/simple; bh=Egm70QFHoPJQeKbJRemzVe3pKzsMp6lZRsVFCxj3tAY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=meiLWGGmjayuW3ELdlfVu0oBZIhD/o1wWchOI7TZX4fmXb9ce79I1MNUENv91FHloqPhec68mJXTu5olg1GS/Tm7lLIUtpVwXxavQ1Zok46dVTf5YtRvmtJF06pXDqsBr1z++66qKYi4lXZI0F16/UDQL6tyCUlAwKqr/8dswi0= 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=CjTLjUk0; arc=none smtp.client-ip=209.85.216.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="CjTLjUk0" Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-2ee67e9287fso5823381a91.0; Wed, 18 Dec 2024 05:09:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734527373; x=1735132173; 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=rqBeWHkwlk4K5tQfUbZueoC1cX5zOkU9dpB02VEAE+k=; b=CjTLjUk0q7PWkD2Wk8lKDND0twaWac56uX+h/mdW2vX6gLjm9Ime3iKmO47wb0slpi /T6eRuJVW1Crm3AdG3O0uz2M6vS5PazvOpVuC9n9alVaZwq6Qo+FkKtsHyEZnECHqJN1 WgKsRXCE5vjre0ZptRvxozWew6vP+J5nLeInYnOAL/mtibxtvEDQqaXB7FCfn04EL6i5 bSQs5rCEx+a8kjwxJS5DyqzkbcGrblbE/CkXjPOKq76DOnKpnXet+At6LipvyfeHZ2rU mJoQ+JuZVIlKZHxmWjrQYhkwzm0sNwcndWnj8mFWohaeVIdl3b6f07IrWY6J6+XT8k0O 7vlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734527373; x=1735132173; 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=rqBeWHkwlk4K5tQfUbZueoC1cX5zOkU9dpB02VEAE+k=; b=l0Qt9Bu+2CaJZfiTxJewFk+cqjTO60upncl4rIGbemDCMkOEucRcK2i/UmE53Dpqnf eesQSzyRWFfWVWcNmrTPRdzUC0cqQL7AvFWk9uBECA5PiUw7kkYoY/ZZkYR5IXc66aB7 M233xz2POUmV1EflBvoZJ4XVga5Y0KICQJzRmBgrSU+p+wGLju9T9RIRK1cWANBFSjug X+J2DrAPbjLv/JoDq7l8TY4rweCNAD3VeghzcV5ESmIOKtu+ESyidFK7Rh34DZtvZo7/ ElNO3xmkfxu0FvNZ3lJZABkNPrN4IMTal4jwyotteRl43cjcOxZta7/dJJZ0eAqaa7vc egQA== X-Forwarded-Encrypted: i=1; AJvYcCUUOCpB2jrdhYLfKT8oFo7PpFUDU72FE/7E6czFa7oare13pkYm3s+RK73tLDeCrlA0DXn6bQzTnIFWfVVtyhM=@vger.kernel.org, AJvYcCVhpvXVl8FB1sFCDZeGr89w2V/5+TxmnPoiWSa4JzzeyqRGigAjH5LYBpPx4O79p8I4ri/JVSQtZwWxpdQTjvtg@vger.kernel.org, AJvYcCWhp+vx+xg5uRT6A1B7zfQ4MDZrlGNHjR1JVxCFEXdNStgQPFC8cuOMf1YtiWqjCaBc5FdFi8x++zMx@vger.kernel.org, AJvYcCWkOs1Gfg7fpRiO/BD841W574rhHDVMYUM0xS0wbVKveTxXwf9lkRLrIh7Bg/aJ1m/Q748=@vger.kernel.org, AJvYcCX1KRy+ndV/nz6TjsfI8NwLjCsRpuAO4cUyfFozh1Stg+UEqQlMPPflGEqsTKusulqa2jAMgMe6Ow2Ra8fx@vger.kernel.org, AJvYcCX9sCvSEILuTyszKqfyPCFS7gGOTLTCNQMCE/vY6oRImm3LtJ2vMgUAambcDjSauci/MNCvkCNVF2VA/w==@vger.kernel.org, AJvYcCXFMQ5F+c56nXRPKxc4VPMuKRPgvB47L8KeBwrJrB4a0rqO4mt5BjhUw0Jtf+IHKLafaI9bL9fhTheV@vger.kernel.org, AJvYcCXQsrj3IGCy00zdp9Z8yA3ron7wwbtKMzdyo+IG9KcELUZK4Te4HveMeyZCsFEEKs8fL5c0pLH75ztIBg==@vger.kernel.org X-Gm-Message-State: AOJu0YwdjcZ6ldzMuBq2PuQ8S6VZ1TIamNBlxlhFaSZbBWVEZYNzStkG LMkJCM5erKcBvF0SqJTDgmJJopdPNBfUgq3J6fBX9RHYfARaFCiRSy6JoOQaeSg= X-Gm-Gg: ASbGncuokuBb5mP9mPPtGw0diTcwKdbXEPhKg8Jh5uOERKM5+37Fjm5/ATj3ai0+4+4 tNQ/DCOXsGFdikCO+c2VWzEQt6CoOaesP0e9SI8mowt27d9IWn2tPI3FxKfUpTTCo9qQWfE8uCD fayTFA96f8xEH5SMdjfkPpdNQntWEH3dTgbmW7oGBjKvY7rLLQJl5yH7lmEprJ2dGOpIpA6SKre x0pl9EYfXc3ayyyz3bSg5Q5Z5q2ybcV4mPBF9kW7EWvXOU= X-Google-Smtp-Source: AGHT+IGwupxRC65MgCyutia2fH86BtEscvZ3hC19otgxhx9O+M/gNgTyzVuSwrO7sHgcHk/UbitTJA== X-Received: by 2002:a17:90b:5490:b0:2ee:48bf:7dc9 with SMTP id 98e67ed59e1d1-2f2e91f1112mr4682540a91.15.1734527372952; Wed, 18 Dec 2024 05:09:32 -0800 (PST) Received: from ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-801d5c0f59asm7434754a12.67.2024.12.18.05.09.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Dec 2024 05:09:32 -0800 (PST) From: Xiao Liang To: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Kuniyuki Iwashima , Jakub Kicinski , Donald Hunter , Paolo Abeni Cc: "David S. Miller" , David Ahern , Eric Dumazet , Ido Schimmel , Andrew Lunn , Simon Horman , Shuah Khan , Jiri Pirko , Hangbin Liu , 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 v6 01/11] rtnetlink: Lookup device in target netns when creating link Date: Wed, 18 Dec 2024 21:08:59 +0800 Message-ID: <20241218130909.2173-2-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241218130909.2173-1-shaw.leon@gmail.com> References: <20241218130909.2173-1-shaw.leon@gmail.com> Precedence: bulk X-Mailing-List: linux-wireless@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 d9e363d9fa31..6a2fa030c8e0 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -3851,20 +3851,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 Wed Dec 18 13:09: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: 13913658 X-Patchwork-Delegate: johannes@sipsolutions.net Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (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 33F451ACEB0; Wed, 18 Dec 2024 13:09:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734527386; cv=none; b=J9S4JL/WnKP1pqbyNviNRblXq6FGn1SV0pnI8minsjgmJR1D3JKge6dtQCuE+Ax5ZMXH08c57c5izieYbRSg/m5GigKA6b57P6wlGYhAAjJyuCkGMlcnZAmL058b0VO6/xs7qKrOx16LZYwUoJt4y0KfV79BC63H4AA/F+wMDeo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734527386; c=relaxed/simple; bh=3tSmXpHzpljDSMUKvhq8eKF6HFI0du0w9lqwwYcAxjY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tDa3cvL1okl1ykV0ipb02B+xA5mbAN2kvPkf5DmK+zrBhyN0fwQTAlUyJWGduPWc65FXVsezHgvctR+2bYzQPh54c0yF8NX+RjX533F61DFbqnI3dJnIvzvs9YqCI1yOnUiQActhvQameflEESQCnaDh0wOLjgGaAIbdG5JmwrY= 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=bPtrO0R0; arc=none smtp.client-ip=209.85.210.171 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="bPtrO0R0" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-725f3594965so5185294b3a.3; Wed, 18 Dec 2024 05:09:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734527382; x=1735132182; 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=WRKMSN48pZYnoonZeIwJ9Ie1J9jfDq82Ru6jTXK+F2U=; b=bPtrO0R092+52iIQFSdq7CA/N3PGdY3NgZ/nfgg6fPQsugNTVR21Qp/42gq0DeRIn4 1BLhfJdhzLZUGoPJ66BDRKTPBnwuOsRkSwVenrMRxmUiFygveePu2ZKuw6bTHfwUDXys hlbf6gQgsHVHYcJeCYXF2vxkft7uhFIJJru3lVd2LOQe72+hRCOjXzcwy2T/DwbByh4B 4du50TXg53rejTFbHaxDUrv7n2+10WxFoMi+Gn2lWmN/sFVT45oKv/PEYNUcUK/0jLgE QKUEe/rTBE9GGrLYuG8oWAlW5oxvoGWU359XnkEeGhO78O/G0wGzgQ9MeQTYvQh+X/aX OTxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734527382; x=1735132182; 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=WRKMSN48pZYnoonZeIwJ9Ie1J9jfDq82Ru6jTXK+F2U=; b=nuL/h4Od3nkoy9dRIO8fNv4a0r9ikclS9iT6zaEoTUPKh97XyMY6NL1Gew0vwB8z0T eVQ/7NQw80F0c+V/CTChYiOdw+ZCuFXi3M3wq8w18OwSjCCzN9WVhk+cccPe5jrjGZR7 rCF2BwrGZPdkwY24I+GU9P9qw9J1em0a+F3flndQk1oIwBjIFaeLbffhySQY+h0icvdi aMWnpoxUAWePSocnM8TURIQQDp6I4NZLSgcp8kfpIt6zm3yAWlVZYPhxL2OHs6y0nBzj RlKnItG+7AECcKXPBdxcVgGETmE6K0GWhIUGgfGQc3SMlqMYuKhkgcGRyRljBYquT9e2 YXmQ== X-Forwarded-Encrypted: i=1; AJvYcCUEQL2Jb2cnQRSfZKLiqaNwj0DKX4aGadKP2/7Pzr8wcAs8H7FuPO95/pJEhD5VwEn/2x9XZFLUzBnlAQ==@vger.kernel.org, AJvYcCUjwNh0w6wjN5Yhdy11XcfdRnSWShn/33UYCxu1AJnXt+K87qQtKi1FziJmIoq4Nrob1zDZDMx53sDB386qzdU=@vger.kernel.org, AJvYcCUum9UM5dKubro/aMHR6IiNpqM6q2gSQbwAUD5hYUI4LYqhtY0xZM8iGCWL/4CMqaPg2pUtOyuvBV/ZJptg@vger.kernel.org, AJvYcCVCDOnuc4vu+zaIp9bHMEiP9CY5w8fCPS95qwTBYary5/qXM5bsT7Dth5Iy+/Jwsee8M/990uSRzhgq@vger.kernel.org, AJvYcCVWXCo70bksyhS/4V2WoAHt3eHVq+N07C3hqyZ43nYd3qMp+UM8OOXYYZWVn7/Jgd9FL98ykXtJ6L3mLw==@vger.kernel.org, AJvYcCWbmecWI8OMv+xCV0Cu+Yw7DfIAAWvW9R+x3afFbhILdTLkbTqSpC2ipgjYoD5aIaD9HJ8cJ7YBKvfQ@vger.kernel.org, AJvYcCWnPHYGeKZdhWHMlkJYHnlWKr52Dl4+wbqGx+Z9jTByqr2TPro+NLpkV7XWa5WuaQUHkeioYNMJJHx9zNJjO/1Y@vger.kernel.org, AJvYcCXYdJamB2hz0vTIAqpbkPBowC8FZzT0TusQkdDIdC8D5Gp0UoCGeIzUNJe+KxBzFK/LbFg=@vger.kernel.org X-Gm-Message-State: AOJu0Yxs2miWnLAOeDtKc6EFtGv1GffAj0wMXuslcYfakcNQ9m8QrZnO mqB2s+5yKAyCVu3FadHskqAnCqxOy8lX5OwRhiwNIN6FP+j3VGlc4SGKvQGCX7o= X-Gm-Gg: ASbGncuhgCQ0vxw6d47ocrm1R+SH1E5vqIPrHWK0KtLfoJGkvfLtFlm4c7KOWc/o+pL mxcCMYlCrAU8DgKpGBA6FO1Wd17gmMCswhM9F/csCiqMbd9RUDYtBJ2fBThoZrAMf06yvITOX6E wYLEnw+bzDJGNQ8r4USoRnp0fCwYuq9ii69Ej3DcXcezrvuI8eYNPREnxmfLnDhKqkC0PO1x79S y7dd09yE9W2uxMl7QFGVYRUCTAQ4K9KLvMbEXCYf7xJHHo= X-Google-Smtp-Source: AGHT+IEShEZqItVN4bpj9F9tKHrdXoI6KNQu9eO7tvDHhdPVTtVP8ra9TuTDu71N+3DZ7BhLG3eWVw== X-Received: by 2002:a05:6a00:1787:b0:727:3fd5:b530 with SMTP id d2e1a72fcca58-72a8d24a775mr3594945b3a.15.1734527381531; Wed, 18 Dec 2024 05:09:41 -0800 (PST) Received: from ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-801d5c0f59asm7434754a12.67.2024.12.18.05.09.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Dec 2024 05:09:40 -0800 (PST) From: Xiao Liang To: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Kuniyuki Iwashima , Jakub Kicinski , Donald Hunter , Paolo Abeni Cc: "David S. Miller" , David Ahern , Eric Dumazet , Ido Schimmel , Andrew Lunn , Simon Horman , Shuah Khan , Jiri Pirko , Hangbin Liu , 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 v6 02/11] rtnetlink: Pack newlink() params into struct Date: Wed, 18 Dec 2024 21:09:00 +0800 Message-ID: <20241218130909.2173-3-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241218130909.2173-1-shaw.leon@gmail.com> References: <20241218130909.2173-1-shaw.leon@gmail.com> Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 There are 4 net namespaces involved when creating links: - source netns - where the netlink socket resides, - target netns - where to put the device being created, - link netns - netns associated with the device (backend), - peer netns - netns of peer device. Currently, two nets are passed to newlink() callback - "src_net" parameter and "dev_net" (implicitly in net_device). They are set as follows, depending on netlink attributes in the request. +------------+-------------------+---------+---------+ | peer netns | IFLA_LINK_NETNSID | src_net | dev_net | +------------+-------------------+---------+---------+ | | absent | source | target | | absent +-------------------+---------+---------+ | | present | link | link | +------------+-------------------+---------+---------+ | | absent | peer | target | | present +-------------------+---------+---------+ | | present | peer | link | +------------+-------------------+---------+---------+ When IFLA_LINK_NETNSID is present, the device is created in link netns first and then moved to target netns. This has some side effects, including extra ifindex allocation, ifname validation and link events. These could be avoided if we create it in target netns from the beginning. On the other hand, the meaning of src_net parameter is ambiguous. It varies depending on how parameters are passed. It is the effective link (or peer netns) by design, but some drivers ignore it and use dev_net instead. This patch packs existing newlink() parameters, along with the source netns, link netns and peer netns, into a struct. The old "src_net" is renamed to "net" to avoid confusion with real source netns, and will be deprecated later. The use of src_net are converted to params->net trivially. To make the semantics more clear, two helper functions - rtnl_newlink_link_net() and rtnl_newlink_peer_net() - are provided for netns fallback logic. Peer netns falls back to link netns, and link netns falls back to source netns. In following patches, to prepare for creating link in target netns directly: - For device drivers that are aware of the old "src_net", the use of it are replace with one of the two helper functions. - And for those that takes dev_net() as link netns, we try params->link_net and then dev_net(), in order to maintain compatibility with the old behavior. Signed-off-by: Xiao Liang --- drivers/infiniband/ulp/ipoib/ipoib_netlink.c | 9 ++-- drivers/net/amt.c | 12 +++-- drivers/net/bareudp.c | 9 ++-- drivers/net/bonding/bond_netlink.c | 8 ++-- drivers/net/can/dev/netlink.c | 4 +- drivers/net/can/vxcan.c | 9 ++-- .../ethernet/qualcomm/rmnet/rmnet_config.c | 9 ++-- drivers/net/geneve.c | 9 ++-- drivers/net/gtp.c | 7 +-- drivers/net/ipvlan/ipvlan.h | 4 +- drivers/net/ipvlan/ipvlan_main.c | 13 ++++-- drivers/net/ipvlan/ipvtap.c | 10 ++-- drivers/net/macsec.c | 13 ++++-- drivers/net/macvlan.c | 7 ++- drivers/net/macvtap.c | 11 +++-- drivers/net/netkit.c | 9 ++-- drivers/net/pfcp.c | 9 ++-- drivers/net/ppp/ppp_generic.c | 8 ++-- drivers/net/team/team_core.c | 7 +-- drivers/net/veth.c | 9 ++-- drivers/net/vrf.c | 11 +++-- drivers/net/vxlan/vxlan_core.c | 9 ++-- drivers/net/wireguard/device.c | 9 ++-- drivers/net/wireless/virtual/virt_wifi.c | 12 +++-- drivers/net/wwan/wwan_core.c | 25 +++++++--- include/net/rtnetlink.h | 46 +++++++++++++++++-- net/8021q/vlan_netlink.c | 13 ++++-- net/batman-adv/soft-interface.c | 16 +++---- net/bridge/br_netlink.c | 12 +++-- net/caif/chnl_net.c | 6 +-- net/core/rtnetlink.c | 16 +++++-- net/hsr/hsr_netlink.c | 8 ++-- net/ieee802154/6lowpan/core.c | 6 +-- net/ipv4/ip_gre.c | 21 ++++++--- net/ipv4/ip_vti.c | 7 +-- net/ipv4/ipip.c | 11 +++-- net/ipv6/ip6_gre.c | 24 ++++++---- net/ipv6/ip6_tunnel.c | 7 +-- net/ipv6/ip6_vti.c | 6 +-- net/ipv6/sit.c | 7 +-- net/xfrm/xfrm_interface_core.c | 7 +-- 41 files changed, 296 insertions(+), 159 deletions(-) diff --git a/drivers/infiniband/ulp/ipoib/ipoib_netlink.c b/drivers/infiniband/ulp/ipoib/ipoib_netlink.c index 9ad8d9856275..61f2457aab77 100644 --- a/drivers/infiniband/ulp/ipoib/ipoib_netlink.c +++ b/drivers/infiniband/ulp/ipoib/ipoib_netlink.c @@ -97,10 +97,13 @@ static int ipoib_changelink(struct net_device *dev, struct nlattr *tb[], return ret; } -static int ipoib_new_child_link(struct net *src_net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int ipoib_new_child_link(struct rtnl_newlink_params *params) { + struct netlink_ext_ack *extack = params->extack; + struct net_device *dev = params->dev; + 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; u16 child_pkey; diff --git a/drivers/net/amt.c b/drivers/net/amt.c index 98c6205ed19f..85878abb51d2 100644 --- a/drivers/net/amt.c +++ b/drivers/net/amt.c @@ -3161,13 +3161,17 @@ static int amt_validate(struct nlattr *tb[], struct nlattr *data[], return 0; } -static int amt_newlink(struct net *net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int amt_newlink(struct rtnl_newlink_params *params) { - struct amt_dev *amt = netdev_priv(dev); + struct netlink_ext_ack *extack = params->extack; + struct net_device *dev = params->dev; + struct nlattr **data = params->data; + struct nlattr **tb = params->tb; + struct net *net = params->net; + struct amt_dev *amt; int err = -EINVAL; + amt = netdev_priv(dev); amt->net = net; amt->mode = nla_get_u32(data[IFLA_AMT_MODE]); diff --git a/drivers/net/bareudp.c b/drivers/net/bareudp.c index 70814303aab8..4c2a50bbf7c0 100644 --- a/drivers/net/bareudp.c +++ b/drivers/net/bareudp.c @@ -698,10 +698,13 @@ static void bareudp_dellink(struct net_device *dev, struct list_head *head) unregister_netdevice_queue(dev, head); } -static int bareudp_newlink(struct net *net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int bareudp_newlink(struct rtnl_newlink_params *params) { + struct netlink_ext_ack *extack = params->extack; + struct net_device *dev = params->dev; + struct nlattr **data = params->data; + struct nlattr **tb = params->tb; + struct net *net = params->net; struct bareudp_conf conf; int err; diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c index 2a6a424806aa..39708a778285 100644 --- a/drivers/net/bonding/bond_netlink.c +++ b/drivers/net/bonding/bond_netlink.c @@ -564,10 +564,12 @@ static int bond_changelink(struct net_device *bond_dev, struct nlattr *tb[], return 0; } -static int bond_newlink(struct net *src_net, struct net_device *bond_dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int bond_newlink(struct rtnl_newlink_params *params) { + struct netlink_ext_ack *extack = params->extack; + struct net_device *bond_dev = params->dev; + struct nlattr **data = params->data; + struct nlattr **tb = params->tb; int err; err = bond_changelink(bond_dev, tb, data, extack); diff --git a/drivers/net/can/dev/netlink.c b/drivers/net/can/dev/netlink.c index 01aacdcda260..52dae0e94858 100644 --- a/drivers/net/can/dev/netlink.c +++ b/drivers/net/can/dev/netlink.c @@ -624,9 +624,7 @@ static int can_fill_xstats(struct sk_buff *skb, const struct net_device *dev) return -EMSGSIZE; } -static int can_newlink(struct net *src_net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int can_newlink(struct rtnl_newlink_params *params) { return -EOPNOTSUPP; } diff --git a/drivers/net/can/vxcan.c b/drivers/net/can/vxcan.c index ca8811941085..5d7717c22fab 100644 --- a/drivers/net/can/vxcan.c +++ b/drivers/net/can/vxcan.c @@ -172,10 +172,13 @@ static void vxcan_setup(struct net_device *dev) /* forward declaration for rtnl_create_link() */ static struct rtnl_link_ops vxcan_link_ops; -static int vxcan_newlink(struct net *peer_net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int vxcan_newlink(struct rtnl_newlink_params *params) { + struct netlink_ext_ack *extack = params->extack; + struct net_device *dev = params->dev; + 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 f3bea196a8f9..b4834651c693 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c @@ -117,11 +117,14 @@ static void rmnet_unregister_bridge(struct rmnet_port *port) rmnet_unregister_real_device(bridge_dev); } -static int rmnet_newlink(struct net *src_net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int rmnet_newlink(struct rtnl_newlink_params *params) { u32 data_format = RMNET_FLAGS_INGRESS_DEAGGREGATION; + struct netlink_ext_ack *extack = params->extack; + struct net_device *dev = params->dev; + 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; struct rmnet_endpoint *ep; diff --git a/drivers/net/geneve.c b/drivers/net/geneve.c index 642155cb8315..ea0a98a513ed 100644 --- a/drivers/net/geneve.c +++ b/drivers/net/geneve.c @@ -1614,10 +1614,13 @@ static void geneve_link_config(struct net_device *dev, geneve_change_mtu(dev, ldev_mtu - info->options_len); } -static int geneve_newlink(struct net *net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int geneve_newlink(struct rtnl_newlink_params *params) { + struct netlink_ext_ack *extack = params->extack; + struct net_device *dev = params->dev; + 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, diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c index 89a996ad8cd0..46d5734da7f3 100644 --- a/drivers/net/gtp.c +++ b/drivers/net/gtp.c @@ -1460,10 +1460,11 @@ static int gtp_create_sockets(struct gtp_dev *gtp, const struct nlattr *nla, #define GTP_TH_MAXLEN (sizeof(struct udphdr) + sizeof(struct gtp0_header)) #define GTP_IPV6_MAXLEN (sizeof(struct ipv6hdr) + GTP_TH_MAXLEN) -static int gtp_newlink(struct net *src_net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int gtp_newlink(struct rtnl_newlink_params *params) { + struct net_device *dev = params->dev; + 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; diff --git a/drivers/net/ipvlan/ipvlan.h b/drivers/net/ipvlan/ipvlan.h index 025e0c19ec25..beff25a1d6f0 100644 --- a/drivers/net/ipvlan/ipvlan.h +++ b/drivers/net/ipvlan/ipvlan.h @@ -166,9 +166,7 @@ struct ipvl_addr *ipvlan_addr_lookup(struct ipvl_port *port, void *lyr3h, void *ipvlan_get_L3_hdr(struct ipvl_port *port, struct sk_buff *skb, int *type); void ipvlan_count_rx(const struct ipvl_dev *ipvlan, unsigned int len, bool success, bool mcast); -int ipvlan_link_new(struct net *src_net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack); +int ipvlan_link_new(struct rtnl_newlink_params *params); void ipvlan_link_delete(struct net_device *dev, struct list_head *head); void ipvlan_link_setup(struct net_device *dev); int ipvlan_link_register(struct rtnl_link_ops *ops); diff --git a/drivers/net/ipvlan/ipvlan_main.c b/drivers/net/ipvlan/ipvlan_main.c index ee2c3cf4df36..a994fd54ada4 100644 --- a/drivers/net/ipvlan/ipvlan_main.c +++ b/drivers/net/ipvlan/ipvlan_main.c @@ -532,16 +532,21 @@ static int ipvlan_nl_fillinfo(struct sk_buff *skb, return ret; } -int ipvlan_link_new(struct net *src_net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +int ipvlan_link_new(struct rtnl_newlink_params *params) { - struct ipvl_dev *ipvlan = netdev_priv(dev); + struct netlink_ext_ack *extack = params->extack; + struct net_device *dev = params->dev; + struct nlattr **data = params->data; + struct net *src_net = params->net; + struct nlattr **tb = params->tb; + struct ipvl_dev *ipvlan; struct ipvl_port *port; struct net_device *phy_dev; int err; u16 mode = IPVLAN_MODE_L3; + ipvlan = netdev_priv(dev); + if (!tb[IFLA_LINK]) return -EINVAL; diff --git a/drivers/net/ipvlan/ipvtap.c b/drivers/net/ipvlan/ipvtap.c index 1afc4c47be73..0b0c65390066 100644 --- a/drivers/net/ipvlan/ipvtap.c +++ b/drivers/net/ipvlan/ipvtap.c @@ -73,13 +73,13 @@ static void ipvtap_update_features(struct tap_dev *tap, netdev_update_features(vlan->dev); } -static int ipvtap_newlink(struct net *src_net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int ipvtap_newlink(struct rtnl_newlink_params *params) { - struct ipvtap_dev *vlantap = netdev_priv(dev); + struct net_device *dev = params->dev; + struct ipvtap_dev *vlantap; int err; + vlantap = netdev_priv(dev); INIT_LIST_HEAD(&vlantap->tap.queue_list); /* Since macvlan supports all offloads by default, make @@ -97,7 +97,7 @@ static int ipvtap_newlink(struct net *src_net, struct net_device *dev, /* Don't put anything that may fail after macvlan_common_newlink * because we can't undo what it does. */ - err = ipvlan_link_new(src_net, dev, tb, data, extack); + err = ipvlan_link_new(params); if (err) { netdev_rx_handler_unregister(dev); return err; diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c index 1bc1e5993f56..9da111a6629c 100644 --- a/drivers/net/macsec.c +++ b/drivers/net/macsec.c @@ -4141,17 +4141,22 @@ static int macsec_add_dev(struct net_device *dev, sci_t sci, u8 icv_len) static struct lock_class_key macsec_netdev_addr_lock_key; -static int macsec_newlink(struct net *net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int macsec_newlink(struct rtnl_newlink_params *params) { - struct macsec_dev *macsec = macsec_priv(dev); + struct netlink_ext_ack *extack = params->extack; + struct net_device *dev = params->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; + struct macsec_dev *macsec; int err, mtu; sci_t sci; + macsec = macsec_priv(dev); + if (!tb[IFLA_LINK]) return -EINVAL; real_dev = __dev_get_by_index(net, nla_get_u32(tb[IFLA_LINK])); diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c index fed4fe2a4748..1915f54bd35a 100644 --- a/drivers/net/macvlan.c +++ b/drivers/net/macvlan.c @@ -1565,11 +1565,10 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev, } EXPORT_SYMBOL_GPL(macvlan_common_newlink); -static int macvlan_newlink(struct net *src_net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int macvlan_newlink(struct rtnl_newlink_params *params) { - return macvlan_common_newlink(src_net, dev, tb, data, extack); + return macvlan_common_newlink(params->net, params->dev, params->tb, + params->data, params->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 29a5929d48e5..e5fd8a147310 100644 --- a/drivers/net/macvtap.c +++ b/drivers/net/macvtap.c @@ -77,13 +77,13 @@ static void macvtap_update_features(struct tap_dev *tap, netdev_update_features(vlan->dev); } -static int macvtap_newlink(struct net *src_net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int macvtap_newlink(struct rtnl_newlink_params *params) { - struct macvtap_dev *vlantap = netdev_priv(dev); + struct net_device *dev = params->dev; + struct macvtap_dev *vlantap; int err; + vlantap = netdev_priv(dev); INIT_LIST_HEAD(&vlantap->tap.queue_list); /* Since macvlan supports all offloads by default, make @@ -105,7 +105,8 @@ static int macvtap_newlink(struct net *src_net, 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(src_net, dev, tb, data, extack); + err = macvlan_common_newlink(params->net, dev, params->tb, params->data, + params->extack); if (err) { netdev_rx_handler_unregister(dev); return err; diff --git a/drivers/net/netkit.c b/drivers/net/netkit.c index c1d881dc6409..f5527bb533ab 100644 --- a/drivers/net/netkit.c +++ b/drivers/net/netkit.c @@ -327,10 +327,13 @@ static int netkit_validate(struct nlattr *tb[], struct nlattr *data[], static struct rtnl_link_ops netkit_link_ops; -static int netkit_new_link(struct net *peer_net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int netkit_new_link(struct rtnl_newlink_params *params) { + struct netlink_ext_ack *extack = params->extack; + struct net_device *dev = params->dev; + 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; enum netkit_action policy_peer = NETKIT_PASS; diff --git a/drivers/net/pfcp.c b/drivers/net/pfcp.c index 69434fd13f96..cb936da99674 100644 --- a/drivers/net/pfcp.c +++ b/drivers/net/pfcp.c @@ -184,14 +184,15 @@ static int pfcp_add_sock(struct pfcp_dev *pfcp) return PTR_ERR_OR_ZERO(pfcp->sock); } -static int pfcp_newlink(struct net *net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int pfcp_newlink(struct rtnl_newlink_params *params) { - struct pfcp_dev *pfcp = netdev_priv(dev); + struct net_device *dev = params->dev; + struct net *net = params->net; + struct pfcp_dev *pfcp; struct pfcp_net *pn; int err; + pfcp = netdev_priv(dev); pfcp->net = net; err = pfcp_add_sock(pfcp); diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c index 4583e15ad03a..5b58e7bb4e7b 100644 --- a/drivers/net/ppp/ppp_generic.c +++ b/drivers/net/ppp/ppp_generic.c @@ -1303,10 +1303,12 @@ static int ppp_nl_validate(struct nlattr *tb[], struct nlattr *data[], return 0; } -static int ppp_nl_newlink(struct net *src_net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int ppp_nl_newlink(struct rtnl_newlink_params *params) { + struct net_device *dev = params->dev; + struct nlattr **data = params->data; + struct net *src_net = params->net; + struct nlattr **tb = params->tb; struct ppp_config conf = { .unit = -1, .ifname_is_set = true, diff --git a/drivers/net/team/team_core.c b/drivers/net/team/team_core.c index 69ea2c3c76bf..820c655249f5 100644 --- a/drivers/net/team/team_core.c +++ b/drivers/net/team/team_core.c @@ -2207,10 +2207,11 @@ static void team_setup(struct net_device *dev) dev->features |= NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_STAG_TX; } -static int team_newlink(struct net *src_net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int team_newlink(struct rtnl_newlink_params *params) { + struct net_device *dev = params->dev; + struct nlattr **tb = params->tb; + if (tb[IFLA_ADDRESS] == NULL) eth_hw_addr_random(dev); diff --git a/drivers/net/veth.c b/drivers/net/veth.c index 01251868a9c2..04229c07023d 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -1765,10 +1765,13 @@ static int veth_init_queues(struct net_device *dev, struct nlattr *tb[]) return 0; } -static int veth_newlink(struct net *peer_net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int veth_newlink(struct rtnl_newlink_params *params) { + struct netlink_ext_ack *extack = params->extack; + struct net_device *dev = params->dev; + struct nlattr **data = params->data; + struct net *peer_net = params->net; + struct nlattr **tb = params->tb; int err; struct net_device *peer; struct veth_priv *priv; diff --git a/drivers/net/vrf.c b/drivers/net/vrf.c index ca81b212a246..9a21bfc5bcc7 100644 --- a/drivers/net/vrf.c +++ b/drivers/net/vrf.c @@ -1677,16 +1677,19 @@ static void vrf_dellink(struct net_device *dev, struct list_head *head) unregister_netdevice_queue(dev, head); } -static int vrf_newlink(struct net *src_net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int vrf_newlink(struct rtnl_newlink_params *params) { - struct net_vrf *vrf = netdev_priv(dev); + struct netlink_ext_ack *extack = params->extack; + struct net_device *dev = params->dev; + struct nlattr **data = params->data; struct netns_vrf *nn_vrf; + struct net_vrf *vrf; bool *add_fib_rules; struct net *net; int err; + vrf = netdev_priv(dev); + if (!data || !data[IFLA_VRF_TABLE]) { NL_SET_ERR_MSG(extack, "VRF table id is missing"); return -EINVAL; diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c index 0c356e0a61ef..b084adb6d319 100644 --- a/drivers/net/vxlan/vxlan_core.c +++ b/drivers/net/vxlan/vxlan_core.c @@ -4393,10 +4393,13 @@ static int vxlan_nl2conf(struct nlattr *tb[], struct nlattr *data[], return 0; } -static int vxlan_newlink(struct net *src_net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int vxlan_newlink(struct rtnl_newlink_params *params) { + struct netlink_ext_ack *extack = params->extack; + struct net_device *dev = params->dev; + struct nlattr **data = params->data; + struct net *src_net = params->net; + struct nlattr **tb = params->tb; struct vxlan_config conf; int err; diff --git a/drivers/net/wireguard/device.c b/drivers/net/wireguard/device.c index 6cf173a008e7..92aac080d2b5 100644 --- a/drivers/net/wireguard/device.c +++ b/drivers/net/wireguard/device.c @@ -307,13 +307,14 @@ static void wg_setup(struct net_device *dev) wg->dev = dev; } -static int wg_newlink(struct net *src_net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int wg_newlink(struct rtnl_newlink_params *params) { - struct wg_device *wg = netdev_priv(dev); + struct net_device *dev = params->dev; + struct net *src_net = params->net; + struct wg_device *wg; int ret = -ENOMEM; + wg = netdev_priv(dev); rcu_assign_pointer(wg->creating_net, src_net); init_rwsem(&wg->static_identity.lock); mutex_init(&wg->socket_update_lock); diff --git a/drivers/net/wireless/virtual/virt_wifi.c b/drivers/net/wireless/virtual/virt_wifi.c index 4ee374080466..d64eb03e0ac8 100644 --- a/drivers/net/wireless/virtual/virt_wifi.c +++ b/drivers/net/wireless/virtual/virt_wifi.c @@ -519,13 +519,17 @@ static rx_handler_result_t virt_wifi_rx_handler(struct sk_buff **pskb) } /* Called with rtnl lock held. */ -static int virt_wifi_newlink(struct net *src_net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int virt_wifi_newlink(struct rtnl_newlink_params *params) { - struct virt_wifi_netdev_priv *priv = netdev_priv(dev); + struct netlink_ext_ack *extack = params->extack; + struct net_device *dev = params->dev; + struct virt_wifi_netdev_priv *priv; + struct net *src_net = params->net; + struct nlattr **tb = params->tb; int err; + priv = netdev_priv(dev); + if (!tb[IFLA_LINK]) return -EINVAL; diff --git a/drivers/net/wwan/wwan_core.c b/drivers/net/wwan/wwan_core.c index a51e2755991a..908a3db61477 100644 --- a/drivers/net/wwan/wwan_core.c +++ b/drivers/net/wwan/wwan_core.c @@ -967,15 +967,20 @@ static struct net_device *wwan_rtnl_alloc(struct nlattr *tb[], return dev; } -static int wwan_rtnl_newlink(struct net *src_net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int wwan_rtnl_newlink(struct rtnl_newlink_params *params) { - struct wwan_device *wwandev = wwan_dev_get_by_parent(dev->dev.parent); - u32 link_id = nla_get_u32(data[IFLA_WWAN_LINK_ID]); - struct wwan_netdev_priv *priv = netdev_priv(dev); + struct netlink_ext_ack *extack = params->extack; + struct net_device *dev = params->dev; + struct nlattr **data = params->data; + struct wwan_netdev_priv *priv; + struct wwan_device *wwandev; + u32 link_id; int ret; + wwandev = wwan_dev_get_by_parent(dev->dev.parent); + link_id = nla_get_u32(data[IFLA_WWAN_LINK_ID]); + priv = netdev_priv(dev); + if (IS_ERR(wwandev)) return PTR_ERR(wwandev); @@ -1064,6 +1069,11 @@ static void wwan_create_default_link(struct wwan_device *wwandev, struct net_device *dev; struct nlmsghdr *nlh; struct sk_buff *msg; + struct rtnl_newlink_params params = { + .net = &init_net, + .tb = tb, + .data = data, + }; /* Forge attributes required to create a WWAN netdev. We first * build a netlink message and then parse it. This looks @@ -1105,7 +1115,8 @@ static void wwan_create_default_link(struct wwan_device *wwandev, if (WARN_ON(IS_ERR(dev))) goto unlock; - if (WARN_ON(wwan_rtnl_newlink(&init_net, dev, tb, data, NULL))) { + params.dev = dev; + if (WARN_ON(wwan_rtnl_newlink(¶ms))) { free_netdev(dev); goto unlock; } diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h index bc0069a8b6ea..ed970b4568d1 100644 --- a/include/net/rtnetlink.h +++ b/include/net/rtnetlink.h @@ -69,6 +69,46 @@ static inline int rtnl_msg_family(const struct nlmsghdr *nlh) return AF_UNSPEC; } +/** + * struct rtnl_newlink_params - parameters of rtnl_link_ops::newlink() + * + * @net: Netns of interest + * @src_net: Source netns of rtnetlink socket + * @link_net: Link netns by IFLA_LINK_NETNSID, NULL if not specified + * @peer_net: Peer netns + * @dev: The net_device being created + * @tb: IFLA_* attributes + * @data: IFLA_INFO_DATA attributes + * @extack: Netlink extended ACK + */ +struct rtnl_newlink_params { + struct net *net; + struct net *src_net; + struct net *link_net; + struct net *peer_net; + struct net_device *dev; + struct nlattr **tb; + struct nlattr **data; + struct netlink_ext_ack *extack; +}; + +/* Get effective link netns from newlink params. Generally, this is link_net + * and falls back to src_net. But for compatibility, a driver may * choose to + * use dev_net(dev) instead. + */ +static inline struct net *rtnl_newlink_link_net(struct rtnl_newlink_params *p) +{ + return p->link_net ? : p->src_net; +} + +/* Get peer netns from newlink params. Fallback to link netns if peer netns is + * not specified explicitly. + */ +static inline struct net *rtnl_newlink_peer_net(struct rtnl_newlink_params *p) +{ + return p->peer_net ? : rtnl_newlink_link_net(p); +} + /** * struct rtnl_link_ops - rtnetlink link operations * @@ -125,11 +165,7 @@ struct rtnl_link_ops { struct nlattr *data[], struct netlink_ext_ack *extack); - int (*newlink)(struct net *src_net, - struct net_device *dev, - struct nlattr *tb[], - struct nlattr *data[], - struct netlink_ext_ack *extack); + int (*newlink)(struct rtnl_newlink_params *params); int (*changelink)(struct net_device *dev, struct nlattr *tb[], struct nlattr *data[], diff --git a/net/8021q/vlan_netlink.c b/net/8021q/vlan_netlink.c index 134419667d59..26a0f0a2ce27 100644 --- a/net/8021q/vlan_netlink.c +++ b/net/8021q/vlan_netlink.c @@ -135,16 +135,21 @@ static int vlan_changelink(struct net_device *dev, struct nlattr *tb[], return 0; } -static int vlan_newlink(struct net *src_net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int vlan_newlink(struct rtnl_newlink_params *params) { - struct vlan_dev_priv *vlan = vlan_dev_priv(dev); + struct netlink_ext_ack *extack = params->extack; + struct net_device *dev = params->dev; + struct nlattr **data = params->data; + struct net *src_net = params->net; + struct nlattr **tb = params->tb; struct net_device *real_dev; + struct vlan_dev_priv *vlan; unsigned int max_mtu; __be16 proto; int err; + vlan = vlan_dev_priv(dev); + if (!data[IFLA_VLAN_ID]) { NL_SET_ERR_MSG_MOD(extack, "VLAN id not specified"); return -EINVAL; diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c index 2758aba47a2f..5f92a25d6b26 100644 --- a/net/batman-adv/soft-interface.c +++ b/net/batman-adv/soft-interface.c @@ -1063,22 +1063,20 @@ static int batadv_softif_validate(struct nlattr *tb[], struct nlattr *data[], /** * batadv_softif_newlink() - pre-initialize and register new batadv link - * @src_net: the applicable net namespace - * @dev: network device to register - * @tb: IFLA_INFO_DATA netlink attributes - * @data: enum batadv_ifla_attrs attributes - * @extack: extended ACK report struct + * @params: rtnl newlink parameters * * Return: 0 if successful or error otherwise. */ -static int batadv_softif_newlink(struct net *src_net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int batadv_softif_newlink(struct rtnl_newlink_params *params) { - struct batadv_priv *bat_priv = netdev_priv(dev); + struct net_device *dev = params->dev; + struct nlattr **data = params->data; + struct batadv_priv *bat_priv; const char *algo_name; int err; + bat_priv = netdev_priv(dev); + if (data && data[IFLA_BATADV_ALGO_NAME]) { algo_name = nla_data(data[IFLA_BATADV_ALGO_NAME]); err = batadv_algo_select(bat_priv, algo_name); diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c index 3e0f47203f2a..362ca10607ba 100644 --- a/net/bridge/br_netlink.c +++ b/net/bridge/br_netlink.c @@ -1553,13 +1553,17 @@ static int br_changelink(struct net_device *brdev, struct nlattr *tb[], return 0; } -static int br_dev_newlink(struct net *src_net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int br_dev_newlink(struct rtnl_newlink_params *params) { - struct net_bridge *br = netdev_priv(dev); + struct netlink_ext_ack *extack = params->extack; + struct net_device *dev = params->dev; + struct nlattr **data = params->data; + struct nlattr **tb = params->tb; + struct net_bridge *br; int err; + br = netdev_priv(dev); + err = register_netdevice(dev); if (err) return err; diff --git a/net/caif/chnl_net.c b/net/caif/chnl_net.c index 94ad09e36df2..748e38908709 100644 --- a/net/caif/chnl_net.c +++ b/net/caif/chnl_net.c @@ -438,10 +438,10 @@ static void caif_netlink_parms(struct nlattr *data[], } } -static int ipcaif_newlink(struct net *src_net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int ipcaif_newlink(struct rtnl_newlink_params *params) { + struct net_device *dev = params->dev; + struct nlattr **data = params->data; int ret; struct chnl_net *caifdev; ASSERT_RTNL(); diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 6a2fa030c8e0..f7c176a2f1a0 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -3757,6 +3757,15 @@ static int rtnl_newlink_create(struct sk_buff *skb, struct ifinfomsg *ifm, struct net_device *dev; char ifname[IFNAMSIZ]; int err; + struct rtnl_newlink_params params = { + .net = net, + .src_net = net, + .link_net = link_net, + .peer_net = peer_net, + .tb = tb, + .data = data, + .extack = extack, + }; if (!ops->alloc && !ops->setup) return -EOPNOTSUPP; @@ -3776,14 +3785,15 @@ static int rtnl_newlink_create(struct sk_buff *skb, struct ifinfomsg *ifm, } dev->ifindex = ifm->ifi_index; + params.dev = dev; if (link_net) - net = link_net; + params.net = link_net; if (peer_net) - net = peer_net; + params.net = peer_net; if (ops->newlink) - err = ops->newlink(net, dev, tb, data, extack); + err = ops->newlink(¶ms); else err = register_netdevice(dev); if (err < 0) { diff --git a/net/hsr/hsr_netlink.c b/net/hsr/hsr_netlink.c index b68f2f71d0e1..08d38e2e2962 100644 --- a/net/hsr/hsr_netlink.c +++ b/net/hsr/hsr_netlink.c @@ -29,10 +29,12 @@ static const struct nla_policy hsr_policy[IFLA_HSR_MAX + 1] = { /* Here, it seems a netdevice has already been allocated for us, and the * hsr_dev_setup routine has been executed. Nice! */ -static int hsr_newlink(struct net *src_net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int hsr_newlink(struct rtnl_newlink_params *params) { + struct netlink_ext_ack *extack = params->extack; + struct net_device *dev = params->dev; + 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; diff --git a/net/ieee802154/6lowpan/core.c b/net/ieee802154/6lowpan/core.c index 175efd860f7b..c16c14807d87 100644 --- a/net/ieee802154/6lowpan/core.c +++ b/net/ieee802154/6lowpan/core.c @@ -129,10 +129,10 @@ static int lowpan_validate(struct nlattr *tb[], struct nlattr *data[], return 0; } -static int lowpan_newlink(struct net *src_net, struct net_device *ldev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int lowpan_newlink(struct rtnl_newlink_params *params) { + struct net_device *ldev = params->dev; + struct nlattr **tb = params->tb; struct net_device *wdev; int ret; diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c index f1f31ebfc793..ecad1d88dd26 100644 --- a/net/ipv4/ip_gre.c +++ b/net/ipv4/ip_gre.c @@ -1389,10 +1389,11 @@ ipgre_newlink_encap_setup(struct net_device *dev, struct nlattr *data[]) return 0; } -static int ipgre_newlink(struct net *src_net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int ipgre_newlink(struct rtnl_newlink_params *params) { + struct net_device *dev = params->dev; + struct nlattr **data = params->data; + struct nlattr **tb = params->tb; struct ip_tunnel_parm_kern p; __u32 fwmark = 0; int err; @@ -1407,10 +1408,11 @@ static int ipgre_newlink(struct net *src_net, struct net_device *dev, return ip_tunnel_newlink(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) +static int erspan_newlink(struct rtnl_newlink_params *params) { + struct net_device *dev = params->dev; + struct nlattr **data = params->data; + struct nlattr **tb = params->tb; struct ip_tunnel_parm_kern p; __u32 fwmark = 0; int err; @@ -1695,6 +1697,10 @@ struct net_device *gretap_fb_dev_create(struct net *net, const char *name, LIST_HEAD(list_kill); struct ip_tunnel *t; int err; + struct rtnl_newlink_params params = { + .net = net, + .tb = tb, + }; memset(&tb, 0, sizeof(tb)); @@ -1707,7 +1713,8 @@ struct net_device *gretap_fb_dev_create(struct net *net, const char *name, t = netdev_priv(dev); t->collect_md = true; - err = ipgre_newlink(net, dev, tb, NULL, NULL); + params.dev = dev; + err = ipgre_newlink(¶ms); if (err < 0) { free_netdev(dev); return ERR_PTR(err); diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c index f0b4419cef34..12ccbf34fb6c 100644 --- a/net/ipv4/ip_vti.c +++ b/net/ipv4/ip_vti.c @@ -575,11 +575,12 @@ static void vti_netlink_parms(struct nlattr *data[], *fwmark = nla_get_u32(data[IFLA_VTI_FWMARK]); } -static int vti_newlink(struct net *src_net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int vti_newlink(struct rtnl_newlink_params *params) { + struct net_device *dev = params->dev; + struct nlattr **data = params->data; struct ip_tunnel_parm_kern parms; + struct nlattr **tb = params->tb; __u32 fwmark = 0; vti_netlink_parms(data, &parms, &fwmark); diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c index dc0db5895e0e..3a737ea3c2e5 100644 --- a/net/ipv4/ipip.c +++ b/net/ipv4/ipip.c @@ -436,15 +436,18 @@ static void ipip_netlink_parms(struct nlattr *data[], *fwmark = nla_get_u32(data[IFLA_IPTUN_FWMARK]); } -static int ipip_newlink(struct net *src_net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int ipip_newlink(struct rtnl_newlink_params *params) { - struct ip_tunnel *t = netdev_priv(dev); + struct net_device *dev = params->dev; + struct nlattr **data = params->data; + struct nlattr **tb = params->tb; struct ip_tunnel_encap ipencap; struct ip_tunnel_parm_kern p; + struct ip_tunnel *t; __u32 fwmark = 0; + t = netdev_priv(dev); + if (ip_tunnel_netlink_encap_parms(data, &ipencap)) { int err = ip_tunnel_encap_setup(t, &ipencap); diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c index 235808cfec70..3efd51f0d7d2 100644 --- a/net/ipv6/ip6_gre.c +++ b/net/ipv6/ip6_gre.c @@ -2005,15 +2005,19 @@ static int ip6gre_newlink_common(struct net *src_net, struct net_device *dev, return err; } -static int ip6gre_newlink(struct net *src_net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int ip6gre_newlink(struct rtnl_newlink_params *params) { - struct ip6_tnl *nt = netdev_priv(dev); + struct netlink_ext_ack *extack = params->extack; + struct net_device *dev = params->dev; + struct nlattr **data = params->data; + struct net *src_net = params->net; + struct nlattr **tb = params->tb; struct net *net = dev_net(dev); struct ip6gre_net *ign; + struct ip6_tnl *nt; int err; + nt = netdev_priv(dev); ip6gre_netlink_parms(data, &nt->parms); ign = net_generic(net, ip6gre_net_id); @@ -2241,15 +2245,19 @@ static void ip6erspan_tap_setup(struct net_device *dev) netif_keep_dst(dev); } -static int ip6erspan_newlink(struct net *src_net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int ip6erspan_newlink(struct rtnl_newlink_params *params) { - struct ip6_tnl *nt = netdev_priv(dev); + struct netlink_ext_ack *extack = params->extack; + struct net_device *dev = params->dev; + struct nlattr **data = params->data; + struct net *src_net = params->net; + struct nlattr **tb = params->tb; struct net *net = dev_net(dev); struct ip6gre_net *ign; + struct ip6_tnl *nt; int err; + nt = netdev_priv(dev); ip6gre_netlink_parms(data, &nt->parms); ip6erspan_set_version(data, &nt->parms); ign = net_generic(net, ip6gre_net_id); diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c index 48fd53b98972..f4bdbabc3246 100644 --- a/net/ipv6/ip6_tunnel.c +++ b/net/ipv6/ip6_tunnel.c @@ -2002,10 +2002,11 @@ static void ip6_tnl_netlink_parms(struct nlattr *data[], parms->fwmark = nla_get_u32(data[IFLA_IPTUN_FWMARK]); } -static int ip6_tnl_newlink(struct net *src_net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int ip6_tnl_newlink(struct rtnl_newlink_params *params) { + struct net_device *dev = params->dev; + struct nlattr **data = params->data; + struct nlattr **tb = params->tb; struct net *net = dev_net(dev); struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id); struct ip_tunnel_encap ipencap; diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c index 590737c27537..79e601e629d2 100644 --- a/net/ipv6/ip6_vti.c +++ b/net/ipv6/ip6_vti.c @@ -997,10 +997,10 @@ static void vti6_netlink_parms(struct nlattr *data[], parms->fwmark = nla_get_u32(data[IFLA_VTI_FWMARK]); } -static int vti6_newlink(struct net *src_net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int vti6_newlink(struct rtnl_newlink_params *params) { + struct net_device *dev = params->dev; + struct nlattr **data = params->data; struct net *net = dev_net(dev); struct ip6_tnl *nt; diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c index 39bd8951bfca..4dd1309d1eb3 100644 --- a/net/ipv6/sit.c +++ b/net/ipv6/sit.c @@ -1550,10 +1550,11 @@ static bool ipip6_netlink_6rd_parms(struct nlattr *data[], } #endif -static int ipip6_newlink(struct net *src_net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int ipip6_newlink(struct rtnl_newlink_params *params) { + struct net_device *dev = params->dev; + struct nlattr **data = params->data; + struct nlattr **tb = params->tb; struct net *net = dev_net(dev); struct ip_tunnel *nt; struct ip_tunnel_encap ipencap; diff --git a/net/xfrm/xfrm_interface_core.c b/net/xfrm/xfrm_interface_core.c index 98f1e2b67c76..77d50d4af4a1 100644 --- a/net/xfrm/xfrm_interface_core.c +++ b/net/xfrm/xfrm_interface_core.c @@ -814,10 +814,11 @@ static void xfrmi_netlink_parms(struct nlattr *data[], parms->collect_md = true; } -static int xfrmi_newlink(struct net *src_net, struct net_device *dev, - struct nlattr *tb[], struct nlattr *data[], - struct netlink_ext_ack *extack) +static int xfrmi_newlink(struct rtnl_newlink_params *params) { + struct netlink_ext_ack *extack = params->extack; + struct net_device *dev = params->dev; + struct nlattr **data = params->data; struct net *net = dev_net(dev); struct xfrm_if_parms p = {}; struct xfrm_if *xi; From patchwork Wed Dec 18 13:09: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: 13913659 X-Patchwork-Delegate: johannes@sipsolutions.net Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.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 D75431B0434; Wed, 18 Dec 2024 13:09:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734527392; cv=none; b=pY6fp3Bc2BusQnRlwZhVl7ErPxtVubl9NQSKM26ikQv4vdu2RaQ9oKiWLK/B8+NPvciPQy3gidTagmzNr4WcmMmU4NNY+gtVyRehtIDZSKT0lpKUu3gmzUcO+U8lJugIyLJOs5g7lSqLGWtcBgTzXnxrtybRT0UA30sb7Eqgkss= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734527392; c=relaxed/simple; bh=k9si6OUTygkBqe/mTrB53rmX+fjK2dXt9TeZipErpYQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EcL7qTh6UP8UG+RC67759hBoPO2HlSElgX22jNnD/ILpWEdEkr2e5PNgIenTlZQGvlVaa4RDywTWfZHxQLpSlP0f2aY2TCOW8T3ecKr4qA3QQWaQdvtHJ6JLedSigUxRKMW0CB/vE6ezZJJPOwmwTRm5V7QsssCLNyHW1GqbMgo= 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=D1jcaC+N; arc=none smtp.client-ip=209.85.210.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="D1jcaC+N" Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-725ee27e905so8142130b3a.2; Wed, 18 Dec 2024 05:09:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734527390; x=1735132190; 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=v6FxJs9/7QYFH33A+3OHee7AY5o5pyw1d0MAaneftBM=; b=D1jcaC+N1Jx+hh+Qy+rpKhZonNYi5lpaD3BwUV5dtUOE3zp9WdFzDUzJh/8aiQEPww wiELhVv/fEJXvJ/FaQNFziPrteIbZKS8qUf8BDKHtdY+J2632bvMudYBqWQ1eATpZrwx ObZxilIrBnPyiFWtOTKk+2d8MFmOlQu7urJT4aF5mWVhjYfuEGOuwX/+PNn3JqRrjs81 c03gG0g4ZLL7EVRMRB8d10H57axZy8J7PYlyr3eJvVbC0W1zfIVmacDZ2t4/j0Ijif9Q eyEvv/26YvoXtyhbtBrfYai3/YsZmafOh9+IUbviWt4NSucRExKBZz5zFagbD7g6xa5U /5HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734527390; x=1735132190; 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=v6FxJs9/7QYFH33A+3OHee7AY5o5pyw1d0MAaneftBM=; b=pheNCF6eqLDh5CRXoJvUN2nh11zJHraW+I9LKgRwLnxZKNpw0UlKi3FTwV7+QK2Qvd RoGxaaLGayrLm+AYXwS8U5+nUDHiVhPiSLi63PDOHocyCD/3/2DgkCPDls3gi0CQ64pl XGgL7ucpkCwj7I3nzqLHiokhZwufT9MwKuN3M6Qf2Kapt6+TIaSPx8eBbDdiv1oCpoGc eIli2DU4TZPFJh5/j6RLwx/LXTLIaRtSV8i0LEORjgTd5Fok7XRQxZJarMGqUz1Uh5YZ DlHsqXMD4y1eL3xcTA9YQ1BbBzy86qZT6SYZtDTgbspfVFMUsS3G0kxWHMvcHDVxndU3 BQTA== X-Forwarded-Encrypted: i=1; AJvYcCUP3mOzG8SMoqNM9p0RnsQXn0vZfNU2GO6h1P0u3SQ3RPY7i/C+Tf28SlcrQXopUi+VCK7iwiegi9nEaoe52VU=@vger.kernel.org, AJvYcCUaO3BnWJNjtAeO4t7g/4+GswUAXRkLxRkuPiOim3WASb10bIVXwkqEvXPPkwp1TZfwyTatvhoTklW4e+NA@vger.kernel.org, AJvYcCUy9BtcT70/uQqrZ2BD2k/0TofNyTURSsqZM5Vca8ZYhW7CsT4iXdzgf9IXUd/BLTRNslA=@vger.kernel.org, AJvYcCVJ8sZSikyeVyARPr0TR2S4tf26SaeeKanHw0mPfEhIj+XFxtd/r1cTNjgju/mLhiIoCWY9ZzyLYMGF/KGbeOkL@vger.kernel.org, AJvYcCWDiE8TLiWCoa8NPSKQOa/eOq6tEMa52TBbYU9m9y16XAolcBzUzsDX/NtQEOGb70cY+l48hAAEXjO68A==@vger.kernel.org, AJvYcCWEt3PtBr4kVMpD/iGwyy8So4aUGWmRGuMbr4CNhThWsGVpZGNIszwzttWZB/rcSABAhVXYzBhbfnoAaA==@vger.kernel.org, AJvYcCWQjwLV8UdhVNPp7q7n5mLGep7c647mp2hQ+6eF1KPSnNrZDzBTZUXUrGsrmuLqIP2Fa3/s1ox4e7rX@vger.kernel.org, AJvYcCXNoGjPDAY6K+y5s6dPH9xE6uQ2Y29OhYq57CN73k534xRDgxmxEBj/YKoNUl/SIOFkKnpmwPi2ETj4@vger.kernel.org X-Gm-Message-State: AOJu0YxEFmt2hyAAUMxLo9t1uJ6/m5/vJxAW6Ydh7LtC6Hqm8b7gdAb7 ruz2GoGp9NO+Q9qgzc7HIRhIyG4rt2CNLs1TGlUY+gB23Mn/YbQPMWuz/RkvLUY= X-Gm-Gg: ASbGncsbFWDVNDKLVM6n3j1PcIkDSdBO2k+zzXWvB5Dvqv5+X23uhIPQnhWLA/aR53r inH00NfzI4aPNpY8igLCRBgUYmOfFWZ9KCmZrrb3ioFZjq9Yk8OyjOuSiJyYkNe1+0tvgvVtuzX Ce7/t/ezQkg1R85mU7gmismJZO2xhC+fKLCIpfF8si7uwMMS9XmWj6P+IvV5axzFB31XbwJfTWh IHJ5ui8rCFNggaAwnuVBnI/JcMxjls7INaimB8dyjchl/A= X-Google-Smtp-Source: AGHT+IH+tvU5/KiA8X+jx87i+ek803hY16k/2JRAl0mg7VLySak7zxczf+KB71TM0YDQSiaCbWH0pA== X-Received: by 2002:a05:6a20:9d93:b0:1e1:9fef:e975 with SMTP id adf61e73a8af0-1e5b482e23cmr5391801637.26.1734527389573; Wed, 18 Dec 2024 05:09:49 -0800 (PST) Received: from ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-801d5c0f59asm7434754a12.67.2024.12.18.05.09.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Dec 2024 05:09:49 -0800 (PST) From: Xiao Liang To: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Kuniyuki Iwashima , Jakub Kicinski , Donald Hunter , Paolo Abeni Cc: "David S. Miller" , David Ahern , Eric Dumazet , Ido Schimmel , Andrew Lunn , Simon Horman , Shuah Khan , Jiri Pirko , Hangbin Liu , 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 v6 03/11] net: Use link netns in newlink() of rtnl_link_ops Date: Wed, 18 Dec 2024 21:09:01 +0800 Message-ID: <20241218130909.2173-4-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241218130909.2173-1-shaw.leon@gmail.com> References: <20241218130909.2173-1-shaw.leon@gmail.com> Precedence: bulk X-Mailing-List: linux-wireless@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 | 5 +++-- 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, 42 insertions(+), 41 deletions(-) diff --git a/drivers/infiniband/ulp/ipoib/ipoib_netlink.c b/drivers/infiniband/ulp/ipoib/ipoib_netlink.c index 61f2457aab77..ac01650b0ac2 100644 --- a/drivers/infiniband/ulp/ipoib/ipoib_netlink.c +++ b/drivers/infiniband/ulp/ipoib/ipoib_netlink.c @@ -99,10 +99,10 @@ static int ipoib_changelink(struct net_device *dev, struct nlattr *tb[], static int ipoib_new_child_link(struct rtnl_newlink_params *params) { + struct net *link_net = rtnl_newlink_link_net(params); struct netlink_ext_ack *extack = params->extack; struct net_device *dev = params->dev; 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 rtnl_newlink_params *params) 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 85878abb51d2..de4ea1a3f3d3 100644 --- a/drivers/net/amt.c +++ b/drivers/net/amt.c @@ -3163,16 +3163,16 @@ static int amt_validate(struct nlattr *tb[], struct nlattr *data[], static int amt_newlink(struct rtnl_newlink_params *params) { + struct net *link_net = rtnl_newlink_link_net(params); struct netlink_ext_ack *extack = params->extack; struct net_device *dev = params->dev; struct nlattr **data = params->data; struct nlattr **tb = params->tb; - struct net *net = params->net; struct amt_dev *amt; int err = -EINVAL; amt = netdev_priv(dev); - amt->net = net; + amt->net = link_net; amt->mode = nla_get_u32(data[IFLA_AMT_MODE]); if (data[IFLA_AMT_MAX_TUNNELS] && @@ -3187,7 +3187,7 @@ static int amt_newlink(struct rtnl_newlink_params *params) 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 4c2a50bbf7c0..1fe5dcae38f5 100644 --- a/drivers/net/bareudp.c +++ b/drivers/net/bareudp.c @@ -700,11 +700,11 @@ static void bareudp_dellink(struct net_device *dev, struct list_head *head) static int bareudp_newlink(struct rtnl_newlink_params *params) { + struct net *link_net = rtnl_newlink_link_net(params); struct netlink_ext_ack *extack = params->extack; struct net_device *dev = params->dev; 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 rtnl_newlink_params *params) 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 5d7717c22fab..e3c52c191086 100644 --- a/drivers/net/can/vxcan.c +++ b/drivers/net/can/vxcan.c @@ -174,10 +174,10 @@ static struct rtnl_link_ops vxcan_link_ops; static int vxcan_newlink(struct rtnl_newlink_params *params) { + struct net *peer_net = rtnl_newlink_peer_net(params); struct netlink_ext_ack *extack = params->extack; struct net_device *dev = params->dev; 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 b4834651c693..7a6b746a3b15 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c @@ -120,10 +120,10 @@ static void rmnet_unregister_bridge(struct rmnet_port *port) static int rmnet_newlink(struct rtnl_newlink_params *params) { u32 data_format = RMNET_FLAGS_INGRESS_DEAGGREGATION; + struct net *link_net = rtnl_newlink_link_net(params); struct netlink_ext_ack *extack = params->extack; struct net_device *dev = params->dev; 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 rtnl_newlink_params *params) 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 ea0a98a513ed..3dec3e5aae79 100644 --- a/drivers/net/geneve.c +++ b/drivers/net/geneve.c @@ -1616,11 +1616,11 @@ static void geneve_link_config(struct net_device *dev, static int geneve_newlink(struct rtnl_newlink_params *params) { + struct net *link_net = rtnl_newlink_link_net(params); struct netlink_ext_ack *extack = params->extack; struct net_device *dev = params->dev; 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 rtnl_newlink_params *params) 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 46d5734da7f3..50f8a0cd1d4b 100644 --- a/drivers/net/gtp.c +++ b/drivers/net/gtp.c @@ -1462,9 +1462,9 @@ static int gtp_create_sockets(struct gtp_dev *gtp, const struct nlattr *nla, static int gtp_newlink(struct rtnl_newlink_params *params) { + struct net *link_net = rtnl_newlink_link_net(params); struct net_device *dev = params->dev; 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; @@ -1495,7 +1495,7 @@ static int gtp_newlink(struct rtnl_newlink_params *params) 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 a994fd54ada4..7d19771383c7 100644 --- a/drivers/net/ipvlan/ipvlan_main.c +++ b/drivers/net/ipvlan/ipvlan_main.c @@ -534,10 +534,10 @@ static int ipvlan_nl_fillinfo(struct sk_buff *skb, int ipvlan_link_new(struct rtnl_newlink_params *params) { + struct net *link_net = rtnl_newlink_link_net(params); struct netlink_ext_ack *extack = params->extack; struct net_device *dev = params->dev; struct nlattr **data = params->data; - struct net *src_net = params->net; struct nlattr **tb = params->tb; struct ipvl_dev *ipvlan; struct ipvl_port *port; @@ -550,7 +550,7 @@ int ipvlan_link_new(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 9da111a6629c..ad53a67410dc 100644 --- a/drivers/net/macsec.c +++ b/drivers/net/macsec.c @@ -4143,11 +4143,11 @@ static struct lock_class_key macsec_netdev_addr_lock_key; static int macsec_newlink(struct rtnl_newlink_params *params) { + struct net *link_net = rtnl_newlink_link_net(params); struct netlink_ext_ack *extack = params->extack; struct net_device *dev = params->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; @@ -4159,7 +4159,7 @@ static int macsec_newlink(struct rtnl_newlink_params *params) 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 1915f54bd35a..7050a061b2b9 100644 --- a/drivers/net/macvlan.c +++ b/drivers/net/macvlan.c @@ -1567,8 +1567,9 @@ EXPORT_SYMBOL_GPL(macvlan_common_newlink); static int macvlan_newlink(struct rtnl_newlink_params *params) { - return macvlan_common_newlink(params->net, params->dev, params->tb, - params->data, params->extack); + return macvlan_common_newlink(rtnl_newlink_link_net(params), + params->dev, params->tb, params->data, + params->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 e5fd8a147310..01cf1efbe4c5 100644 --- a/drivers/net/macvtap.c +++ b/drivers/net/macvtap.c @@ -105,8 +105,8 @@ static int macvtap_newlink(struct rtnl_newlink_params *params) /* 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, - params->extack); + err = macvlan_common_newlink(rtnl_newlink_link_net(params), dev, + params->tb, params->data, params->extack); if (err) { netdev_rx_handler_unregister(dev); return err; diff --git a/drivers/net/netkit.c b/drivers/net/netkit.c index f5527bb533ab..79a2c37990fd 100644 --- a/drivers/net/netkit.c +++ b/drivers/net/netkit.c @@ -329,10 +329,10 @@ static struct rtnl_link_ops netkit_link_ops; static int netkit_new_link(struct rtnl_newlink_params *params) { + struct net *peer_net = rtnl_newlink_peer_net(params); struct netlink_ext_ack *extack = params->extack; struct net_device *dev = params->dev; 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 cb936da99674..e98724a71c22 100644 --- a/drivers/net/pfcp.c +++ b/drivers/net/pfcp.c @@ -186,14 +186,14 @@ static int pfcp_add_sock(struct pfcp_dev *pfcp) static int pfcp_newlink(struct rtnl_newlink_params *params) { + struct net *link_net = rtnl_newlink_link_net(params); struct net_device *dev = params->dev; - struct net *net = params->net; struct pfcp_dev *pfcp; struct pfcp_net *pn; int err; pfcp = netdev_priv(dev); - 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 5b58e7bb4e7b..316b6d01436b 100644 --- a/drivers/net/ppp/ppp_generic.c +++ b/drivers/net/ppp/ppp_generic.c @@ -1305,9 +1305,9 @@ static int ppp_nl_validate(struct nlattr *tb[], struct nlattr *data[], static int ppp_nl_newlink(struct rtnl_newlink_params *params) { + struct net *link_net = rtnl_newlink_link_net(params); struct net_device *dev = params->dev; struct nlattr **data = params->data; - struct net *src_net = params->net; struct nlattr **tb = params->tb; struct ppp_config conf = { .unit = -1, @@ -1345,7 +1345,7 @@ static int ppp_nl_newlink(struct rtnl_newlink_params *params) 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 04229c07023d..11ee821edcd6 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -1767,10 +1767,10 @@ static int veth_init_queues(struct net_device *dev, struct nlattr *tb[]) static int veth_newlink(struct rtnl_newlink_params *params) { + struct net *peer_net = rtnl_newlink_peer_net(params); struct netlink_ext_ack *extack = params->extack; struct net_device *dev = params->dev; 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 b084adb6d319..751da726cf56 100644 --- a/drivers/net/vxlan/vxlan_core.c +++ b/drivers/net/vxlan/vxlan_core.c @@ -4395,10 +4395,10 @@ static int vxlan_nl2conf(struct nlattr *tb[], struct nlattr *data[], static int vxlan_newlink(struct rtnl_newlink_params *params) { + struct net *link_net = rtnl_newlink_link_net(params); struct netlink_ext_ack *extack = params->extack; struct net_device *dev = params->dev; 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 rtnl_newlink_params *params) 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 92aac080d2b5..b2ba9d9c6ad3 100644 --- a/drivers/net/wireguard/device.c +++ b/drivers/net/wireguard/device.c @@ -309,13 +309,13 @@ static void wg_setup(struct net_device *dev) static int wg_newlink(struct rtnl_newlink_params *params) { + struct net *link_net = rtnl_newlink_link_net(params); struct net_device *dev = params->dev; - struct net *src_net = params->net; struct wg_device *wg; int ret = -ENOMEM; wg = netdev_priv(dev); - 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 d64eb03e0ac8..5e7c7a1d7d5f 100644 --- a/drivers/net/wireless/virtual/virt_wifi.c +++ b/drivers/net/wireless/virtual/virt_wifi.c @@ -521,10 +521,10 @@ static rx_handler_result_t virt_wifi_rx_handler(struct sk_buff **pskb) /* Called with rtnl lock held. */ static int virt_wifi_newlink(struct rtnl_newlink_params *params) { + struct net *link_net = rtnl_newlink_link_net(params); struct netlink_ext_ack *extack = params->extack; struct net_device *dev = params->dev; struct virt_wifi_netdev_priv *priv; - struct net *src_net = params->net; struct nlattr **tb = params->tb; int err; @@ -536,7 +536,7 @@ static int virt_wifi_newlink(struct rtnl_newlink_params *params) 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 908a3db61477..06a2172d1856 100644 --- a/drivers/net/wwan/wwan_core.c +++ b/drivers/net/wwan/wwan_core.c @@ -1070,7 +1070,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 26a0f0a2ce27..0a9930017bba 100644 --- a/net/8021q/vlan_netlink.c +++ b/net/8021q/vlan_netlink.c @@ -137,10 +137,10 @@ static int vlan_changelink(struct net_device *dev, struct nlattr *tb[], static int vlan_newlink(struct rtnl_newlink_params *params) { + struct net *link_net = rtnl_newlink_link_net(params); struct netlink_ext_ack *extack = params->extack; struct net_device *dev = params->dev; struct nlattr **data = params->data; - struct net *src_net = params->net; struct nlattr **tb = params->tb; struct net_device *real_dev; struct vlan_dev_priv *vlan; @@ -160,7 +160,7 @@ static int vlan_newlink(struct rtnl_newlink_params *params) 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 08d38e2e2962..9bc564e81827 100644 --- a/net/hsr/hsr_netlink.c +++ b/net/hsr/hsr_netlink.c @@ -31,10 +31,10 @@ static const struct nla_policy hsr_policy[IFLA_HSR_MAX + 1] = { */ static int hsr_newlink(struct rtnl_newlink_params *params) { + struct net *link_net = rtnl_newlink_link_net(params); struct netlink_ext_ack *extack = params->extack; struct net_device *dev = params->dev; 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 rtnl_newlink_params *params) 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 rtnl_newlink_params *params) 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 rtnl_newlink_params *params) } 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 Wed Dec 18 13:09: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: 13913660 X-Patchwork-Delegate: johannes@sipsolutions.net Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.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 4EF851F236A; Wed, 18 Dec 2024 13:09:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734527400; cv=none; b=Ph/b+m1/gk4U6iLhkn+sfACoK+fx61HnDCehQEnYRSma4xBnhXkYOROW5ZsCLn2H/FFTXRdU9KRlujfJglJNLVFFgs4J6KWnkn0LwKVGSSs38B5E4GyrJG2JSPRvTsiiK+djjBKYg1O3idZ/g0Wpj6k8rtdD9tgfcWcJ7s685kE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734527400; c=relaxed/simple; bh=cjTzwWbCJa7r3TyEGggN4J7HFrp5Bpypfn8vCgGnGtI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N85RVcmj4FjlwCy6ems+pvHwYTBwOaaoUIJXnNau9jGqJsdDmaWnHVpi2hPFg5bDysE8CaHeVQouHnWwH+pqqgD+EwSb0v0flRxOd64YN4RVaOUpD0hDgigur+YRnx2But4DNZ3IGlrtGfOyYWbS+ExoHodlKRrWLcWfeo0qIVA= 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=Mt0GTFMX; arc=none smtp.client-ip=209.85.210.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="Mt0GTFMX" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-728f1e66418so5660108b3a.2; Wed, 18 Dec 2024 05:09:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734527398; x=1735132198; 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=ZWtx/GpPr8Y7UYus5aPINKHxwSB0EzMFBw6o16b+Q3k=; b=Mt0GTFMXgKO9eS3uXRG7wKLOkih9FqcuXtN2dHpF0Q4Bok3NVoZAbQUecJhy832hLR 7nNaLKiNCz75LJKd/3nrj4u5UNSOcYthvBqH8pvwLAAq630Eb0XrUAlfxdrYAv0PXXC+ NRc9LHrPCoh+DDLUCCfVBqAWQJXG6p1bCwxrvxFvRM1MfJScGJL0iAw3h275d4kKppsY ixzn0nWd4uZSVSTHUeRglg9pHBxLDr79yBb5iOppILXZyTPj0TaYhBZqfIVPOdHt+c3g d0yomUBohUwl36hZEp7/LUnabEwg+13zHgW8dZTPu8Fo9yiypBehvUzTix2ZTe4w+21q MvXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734527398; x=1735132198; 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=ZWtx/GpPr8Y7UYus5aPINKHxwSB0EzMFBw6o16b+Q3k=; b=wBZmwvW4r9dPEklMZeZpNa4YL8UyVZhKMBubYkoah9IPUy05i3eAaHIHIeXpY0KhyP mTbtt1cum0In9i1SkYp7R2w5eMAJlrqqWG9txLupokmn0X8NF0ZlY3hz+oOKgMsNhhK6 k8Cz3LjEODvsQKCH9k7TMB3ENou/TPVZO/0vKJdkULCzO5qCzAOyK26xV2MfVnkiFQhJ tb2a+nyy/IkNXgu/wUdM2PbgHKrT+fJaWJxzX7DMJl5lb2ifcN38BkMniDjSDpUXP5k+ 15zlDL1TvFg1LOwP0B3IvW4eV1RJbx3r553UHanKyUnUlh5BiP73bnoaOqV+bfobIcyk 88bg== X-Forwarded-Encrypted: i=1; AJvYcCU/Mix1GlTNATgVxMbZ7bOqQ80sf3RE/SZRauH8zoQSuG83Hl+Evl/yG53AysbekG8pf4mGfSAbpeHm@vger.kernel.org, AJvYcCUG+U6h20BdyA39BPVoMbjBYTGNDc1N6Cc70lTlAyQkojU8744cU7Q5dhb4cyUDrEXxnrH9qzACzSbW@vger.kernel.org, AJvYcCURqLRiJFSQ1tdLdn+7XPtv4JT0WwviMRm49o1ekmydXkuNCBRY+sDvB8HA+eXazuOCaRw=@vger.kernel.org, AJvYcCUX+y6PxKwmhsNiepiaGX/+/xhiDOW4o5iC13SO5vtkH3LbU5zbikE+qsX+W6K3oguVssn+lbulgrv7K2x3x8Y=@vger.kernel.org, AJvYcCVNmxwiDB+Bf6iqqXnpUg2EApZkn4oikDWSiIuig4jqdxsoLB9FS5acf+wky50rjUE+VtJ9EPs11ZMCt57E@vger.kernel.org, AJvYcCVTXAl/5CdDCg2PLgkjroCnaDOUILPMnSfpljuJ3jCTOsCw2HGc45qlf33gqtyuo1KFsVv0XT95pYrKyHiWTrgR@vger.kernel.org, AJvYcCW900/P7MqZujJpET65zZ8XqTzO2z8AvN1eQwVP2x6A+xpKKgkNOUKIBfRp+mmUF77HJgCKBpdKTk1EoQ==@vger.kernel.org, AJvYcCXXzm2Qfyv5kd+vqR653ytDxBRGyiw2CAIWr7Ogmvszk8TeBpfXi5pMcsObs2PfNRj8fKvZHCh8z6vcVQ==@vger.kernel.org X-Gm-Message-State: AOJu0Yw6KCKAczYpjD7Jz88Z6Ar1H5MqjPnm/nhmZ1ENMPqjdW7eudhm hHbSx8H1JD68cnur9GDqWb4ZXXahOh8UDpQi6k6CKb7cEUYbqvsgJbKoEKKnOv4= X-Gm-Gg: ASbGncvRFwhCp/2vglDdYgkD8Dxgq0Y+xt8m6+ZOMmGYxT0Vwk6NSaQlZLb3yYPYE0e Urb1DgVTYo/jVrVMog930MXU2kg1AVajhcr9jpKbGNUA1o9/QD9gE3g9oGPjah+0/HR0HFobiG9 DiBuBfEY9uZaef+9/noCt1+FY8i4UN/fSFgcEtL9OG1bCCdp1TriI6ZqAMxnVAQ5i9cRtRO03WL +heMb+tyzGpVVfqMc/qsj9msRefFNIP2C+5O5bzybYVxXc= X-Google-Smtp-Source: AGHT+IGmYU6ujKxLBy1JGYsxY/MwVi8oxkRDUmwYNBJP1y7XmPRqmJNLVIgjjMfYAOzzfAymm/3esA== X-Received: by 2002:a05:6a00:35c3:b0:71e:1722:d019 with SMTP id d2e1a72fcca58-72a8d2f0b92mr4132701b3a.22.1734527397729; Wed, 18 Dec 2024 05:09:57 -0800 (PST) Received: from ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-801d5c0f59asm7434754a12.67.2024.12.18.05.09.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Dec 2024 05:09:57 -0800 (PST) From: Xiao Liang To: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Kuniyuki Iwashima , Jakub Kicinski , Donald Hunter , Paolo Abeni Cc: "David S. Miller" , David Ahern , Eric Dumazet , Ido Schimmel , Andrew Lunn , Simon Horman , Shuah Khan , Jiri Pirko , Hangbin Liu , 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 v6 04/11] ieee802154: 6lowpan: Use link netns in newlink() of rtnl_link_ops Date: Wed, 18 Dec 2024 21:09:02 +0800 Message-ID: <20241218130909.2173-5-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241218130909.2173-1-shaw.leon@gmail.com> References: <20241218130909.2173-1-shaw.leon@gmail.com> Precedence: bulk X-Mailing-List: linux-wireless@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/ieee802154/6lowpan/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/ieee802154/6lowpan/core.c b/net/ieee802154/6lowpan/core.c index c16c14807d87..65a5c61cf38c 100644 --- a/net/ieee802154/6lowpan/core.c +++ b/net/ieee802154/6lowpan/core.c @@ -143,7 +143,8 @@ static int lowpan_newlink(struct rtnl_newlink_params *params) if (!tb[IFLA_LINK]) return -EINVAL; /* find and hold wpan device */ - wdev = dev_get_by_index(dev_net(ldev), nla_get_u32(tb[IFLA_LINK])); + wdev = dev_get_by_index(params->link_net ? : dev_net(ldev), + nla_get_u32(tb[IFLA_LINK])); if (!wdev) return -ENODEV; if (wdev->type != ARPHRD_IEEE802154) { From patchwork Wed Dec 18 13:09: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: 13913661 X-Patchwork-Delegate: johannes@sipsolutions.net Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.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 2115A1F37A0; Wed, 18 Dec 2024 13:10:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734527410; cv=none; b=ENfY3S62VJ11PnWpmkNyNFpmIIGEOmNFtCM2jnmk/9S3we9h1O8UyPKey7N/jPQ5Opa+x6wisUFlD1peI/fa6lNh02xckFiXCc/vw+zTHRhk6kppXBd7guR++QmsAatBwgqGRqLIHhCCkE8upG47dCQbeU3pwvXIS93SFcWiZO4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734527410; c=relaxed/simple; bh=Q/SDsLYvLvxL7f1ap2ESVK2p4seJuOkLNCClDpbcn1g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=f0Svr0HtZWhcmo+Ol78dgXMlzuOQ05okniYwA5gV3jNkxbr2Kqs/ZbC5zqziRMuOcRbp2orQBWIRJStRdN3fdtmPKIrbUU1v0EVRhOVKLvpBszTmEdbOVx2xh51+ttIstKPz0U8ul4czkEUGmk8O0fsX/bymsqPtLbwXeNeQdzo= 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=RZG1Vlzc; arc=none smtp.client-ip=209.85.210.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="RZG1Vlzc" Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-728ec840a8aso6878525b3a.0; Wed, 18 Dec 2024 05:10:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734527406; x=1735132206; 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=duDRQNaydM9MnygAgym8Q8/9ko+la+IiXsEzlSyfpMg=; b=RZG1VlzcbzWj1TnXah8Pu9Wk6Cg12gTERlWp1pJw8xOfOJPwXgPUXbq2shluoEbyNM /6dCB4ujlcldB/swMJVrwZAHWAUWA8Y4yNCp12lqC5fcchRPbUdY3S0cOsV5RcOvr4bT Dv7dyQmNztBaWK/Mz0C2Og9NSWH39x4uyu+uVG+5EoGBFS4SqH9/p8fLyLJ47I8+ZUsR 6SediXsDzEWhgFEqBjaWA2CEeaDmzxfu7Q/7Q1NlzR1NfuJMPxbimc+/9pKJGrioIAeP uaye4v5beZGtoKIdS6w2bD/+tfNVIdWzVwfC0ZjhwYX6VlN6x03b10hrrZuPAbOS/yFj UjRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734527406; x=1735132206; 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=duDRQNaydM9MnygAgym8Q8/9ko+la+IiXsEzlSyfpMg=; b=IFJ3zMwPEdIacEE6UX5ersJEHV9whJj9MPGZufeBraurxqzeN0YAg1QmLbQKhE9H18 jjwP5qTLtpDF+Ah1j/oXMEJreiqhNez6gSKjq4AnKmCuxGOjblVX/LGUqWm2sETRmj8q TgQLDnAtuCbwtA+YNJAbw2HiBC/B3w7xOAD7KsagNBmF/YKvP00bmHzEpn5BgxDvnTJ0 eAWxqAlcBINi6Tdgbp89yLtzLWMU6VJ+ePPU3TjnvPDKnl2dZvWK2YxU8i7e90bytFRM mCWBGFEFbQct42e+kh8tExFSJII8JfRQtETRFDMiCYgquPEx0Ai0xTLV3r9Wmh6EPq/P bUZQ== X-Forwarded-Encrypted: i=1; AJvYcCUht++vYCJA33AUhuEJbagYLkzInsYsG97AuvXnJcO1fm1BMypLP2jAHckObHH2JsKOAik=@vger.kernel.org, AJvYcCUtIUF2jfXGmw7CwE4ZgePUTUoF9OAEhj0SIq6o8DmHu/r5JS+V2pUKQGee7zyHuBUtKxj9mmX9V9Pc7w==@vger.kernel.org, AJvYcCV/ParyEqKHXXzq29BB08O1XgEuvDIyN9MwmYlEWFyAhNw6/CQiQREUropNqcsxIq5P4+WvjnSkFfRg@vger.kernel.org, AJvYcCW0Fq00wP0XcfkoncyqIsRefvEKIOq2MTwvyZaM95Sc6UnEKtiI+VzWkD0EPosuNgWw9IV0QQygzI46@vger.kernel.org, AJvYcCW96md3YpDJGm4vJgWsnpfqL6+Ni4edHirkl9Sn87EfVC/f6bWlYR9hiMi0OkCX4S4AqsqFGj3yJ7bAOU+pwZE=@vger.kernel.org, AJvYcCWHrzslm8HpMve0LtUzQLrGrnBZy8SpUQUNFvnDxsK2Oro/GWDPZNuTbcwbIpmII3zvZ7RruUafjWcj8ufz@vger.kernel.org, AJvYcCWc9KSc3BfxDLYjk7UrkMKj+kKGL18N1DWRDsjpqWoPurLsiJL99YVnZH/KjMagdRbDbDdXPlEKpt96oA==@vger.kernel.org, AJvYcCXOANKnkL5lzoeGV2B4ejVBKbgH3hiHO2h7hnROiNgy1KuSzeGhp1THSy6N+27eVj2/uSnJA5LW6uZ0d/rCeTqA@vger.kernel.org X-Gm-Message-State: AOJu0YzGtPXWssUDDyc/byyZ5EV8BjqgwFCN5bF45GGeuqvdUtSvUQ4T rK8dOxG8xFaDHbWDb8CRyNIvlJKuxlfVfkuxQZs9s4Lralcd97KNDQ7Ita98ox8= X-Gm-Gg: ASbGncu9OqUqwpY6qTIcAE7ExD0tQB8cLgKqiIwL22pE5k1i8Afcuc/VR/1YvZX1Fxt ig8FrPGWPQXERePC6EHiBOpbWS8o0Xn2btfjRaTr+bAg1saNYX97x0ruryFFNywANMEVatvQOf1 PhN33zKNDeyd86zmNf4SXD2dFfOKotms4bQOfXdhtVCACct8R88IgCEValcBzPAXiekG1vPsAaA Z5x5JGmc0RwATpKfxeNRf3lAb7aypTVlOVE1k3WOM9WFko= X-Google-Smtp-Source: AGHT+IHjAWByhkuRCvJpT02c4DgXI4s1gEBDobTpc14t8liBEMaFpl/IXfL3hYD82aWPv+sYgjfNgQ== X-Received: by 2002:a05:6a21:c94:b0:1e1:a647:8a3f with SMTP id adf61e73a8af0-1e5b4824307mr5763308637.22.1734527405806; Wed, 18 Dec 2024 05:10:05 -0800 (PST) Received: from ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-801d5c0f59asm7434754a12.67.2024.12.18.05.09.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Dec 2024 05:10:05 -0800 (PST) From: Xiao Liang To: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Kuniyuki Iwashima , Jakub Kicinski , Donald Hunter , Paolo Abeni Cc: "David S. Miller" , David Ahern , Eric Dumazet , Ido Schimmel , Andrew Lunn , Simon Horman , Shuah Khan , Jiri Pirko , Hangbin Liu , 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 v6 05/11] net: ip_tunnel: Use link netns in newlink() of rtnl_link_ops Date: Wed, 18 Dec 2024 21:09:03 +0800 Message-ID: <20241218130909.2173-6-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241218130909.2173-1-shaw.leon@gmail.com> References: <20241218130909.2173-1-shaw.leon@gmail.com> Precedence: bulk X-Mailing-List: linux-wireless@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 ecad1d88dd26..bae80bb7839a 100644 --- a/net/ipv4/ip_gre.c +++ b/net/ipv4/ip_gre.c @@ -1405,7 +1405,8 @@ static int ipgre_newlink(struct rtnl_newlink_params *params) 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 rtnl_newlink_params *params) @@ -1424,7 +1425,8 @@ static int erspan_newlink(struct rtnl_newlink_params *params) 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[], @@ -1698,7 +1700,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 25505f9b724c..952d2241c9b1 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 12ccbf34fb6c..98752b4d28ad 100644 --- a/net/ipv4/ip_vti.c +++ b/net/ipv4/ip_vti.c @@ -584,7 +584,8 @@ static int vti_newlink(struct rtnl_newlink_params *params) __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 3a737ea3c2e5..c65c8b0e838f 100644 --- a/net/ipv4/ipip.c +++ b/net/ipv4/ipip.c @@ -456,7 +456,8 @@ static int ipip_newlink(struct rtnl_newlink_params *params) } 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 Wed Dec 18 13:09:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Liang X-Patchwork-Id: 13913662 X-Patchwork-Delegate: johannes@sipsolutions.net Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (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 786D11B0406; Wed, 18 Dec 2024 13:10:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734527418; cv=none; b=MWUUegZReS3AjxLyePMfvt6w430E3mduBsXs/J2aL01HqV5NiRxmQax/TxaunPtJXcz/Y3U/abL01wMWUNHb04I94Av5fHtMrqdvt3MQpXB8BhaDn/CwjGs6uV6tzn7+1rORSnMcd5Emq6WMCg3TgpLKZKhqZAkvVrsxFvWzMuM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734527418; c=relaxed/simple; bh=ExcFFASRL0JOBX+JRaYP5UZ03RNRSWOI8Fw5iiUDoBM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qolKQu96xaqxI7CxPSh2Hfnhosj63/a/ogqlmJDgqsW81QynVgPLNkdmhmkQ47B8XyclYVgRfN6zHOBgSkWqfPiUxa7RbqK9ZzEfz3GTeIMoJwwS1dTP/EZqI1q5x8+p07+WZ8HAEZntZT8Wkm6KJDAU6HwNdh2WyduF1D2S5Ik= 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=k58c8fR5; arc=none smtp.client-ip=209.85.210.173 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="k58c8fR5" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-728f1525565so7669855b3a.1; Wed, 18 Dec 2024 05:10:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734527415; x=1735132215; 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=pGKuR9iwJLKB00bK/9yuK8uQjR1STrnypDr+9jM2ZjQ=; b=k58c8fR5Keswx3idccyEnvIDUTHA7CZHJvsT5wzJYta5LpxyyAd5apTc4JQwP3q3ql 3n6bubBCzjEJXO3hcvYnkET0VXOQOw6ce0ZyyptQnKlitRF8T22KeC3FS3OPf+gnuhFc G6Q+EkGgGAOU+pYs+l8XPiIyRT3JBQnaTY9FiO1Cxjrtx7TFrC0DSpYV8SLoJusN/p+6 Wb8Pv66zm4NsTuJe+J3jIrRHZ0WOHftefdDONQ7xX3yNbMM6su9jtYzbgfuENVOjLsfY Not+dxdU0sZ5RLkr7sXhVygrTaATCKwNOcY+qq2/TfpyTCOBcbfq/BaVWTAqo/XNaiTb J3HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734527415; x=1735132215; 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=pGKuR9iwJLKB00bK/9yuK8uQjR1STrnypDr+9jM2ZjQ=; b=Qdem2b3z0fkGr21DHFYKLPwavw9OmASnX9CMwHpV4vni4gHpJBeX/aDA4fI49QDZ7+ ZaD2lwyaiG3m+2SKZURzckgpRO8uoPDjT3WcyGgZRxxPQwW/XSkNe6FThOaxKcA/3MMB r6A3JYQA++ylZ9uEQfWoGU/E8TFiKENysI1bj5fSQ3WCxOYmguLajjEV+qxWcN7ROVbT QHAwNmSr+O4+QHuMyLBHj7pom9ei+yVX29emOB+UP/rvm7aKXMf7JlnregYaDs8ZX8Q5 zLe5g8Vr5D7iuJZpv6/effztUiA2awmzPXS1eRVDZ9P41n5UK2a/e18DC7OvIqt0Z8GH ZaWw== X-Forwarded-Encrypted: i=1; AJvYcCUBuQSS/7bOaIkfdmZsPyazGRywEliljUxHTElvD0ZvfsnSuQFtuZsfdeaX+tT+c1omlOHaNqZL7pKj312dxijq@vger.kernel.org, AJvYcCV1KgMdfERDNebFWwpKRtN1l4S+UUwLA7BA8RIUjqBCOoNEM/uB9Cs8mT6OpD3eae23EtM=@vger.kernel.org, AJvYcCVGTaqnWPDMkZDQBa2CynBu/C2ovHSnqXxrl4jH8G3poV6kWPe0ojKMs5vL8s8ORJYgWl61yUS5Eq1w@vger.kernel.org, AJvYcCVV2YuMMhr/43NSRME6qk8ZzZ67amg8ZaJke73MUx3feq76Awtc7XQKgrzRik1hEumLQozCddAcmXmpDw==@vger.kernel.org, AJvYcCW8kygT/FwiLFkgOaFB5leU1OGQWqwB1SeW5lvAmBaXidta1xOdfFcimcSkEQ0IC3lQFFE9hQVMpDg3JA==@vger.kernel.org, AJvYcCWiOP9UN3t+pnRk0nixpltWtxkhPiFpELxxb62wDuvXgOPV9MHJH58Op24CwpTteknHfkJTNYMcdRe+aPpa@vger.kernel.org, AJvYcCXED5Cg+ZeksM/BIoKsx8pp+0ZU0BIbyxFts84ogf+QVTBfls6iVnYkn/woXnJ/vb8d8YqIbPvyr9zRubmUrBU=@vger.kernel.org, AJvYcCXIMQG/VMF3tLt/yUe1zTgA3kY/TdifEaPUEmFB1DsBY6JOz39Zl83CyJeHFTLjf74S2fv2tuWmlszL@vger.kernel.org X-Gm-Message-State: AOJu0YyKrtw2zQASRKDYZLQuUhY7JC7+U8cQZ3O37c4sZMmhzu5ELi2F B0e40FS+BASmcK7vUkb9KnLNErpYog9PobUb+WM4dmGZG2SiqcrSv+6Ex9H9wR0= X-Gm-Gg: ASbGncsLkiB9504GqVskjz5RoVyDxAeMsPUCugi/gjArGMnxyckYHq4ikyJLSfDN8NK IGQ30LK2Np0646bniRlXhaZqEP4KVdb0cT8uPsRFdrKBH2qssgImQkoff/WNejIhMnlH+pDCivR MV8BI5nuCXMhDtPthCb/zuK+VLmr5GMYaoOhNKw/k6oRoVekmIsETsQJOK6odNR2sFqggpd3wZv GLZU0zjhjY1Jq+UHr1aXSj2f6kP4HlrnlziLppgOJxQ4oQ= X-Google-Smtp-Source: AGHT+IGQHpjG9Zvq9f/GAFOY7LWqEtsiV3DpqBRQY31QGrPpt7r1KVlmyyAbS3TmBXSPxo4Izh1/lg== X-Received: by 2002:a05:6a20:7288:b0:1e2:5c9:65e0 with SMTP id adf61e73a8af0-1e5b48891d8mr4000269637.32.1734527413950; Wed, 18 Dec 2024 05:10:13 -0800 (PST) Received: from ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-801d5c0f59asm7434754a12.67.2024.12.18.05.10.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Dec 2024 05:10:13 -0800 (PST) From: Xiao Liang To: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Kuniyuki Iwashima , Jakub Kicinski , Donald Hunter , Paolo Abeni Cc: "David S. Miller" , David Ahern , Eric Dumazet , Ido Schimmel , Andrew Lunn , Simon Horman , Shuah Khan , Jiri Pirko , Hangbin Liu , 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 v6 06/11] net: ipv6: Use link netns in newlink() of rtnl_link_ops Date: Wed, 18 Dec 2024 21:09:04 +0800 Message-ID: <20241218130909.2173-7-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241218130909.2173-1-shaw.leon@gmail.com> References: <20241218130909.2173-1-shaw.leon@gmail.com> Precedence: bulk X-Mailing-List: linux-wireless@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. Set correct netns in priv before registering device, and avoid overwriting it in ndo_init() path. Signed-off-by: Xiao Liang --- net/ipv6/ip6_gre.c | 22 ++++++++++++---------- net/ipv6/ip6_tunnel.c | 13 ++++++++----- net/ipv6/ip6_vti.c | 10 ++++++---- net/ipv6/sit.c | 11 +++++++---- 4 files changed, 33 insertions(+), 23 deletions(-) diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c index 3efd51f0d7d2..1d47c229068d 100644 --- a/net/ipv6/ip6_gre.c +++ b/net/ipv6/ip6_gre.c @@ -1498,7 +1498,8 @@ static int ip6gre_tunnel_init_common(struct net_device *dev) tunnel = netdev_priv(dev); tunnel->dev = dev; - tunnel->net = dev_net(dev); + if (!tunnel->net) + tunnel->net = dev_net(dev); strcpy(tunnel->parms.name, dev->name); ret = dst_cache_init(&tunnel->dst_cache, GFP_KERNEL); @@ -1882,7 +1883,8 @@ static int ip6erspan_tap_init(struct net_device *dev) tunnel = netdev_priv(dev); tunnel->dev = dev; - tunnel->net = dev_net(dev); + if (!tunnel->net) + tunnel->net = dev_net(dev); strcpy(tunnel->parms.name, dev->name); ret = dst_cache_init(&tunnel->dst_cache, GFP_KERNEL); @@ -1971,7 +1973,7 @@ static bool ip6gre_netlink_encap_parms(struct nlattr *data[], return ret; } -static int ip6gre_newlink_common(struct net *src_net, struct net_device *dev, +static int ip6gre_newlink_common(struct net *link_net, struct net_device *dev, struct nlattr *tb[], struct nlattr *data[], struct netlink_ext_ack *extack) { @@ -1992,7 +1994,7 @@ static int ip6gre_newlink_common(struct net *src_net, struct net_device *dev, eth_hw_addr_random(dev); nt->dev = dev; - nt->net = dev_net(dev); + nt->net = link_net; err = register_netdevice(dev); if (err) @@ -2010,13 +2012,13 @@ static int ip6gre_newlink(struct rtnl_newlink_params *params) struct netlink_ext_ack *extack = params->extack; struct net_device *dev = params->dev; struct nlattr **data = params->data; - struct net *src_net = params->net; struct nlattr **tb = params->tb; - struct net *net = dev_net(dev); struct ip6gre_net *ign; struct ip6_tnl *nt; + struct net *net; int err; + net = params->link_net ? : dev_net(dev); nt = netdev_priv(dev); ip6gre_netlink_parms(data, &nt->parms); ign = net_generic(net, ip6gre_net_id); @@ -2029,7 +2031,7 @@ static int ip6gre_newlink(struct rtnl_newlink_params *params) return -EEXIST; } - err = ip6gre_newlink_common(src_net, dev, tb, data, extack); + err = ip6gre_newlink_common(net, dev, tb, data, extack); if (!err) { ip6gre_tnl_link_config(nt, !tb[IFLA_MTU]); ip6gre_tunnel_link_md(ign, nt); @@ -2250,13 +2252,13 @@ static int ip6erspan_newlink(struct rtnl_newlink_params *params) struct netlink_ext_ack *extack = params->extack; struct net_device *dev = params->dev; struct nlattr **data = params->data; - struct net *src_net = params->net; struct nlattr **tb = params->tb; - struct net *net = dev_net(dev); struct ip6gre_net *ign; struct ip6_tnl *nt; + struct net *net; int err; + net = params->link_net ? : dev_net(dev); nt = netdev_priv(dev); ip6gre_netlink_parms(data, &nt->parms); ip6erspan_set_version(data, &nt->parms); @@ -2270,7 +2272,7 @@ static int ip6erspan_newlink(struct rtnl_newlink_params *params) return -EEXIST; } - err = ip6gre_newlink_common(src_net, dev, tb, data, extack); + err = ip6gre_newlink_common(net, dev, tb, data, extack); if (!err) { ip6erspan_tnl_link_config(nt, !tb[IFLA_MTU]); ip6erspan_tunnel_link_md(ign, nt); diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c index f4bdbabc3246..cb09cc878dee 100644 --- a/net/ipv6/ip6_tunnel.c +++ b/net/ipv6/ip6_tunnel.c @@ -253,8 +253,7 @@ static void ip6_dev_free(struct net_device *dev) static int ip6_tnl_create2(struct net_device *dev) { struct ip6_tnl *t = netdev_priv(dev); - struct net *net = dev_net(dev); - struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id); + struct ip6_tnl_net *ip6n = net_generic(t->net, ip6_tnl_net_id); int err; dev->rtnl_link_ops = &ip6_link_ops; @@ -1878,7 +1877,8 @@ ip6_tnl_dev_init_gen(struct net_device *dev) int t_hlen; t->dev = dev; - t->net = dev_net(dev); + if (!t->net) + t->net = dev_net(dev); ret = dst_cache_init(&t->dst_cache, GFP_KERNEL); if (ret) @@ -2007,13 +2007,16 @@ static int ip6_tnl_newlink(struct rtnl_newlink_params *params) struct net_device *dev = params->dev; struct nlattr **data = params->data; struct nlattr **tb = params->tb; - struct net *net = dev_net(dev); - struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id); struct ip_tunnel_encap ipencap; + struct ip6_tnl_net *ip6n; struct ip6_tnl *nt, *t; + struct net *net; int err; + net = params->link_net ? : dev_net(dev); + ip6n = net_generic(net, ip6_tnl_net_id); nt = netdev_priv(dev); + nt->net = net; if (ip_tunnel_netlink_encap_parms(data, &ipencap)) { err = ip6_tnl_encap_setup(nt, &ipencap); diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c index 79e601e629d2..a3108a7464c7 100644 --- a/net/ipv6/ip6_vti.c +++ b/net/ipv6/ip6_vti.c @@ -177,8 +177,7 @@ vti6_tnl_unlink(struct vti6_net *ip6n, struct ip6_tnl *t) static int vti6_tnl_create2(struct net_device *dev) { struct ip6_tnl *t = netdev_priv(dev); - struct net *net = dev_net(dev); - struct vti6_net *ip6n = net_generic(net, vti6_net_id); + struct vti6_net *ip6n = net_generic(t->net, vti6_net_id); int err; dev->rtnl_link_ops = &vti6_link_ops; @@ -925,7 +924,8 @@ static inline int vti6_dev_init_gen(struct net_device *dev) struct ip6_tnl *t = netdev_priv(dev); t->dev = dev; - t->net = dev_net(dev); + if (!t->net) + t->net = dev_net(dev); netdev_hold(dev, &t->dev_tracker, GFP_KERNEL); netdev_lockdep_set_classes(dev); return 0; @@ -1001,13 +1001,15 @@ static int vti6_newlink(struct rtnl_newlink_params *params) { struct net_device *dev = params->dev; struct nlattr **data = params->data; - struct net *net = dev_net(dev); struct ip6_tnl *nt; + struct net *net; + net = params->link_net ? : dev_net(dev); nt = netdev_priv(dev); vti6_netlink_parms(data, &nt->parms); nt->parms.proto = IPPROTO_IPV6; + nt->net = net; if (vti6_locate(net, &nt->parms, 0)) return -EEXIST; diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c index 4dd1309d1eb3..8888fc51fa0b 100644 --- a/net/ipv6/sit.c +++ b/net/ipv6/sit.c @@ -201,8 +201,7 @@ static void ipip6_tunnel_clone_6rd(struct net_device *dev, struct sit_net *sitn) static int ipip6_tunnel_create(struct net_device *dev) { struct ip_tunnel *t = netdev_priv(dev); - struct net *net = dev_net(dev); - struct sit_net *sitn = net_generic(net, sit_net_id); + struct sit_net *sitn = net_generic(t->net, sit_net_id); int err; __dev_addr_set(dev, &t->parms.iph.saddr, 4); @@ -270,6 +269,7 @@ static struct ip_tunnel *ipip6_tunnel_locate(struct net *net, nt = netdev_priv(dev); nt->parms = *parms; + nt->net = net; if (ipip6_tunnel_create(dev) < 0) goto failed_free; @@ -1449,7 +1449,8 @@ static int ipip6_tunnel_init(struct net_device *dev) int err; tunnel->dev = dev; - tunnel->net = dev_net(dev); + if (!tunnel->net) + tunnel->net = dev_net(dev); strcpy(tunnel->parms.name, dev->name); ipip6_tunnel_bind_dev(dev); @@ -1555,15 +1556,17 @@ static int ipip6_newlink(struct rtnl_newlink_params *params) struct net_device *dev = params->dev; struct nlattr **data = params->data; struct nlattr **tb = params->tb; - struct net *net = dev_net(dev); struct ip_tunnel *nt; struct ip_tunnel_encap ipencap; #ifdef CONFIG_IPV6_SIT_6RD struct ip_tunnel_6rd ip6rd; #endif + struct net *net; int err; + net = params->link_net ? : dev_net(dev); nt = netdev_priv(dev); + nt->net = net; if (ip_tunnel_netlink_encap_parms(data, &ipencap)) { err = ip_tunnel_encap_setup(nt, &ipencap); From patchwork Wed Dec 18 13:09:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Liang X-Patchwork-Id: 13913663 X-Patchwork-Delegate: johannes@sipsolutions.net Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (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 7DF631AA1D1; Wed, 18 Dec 2024 13:10:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734527425; cv=none; b=ss32dZfC9YI6+4j5bg2fytjuoIWa8Q0H1+PXLTRG7V8DF6RgxofKYyFa/9M46tkkmW80sB39ZSwe4gGtf6zMvOG4W/m7RfMRqyfXcWH+2Mzd3X1q8hm/Rv5ibBdByuws0YSwRg4pYWFDAQPxho5kYRj4fLbTK7JAxLbsAkZN59s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734527425; c=relaxed/simple; bh=FrNFlIgaLGZInVfg7c+Ua7z0X9F1i2NtBJYO15VwRj4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jtdJ8nud3xUX4PVDtByk8VD0raqVXrs2EUkxMzOQtKdHCEykc0Ug49dP/YF4uxfPHAw2LCujgO5mfKMmqLwlSmDryuaJUKfhaEejMyrb3zvzNZl56j7jrkNQYFdmN7OFksqaK2qZ2NfY3skUUw4UyHQMgKQaky7tOwv1dilVQTE= 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=LXFfFAJS; arc=none smtp.client-ip=209.85.210.169 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="LXFfFAJS" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-728eedfca37so6598128b3a.2; Wed, 18 Dec 2024 05:10:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734527422; x=1735132222; 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=bXH8tUP/h7NPxTwhkU8DrmHX10k3nPXxIbmClQOEn5A=; b=LXFfFAJStzsAvJ4WY0N0t92Sz+QQpM5xZfw9bvPJsSKC7oPWpjeBxXOHd8+7rsBj7t UBEGYAF42K3f/1K+h4RiDHOX5eTsWAcCR4lA41kPLWRDgBZxoF82nG3sbECRkHxqXI+S xBCH/GXgQ1OoBEh4U0l2OAyCh2RNVK7kf90cbWMiEGGI8Dte3wj6zofVFkf6T/+791Pd 1Flds0ACPqJQvszkoHG1rr4a3Yp42AFWDKii3HIVEiI5Fz/N2/sYKRn7Ajt6MdI968HS q4bB0LayuJKmYVB1wlMRpTEJzFrO6G+Y93G6hIUsbPUmcAiZLsteZOhQwyJB8kSuv1ZN rVNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734527422; x=1735132222; 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=bXH8tUP/h7NPxTwhkU8DrmHX10k3nPXxIbmClQOEn5A=; b=DRV0IIkKN8nNEKrYqn0uGibhcMRKfVQIk6RH31aXm14c43NXSDxwbje8hx+ilBa/ut d3ivEP8/tEkSPmmBkc4TYoL3z9U3j7/UFCPwnyfnFOasnQDhmuUk4MCsDjIpHARj/eFn 0XZ93t6U8X4xecOrnjbEex0NbajZ44aBRiZ4xRsnOlQYjryOP0YJOEGDA5PlszUbBpcw YUGjJS9K05DVDsrRw7YlsAP1kQc941Rk7vJXDdmY1ngEAjj9lSWNCThBazZSxEsdOwIB SXhOR+/NZ2uVH7nNQN+a7dgvBiURfLMzz+0gIc0ZIJMIMvm9g8qQc2/CitOjn3CEOi01 ir0w== X-Forwarded-Encrypted: i=1; AJvYcCVEnxedAMrHl0J5Cf7EZsd+PV6PYzdkAaxCJ9nqhyV4Ro9VYGTf5YgoFtN6HY1UO2qDeAeJOZuRdjzsoQ==@vger.kernel.org, AJvYcCVI3JzEDJheQzB3xlrjMWks5M8yc+vNOWfwiGznkjdIvTKpAlWIFvUHiUQcP3GPmsewH5R8Vis+LC4Bfb50/c0=@vger.kernel.org, AJvYcCVZt+qLtz+W7TRo4YHMxnLGudJxR1zA7s1xGw7FbsJo14iSfId/viHJoHv8nst+TIvTqtc=@vger.kernel.org, AJvYcCVdQo8WkP++f+IlQBwrxyPSWkzxH8t4ZAMuCXveuoyy8tSEHImkl9Te3Ekfci+LilLcGLAobJaJbaGR1Q==@vger.kernel.org, AJvYcCXAjWu9ushPnyKubCWA1Gg8h8tkrPaQVOdnZnfOt9bkKGcAq2nX4nb6XjZLzmk8TDXfleTqiSUT3BUQUJqd@vger.kernel.org, AJvYcCXQqLdYs4yvqIsjeQty4dyRmEP1w8bG5OGJIwK4lJcKChevSQutHFo5JptehncHIwq7UXsTz8Vy2aBI@vger.kernel.org, AJvYcCXmjzhblLfQ9u9b2VvcT1IX2DFJNmw1Q5qCsZG+je628iPolFx+EhNIG+C7DSQDMxtcn9OOSqsco8NE@vger.kernel.org, AJvYcCXnbMOwMRII9dkwL7VxLP9lyNmk21xvLFeQw6lhbosyilUUOV8LRrmGaNLKNoLmYPlCwH/m/qKlerMY2rZGJ2nb@vger.kernel.org X-Gm-Message-State: AOJu0YwhIy5KVc+GwH7kWsjraqVZGIcO9eyWp9jaAy5o4bRdHfA3r+eA HXYsY2XKSS5LJdip98N+7kn3OvvKnIoUFJnTcwFQwVtiC74avRitm3a3TGyN1uw= X-Gm-Gg: ASbGncvZHp5R4jpUPmkWEkXUXkAULvm+t5svNRAzTOiyMz43xaWsLIrJW2+lXcskFKb k213jGDk3k6oChdpU0BSQeb1OlHGmoTaVZ0WYYRZkzLw73ip9MqZVWZrBq36awXKh75NerIGd6x d297vuKqoThrdL0yQQgzsYLKaYXOslLIqi6Q1r+pwfaW1UQLIQ/AmAzy5KdqtwHEg4ppTujkjwp 67PzArbtl1PCue39Zg+oowktGZiZkeV6/jIG8n5rNbRwnI= X-Google-Smtp-Source: AGHT+IGLrMJpewCg9a6Mvczs3iBMMwjIWUW57/cgClFku2ou3JPxqZ6yK8d+Q9sS8i4XncDR+dfRig== X-Received: by 2002:a05:6a20:12c6:b0:1e1:bee3:50ea with SMTP id adf61e73a8af0-1e5b47f94bcmr5116348637.11.1734527422239; Wed, 18 Dec 2024 05:10:22 -0800 (PST) Received: from ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-801d5c0f59asm7434754a12.67.2024.12.18.05.10.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Dec 2024 05:10:21 -0800 (PST) From: Xiao Liang To: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Kuniyuki Iwashima , Jakub Kicinski , Donald Hunter , Paolo Abeni Cc: "David S. Miller" , David Ahern , Eric Dumazet , Ido Schimmel , Andrew Lunn , Simon Horman , Shuah Khan , Jiri Pirko , Hangbin Liu , 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 v6 07/11] net: xfrm: Use link netns in newlink() of rtnl_link_ops Date: Wed, 18 Dec 2024 21:09:05 +0800 Message-ID: <20241218130909.2173-8-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241218130909.2173-1-shaw.leon@gmail.com> References: <20241218130909.2173-1-shaw.leon@gmail.com> Precedence: bulk X-Mailing-List: linux-wireless@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 77d50d4af4a1..d1198c63dd23 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 rtnl_newlink_params *params) struct netlink_ext_ack *extack = params->extack; struct net_device *dev = params->dev; 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 rtnl_newlink_params *params) xi->net = net; xi->dev = dev; - err = xfrmi_create(dev); + err = xfrmi_create(net, dev); return err; } From patchwork Wed Dec 18 13:09:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Liang X-Patchwork-Id: 13913664 X-Patchwork-Delegate: johannes@sipsolutions.net 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 AF22D1B423E; Wed, 18 Dec 2024 13:10:31 +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=1734527435; cv=none; b=BNrR6XklckZbORhb3atFXeZh4W6PLCkP0mGTWxi2ek31+Ld9vZHECmrteo6vnAXNznRE/nlwvLbUpoOtT5cS+WuqipgmF9kwsMssxGHNthrW7oJSVOGaaM+Sbil8Z781yJtiSxAlQA57G+h6J7O7UQ1I/AkgP6tqWSs2+sP8iVI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734527435; c=relaxed/simple; bh=7cGPxfnNq5yiQ2uUz1I87Ai/9MiFtraEfBlwrKXtY4c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CwC33EgUitcz/3JOUrsHrzmQQyo0BLusPAPtAAKwpQypbRdWzipggm9JKKVfA0URqFezINQluwd9jBMV0WSvYbKhRKlCY6/85psb+l4icZnE/oVp6sRwDLnm1295N8LsiqMhQ+q+nMZdMYEtAl7D9oISqeF2y/rKLDyIbPlC+bM= 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=WX1ApjrK; 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="WX1ApjrK" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-2163dc5155fso56034765ad.0; Wed, 18 Dec 2024 05:10:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734527430; x=1735132230; 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=vKRdbuSYL7hnJpCbxB6/aqEJFoCo8iX729XZZAsUkqw=; b=WX1ApjrKSCPOyATiok7JMfwd5sYsJpFj/0OUjClOIR8JMZTBPvIcPZJhpBScv7l7pK wLLduNYRX3HXCDf3+4KF5G4yhNNPq+W6SGrImvV8RzDdOQ8G2Ef6gBRchlnDPWv0efNM hieuO9XaSZy95nkWZNd+neqyOjwjYRs6gdSp4y0ozyzRODG+eWfvfZebUrXZkvzXT1Ch PZ8qPUw2AB4l6BFGbDW7nRXFPAD/Mj3Uk30NB+xNi9qAT9D2RWyLmSGdjAIdDo9kXVZ0 5M+59L4GEwY8+Y4HqC/G3w+hLAk3Hc5kqBpSxy+LcZ/pxHNN6cKwfWEEGoOAGv46DfOP D/cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734527430; x=1735132230; 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=vKRdbuSYL7hnJpCbxB6/aqEJFoCo8iX729XZZAsUkqw=; b=QUdNhIz0YCJE4cMBcZvU6kvBePgBe2R6bGc2KdVRQTazpSEWz/DmylXqRQZVVUW5JQ w5VVq/dTYKCkT525sy1JbwWC/dlQFN8+31x+g1qWr9UOyFxS0uhK0FSvO+HMhnr0i/xE 5L13yBkkrHWgTGb9yY3JZjUrzdtmpgWsPqaakbvw4UUfISpon6++qpnxAdlW5OCCagcG TWDVj31ifMyuvkJRZKBpXSWYhd2yjgzjY4x/oXWfztoXwnH196ymGdpEtOcmbGyveRWj 9pyKHiu7JwRU7yxFvJpdT7Vw84W84m383G8NOVfFaLv4EKkj37P6bwwemszzFEVg6iXQ 5Qeg== X-Forwarded-Encrypted: i=1; AJvYcCUBaEfNqWUc69kmJLnJS27KTF4fo5Y9VnQ7JI518lHYMwM2K29o+DmSDm4OcG+PAGvCVzbuwddyrA3z0Q==@vger.kernel.org, AJvYcCUyx21jtEv9ZC1AD+oMwoGMKgQqwyU4/YvWf7oECT3+rM/NBjHkGWYZnYXYHT0dFzB6JstHePD3yvlaIq5A@vger.kernel.org, AJvYcCV5ht67sbEermWtg8HmOLO2n22oOCjaUh4yqdZ7ihNLo+8glFuDhQWEeTb9EisvCjppRmYzx0n7A6cm3S90CWvs@vger.kernel.org, AJvYcCVGhSBbY6VFHKr3RKRYRBgjguxvdX1tqoqEnYjEIQHFBlNnAKl+89V3mXz5iJ/l8x1xr2kBWl+N2WpUWg==@vger.kernel.org, AJvYcCVbfUcyybS5XllNVoikl7UhDna2DXxPChWRL4e0uyGuDgO5wtMZEs9v15jSzvLjdZ9zl4g=@vger.kernel.org, AJvYcCVjw6rYHFDKFZCjaLhGVVdUHzPP036BBG81fdCMBX5QR1nSVqJUcvjwyAlse5RdZGKVUry57vv90Zxnneo1D6M=@vger.kernel.org, AJvYcCW2ZDYjqDUSbdcdfLX+NimCjv5myDrnRGFqUHPodrve9tUbkkosO3p+gqKkPYIpIAPl5xWs04DibLWe@vger.kernel.org, AJvYcCW9wzg1rh+IJTbKI5pCzxydVfVvATlWm5uEkJCJCaeD/fuH2LDlIsopA+iV05BHyyl9q0n9D/xhdkUW@vger.kernel.org X-Gm-Message-State: AOJu0YwHzsbdYxSdCub6boH1unYBDF1W12Kkhz9N5mNlrYQuf65j2mfG QbaUEADgUzcXAfgKHn9b5bd7iDvYnrKOcI4YcRdm0PcMB67f1Q9NfTgbJlNrd1k= X-Gm-Gg: ASbGncu42Ns/FvOnS526P2yskrRj0iBwy6Z5fTDocJhAyd0dTLdZHAYbeehU2Kl/blg 4o1443KPF2Xyzu0miRvjiSyBNaY7mwheRPUvZn+Op6xWTyydHy4RQzsPzoO9nBDsqx5cLZn3TV5 RPVkCUn56TgU80VICUmLh7gxf5O8ixb8JFBsoMlLzqiQTUrBVWlLSyJue4HbgFwulmRg9X8n1E4 ODHXk4I1klHunOlwzDfJyzF/jOOTqAm1FrK2+6/0kEyj0U= X-Google-Smtp-Source: AGHT+IG5uNon7/+5tavnAU1+6ODsDyulZAAiwNo5sldF4FHk8kNssZ4/V0oQpI2qOsRTRp3qJQ4m2Q== X-Received: by 2002:a17:902:db01:b0:216:5867:976a with SMTP id d9443c01a7336-218d725b7aamr38087595ad.45.1734527430302; Wed, 18 Dec 2024 05:10:30 -0800 (PST) Received: from ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-801d5c0f59asm7434754a12.67.2024.12.18.05.10.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Dec 2024 05:10:29 -0800 (PST) From: Xiao Liang To: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Kuniyuki Iwashima , Jakub Kicinski , Donald Hunter , Paolo Abeni Cc: "David S. Miller" , David Ahern , Eric Dumazet , Ido Schimmel , Andrew Lunn , Simon Horman , Shuah Khan , Jiri Pirko , Hangbin Liu , 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 v6 08/11] rtnetlink: Remove "net" from newlink params Date: Wed, 18 Dec 2024 21:09:06 +0800 Message-ID: <20241218130909.2173-9-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241218130909.2173-1-shaw.leon@gmail.com> References: <20241218130909.2173-1-shaw.leon@gmail.com> Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Now that devices have been converted to use the specific netns instead of ambiguous "net", let's remove it from newlink parameters. Signed-off-by: Xiao Liang --- include/net/rtnetlink.h | 2 -- net/core/rtnetlink.c | 6 ------ 2 files changed, 8 deletions(-) diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h index ed970b4568d1..04fc0e91af42 100644 --- a/include/net/rtnetlink.h +++ b/include/net/rtnetlink.h @@ -72,7 +72,6 @@ static inline int rtnl_msg_family(const struct nlmsghdr *nlh) /** * struct rtnl_newlink_params - parameters of rtnl_link_ops::newlink() * - * @net: Netns of interest * @src_net: Source netns of rtnetlink socket * @link_net: Link netns by IFLA_LINK_NETNSID, NULL if not specified * @peer_net: Peer netns @@ -82,7 +81,6 @@ static inline int rtnl_msg_family(const struct nlmsghdr *nlh) * @extack: Netlink extended ACK */ struct rtnl_newlink_params { - struct net *net; struct net *src_net; struct net *link_net; struct net *peer_net; diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index f7c176a2f1a0..e33ef8a0a6d6 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -3758,7 +3758,6 @@ static int rtnl_newlink_create(struct sk_buff *skb, struct ifinfomsg *ifm, char ifname[IFNAMSIZ]; int err; struct rtnl_newlink_params params = { - .net = net, .src_net = net, .link_net = link_net, .peer_net = peer_net, @@ -3787,11 +3786,6 @@ static int rtnl_newlink_create(struct sk_buff *skb, struct ifinfomsg *ifm, dev->ifindex = ifm->ifi_index; params.dev = dev; - if (link_net) - params.net = link_net; - if (peer_net) - params.net = peer_net; - if (ops->newlink) err = ops->newlink(¶ms); else From patchwork Wed Dec 18 13:09:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Liang X-Patchwork-Id: 13913665 X-Patchwork-Delegate: johannes@sipsolutions.net Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.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 8C1B31B4255; Wed, 18 Dec 2024 13:10:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734527441; cv=none; b=IcaLMGSH8A0Nb4bX8X9drsnm6DyjizRUxcCps6+3mwX36gmonByzDERkI4Ert/3L9S9pTQ9ZSnCPCQKr1++RUteUs/pCH9uuYHbw4UlLtpqluoniNNbINlOcE/Mv24u69s4TGmJZL7NQzRkatoppCNmkTrqgz50qy58dODohtAo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734527441; c=relaxed/simple; bh=v/XyDBj1rv0kMGLFRo/fVc4C1+xJWpbKQllsecdMufM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j2HTH3m4HVqkQOI8Opo0t5Gp/oD1FXyq4qMRox5ZJhB0QEtcCfITr+AMl4vqlpZuhEs6U/ZmWqGpeQ39n2uN5GWJN54cEj6vKDV5NyuWBdtZopF6/aUrco3MDomJb1M3eKqkdlnIC7SyHee1jR7mlhRUhhczsiOVNC8wRgTYgdk= 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=fwjuFNV1; arc=none smtp.client-ip=209.85.216.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="fwjuFNV1" Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-2eec9b3a1bbso4477312a91.3; Wed, 18 Dec 2024 05:10:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734527438; x=1735132238; 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=VEdGbFyA09FJ7+QqmmCxpz6A7u+HUg5+S5fgAXCQeJc=; b=fwjuFNV1Nk0lLZdtKVIBtPvEmD0FpM2Zg6hA83lyD/ntezolOf7RjQezpYZLedaCAO CBQQ3nR5c3ANBuuqwCpfFChZcr5z/HKH1/1GM60VwS272bWKTo376LdLiOdBeiW5PxNB nsbTQZZqywvQoBFIi0D7K+L2GxL+TKNTo5npJW8AO6pCoPa1h5DWYhynbniWX57rBtFG 69ffIDwWbugDdWHsL3I9bD1R43J8582tYTwXOS0CA6o1rUcMRKz5yS+eUMHNmC4OrJlF MzYZjhppO/4+U1VPQi06z7hix7p2pRS6ybZ1AzZjq7kOc58EPOdBqZl4TTZgt24VEnKE aL2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734527438; x=1735132238; 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=VEdGbFyA09FJ7+QqmmCxpz6A7u+HUg5+S5fgAXCQeJc=; b=wT4DVu70ZFX9BWkAWmUSwYH/pIX21nzGjrlmUxNkhe8HPAv+Yt2Dgh4sXmLw/HJwV3 8MdsycTZnUQzxSJH7/Z0OysiZrO3l2tf/42sB8XtZuSb1/VLHtPSOSN06Ci/HyLZIAcJ /lDZpAvNiVB7Qwcfq4eIMJnfsuAu1vVIBqSQbZlUu8JXmCCY23/NLMKdfBJ2ofo62rC4 ZjQDopf6m38WguCoBOq8Xkfmyr9u/MD5/ysTT0I53E+5cXJZnnpI9K0gmp9WdEQqg02h bzf1x2cWIt5KJZPGYreBcW460zAHx8XJL9wUJp77Tu29yc/gN3dQ0Tek9zD5KGFwBhsH 1MwQ== X-Forwarded-Encrypted: i=1; AJvYcCUAl9e4MDZcJ+h7IPtI68GUULbmM5E7Gf5PYQm2b2IE76G1ugzNdCvO//yOmhW/qVUw+Vsth4YjWJZIFg==@vger.kernel.org, AJvYcCURioy7SHTJlJcJYlWl4sb3O4/BQuSLNKUpmDwK2iOlIba3ajX2AnbXRrcLyI8annyHjB8rfUoCa933@vger.kernel.org, AJvYcCUfW7Nah+vHQ2HEz/imgAduouCzmITMjOztocQ+ynd1h0mR7j6yhbfPB0OCA22PbvSOzw4GTHbIJmb1DQ==@vger.kernel.org, AJvYcCV1p8UXnZaHodIQlB3+cUQKEk2FVLeT3ufLLY8cmfvJocyHWiJVaH/Jrsn49mbyONTeVg27ybkcKy48@vger.kernel.org, AJvYcCVEBXCwuTJT8A6QJJUcokZbLCqMXhdQdHuTyMwLZaO6dwyokbeTYdk8UhtGZYX81B5zEI8=@vger.kernel.org, AJvYcCXCHS+nUsnU0qw3jocrkhENblK/EncJwFxn1lFOD72pJa+ZMCpJ1D3lII8Zai0/EEio5bfU9JiZtFqkX90Z@vger.kernel.org, AJvYcCXP34SdKGF20dIzWaKpZAMrwpQgavmVDFeHJ4gT6APXBsos7QJnt0xg3OOv4ezH9ssvk93I1c4VcLZJ4sLxxbA=@vger.kernel.org, AJvYcCXwvOaYnZQ7yN+KO59dLjSRSUEeBVkatgNrbGXFoRFNdzp9QztvJEQ7gShbZ7c58S5RjKoZYzYBXV8EKgdfOAZy@vger.kernel.org X-Gm-Message-State: AOJu0YxpbtWnlGkXShR/u6X1uNwa92+yCtSq3OifTnxk+4XhnD0LtQf/ wOxlrUauhk1zS426rDxMH0FZ3/hhih/MUPr9WnE/rfasKEMdUKdYB/e4JbiZf6c= X-Gm-Gg: ASbGnctWmgNu+D+GOJd9/Zd5bcO53/q9mIwsh7qoWSOoyygoYgtCTncxlNyZwQAfERv K3wTvy8nDCofBfVyZ+XTzevwZVqjvGyTXZaxcPKd+C2X1toIuu7Ux74DAuGEiH16R7JEnB6b/AE IA9Q9uf9Zi+QNN6+2VOb13DH0bgJQqJfa+8Srse9P2x2sHUUyKBzUmFNhxq+zfBYwQn/HsfpgHm lkvCUpWp+eI3DZm3FZ5XP1xR44bmka5SRd0yRSK7HVfGb4= X-Google-Smtp-Source: AGHT+IH6m2w3HOgAGhkzn76085OHsWsSUyL1uFaSoqu4LH4xby0CPd4muKbobH9sGAmWFqgh4Hldug== X-Received: by 2002:a17:90b:53cc:b0:2ee:fd53:2b17 with SMTP id 98e67ed59e1d1-2f2e934616amr4153078a91.29.1734527438446; Wed, 18 Dec 2024 05:10:38 -0800 (PST) Received: from ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-801d5c0f59asm7434754a12.67.2024.12.18.05.10.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Dec 2024 05:10:37 -0800 (PST) From: Xiao Liang To: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Kuniyuki Iwashima , Jakub Kicinski , Donald Hunter , Paolo Abeni Cc: "David S. Miller" , David Ahern , Eric Dumazet , Ido Schimmel , Andrew Lunn , Simon Horman , Shuah Khan , Jiri Pirko , Hangbin Liu , 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 v6 09/11] rtnetlink: Create link directly in target net namespace Date: Wed, 18 Dec 2024 21:09:07 +0800 Message-ID: <20241218130909.2173-10-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241218130909.2173-1-shaw.leon@gmail.com> References: <20241218130909.2173-1-shaw.leon@gmail.com> Precedence: bulk X-Mailing-List: linux-wireless@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 e33ef8a0a6d6..ce5bea096bac 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -3776,8 +3776,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; @@ -3798,11 +3798,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 Wed Dec 18 13:09:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Liang X-Patchwork-Id: 13913666 X-Patchwork-Delegate: johannes@sipsolutions.net Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (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 7EF921B0425; Wed, 18 Dec 2024 13:10:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734527450; cv=none; b=aXhsRxupDrvRF8bZT7K11teihRPQyXYDWoEMNvXL29ThyoAXa4a4JHg3IpU3lg5WfQBkWAbTxJezuZv0XWTHsw10L3HuGKEY1bZa9VrVk+x/C5pVvcdF6dEjP3HfFWe/jFwYfNBpDgBtUqPmYWds8784C3+7+K/no5lDggN9LLI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734527450; c=relaxed/simple; bh=PdyhCxIiCvxYyD0kNCUPOuthJbFGoqxPJVmAtqTiJvU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X+upu15c+aGsUgNT9ne4Z6AH0hDkVs+/YM1Ib8WTlYw1r13dtW6k4GcIjXFx8BtNP1/3HH/20dFQDmbsW4QdpuFqYa9+i8AskEqi+fzrb+jMsiP15aqK/DJ6T8GVD+8lwPN9FtGvTVUZhGx440Vl9YrcunWpbIl+RzK3Nqd3R14= 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=mwyUxSWg; arc=none smtp.client-ip=209.85.210.176 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="mwyUxSWg" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-725ef0397aeso5776280b3a.2; Wed, 18 Dec 2024 05:10:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734527446; x=1735132246; 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=f/aVoxIsj2NaHZxO0wthneclpZNQFTaEi7bz2gcdad0=; b=mwyUxSWgeAJstMKG1S3NO3wvrfsxcTMy/Td3gywlCDDXyFkuljjDvBWu9j6AaPO0VA XOyHWhWe3jRUgZ0lH8wfItdHIvEbPc/A6LdDYL+PglqLGu6xdTWMl6enzoh8B8MsqnXk iQFR7DLcpTYTDqd4abfa25vCkOaGq88AziJ0wZtaGY1OVH9CrKhlSOZc/EWtG7Axe1DC nj1/XQu7dP+zpq1yVxjoi9kFOYVBIWMsSKKGAbo1wBsYEhUL9x8KKqUodM5LfmZRW5Ai 318K76Hhba64sMVp1DUzwnj5/adoRTx0ThQUXvAJTGpiLyu7fHtHK+GetI9wXaS29I/d GCdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734527446; x=1735132246; 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=f/aVoxIsj2NaHZxO0wthneclpZNQFTaEi7bz2gcdad0=; b=wfmyQKimoCWqSgEHRTMap0Eh+vpBtQBiGM/AuJUR/jt2dIPaPAd5asb9HI3FUxD713 gNQoAau3YIm0xOo86Osf4PFCTia81YS59GhBff89s94A1qyBs45Tk3dB8hazgciaKBqN 3+gBxoknJ+v91IzzaENwPUDZ9SwYEjKS/EElTdYRvGD0jcim9KsA21N+oVrlIP/YolEu 2BSD/xM9E8A1Mo9C3lcBnvtK5zyuItpaM0xObg3C2Wi9RMhIDAkLwjku+NbJEjTkJI05 JUve8rcXgIUFNp+gwzJ3Kt9JpuxQaYfzxocdiqz0dPWjj0K+5PBKSXPolJy+k2tzbq5z H/4g== X-Forwarded-Encrypted: i=1; AJvYcCUKnRx/Q+f3sntBQXep7f8/Q/p1cUnoGuxSimCrQB4vno5zGDD9fkZN1ih6feKTFcxUnQ9dt87GMwES6chDtYw=@vger.kernel.org, AJvYcCVG9JrjftG/LemhBpDWmgBjTu3Q74yNeMM4w57TTD4dt+/lj+8s213HfXbrBrDvKg6HK45oCgIE787zRL9B@vger.kernel.org, AJvYcCVsGyUFkrNBUTrWzfSYsbCEHga00i19lfYYinFvbUapjZjvxUbtbQulL/8N3I4m01eeI+NJgAp4yVDy9Yfwd3RK@vger.kernel.org, AJvYcCWII15uQIMa6RhdbZR6EH/QjqhQmnH4Vpny6pNvTAZyCV3ARC8PGOc0KzWrmhh3kU6dPC8=@vger.kernel.org, AJvYcCWfyQRxtZ1CCxx1qzCu2V+GYwQb9vwGCqZcVrODbmZjoqTe0PsH4ksQL/ol1s/M26UGAjhPXooAmSCl@vger.kernel.org, AJvYcCWrMTq3BucU//B522/2nuDmfVkjiUKAgyVNJ+cv5FP1U3+OfvrBleqJ65+UWlKtVlZespG0JrHgZzRjWw==@vger.kernel.org, AJvYcCXZgAYDKB79vNAuWn9l3nsYVQYqiY64w3NqY78wdaMg7l9njg9Sbdh6xwwEWAnlv5b1N4EvnTNmhGJnEA==@vger.kernel.org, AJvYcCXvTqbZUdiJSXNiS66LjaYDWyxraUUkA6lnoar6zlboXrPmHeVtb3dQSkuLQQkaenvXy07Mz1t+322M@vger.kernel.org X-Gm-Message-State: AOJu0YzsDG2R0ybQ04K5alL9oA3qDm5AlTlSqNlogZopvGOiLeJlTmgW /zSLWCu0JbEB6rSNHv7NNlUjsZb4PmvZ+47NL0IcJBeEMY3SyXk3mvk0U1dvYY0= X-Gm-Gg: ASbGnctir3FQR13Z87on4ZWCdZ6M8ylYYTwKOMCGSzSC05mj2EfHXOUhGzABTd7qSpw +7/i2yCEL7wa7ABkkWR/3bxai+WLDfMvYOQXJ+T3j1F5qiYxrkGTNA87fJZqIkN6zaPQgxtWHcN vUytLi/k81VdmzkTHkOuBuWi3Idv0FzKmwmjEiieP53C8etgvgKGzIJaRiscEYX5yxHnxcRyvzL cuZd1uq/SXBlgb7nuvnMjDcoGhI3xnOF1pb7AsLpgG4cg4= X-Google-Smtp-Source: AGHT+IFJSba0hMYoxDtWWfQo3+fMH+6cNLxoIt5yunX4KkQHyaeVCZq9fnVPYHJO8DT42j8sEsCrNg== X-Received: by 2002:a05:6a21:6f02:b0:1e0:dcc5:164d with SMTP id adf61e73a8af0-1e5b47f3b12mr5217374637.8.1734527446438; Wed, 18 Dec 2024 05:10:46 -0800 (PST) Received: from ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-801d5c0f59asm7434754a12.67.2024.12.18.05.10.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Dec 2024 05:10:45 -0800 (PST) From: Xiao Liang To: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Kuniyuki Iwashima , Jakub Kicinski , Donald Hunter , Paolo Abeni Cc: "David S. Miller" , David Ahern , Eric Dumazet , Ido Schimmel , Andrew Lunn , Simon Horman , Shuah Khan , Jiri Pirko , Hangbin Liu , 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 v6 10/11] selftests: net: Add python context manager for netns entering Date: Wed, 18 Dec 2024 21:09:08 +0800 Message-ID: <20241218130909.2173-11-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241218130909.2173-1-shaw.leon@gmail.com> References: <20241218130909.2173-1-shaw.leon@gmail.com> Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Change netns of current thread and switch back on context exit. For example: with NetNSEnter("ns1"): ip("link add dummy0 type dummy") The command be executed in netns "ns1". Signed-off-by: Xiao Liang --- tools/testing/selftests/net/lib/py/__init__.py | 2 +- tools/testing/selftests/net/lib/py/netns.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/net/lib/py/__init__.py b/tools/testing/selftests/net/lib/py/__init__.py index 54d8f5eba810..e2d6c7b63019 100644 --- a/tools/testing/selftests/net/lib/py/__init__.py +++ b/tools/testing/selftests/net/lib/py/__init__.py @@ -2,7 +2,7 @@ from .consts import KSRC from .ksft import * -from .netns import NetNS +from .netns import NetNS, NetNSEnter from .nsim import * from .utils import * from .ynl import NlError, YnlFamily, EthtoolFamily, NetdevFamily, RtnlFamily diff --git a/tools/testing/selftests/net/lib/py/netns.py b/tools/testing/selftests/net/lib/py/netns.py index ecff85f9074f..8e9317044eef 100644 --- a/tools/testing/selftests/net/lib/py/netns.py +++ b/tools/testing/selftests/net/lib/py/netns.py @@ -1,9 +1,12 @@ # SPDX-License-Identifier: GPL-2.0 from .utils import ip +import ctypes import random import string +libc = ctypes.cdll.LoadLibrary('libc.so.6') + class NetNS: def __init__(self, name=None): @@ -29,3 +32,18 @@ class NetNS: def __repr__(self): return f"NetNS({self.name})" + + +class NetNSEnter: + 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) + return self + + def __exit__(self, exc_type, exc_value, traceback): + libc.setns(self.saved.fileno(), 0) + self.saved.close() From patchwork Wed Dec 18 13:09:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Liang X-Patchwork-Id: 13913667 X-Patchwork-Delegate: johannes@sipsolutions.net Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.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 7A8771FCFC2; Wed, 18 Dec 2024 13:10:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734527457; cv=none; b=Kg5X+Asqsh/CeptfwkVuJxe1OLuZUK9e9rDRUEWrDO88dNVsTUIyWUlDjs7Su3iObEHE10J1LjwA4gQ6Wlz/ram+wDcB064iWa0h6S73tqvJZlgPhyxQ7wK48G5FlX4/qFznhslZudcHPuu/mIdK4XOSAVTI6o6tl1o1sqlTK2k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734527457; c=relaxed/simple; bh=MmoB5+7EOmwBm0nVVOoQDyuB6FG4U5u804h3NW5wIi8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jGQJU5vPH+o2UpEFvcP95GWKyMXI23dywS+AoOKLCwhRbyLfSVevQpeNcL3xX1hUBQEyd+s+2i0nMOWF2JQaVbuHxFI8T7jFmxgw2ADGZ9vEuo4UM+4BegR3Jemuho550E79nPIL8n0tX8CifgXgX+DOwEnPiS/0r0DbePoKGgw= 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=B67qp6RZ; arc=none smtp.client-ip=209.85.214.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="B67qp6RZ" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2166651f752so68023295ad.3; Wed, 18 Dec 2024 05:10:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734527454; x=1735132254; 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=cEe2srsfNQuo3cFtk4Exr0i8mchzSjDC/1TEtzbMZ8U=; b=B67qp6RZKhQnvemU+DKJ1ktWXZyOdMzlOUqwo+QdAnhWwxIbRRECHjtiyCieQlie1M ShXJ6QzBrCtLNjzOwHlLheFKjP5qOT+Rx0/aMc42SatHLVV+Q/h2UGHVFtCHYqHGSVKc wWZ2/3lz1vJ5jLnKe37l5B8Xr8wKa9FgRXT2hOAYMpfdki0EifFNy+LwmtzYxNaH9hkR 5H/IZ8wK+ySzuIETBb/FA167p9uls/EasNPlIg/IkTXrqY/k+WZxrkDzbxXnB0aZLhiW JhTfIv44cxi2wX6IaDqTRJRc7hqa0cfMRp2LQ2oPheJacMrDaSaWOb8TvNwFtldka3zv 8J1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734527454; x=1735132254; 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=cEe2srsfNQuo3cFtk4Exr0i8mchzSjDC/1TEtzbMZ8U=; b=P0ry8xqrRBtX9Hkw91oTG1LaO1556Az8EfRNMtaQJvG/IySN1JfHj2TBUDdEg2sdfS ivjceOyi6dwRSN7pswoazQ7GZpIaRJkz1i4830puKCixlkchrpdegW5dwx7bapeEhPBC EcGVfvZ+e6YWbH7cRxZEbGuLGx8EOFDAFDvTXIRgBFvYM+O4OP5HzisvWQKwkz8bFOaT DbfVBrcHVbaV0TdGIgTM3ZMG8veQL/bUfvdjs8HUu8tlOAV8cd1i8cXqcdQELSJVe8RK VdrWccETtVyr+ESgImlFEbsIfeXtZ9mwr1L6lQHmEMhTWAiVXTP521epRsPKOPvh52ls 74bA== X-Forwarded-Encrypted: i=1; AJvYcCU6VCx46l+HPxRjkcW/eY9nODZJfX6oTTxPhdJ7G9g/ccjG0bJTEaHG5FPmS0uO4eEWZrWZ2ih3obXoCQ==@vger.kernel.org, AJvYcCUFfnK+jkJ9NIrXYlCmfmsgoOEOJ7rW1+mlbFSf8BD5gBO+KJc5L/WhKeHr4dYoEZohHKMBy/37IitV7LKFfiU=@vger.kernel.org, AJvYcCUSu97E2Je16rP74s4aLc83+TWqmhsS9hgSkDUAAO6VcEAswUCBM8v1HQ0EwfeQ4n8sMFVPVG8L4qJl@vger.kernel.org, AJvYcCUhCqtIjqro8hkwPtPmgsOoH8UNalKTToqjU5xOpv8qVuDrBkXeP9liH716c67jYOjfwOpoG/r0ARYm@vger.kernel.org, AJvYcCWRjkc64wGLdK+fvVkf/iqEaZaksPBzuPOADFdEWlimqNJbC4Z4KpT+owzRtwrdBwhGewwX2hIVtQSoF9R4@vger.kernel.org, AJvYcCWXHow90aZJ0YUdmrvqY1VLXkY5U13a011VTYqypeaDg5HyfOxtdGgIiLG57lBYSIYDi3dNzpfQdugxqocDSFhx@vger.kernel.org, AJvYcCXLQFOuB6ytpGz2qRBQbTo/G0Le9oNTy2V4rnbHkq8BPOuXeb3nM++kkt/G0uvl+QzRwGI9vWK5iHcnYg==@vger.kernel.org, AJvYcCXqIouqt+x1KtfysuulEdDt31ZY1ZEWE3aFYP8Ijb/l6oNzbOJ2xxnsHgNJlW6ivuZfMlk=@vger.kernel.org X-Gm-Message-State: AOJu0YxZWAna5M1IJvQ0A7c6tOCigB6Qieym3J9sKWRP6JTvGnY2xK9L 66+QzuCNxJwUl7NbIZom46ZC/CGMAhK3YMFN6tt6s22aTD/GTk5VnxnUX/afFxk= X-Gm-Gg: ASbGnctbqw0lI4keK6Bv16I8TF6yIYG6I6JwjcX+kI9qbX1Ipl+iIH3C6308wQfOqbh QDhNFoqJ2AcBENx3bdJM3i/Y+wggGuyDi2fYSDI8J3ks0tzWSslskNlbChMUJyFKjxVaZexvI16 qE4QdiO8Zfbr6KK6wUAc7PNz+l1JUpauVrByxEqDaXUwgGRN6+i3JLz5fgUDvLfwTCwp0h3aNu0 9ce7tUGk5Mpwi4u2KuDrnwKzS4YHKidcGAKO9/FFJr/EJs= X-Google-Smtp-Source: AGHT+IGW2ivQBr6ib7m/cmjzjnkogelPQGpBxwq3iWWAr6K+/MU6YNZqq3IUhKj+TIVnGpc4fMVSow== X-Received: by 2002:a17:902:f985:b0:216:6c77:7bbb with SMTP id d9443c01a7336-218d70dc242mr29804885ad.17.1734527454469; Wed, 18 Dec 2024 05:10:54 -0800 (PST) Received: from ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-801d5c0f59asm7434754a12.67.2024.12.18.05.10.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Dec 2024 05:10:53 -0800 (PST) From: Xiao Liang To: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Kuniyuki Iwashima , Jakub Kicinski , Donald Hunter , Paolo Abeni Cc: "David S. Miller" , David Ahern , Eric Dumazet , Ido Schimmel , Andrew Lunn , Simon Horman , Shuah Khan , Jiri Pirko , Hangbin Liu , 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 v6 11/11] selftests: net: Add test cases for link and peer netns Date: Wed, 18 Dec 2024 21:09:09 +0800 Message-ID: <20241218130909.2173-12-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241218130909.2173-1-shaw.leon@gmail.com> References: <20241218130909.2173-1-shaw.leon@gmail.com> Precedence: bulk X-Mailing-List: linux-wireless@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/link_netns.py | 142 ++++++++++++++++++++++ tools/testing/selftests/net/netns-name.sh | 10 ++ 3 files changed, 153 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 f09bd96cc978..cc6665212304 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/link_netns.py b/tools/testing/selftests/net/link_netns.py new file mode 100755 index 000000000000..c4b2ddf201ff --- /dev/null +++ b/tools/testing/selftests/net/link_netns.py @@ -0,0 +1,142 @@ +#!/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), + ("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 ]"