From patchwork Mon Jan 13 14:37:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Liang X-Patchwork-Id: 13937450 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA2DE2397BF; Mon, 13 Jan 2025 14:37:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736779069; cv=none; b=R9FdYnIMc3pQEOCITKlPXXBhYQR24P+6MWk8iyqa5WndYRoXfmEXYixG9p2UsxYbVBO5EtyZr2lFHndTShGN9XCLD5bCmSgwqyE+p8bECrj9zHFVVS1iEGWWm19PldK7RJnUZ5pZfulB7tx/bMouJ8tWYrnOOwSM3XSjL+SI0a4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736779069; c=relaxed/simple; bh=1RoOlxGJ2Sn6kgEHCY+FxkXtwcVhSAPqVZyj9KxB0EE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RwwTQZp0CGMdVaMEiUgAlGgdGe7pyUWH0T3+Rjwr7g1zrTz72zu1chA5mcsm9xax6v/chsiMICWYP3c4aYIrENPifDgteP4PYmGuu1Xmd+PIjLSedIjpTrE7mIG+3hdgDssmKWDavjaQxheqPROeMI0klhAmentjXkytqWso04c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kixnE4u7; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kixnE4u7" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-2165cb60719so77851745ad.0; Mon, 13 Jan 2025 06:37:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736779066; x=1737383866; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aStnhmnU+u9WzYJvS9wSRsKutCltWxiDBFKzpdLaN7A=; b=kixnE4u7j4CxKmHe38ncW1VAPwhl9JI40my+hvEntMKz/Cm4clDrwcRWQAOYkYMSs1 jalfniK1aiHmM2Te+vM2A0koEXd+BugmA8FAys62oRgJ4E+wGerQ0DyHeA03yPNvPmBn Byl8B1ozIr8U/9Ltp5mcjZQh5QqxcMFZvnE0JDc9J92QH1DZyqhKFQc9ZvF4DVXVVqd1 lqn+F3d01Er4JIsLl+DZH/19tIJJb6Mls4kRW47md21WK4fTon76/4jwHXIRU3vez+eK LPACa80/Yep3eGSIGL3eeBA/05/aAhsSGQ5Re88sEYV2SBFFWHN641vB4zVCfmlsTwpd 3DeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736779066; x=1737383866; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aStnhmnU+u9WzYJvS9wSRsKutCltWxiDBFKzpdLaN7A=; b=qL9VuZNdkhOKzg0NvvNX7ac302963UxtOzv5nnENPLe8bTXv5bX7GO7vZr6HVSsPuQ pgZl4vFMVkZivShBrrwVZqdN34xGWWqenpJeBQCjpZUm7aZNp2GE0uEube+RgqxlM2ie k9yxPCQcamzy5EJzhtJdsI/pi/oWTPNUtZXg3Z7SYx+Fnu9XlXKA/6uYkTyiJwZHWLbG 5y1eRLzbQQMiX5h3rPyT8JMcdjO+GwuJ8HcaRIVxNGKOPPuXLGR/5Llu/jMYxnVshdyY LJMjT4x87UNFppTZnYxL5QD2GufsWilKTPrcvfcsXZGI4rhBbzQJGXl0guNYyhKs+yO1 hzLQ== X-Forwarded-Encrypted: i=1; AJvYcCU0wRAGsDry2pZT2YrphN9gGrfqTaF7MPWyiYTo+vulK5AkjwNT9H+kv9N2Y2s3VqywEriwAzKhjj/P@vger.kernel.org, AJvYcCUKb0wo+tvKXgb3uI0l2Wz09TU5d3AdOj6fSvKyYEikt9J5Q+DgnBo7leS3lROL7i3u4pfdHcERhV9ZU1z6fAkb@vger.kernel.org, AJvYcCUZ6IFBAac+R3bM8V9pERNBqHyVB83gPvIzKc1GYOVmQChskE5+DLai5OAm1qGbt7RsdXbEubgoZboP5y74Uls=@vger.kernel.org, AJvYcCV+adA/qdbX+P1jlLOj6eMmLiweIRweTZc+WgOeq4lOiiFxfhDFUmhkeXnLaMpQIIH+fyrpzEIdj3d4DKDv@vger.kernel.org, AJvYcCVPhcX5xcNl2GgxXmGE1lrd1BIwSSs8XPM3FdO+53WAiXnGBbgyo5cer6/32LrlZ1T27LE/57//vn3/@vger.kernel.org, AJvYcCVcH5AX0wNe3852401/JfpM0E8mdfDYalbWWUtDZKGGtMMeeuwfFpmWkXSVpHdUCA3IyA4VTXbXd8cYUg==@vger.kernel.org, AJvYcCXXIFOanl1R0GnVgHeBRNOa0O/Wtxt5gEtHF7lT+75GdcIzh1VRywMxBYC6cHVwdGYQ1Oo=@vger.kernel.org, AJvYcCXY/uSxWP7uaLsuEwlz+w1NXWBYp0wL/RenwO2t/CVEI3PnW6wAoIkaHi66rFHa86FjHOlK9jSEkFbqzg==@vger.kernel.org X-Gm-Message-State: AOJu0YzSbjOPc0QBJ9pRF4pE2eeNavmtHNWqrfgGzh1xrSED8nwwKrLX rRpggr5uFkQ4Kq7/pJGO7X5dZEzO60VrAkEf2+/leb29qGH8FJbmwTe9SGwBIpw= X-Gm-Gg: ASbGncuKttoRMBd8lRpINXdxGv4kd2lFplRhs6Ggp91IHcaADqeRq1+RRdUQPCelUR/ HhmKfxtOSwCyrxb0Y1NzcFlu9bsWV/fpHtFBb1TvNm0pism3y7iaMahZqZTKmBr0TaS2jV/vnCE ifTo/LZbd21XojGd3tjIq/wl23aA2IsvYqobRde9DNig/kdAmp7KCQugjMQb4AwHZm0RBcNE0xT WIDYZteUyWmXMKlo51/WNartOitcVozWIguLGdvd26J3/4= X-Google-Smtp-Source: AGHT+IEEIzRcAyOPsqmoPyg3LqUO10MpSinA1zy4f8+lVawQb15WuSETw63Trl8RPwnuvmvDM8k1Dw== X-Received: by 2002:a17:902:e74e:b0:215:aee1:7e3e with SMTP id d9443c01a7336-21a83f36d48mr318259495ad.5.1736779066532; Mon, 13 Jan 2025 06:37:46 -0800 (PST) Received: from ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f155e00sm54328715ad.103.2025.01.13.06.37.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 06:37:46 -0800 (PST) From: Xiao Liang To: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Kuniyuki Iwashima , Jakub Kicinski Cc: "David S. Miller" , David Ahern , Eric Dumazet , Paolo Abeni , Andrew Lunn , Simon Horman , Shuah Khan , Donald Hunter , Alexander Aring , Stefan Schmidt , Miquel Raynal , Steffen Klassert , Herbert Xu , linux-rdma@vger.kernel.org, linux-can@vger.kernel.org, osmocom-net-gprs@lists.osmocom.org, bpf@vger.kernel.org, linux-ppp@vger.kernel.org, wireguard@lists.zx2c4.com, linux-wireless@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org, bridge@lists.linux.dev, linux-wpan@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v8 01/11] rtnetlink: Lookup device in target netns when creating link Date: Mon, 13 Jan 2025 22:37:09 +0800 Message-ID: <20250113143719.7948-2-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250113143719.7948-1-shaw.leon@gmail.com> References: <20250113143719.7948-1-shaw.leon@gmail.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When creating link, lookup for existing device in target net namespace instead of current one. For example, two links created by: # ip link add dummy1 type dummy # ip link add netns ns1 dummy1 type dummy should have no conflict since they are in different namespaces. Signed-off-by: Xiao Liang Reviewed-by: Kuniyuki Iwashima --- net/core/rtnetlink.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 1f4d4b5570ab..ec98349b9620 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -3861,20 +3861,26 @@ static int __rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh, { struct nlattr ** const tb = tbs->tb; struct net *net = sock_net(skb->sk); + struct net *device_net; struct net_device *dev; struct ifinfomsg *ifm; bool link_specified; + /* When creating, lookup for existing device in target net namespace */ + device_net = (nlh->nlmsg_flags & NLM_F_CREATE) && + (nlh->nlmsg_flags & NLM_F_EXCL) ? + tgt_net : net; + ifm = nlmsg_data(nlh); if (ifm->ifi_index > 0) { link_specified = true; - dev = __dev_get_by_index(net, ifm->ifi_index); + dev = __dev_get_by_index(device_net, ifm->ifi_index); } else if (ifm->ifi_index < 0) { NL_SET_ERR_MSG(extack, "ifindex can't be negative"); return -EINVAL; } else if (tb[IFLA_IFNAME] || tb[IFLA_ALT_IFNAME]) { link_specified = true; - dev = rtnl_dev_get(net, tb); + dev = rtnl_dev_get(device_net, tb); } else { link_specified = false; dev = NULL; From patchwork Mon Jan 13 14:37:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Liang X-Patchwork-Id: 13937451 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 3B9D323ED66; Mon, 13 Jan 2025 14:37:57 +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=1736779079; cv=none; b=XUCAkVQvni6JB025+j575rdeFDvu/R09PoZaA9oOaE3poMeHnHfuW6Lm1JWLCyGUGafXt3W6CABlsV054NAU2DM85rMbbYP5iuT7fgWktsDfC24g5+g13qz3daazkzZt6rH0LQwp2Zz61QA3CSD4XDfHXDEfQXG9w8IZhprZ6pQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736779079; c=relaxed/simple; bh=NMh4AdGSNRh/OJh2o+MV7oDIHZRdnrvogzIpay/Wa/s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pAtw+iGueBhuFzozWXHzziCoL/m7MPf9ntIYzmo3OuWTPN4c77ifGrGif0pptbXfRqk1OPZG4gxXk2EzTcNryGBMNVizqIBEpWNoehshWx5yGNWuT5D+FTlmrfkDTjHGCooTE4FXbzq6T75oEuxCvku3Bm30wHPSfCaUVu/TJ3M= 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=nRCD8ZN/; 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="nRCD8ZN/" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2165cb60719so77857415ad.0; Mon, 13 Jan 2025 06:37:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736779076; x=1737383876; 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=DBbRE3ugLp3qkRsaKhazYkz+BhLIeMQdruLA0C2fOWQ=; b=nRCD8ZN/fN3SmAwDmYCDPzE0tWfAVN5bqm8eq8IU36qViQi9kTf8ySAQqJyEKnsW5/ GN/qkKUnWd6QoQSuIg1Suxix86TMwGedOW6s57CNX+Bih3zjD3FawERxkvy8ERjaYH2g QmXf9lqApAdmeklixmgTPvHBA+VDt/pfq6tYrPfvwF3WzlQdJNfF89uAkMK7MpZ/me3g xs6ZV4orrt+eVtuA6lSx1HKcj89VT/FtEvCjj5X2m0NP2gC72d0A804ydZ35SAIGNUNh QZ8Wl0vTEmeT4FN9gAy7azMV9knoQhBw3KglHdYc/FE5PuneZ16+rzUYgCOct8nGV3Zc tynA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736779076; x=1737383876; 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=DBbRE3ugLp3qkRsaKhazYkz+BhLIeMQdruLA0C2fOWQ=; b=Wur/1bLHtbQTbCBhh+tnciKlMY8Ib1tEhPU+XJbvNifcw/m6ecrPtMDUYTzHkrKuUC WS7LsYlIk10ryU44Wo/5yzZ9il/lSEvwiGg0NzDkurS0KLLzheB5JtEadwKQBpY1NxhS uwRnOHZnpR5NL7b+ittiCmvCH8LT+IqrwiA5UPdgusaiobCKGIn/5dYEpXG43pRf9Q/z OJFeYCU2knmVBr5kIC8rU5oZZXPHdDdPjD/WPPT2EwCsu0KjdzwFJgFWebdBcHGVR5Rs 08V3NMTPlu70JMu+ZrrI3Eft7XngCLbb/kE5c3RdHze2vmYt8QjSYp/dXApLGLTo5l1z 7MBw== X-Forwarded-Encrypted: i=1; AJvYcCUF4TO5pWgDq7zu8jSbbxZRmQDLZQ7oUid+fl7szr/MdIxSO7pKBVwGEmQ2FRo1wgmsOeBqpL/TZWdg@vger.kernel.org, AJvYcCVRPVtVKFgcb02SY+ZMsyD4IEmqewmm156OPmjnBVmutGDMxVNOnTPby/HQCO8N3vu0YJZMS/QE1xUDmA==@vger.kernel.org, AJvYcCVrJIfC1GXGSpFsoCBNdJWX2EcpxYXBiTjjx1mIrSREJ0XBKgmDb7rb9m5kgzGusW7YUZs=@vger.kernel.org, AJvYcCWrzRtTe7J+Px78BkXFVEkPOIX0xndbDf5bhb9Js6prGd7Olt6BUGlG8JKQTZ2OPnHaBRhovFMB3Fqla7re@vger.kernel.org, AJvYcCWuT8BeIAXmcWsTFHCzXdbLiePelZuS1tjlFLwM3oWWh6x01NwEHO4gBRSH5SWx2IQkaTY9rjBaM9nE@vger.kernel.org, AJvYcCXFEaray/2BQv0rN2CtCrxxI3r0BtIyvfxF0E7TNzOfl5O6VFRkaLa6MBV4svqqotrGZFbRjgw8ElS4O4njc/o=@vger.kernel.org, AJvYcCXmANKDdyyJvhUsdnLZ5sNU9i+cdhMjtLyTBblAwV6/1KJUiLON5QZAV6fZXtqn3Bo3AQlz1YGHiGGUi5M3e5B1@vger.kernel.org, AJvYcCXmNTFWcP57WbprwxmlbAbjD9b07XQacehOffRlW/tTbvqmyyonK8rRr5bPLxs73vQhgvbQU43i5Ew/eA==@vger.kernel.org X-Gm-Message-State: AOJu0YxyY5U+hImWqFyj7DFjLEtG9dfQcBHTsoqOlc9rLReFrh1pAPtQ rLiqG/1HHK39efQbhkp04+bmCLmuy8FV/osS+Ica1Q8jE2z3B5ggIrreLczCfh4= X-Gm-Gg: ASbGnctXwhHdJRJFPjiaKSN35NCKDS2rWviFkRL9cFNggTBXXz60hbV/FQ4zMKdieyn LNRFCOFvnerD2dLD3x9/0yTTAv+5mudA4NINABzjo2DgLknWf1mj/Fg5pbssrztJl0GRBOznKhY DFS02nCl9XhzRcwPkCgu9r2ySie6oSi09jRmORB4QOJke6/S0pX3ahO4jGhLtFiPD1icYMzG7L2 OaaT+yeCfw0Y6d3iEcFwikNNluyLx5dfehXceB0sfS4G/w= X-Google-Smtp-Source: AGHT+IFX1cL4DfnHS+w2s6yKcG/x/MBPAXrsYGSj+XPFymnbU/AVlf8tHVoVJUMT8dz5+FAel+SppA== X-Received: by 2002:a17:902:ea09:b0:216:2a36:5b2e with SMTP id d9443c01a7336-21a83f76879mr310005155ad.32.1736779075712; Mon, 13 Jan 2025 06:37:55 -0800 (PST) Received: from ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f155e00sm54328715ad.103.2025.01.13.06.37.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 06:37:55 -0800 (PST) From: Xiao Liang To: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Kuniyuki Iwashima , Jakub Kicinski Cc: "David S. Miller" , David Ahern , Eric Dumazet , Paolo Abeni , Andrew Lunn , Simon Horman , Shuah Khan , Donald Hunter , Alexander Aring , Stefan Schmidt , Miquel Raynal , Steffen Klassert , Herbert Xu , linux-rdma@vger.kernel.org, linux-can@vger.kernel.org, osmocom-net-gprs@lists.osmocom.org, bpf@vger.kernel.org, linux-ppp@vger.kernel.org, wireguard@lists.zx2c4.com, linux-wireless@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org, bridge@lists.linux.dev, linux-wpan@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v8 02/11] rtnetlink: Pack newlink() params into struct Date: Mon, 13 Jan 2025 22:37:10 +0800 Message-ID: <20250113143719.7948-3-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250113143719.7948-1-shaw.leon@gmail.com> References: <20250113143719.7948-1-shaw.leon@gmail.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 | 7 +++- drivers/net/amt.c | 7 +++- drivers/net/bareudp.c | 7 +++- drivers/net/bonding/bond_netlink.c | 6 ++- drivers/net/can/dev/netlink.c | 4 +- drivers/net/can/vxcan.c | 7 +++- .../ethernet/qualcomm/rmnet/rmnet_config.c | 7 +++- drivers/net/geneve.c | 7 +++- drivers/net/gtp.c | 6 ++- drivers/net/ipvlan/ipvlan.h | 3 +- drivers/net/ipvlan/ipvlan_main.c | 6 ++- drivers/net/ipvlan/ipvtap.c | 6 +-- drivers/net/macsec.c | 7 +++- drivers/net/macvlan.c | 7 ++-- drivers/net/macvtap.c | 7 ++-- drivers/net/netkit.c | 7 +++- drivers/net/pfcp.c | 5 ++- drivers/net/ppp/ppp_generic.c | 7 +++- drivers/net/team/team_core.c | 6 ++- drivers/net/veth.c | 7 +++- drivers/net/vrf.c | 5 ++- drivers/net/vxlan/vxlan_core.c | 7 +++- drivers/net/wireguard/device.c | 5 ++- drivers/net/wireless/virtual/virt_wifi.c | 6 ++- drivers/net/wwan/wwan_core.c | 16 +++++-- include/net/rtnetlink.h | 42 +++++++++++++++++-- net/8021q/vlan_netlink.c | 7 +++- net/batman-adv/soft-interface.c | 9 ++-- net/bridge/br_netlink.c | 6 ++- net/caif/chnl_net.c | 5 ++- net/core/rtnetlink.c | 14 +++++-- net/hsr/hsr_netlink.c | 6 ++- net/ieee802154/6lowpan/core.c | 5 ++- net/ipv4/ip_gre.c | 18 +++++--- net/ipv4/ip_vti.c | 6 ++- net/ipv4/ipip.c | 6 ++- net/ipv6/ip6_gre.c | 14 +++++-- net/ipv6/ip6_tunnel.c | 6 ++- net/ipv6/ip6_vti.c | 5 ++- net/ipv6/sit.c | 6 ++- net/xfrm/xfrm_interface_core.c | 7 ++-- 41 files changed, 228 insertions(+), 99 deletions(-) diff --git a/drivers/infiniband/ulp/ipoib/ipoib_netlink.c b/drivers/infiniband/ulp/ipoib/ipoib_netlink.c index 9ad8d9856275..16cb8ced9f35 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[], +static int ipoib_new_child_link(struct net_device *dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + 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..96b7ec9a2c13 100644 --- a/drivers/net/amt.c +++ b/drivers/net/amt.c @@ -3161,11 +3161,14 @@ 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[], +static int amt_newlink(struct net_device *dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { struct amt_dev *amt = netdev_priv(dev); + struct nlattr **data = params->data; + struct nlattr **tb = params->tb; + struct net *net = params->net; int err = -EINVAL; amt->net = net; diff --git a/drivers/net/bareudp.c b/drivers/net/bareudp.c index 70814303aab8..fc21dcfb4848 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[], +static int bareudp_newlink(struct net_device *dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + 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..ac5e402c34bc 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[], +static int bond_newlink(struct net_device *bond_dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + 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..f1db9b7ffd4d 100644 --- a/drivers/net/can/dev/netlink.c +++ b/drivers/net/can/dev/netlink.c @@ -624,8 +624,8 @@ 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[], +static int can_newlink(struct net_device *dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { return -EOPNOTSUPP; diff --git a/drivers/net/can/vxcan.c b/drivers/net/can/vxcan.c index ca8811941085..6f8ebb1cfd7b 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[], +static int vxcan_newlink(struct net_device *dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + 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..8151e91395e2 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[], +static int rmnet_newlink(struct net_device *dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { u32 data_format = RMNET_FLAGS_INGRESS_DEAGGREGATION; + 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..d373a851930c 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[], +static int geneve_newlink(struct net_device *dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + 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..80ad618ba423 100644 --- a/drivers/net/gtp.c +++ b/drivers/net/gtp.c @@ -1460,10 +1460,12 @@ 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[], +static int gtp_newlink(struct net_device *dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + 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..50de3ee204db 100644 --- a/drivers/net/ipvlan/ipvlan.h +++ b/drivers/net/ipvlan/ipvlan.h @@ -166,8 +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[], +int ipvlan_link_new(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack); void ipvlan_link_delete(struct net_device *dev, struct list_head *head); void ipvlan_link_setup(struct net_device *dev); diff --git a/drivers/net/ipvlan/ipvlan_main.c b/drivers/net/ipvlan/ipvlan_main.c index da3a97a65507..19ce19ca7e32 100644 --- a/drivers/net/ipvlan/ipvlan_main.c +++ b/drivers/net/ipvlan/ipvlan_main.c @@ -532,11 +532,13 @@ 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[], +int ipvlan_link_new(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { struct ipvl_dev *ipvlan = netdev_priv(dev); + struct nlattr **data = params->data; + struct net *src_net = params->net; + struct nlattr **tb = params->tb; struct ipvl_port *port; struct net_device *phy_dev; int err; diff --git a/drivers/net/ipvlan/ipvtap.c b/drivers/net/ipvlan/ipvtap.c index 1afc4c47be73..edd13916831a 100644 --- a/drivers/net/ipvlan/ipvtap.c +++ b/drivers/net/ipvlan/ipvtap.c @@ -73,8 +73,8 @@ 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[], +static int ipvtap_newlink(struct net_device *dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { struct ipvtap_dev *vlantap = netdev_priv(dev); @@ -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(dev, params, extack); if (err) { netdev_rx_handler_unregister(dev); return err; diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c index 1bc1e5993f56..1869b0513f57 100644 --- a/drivers/net/macsec.c +++ b/drivers/net/macsec.c @@ -4141,11 +4141,14 @@ 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[], +static int macsec_newlink(struct net_device *dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { struct macsec_dev *macsec = macsec_priv(dev); + struct nlattr **data = params->data; + struct nlattr **tb = params->tb; + struct net *net = params->net; rx_handler_func_t *rx_handler; u8 icv_len = MACSEC_DEFAULT_ICV_LEN; struct net_device *real_dev; diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c index fed4fe2a4748..0c496aa1f706 100644 --- a/drivers/net/macvlan.c +++ b/drivers/net/macvlan.c @@ -1565,11 +1565,12 @@ 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[], +static int macvlan_newlink(struct net_device *dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { - return macvlan_common_newlink(src_net, dev, tb, data, extack); + return macvlan_common_newlink(params->net, dev, params->tb, + params->data, extack); } void macvlan_dellink(struct net_device *dev, struct list_head *head) diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c index 29a5929d48e5..6dbfeeac5c99 100644 --- a/drivers/net/macvtap.c +++ b/drivers/net/macvtap.c @@ -77,8 +77,8 @@ 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[], +static int macvtap_newlink(struct net_device *dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { struct macvtap_dev *vlantap = netdev_priv(dev); @@ -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, + extack); if (err) { netdev_rx_handler_unregister(dev); return err; diff --git a/drivers/net/netkit.c b/drivers/net/netkit.c index 1e1b00756be7..1e9eadc77da2 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[], +static int netkit_new_link(struct net_device *dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + 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..d9e4b5185c51 100644 --- a/drivers/net/pfcp.c +++ b/drivers/net/pfcp.c @@ -184,11 +184,12 @@ 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[], +static int pfcp_newlink(struct net_device *dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { struct pfcp_dev *pfcp = netdev_priv(dev); + struct net *net = params->net; struct pfcp_net *pn; int err; diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c index 4583e15ad03a..b3340f8a6149 100644 --- a/drivers/net/ppp/ppp_generic.c +++ b/drivers/net/ppp/ppp_generic.c @@ -1303,10 +1303,13 @@ 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[], +static int ppp_nl_newlink(struct net_device *dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + 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 dc7cbd6a9798..10e03fa33530 100644 --- a/drivers/net/team/team_core.c +++ b/drivers/net/team/team_core.c @@ -2218,10 +2218,12 @@ 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[], +static int team_newlink(struct net_device *dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + 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..7dfda89f072f 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[], +static int veth_newlink(struct net_device *dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + 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..b2cf13ac0e47 100644 --- a/drivers/net/vrf.c +++ b/drivers/net/vrf.c @@ -1677,11 +1677,12 @@ 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[], +static int vrf_newlink(struct net_device *dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { struct net_vrf *vrf = netdev_priv(dev); + struct nlattr **data = params->data; struct netns_vrf *nn_vrf; bool *add_fib_rules; struct net *net; diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c index 05c10acb2a57..86c620b4c26f 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[], +static int vxlan_newlink(struct net_device *dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + 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..404cf05bd72b 100644 --- a/drivers/net/wireguard/device.c +++ b/drivers/net/wireguard/device.c @@ -307,11 +307,12 @@ 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[], +static int wg_newlink(struct net_device *dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { struct wg_device *wg = netdev_priv(dev); + struct net *src_net = params->net; int ret = -ENOMEM; rcu_assign_pointer(wg->creating_net, src_net); diff --git a/drivers/net/wireless/virtual/virt_wifi.c b/drivers/net/wireless/virtual/virt_wifi.c index 4ee374080466..26905b2b3ba3 100644 --- a/drivers/net/wireless/virtual/virt_wifi.c +++ b/drivers/net/wireless/virtual/virt_wifi.c @@ -519,11 +519,13 @@ 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[], +static int virt_wifi_newlink(struct net_device *dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { struct virt_wifi_netdev_priv *priv = netdev_priv(dev); + struct net *src_net = params->net; + struct nlattr **tb = params->tb; int err; if (!tb[IFLA_LINK]) diff --git a/drivers/net/wwan/wwan_core.c b/drivers/net/wwan/wwan_core.c index a51e2755991a..53a6c437ff79 100644 --- a/drivers/net/wwan/wwan_core.c +++ b/drivers/net/wwan/wwan_core.c @@ -967,15 +967,18 @@ 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[], +static int wwan_rtnl_newlink(struct net_device *dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { 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 nlattr **data = params->data; + u32 link_id; int ret; + link_id = nla_get_u32(data[IFLA_WWAN_LINK_ID]); + if (IS_ERR(wwandev)) return PTR_ERR(wwandev); @@ -1064,6 +1067,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 +1113,7 @@ 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))) { + if (WARN_ON(wwan_rtnl_newlink(dev, ¶ms, NULL))) { free_netdev(dev); goto unlock; } diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h index bc0069a8b6ea..00c086ca0c11 100644 --- a/include/net/rtnetlink.h +++ b/include/net/rtnetlink.h @@ -69,6 +69,42 @@ 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 + * @tb: IFLA_* attributes + * @data: IFLA_INFO_DATA attributes + */ +struct rtnl_newlink_params { + struct net *net; + struct net *src_net; + struct net *link_net; + struct net *peer_net; + struct nlattr **tb; + struct nlattr **data; +}; + +/* 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,10 +161,8 @@ 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[], + int (*newlink)(struct net_device *dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack); int (*changelink)(struct net_device *dev, struct nlattr *tb[], diff --git a/net/8021q/vlan_netlink.c b/net/8021q/vlan_netlink.c index 134419667d59..91df0f96e32a 100644 --- a/net/8021q/vlan_netlink.c +++ b/net/8021q/vlan_netlink.c @@ -135,11 +135,14 @@ 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[], +static int vlan_newlink(struct net_device *dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { struct vlan_dev_priv *vlan = vlan_dev_priv(dev); + struct nlattr **data = params->data; + struct net *src_net = params->net; + struct nlattr **tb = params->tb; struct net_device *real_dev; unsigned int max_mtu; __be16 proto; diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c index 2758aba47a2f..b85b368f8593 100644 --- a/net/batman-adv/soft-interface.c +++ b/net/batman-adv/soft-interface.c @@ -1063,19 +1063,18 @@ 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 + * @params: rtnl newlink parameters * @extack: extended ACK report struct * * 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[], +static int batadv_softif_newlink(struct net_device *dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { struct batadv_priv *bat_priv = netdev_priv(dev); + struct nlattr **data = params->data; const char *algo_name; int err; diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c index 3e0f47203f2a..6e337937d0d7 100644 --- a/net/bridge/br_netlink.c +++ b/net/bridge/br_netlink.c @@ -1553,11 +1553,13 @@ 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[], +static int br_dev_newlink(struct net_device *dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { struct net_bridge *br = netdev_priv(dev); + struct nlattr **data = params->data; + struct nlattr **tb = params->tb; int err; err = register_netdevice(dev); diff --git a/net/caif/chnl_net.c b/net/caif/chnl_net.c index 94ad09e36df2..fa6a3c2634a8 100644 --- a/net/caif/chnl_net.c +++ b/net/caif/chnl_net.c @@ -438,10 +438,11 @@ 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[], +static int ipcaif_newlink(struct net_device *dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + 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 ec98349b9620..7ff5e96f6ba7 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -3766,6 +3766,14 @@ 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, + }; if (!ops->alloc && !ops->setup) return -EOPNOTSUPP; @@ -3787,12 +3795,12 @@ static int rtnl_newlink_create(struct sk_buff *skb, struct ifinfomsg *ifm, dev->ifindex = ifm->ifi_index; 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(dev, ¶ms, extack); else err = register_netdevice(dev); if (err < 0) { diff --git a/net/hsr/hsr_netlink.c b/net/hsr/hsr_netlink.c index b68f2f71d0e1..39add538ba99 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[], +static int hsr_newlink(struct net_device *dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + 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..704bf9e3f097 100644 --- a/net/ieee802154/6lowpan/core.c +++ b/net/ieee802154/6lowpan/core.c @@ -129,10 +129,11 @@ 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[], +static int lowpan_newlink(struct net_device *ldev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + 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 a020342f618d..4e8c310769ad 100644 --- a/net/ipv4/ip_gre.c +++ b/net/ipv4/ip_gre.c @@ -1392,10 +1392,12 @@ 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[], +static int ipgre_newlink(struct net_device *dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + struct nlattr **data = params->data; + struct nlattr **tb = params->tb; struct ip_tunnel_parm_kern p; __u32 fwmark = 0; int err; @@ -1410,10 +1412,12 @@ 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[], +static int erspan_newlink(struct net_device *dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + struct nlattr **data = params->data; + struct nlattr **tb = params->tb; struct ip_tunnel_parm_kern p; __u32 fwmark = 0; int err; @@ -1698,6 +1702,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)); @@ -1710,7 +1718,7 @@ 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); + err = ipgre_newlink(dev, ¶ms, NULL); 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..b901bee03e6d 100644 --- a/net/ipv4/ip_vti.c +++ b/net/ipv4/ip_vti.c @@ -575,11 +575,13 @@ 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[], +static int vti_newlink(struct net_device *dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + 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..a8b844bcfc64 100644 --- a/net/ipv4/ipip.c +++ b/net/ipv4/ipip.c @@ -436,11 +436,13 @@ 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[], +static int ipip_newlink(struct net_device *dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { struct ip_tunnel *t = netdev_priv(dev); + struct nlattr **data = params->data; + struct nlattr **tb = params->tb; struct ip_tunnel_encap ipencap; struct ip_tunnel_parm_kern p; __u32 fwmark = 0; diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c index 235808cfec70..863852abe8ea 100644 --- a/net/ipv6/ip6_gre.c +++ b/net/ipv6/ip6_gre.c @@ -2005,11 +2005,14 @@ 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[], +static int ip6gre_newlink(struct net_device *dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { struct ip6_tnl *nt = netdev_priv(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; int err; @@ -2241,11 +2244,14 @@ 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[], +static int ip6erspan_newlink(struct net_device *dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { struct ip6_tnl *nt = netdev_priv(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; int err; diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c index 48fd53b98972..54b843d20870 100644 --- a/net/ipv6/ip6_tunnel.c +++ b/net/ipv6/ip6_tunnel.c @@ -2002,10 +2002,12 @@ 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[], +static int ip6_tnl_newlink(struct net_device *dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + 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..993f85aeb882 100644 --- a/net/ipv6/ip6_vti.c +++ b/net/ipv6/ip6_vti.c @@ -997,10 +997,11 @@ 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[], +static int vti6_newlink(struct net_device *dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + 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..e2bd52cabdee 100644 --- a/net/ipv6/sit.c +++ b/net/ipv6/sit.c @@ -1550,10 +1550,12 @@ 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[], +static int ipip6_newlink(struct net_device *dev, + struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + 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..b7ac558025d5 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 net_device *dev, + struct rtnl_newlink_params *params, + struct netlink_ext_ack *extack) { + struct nlattr **data = params->data; struct net *net = dev_net(dev); struct xfrm_if_parms p = {}; struct xfrm_if *xi; From patchwork Mon Jan 13 14:37:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Liang X-Patchwork-Id: 13937452 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 13DE124633B; Mon, 13 Jan 2025 14:38:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736779088; cv=none; b=YtyXWrCAyyW9UPsGhveXIXFT7g8ta7m/OIy4vx5jZ1DDxEWj+fl53ABGPnPtfz5Ers9/f4jvglqC6laaVg5S/IVdMAhJ0K7t2dDIN0vRxsrdnCN6GlxhKS3xtfZAWebP8XkcIJtriy9hz9jOIz39cjTYwH4wdEsHp8iGcFaa/K0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736779088; c=relaxed/simple; bh=yVXZazNTD2EBAWknl/LWkjWGKnNjfNLy9fPEJ6+d1rc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Om4MinTlDxz3G0E7SzffK/e839bMHdsTzRzuO3vdhIssooQDfRs87NGGlMXjyP3C6Hk3TV5X4bxWeZWw2tj4lLUGLNRH0U+5eDDBHFiEUykV1IBRgv9GGPHX8GMhqJtzk5bbatPHrNt9umPnO/w5Gb55xRzKNFbQMWRwzs9UywA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=WXaf42pl; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WXaf42pl" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-2163b0c09afso78914825ad.0; Mon, 13 Jan 2025 06:38:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736779084; x=1737383884; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LZBCyw57IE7Zso6/WsMTOb7GBu1vP4ikeykgITmoGTY=; b=WXaf42pliAXm7S2hpDW6Y50VJZyXP3nvAsohzdfG/FQwrTQQNC6qhuBc2DK5nLJpBt aST/j5jIhKYoMnt2Br4UIFHJYdLE8Q9r8BYPAUovI4j4EN1K0EB3aep/tFajE5n1Nhjm HLuNicT/DFMcw5W22vgkSCp4YB0s9pfZLThlQdsOPUrA3UUFq7b7i/ILZPpmUxCBrXmY +hQF01Dd4CGE32IbGWWGFxgKNIFahlVsVAS36x1hNUbB6fvikc+PvhxtH2I+kxaV+Ndm OA3AWchpBvOb1u8GUM6NS/KhrLSlov3wrpLhc4rd5PJbpyRiacwt6U6pdpmheiW/1r/+ OJbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736779084; x=1737383884; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LZBCyw57IE7Zso6/WsMTOb7GBu1vP4ikeykgITmoGTY=; b=ezZpZFe6rJ009dvDMl2+AINVfA/THqMF9yZSqw6tdtcm8l0+OZ1mQGLBI/R7CGJ1w3 RhDBSv3kuodFNNkcpj/3tNcwu3UkfRLTx/T9HPn2aF/eAU5GJziyMFEJxJW2/6A1+K7A QPqdQchNQaYY7U2oEYQNAbsuGpOHxo30+kZwBPe63YhhmpYS1vhML/8yt6rrp3NKXX4f ++h9zgGPdWTfWSeSRP5wlTnYd9gwO0nmmTHLZqGHlmBEQMIFker4HYMxZOlDEz1oz519 EwLLxkojsIfUymAPRgU7GRgtqoQjJNmlXx7JT/gezwMzUJem+MkoQp0GtfiLGBPC+Kyd 3eXQ== X-Forwarded-Encrypted: i=1; AJvYcCUDrD4Oix9RrrIxxidzHG0vYDg1S/iS/hdvBp0QhmVaoxUuM4oM1Xwq9ANtzO59L/5BJVqtI8qxGf6OYoM5r4RF@vger.kernel.org, AJvYcCUqd+cCn/MzZu4gciqOA9KaDg8kA6JOWMaVVAtJQwzTbPjMe/OqiWxnxG4WX8K4IwVYoERK0m+lUg6J@vger.kernel.org, AJvYcCVBU+D/J6dMuNMHX81KXaRiy68XcLCQWRoL1URptgfbP3+Nlxj8fJJ5Z6M9kdYgdG1MnzQ=@vger.kernel.org, AJvYcCVQAyqTntfopVU8owlO4Vpwl2MYUKbZcuoMmlTScygEAslQDrzUbomF0y9KhobljvUpBfQiDJ2HfWYK@vger.kernel.org, AJvYcCVmpp65t6x+HXGgeZzHTFFw4CD5n5JkiAjxharKd3GTsut/sdzvlDFaJLj4QMsSBgvAMcfQLsFOYeR8QVuA@vger.kernel.org, AJvYcCVoVA7mUaJ9eN7vthXp5aYC9Tg1J7keRNzcodoQ4SAB5fxD03iVpMHE1Hr0oDpyEyRPsClhsd44IPgInQ==@vger.kernel.org, AJvYcCWGT6SnKvdojOPbFrwcZ+3SCRQhfArNyGZFOOwmSnxPpUzxUxgeDxTqXWSJo39oS8Z1S2M8wdJRbNwKvg==@vger.kernel.org, AJvYcCWnOLOfHoClGKsRI9FaVj6EFEg+K0zyJO5V5KePVlgyofn2cPwJIfnWBkyRPk7L9Cvn6xHTd290fmPhKTUxvtc=@vger.kernel.org X-Gm-Message-State: AOJu0YxeU/4C+ATvrglbabxKJNL9fj5ONv9LPiEK+OqHttPLW7h9TMgU xxP6uZWBuOsEB8/394g6m69dJ+dx4+SIArAMrRhdOkkexKe0lo5ggh3GkoikL6k= X-Gm-Gg: ASbGncviWypHVfx51Ts138AHQFDkyQX0o21diRdjXm4xA+AvwTxoM6HryJfY2RDg3YX 1p9rPQ2rqkKqBW/GDpN4sX3ccskqubbDJFFyjj47uB7GpdsBZ3nDvMmWqj5AOHhrLh9lXXM743c V8mKPg3wPkbysaJlY//447Hmd37zmBObTuKI1VoJxjNa/7XSgUBmJTShcQJOGE+sNCoO69Ltz7d 5cMovbHNlsQRSDrEuaLX/WK00sch9kDgHxtRoGxnp8EAvU= X-Google-Smtp-Source: AGHT+IE+8qVbma2Qb/CZO5qK/8pf/aA+GET4Kf+ksPfd0XQFxcjbmABnzOsLzbZBSWi1j8h4JBn4Hg== X-Received: by 2002:a17:903:32ce:b0:215:b8c6:338a with SMTP id d9443c01a7336-21a83f338a5mr322037415ad.4.1736779084410; Mon, 13 Jan 2025 06:38:04 -0800 (PST) Received: from ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f155e00sm54328715ad.103.2025.01.13.06.37.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 06:38:03 -0800 (PST) From: Xiao Liang To: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Kuniyuki Iwashima , Jakub Kicinski Cc: "David S. Miller" , David Ahern , Eric Dumazet , Paolo Abeni , Andrew Lunn , Simon Horman , Shuah Khan , Donald Hunter , Alexander Aring , Stefan Schmidt , Miquel Raynal , Steffen Klassert , Herbert Xu , linux-rdma@vger.kernel.org, linux-can@vger.kernel.org, osmocom-net-gprs@lists.osmocom.org, bpf@vger.kernel.org, linux-ppp@vger.kernel.org, wireguard@lists.zx2c4.com, linux-wireless@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org, bridge@lists.linux.dev, linux-wpan@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v8 03/11] net: Use link netns in newlink() of rtnl_link_ops Date: Mon, 13 Jan 2025 22:37:11 +0800 Message-ID: <20250113143719.7948-4-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250113143719.7948-1-shaw.leon@gmail.com> References: <20250113143719.7948-1-shaw.leon@gmail.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 These netdevice drivers already uses netns parameter in newlink() callback. Convert them to use rtnl_newlink_link_net() or rtnl_newlink_peer_net() for clarity and deprecate params->net. Signed-off-by: Xiao Liang --- drivers/infiniband/ulp/ipoib/ipoib_netlink.c | 4 ++-- drivers/net/amt.c | 6 +++--- drivers/net/bareudp.c | 4 ++-- drivers/net/can/vxcan.c | 2 +- drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c | 4 ++-- drivers/net/geneve.c | 4 ++-- drivers/net/gtp.c | 4 ++-- drivers/net/ipvlan/ipvlan_main.c | 4 ++-- drivers/net/macsec.c | 4 ++-- drivers/net/macvlan.c | 4 ++-- drivers/net/macvtap.c | 4 ++-- drivers/net/netkit.c | 2 +- drivers/net/pfcp.c | 4 ++-- drivers/net/ppp/ppp_generic.c | 4 ++-- drivers/net/veth.c | 2 +- drivers/net/vxlan/vxlan_core.c | 4 ++-- drivers/net/wireguard/device.c | 4 ++-- drivers/net/wireless/virtual/virt_wifi.c | 4 ++-- drivers/net/wwan/wwan_core.c | 2 +- net/8021q/vlan_netlink.c | 4 ++-- net/hsr/hsr_netlink.c | 8 ++++---- 21 files changed, 41 insertions(+), 41 deletions(-) diff --git a/drivers/infiniband/ulp/ipoib/ipoib_netlink.c b/drivers/infiniband/ulp/ipoib/ipoib_netlink.c index 16cb8ced9f35..53db7c8191e3 100644 --- a/drivers/infiniband/ulp/ipoib/ipoib_netlink.c +++ b/drivers/infiniband/ulp/ipoib/ipoib_netlink.c @@ -101,8 +101,8 @@ static int ipoib_new_child_link(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + struct net *link_net = rtnl_newlink_link_net(params); struct nlattr **data = params->data; - struct net *src_net = params->net; struct nlattr **tb = params->tb; struct net_device *pdev; struct ipoib_dev_priv *ppriv; @@ -112,7 +112,7 @@ static int ipoib_new_child_link(struct net_device *dev, if (!tb[IFLA_LINK]) return -EINVAL; - pdev = __dev_get_by_index(src_net, nla_get_u32(tb[IFLA_LINK])); + pdev = __dev_get_by_index(link_net, nla_get_u32(tb[IFLA_LINK])); if (!pdev || pdev->type != ARPHRD_INFINIBAND) return -ENODEV; diff --git a/drivers/net/amt.c b/drivers/net/amt.c index 96b7ec9a2c13..53899b70fae1 100644 --- a/drivers/net/amt.c +++ b/drivers/net/amt.c @@ -3165,13 +3165,13 @@ static int amt_newlink(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + struct net *link_net = rtnl_newlink_link_net(params); struct amt_dev *amt = netdev_priv(dev); struct nlattr **data = params->data; struct nlattr **tb = params->tb; - struct net *net = params->net; int err = -EINVAL; - amt->net = net; + amt->net = link_net; amt->mode = nla_get_u32(data[IFLA_AMT_MODE]); if (data[IFLA_AMT_MAX_TUNNELS] && @@ -3186,7 +3186,7 @@ static int amt_newlink(struct net_device *dev, amt->hash_buckets = AMT_HSIZE; amt->nr_tunnels = 0; get_random_bytes(&amt->hash_seed, sizeof(amt->hash_seed)); - amt->stream_dev = dev_get_by_index(net, + amt->stream_dev = dev_get_by_index(link_net, nla_get_u32(data[IFLA_AMT_LINK])); if (!amt->stream_dev) { NL_SET_ERR_MSG_ATTR(extack, tb[IFLA_AMT_LINK], diff --git a/drivers/net/bareudp.c b/drivers/net/bareudp.c index fc21dcfb4848..d1473c5f8eef 100644 --- a/drivers/net/bareudp.c +++ b/drivers/net/bareudp.c @@ -702,9 +702,9 @@ static int bareudp_newlink(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + struct net *link_net = rtnl_newlink_link_net(params); struct nlattr **data = params->data; struct nlattr **tb = params->tb; - struct net *net = params->net; struct bareudp_conf conf; int err; @@ -712,7 +712,7 @@ static int bareudp_newlink(struct net_device *dev, if (err) return err; - err = bareudp_configure(net, dev, &conf, extack); + err = bareudp_configure(link_net, dev, &conf, extack); if (err) return err; diff --git a/drivers/net/can/vxcan.c b/drivers/net/can/vxcan.c index 6f8ebb1cfd7b..99a78a757167 100644 --- a/drivers/net/can/vxcan.c +++ b/drivers/net/can/vxcan.c @@ -176,8 +176,8 @@ static int vxcan_newlink(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + struct net *peer_net = rtnl_newlink_peer_net(params); struct nlattr **data = params->data; - struct net *peer_net = params->net; struct nlattr **tb = params->tb; struct vxcan_priv *priv; struct net_device *peer; diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c index 8151e91395e2..ab7e5b6649b2 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c @@ -122,8 +122,8 @@ static int rmnet_newlink(struct net_device *dev, struct netlink_ext_ack *extack) { u32 data_format = RMNET_FLAGS_INGRESS_DEAGGREGATION; + struct net *link_net = rtnl_newlink_link_net(params); struct nlattr **data = params->data; - struct net *src_net = params->net; struct nlattr **tb = params->tb; struct net_device *real_dev; int mode = RMNET_EPMODE_VND; @@ -137,7 +137,7 @@ static int rmnet_newlink(struct net_device *dev, return -EINVAL; } - real_dev = __dev_get_by_index(src_net, nla_get_u32(tb[IFLA_LINK])); + real_dev = __dev_get_by_index(link_net, nla_get_u32(tb[IFLA_LINK])); if (!real_dev) { NL_SET_ERR_MSG_MOD(extack, "link does not exist"); return -ENODEV; diff --git a/drivers/net/geneve.c b/drivers/net/geneve.c index d373a851930c..c7700deefb00 100644 --- a/drivers/net/geneve.c +++ b/drivers/net/geneve.c @@ -1618,9 +1618,9 @@ static int geneve_newlink(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + struct net *link_net = rtnl_newlink_link_net(params); struct nlattr **data = params->data; struct nlattr **tb = params->tb; - struct net *net = params->net; struct geneve_config cfg = { .df = GENEVE_DF_UNSET, .use_udp6_rx_checksums = false, @@ -1634,7 +1634,7 @@ static int geneve_newlink(struct net_device *dev, if (err) return err; - err = geneve_configure(net, dev, extack, &cfg); + err = geneve_configure(link_net, dev, extack, &cfg); if (err) return err; diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c index 80ad618ba423..646d0fdd42f4 100644 --- a/drivers/net/gtp.c +++ b/drivers/net/gtp.c @@ -1464,8 +1464,8 @@ static int gtp_newlink(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + struct net *link_net = rtnl_newlink_link_net(params); struct nlattr **data = params->data; - struct net *src_net = params->net; unsigned int role = GTP_ROLE_GGSN; struct gtp_dev *gtp; struct gtp_net *gn; @@ -1496,7 +1496,7 @@ static int gtp_newlink(struct net_device *dev, gtp->restart_count = nla_get_u8_default(data[IFLA_GTP_RESTART_COUNT], 0); - gtp->net = src_net; + gtp->net = link_net; err = gtp_hashtable_new(gtp, hashsize); if (err < 0) diff --git a/drivers/net/ipvlan/ipvlan_main.c b/drivers/net/ipvlan/ipvlan_main.c index 19ce19ca7e32..b56144ca2fde 100644 --- a/drivers/net/ipvlan/ipvlan_main.c +++ b/drivers/net/ipvlan/ipvlan_main.c @@ -535,9 +535,9 @@ static int ipvlan_nl_fillinfo(struct sk_buff *skb, int ipvlan_link_new(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + struct net *link_net = rtnl_newlink_link_net(params); struct ipvl_dev *ipvlan = netdev_priv(dev); struct nlattr **data = params->data; - struct net *src_net = params->net; struct nlattr **tb = params->tb; struct ipvl_port *port; struct net_device *phy_dev; @@ -547,7 +547,7 @@ int ipvlan_link_new(struct net_device *dev, struct rtnl_newlink_params *params, if (!tb[IFLA_LINK]) return -EINVAL; - phy_dev = __dev_get_by_index(src_net, nla_get_u32(tb[IFLA_LINK])); + phy_dev = __dev_get_by_index(link_net, nla_get_u32(tb[IFLA_LINK])); if (!phy_dev) return -ENODEV; diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c index 1869b0513f57..4de5d63fd577 100644 --- a/drivers/net/macsec.c +++ b/drivers/net/macsec.c @@ -4145,10 +4145,10 @@ static int macsec_newlink(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + struct net *link_net = rtnl_newlink_link_net(params); struct macsec_dev *macsec = macsec_priv(dev); struct nlattr **data = params->data; struct nlattr **tb = params->tb; - struct net *net = params->net; rx_handler_func_t *rx_handler; u8 icv_len = MACSEC_DEFAULT_ICV_LEN; struct net_device *real_dev; @@ -4157,7 +4157,7 @@ static int macsec_newlink(struct net_device *dev, if (!tb[IFLA_LINK]) return -EINVAL; - real_dev = __dev_get_by_index(net, nla_get_u32(tb[IFLA_LINK])); + real_dev = __dev_get_by_index(link_net, nla_get_u32(tb[IFLA_LINK])); if (!real_dev) return -ENODEV; if (real_dev->type != ARPHRD_ETHER) diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c index 0c496aa1f706..689759bbd159 100644 --- a/drivers/net/macvlan.c +++ b/drivers/net/macvlan.c @@ -1569,8 +1569,8 @@ static int macvlan_newlink(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { - return macvlan_common_newlink(params->net, dev, params->tb, - params->data, extack); + return macvlan_common_newlink(rtnl_newlink_link_net(params), dev, + params->tb, params->data, extack); } void macvlan_dellink(struct net_device *dev, struct list_head *head) diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c index 6dbfeeac5c99..ee1bfd4298c2 100644 --- a/drivers/net/macvtap.c +++ b/drivers/net/macvtap.c @@ -105,8 +105,8 @@ static int macvtap_newlink(struct net_device *dev, /* Don't put anything that may fail after macvlan_common_newlink * because we can't undo what it does. */ - err = macvlan_common_newlink(params->net, dev, params->tb, params->data, - extack); + err = macvlan_common_newlink(rtnl_newlink_link_net(params), dev, + params->tb, params->data, extack); if (err) { netdev_rx_handler_unregister(dev); return err; diff --git a/drivers/net/netkit.c b/drivers/net/netkit.c index 1e9eadc77da2..d278d7697cee 100644 --- a/drivers/net/netkit.c +++ b/drivers/net/netkit.c @@ -331,8 +331,8 @@ static int netkit_new_link(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + struct net *peer_net = rtnl_newlink_peer_net(params); struct nlattr **data = params->data; - struct net *peer_net = params->net; struct nlattr **tb = params->tb; struct nlattr *peer_tb[IFLA_MAX + 1], **tbp = tb, *attr; enum netkit_action policy_prim = NETKIT_PASS; diff --git a/drivers/net/pfcp.c b/drivers/net/pfcp.c index d9e4b5185c51..33eaded152ce 100644 --- a/drivers/net/pfcp.c +++ b/drivers/net/pfcp.c @@ -188,12 +188,12 @@ static int pfcp_newlink(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + struct net *link_net = rtnl_newlink_link_net(params); struct pfcp_dev *pfcp = netdev_priv(dev); - struct net *net = params->net; struct pfcp_net *pn; int err; - pfcp->net = net; + pfcp->net = link_net; err = pfcp_add_sock(pfcp); if (err) { diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c index b3340f8a6149..6220866258fc 100644 --- a/drivers/net/ppp/ppp_generic.c +++ b/drivers/net/ppp/ppp_generic.c @@ -1307,8 +1307,8 @@ static int ppp_nl_newlink(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + struct net *link_net = rtnl_newlink_link_net(params); struct nlattr **data = params->data; - struct net *src_net = params->net; struct nlattr **tb = params->tb; struct ppp_config conf = { .unit = -1, @@ -1346,7 +1346,7 @@ static int ppp_nl_newlink(struct net_device *dev, if (!tb[IFLA_IFNAME] || !nla_len(tb[IFLA_IFNAME]) || !*(char *)nla_data(tb[IFLA_IFNAME])) conf.ifname_is_set = false; - err = ppp_dev_configure(src_net, dev, &conf); + err = ppp_dev_configure(link_net, dev, &conf); out_unlock: mutex_unlock(&ppp_mutex); diff --git a/drivers/net/veth.c b/drivers/net/veth.c index 7dfda89f072f..ba3ae2d8092f 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -1769,8 +1769,8 @@ static int veth_newlink(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + struct net *peer_net = rtnl_newlink_peer_net(params); struct nlattr **data = params->data; - struct net *peer_net = params->net; struct nlattr **tb = params->tb; int err; struct net_device *peer; diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c index 86c620b4c26f..cd0964823864 100644 --- a/drivers/net/vxlan/vxlan_core.c +++ b/drivers/net/vxlan/vxlan_core.c @@ -4397,8 +4397,8 @@ static int vxlan_newlink(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + struct net *link_net = rtnl_newlink_link_net(params); struct nlattr **data = params->data; - struct net *src_net = params->net; struct nlattr **tb = params->tb; struct vxlan_config conf; int err; @@ -4407,7 +4407,7 @@ static int vxlan_newlink(struct net_device *dev, if (err) return err; - return __vxlan_dev_create(src_net, dev, &conf, extack); + return __vxlan_dev_create(link_net, dev, &conf, extack); } static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[], diff --git a/drivers/net/wireguard/device.c b/drivers/net/wireguard/device.c index 404cf05bd72b..c496d35b266d 100644 --- a/drivers/net/wireguard/device.c +++ b/drivers/net/wireguard/device.c @@ -311,11 +311,11 @@ static int wg_newlink(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + struct net *link_net = rtnl_newlink_link_net(params); struct wg_device *wg = netdev_priv(dev); - struct net *src_net = params->net; int ret = -ENOMEM; - rcu_assign_pointer(wg->creating_net, src_net); + rcu_assign_pointer(wg->creating_net, link_net); init_rwsem(&wg->static_identity.lock); mutex_init(&wg->socket_update_lock); mutex_init(&wg->device_update_lock); diff --git a/drivers/net/wireless/virtual/virt_wifi.c b/drivers/net/wireless/virtual/virt_wifi.c index 26905b2b3ba3..f9d11a023313 100644 --- a/drivers/net/wireless/virtual/virt_wifi.c +++ b/drivers/net/wireless/virtual/virt_wifi.c @@ -524,7 +524,7 @@ static int virt_wifi_newlink(struct net_device *dev, struct netlink_ext_ack *extack) { struct virt_wifi_netdev_priv *priv = netdev_priv(dev); - struct net *src_net = params->net; + struct net *link_net = rtnl_newlink_link_net(params); struct nlattr **tb = params->tb; int err; @@ -534,7 +534,7 @@ static int virt_wifi_newlink(struct net_device *dev, netif_carrier_off(dev); priv->upperdev = dev; - priv->lowerdev = __dev_get_by_index(src_net, + priv->lowerdev = __dev_get_by_index(link_net, nla_get_u32(tb[IFLA_LINK])); if (!priv->lowerdev) diff --git a/drivers/net/wwan/wwan_core.c b/drivers/net/wwan/wwan_core.c index 53a6c437ff79..34e34bc3ae94 100644 --- a/drivers/net/wwan/wwan_core.c +++ b/drivers/net/wwan/wwan_core.c @@ -1068,7 +1068,7 @@ static void wwan_create_default_link(struct wwan_device *wwandev, struct nlmsghdr *nlh; struct sk_buff *msg; struct rtnl_newlink_params params = { - .net = &init_net, + .src_net = &init_net, .tb = tb, .data = data, }; diff --git a/net/8021q/vlan_netlink.c b/net/8021q/vlan_netlink.c index 91df0f96e32a..a000b1ef0520 100644 --- a/net/8021q/vlan_netlink.c +++ b/net/8021q/vlan_netlink.c @@ -139,9 +139,9 @@ static int vlan_newlink(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + struct net *link_net = rtnl_newlink_link_net(params); struct vlan_dev_priv *vlan = vlan_dev_priv(dev); struct nlattr **data = params->data; - struct net *src_net = params->net; struct nlattr **tb = params->tb; struct net_device *real_dev; unsigned int max_mtu; @@ -158,7 +158,7 @@ static int vlan_newlink(struct net_device *dev, return -EINVAL; } - real_dev = __dev_get_by_index(src_net, nla_get_u32(tb[IFLA_LINK])); + real_dev = __dev_get_by_index(link_net, nla_get_u32(tb[IFLA_LINK])); if (!real_dev) { NL_SET_ERR_MSG_MOD(extack, "link does not exist"); return -ENODEV; diff --git a/net/hsr/hsr_netlink.c b/net/hsr/hsr_netlink.c index 39add538ba99..b120470246cc 100644 --- a/net/hsr/hsr_netlink.c +++ b/net/hsr/hsr_netlink.c @@ -33,8 +33,8 @@ static int hsr_newlink(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + struct net *link_net = rtnl_newlink_link_net(params); struct nlattr **data = params->data; - struct net *src_net = params->net; enum hsr_version proto_version; unsigned char multicast_spec; u8 proto = HSR_PROTOCOL_HSR; @@ -48,7 +48,7 @@ static int hsr_newlink(struct net_device *dev, NL_SET_ERR_MSG_MOD(extack, "Slave1 device not specified"); return -EINVAL; } - link[0] = __dev_get_by_index(src_net, + link[0] = __dev_get_by_index(link_net, nla_get_u32(data[IFLA_HSR_SLAVE1])); if (!link[0]) { NL_SET_ERR_MSG_MOD(extack, "Slave1 does not exist"); @@ -58,7 +58,7 @@ static int hsr_newlink(struct net_device *dev, NL_SET_ERR_MSG_MOD(extack, "Slave2 device not specified"); return -EINVAL; } - link[1] = __dev_get_by_index(src_net, + link[1] = __dev_get_by_index(link_net, nla_get_u32(data[IFLA_HSR_SLAVE2])); if (!link[1]) { NL_SET_ERR_MSG_MOD(extack, "Slave2 does not exist"); @@ -71,7 +71,7 @@ static int hsr_newlink(struct net_device *dev, } if (data[IFLA_HSR_INTERLINK]) - interlink = __dev_get_by_index(src_net, + interlink = __dev_get_by_index(link_net, nla_get_u32(data[IFLA_HSR_INTERLINK])); if (interlink && interlink == link[0]) { From patchwork Mon Jan 13 14:37:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Liang X-Patchwork-Id: 13937453 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9BFB028EC79; Mon, 13 Jan 2025 14:38:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736779096; cv=none; b=sJMSTcoJHW0q3D0ljsi2bOKCLITUPsCatlBVYWdr+JSYkGSWmRP6t9uo4jhBu9078IuzP6jXDP9O10yL9qGfFKEp4LTQA3rS3Zmhuphph/PKTGYjLedzIu5VxGi4iSEqAUqWZlwxiPIh0EQ6ldLuP0VUGK2BbuznMcEAfjZeBdk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736779096; c=relaxed/simple; bh=UswJPFD7QmjNf9lnKyVnvoe2wLuFgTdsosj3eJpjk+c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NFBJya9+/2ST+QHD9RH0iRlnfIcggsaShzGR5VegLYDh8L6wisf0yPnizVF+IaIpd6elHipJRs3mxou7DD35fkMkkcdFAvMt0UfwoHtAq+nbZ8VulhSWTiRGLU1OOpKgR9qf+6ad84OBxolmuUfGhLod9/ApS1X2vnvq0Zq+NJQ= 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=P7nvOU1B; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="P7nvOU1B" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-21680814d42so63198495ad.2; Mon, 13 Jan 2025 06:38:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736779093; x=1737383893; 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=MlOA56xQJRVfhoUOrNRPIk7EOBdTk/e52r4/wRWgOdc=; b=P7nvOU1BAVVJX1pcnp7iwBxwFvhx72OP6LhQPvJ5zpjEJOzBN4sBwGopb4YoOsRKPM 7zvnb4MT0iG0DwRujS2lfYJ12u+U2Jz3dyaiZgFDZ5V3fjvZrYXTqoG+PBprAl0sRiBK nI+b1n6CHABpH2XpjwvOFlVWGSX1nOpUIjtcMYQ9fYgKGemCFWCFy5ga/pO6IjQY+Dxi +5Hw74YrnR6o3DXIwr585ErIIQZkWL7QLlIpNcdTd3M+XVKlCz9RkgssIEi/qZoR9G36 qorMca4lHqQbXoPa6G7BTa24hvX2fHGjcSeLPIvjWmT/7YhFeudZfnV2uJSlSjwb7dRH knVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736779093; x=1737383893; 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=MlOA56xQJRVfhoUOrNRPIk7EOBdTk/e52r4/wRWgOdc=; b=sTWVuh8zUJSfieh0OOuSBiba3eHAMY8QVg6F/ezkIsWOjhKZWzMNSz1n0K/I0qNDu/ 0oFnKA844Y2yXNSjzmFgZv9KeZoufsXSvkFbX9JdcC56eg1sOoLELxZD+P19zVEl35ss Q9dVQ+obdVfRLEr+Hnclp25+dXm0MsmvQWfHDlSxFayDfBb2q1baUB6jxg2hZC2XJGOS iS8yj9XasqNalcPJcUlHrYUFXHdt8e6FgQqAzTM1ssh65OoZ9nXgyLC9WWbNuFxk+GnQ aFbx6BU9mHNkChSwjh8yx8bsejqD7VlIPmlNvy2elu3IOWZGjv4E+onZkvYK4AgP6S+t WBEw== X-Forwarded-Encrypted: i=1; AJvYcCV79Q6YCyuLd9HOOgEC4uefg8nyclqynMuVCNKnXevsktnj207pLWQ715uE42cIJ7j/sgmTwotYEKJlm/BwtTin@vger.kernel.org, AJvYcCVUWQrGsThYqvCVK0TltVomGS0kny5hfm1IBI1kQl5bEGBct5cfWIb5FpAwNr7XJZbF/7LuPSQFVMbOVQ==@vger.kernel.org, AJvYcCVcdct8WQehNT+H+ddfuxHIvlEsQrfDXYvrqK188phpYpFRI6tCLXxCkHdmgBkfKuQflNnWv/7G9KuQ@vger.kernel.org, AJvYcCVey9sqsa62ob3mDqgOCyScDa5sKY0//W+fqi0V1lBPdYZD3IWTxLQVXuDBCAVl2SlNzwY=@vger.kernel.org, AJvYcCVyqPL5pOOLY257Js1kYL9xftAtsgHuRKUScxxvHDeWeBSXOkJhNC/gB1ognbs2fpQXYvi7VYdRBkVR3A==@vger.kernel.org, AJvYcCWIJ/OEdftjY2GfRXnR3mOOUhrxeZHG2xYwAc5swEDXBKj6hKoGI9/kC0UT5o/H4D9KGgRFqi3w6RavZyffajg=@vger.kernel.org, AJvYcCWtqh2IYFchfdmGkhjC+TCUMYFFQgUQxYhMk1lkvWruuSjVboc0TizRDdieEwpo+Y3ua3dl3Vcsa1stWgtI@vger.kernel.org, AJvYcCXBzgP1UMDag37CgheJImBdJevSuDBHm3ApCBbE+6Yr0yHT96ejrqLvccyxP9h0MCrtL87Y3HqLidaM@vger.kernel.org X-Gm-Message-State: AOJu0YxmwsqSG/Rhsf7iluZIJSflOeA3C2hHMix8NNj1r430FbfdIl+k 6YKNbBX0PQZCKrWy3549cb6NrzB0zOswpX8SeOznimWqTndbNZBfmg5YO4WGod4= X-Gm-Gg: ASbGncvUatyTxjgZ8GT8qMOxngVhPx8GKu6Nx58oJo8CbFAtNWAoxQFCh+6tJdXgHJ2 tHPRPjJfH5hirAYF4b7ciZCxbu83+2s7ZQycGBehL10wzPcqrq3QcHazRCYdSsplbA4J/CPfEqF C8HewfZqkLNprfIXYxGk6D5pR4SBQhjccHAjnjuDQapkKdW5rfGTxsbN9f9yz+jTgWW4BLbmdq0 NkZGlTpnzCEWDvjFyrabaFl8dXjvU5Zao6iWR7mIkQ7T9s= X-Google-Smtp-Source: AGHT+IETQgOg7AunUSIVLfQXCmw6Miexgpzxtq5jBXEGmuKIo/a/YyzF3Hf0c0R30+3xPOc3lWG52w== X-Received: by 2002:a17:902:bb8f:b0:21a:8d4c:a9b5 with SMTP id d9443c01a7336-21a8d4cab74mr209427215ad.12.1736779093022; Mon, 13 Jan 2025 06:38:13 -0800 (PST) Received: from ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f155e00sm54328715ad.103.2025.01.13.06.38.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 06:38:12 -0800 (PST) From: Xiao Liang To: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Kuniyuki Iwashima , Jakub Kicinski Cc: "David S. Miller" , David Ahern , Eric Dumazet , Paolo Abeni , Andrew Lunn , Simon Horman , Shuah Khan , Donald Hunter , Alexander Aring , Stefan Schmidt , Miquel Raynal , Steffen Klassert , Herbert Xu , linux-rdma@vger.kernel.org, linux-can@vger.kernel.org, osmocom-net-gprs@lists.osmocom.org, bpf@vger.kernel.org, linux-ppp@vger.kernel.org, wireguard@lists.zx2c4.com, linux-wireless@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org, bridge@lists.linux.dev, linux-wpan@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v8 04/11] ieee802154: 6lowpan: Validate link netns in newlink() of rtnl_link_ops Date: Mon, 13 Jan 2025 22:37:12 +0800 Message-ID: <20250113143719.7948-5-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250113143719.7948-1-shaw.leon@gmail.com> References: <20250113143719.7948-1-shaw.leon@gmail.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Device denoted by IFLA_LINK is in link_net (IFLA_LINK_NETNSID) or source netns by design, but 6lowpan uses dev_net. Note dev->netns_local is set to true and currently link_net is implemented via a netns change. These together effectively reject IFLA_LINK_NETNSID. This patch adds a validation to ensure link_net is either NULL or identical to dev_net. Thus it would be fine to continue using dev_net when rtnetlink core begins to create devices directly in target netns. Signed-off-by: Xiao Liang --- net/ieee802154/6lowpan/core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/ieee802154/6lowpan/core.c b/net/ieee802154/6lowpan/core.c index 704bf9e3f097..ee318d46817d 100644 --- a/net/ieee802154/6lowpan/core.c +++ b/net/ieee802154/6lowpan/core.c @@ -143,6 +143,8 @@ static int lowpan_newlink(struct net_device *ldev, if (!tb[IFLA_LINK]) return -EINVAL; + if (params->link_net && !net_eq(params->link_net, dev_net(ldev))) + return -EINVAL; /* find and hold wpan device */ wdev = dev_get_by_index(dev_net(ldev), nla_get_u32(tb[IFLA_LINK])); if (!wdev) From patchwork Mon Jan 13 14:37:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Liang X-Patchwork-Id: 13937454 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C24C3246355; Mon, 13 Jan 2025 14:38:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736779104; cv=none; b=OGAJUkd6YCuoVYtsvE+wNoDs+p0CPYAT7Hxek9520tqirhy6/dZpqxXg+Eugjj6WmmiUq2zxXz1Yjv1aRna7yS+H2PMaOIw1qe30rMcqvLp/3Nq6Jno8YGmgbwwBHJSbiP/S/AMln+EyO9iFIARJ9y07KKHS6A87g8KFMtBCbPg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736779104; c=relaxed/simple; bh=4+uj3n3qzLmPEBfggnLAVLnO/V0f9mUleOD9sy+kwQs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BpaBH6K1KHBBhrr6mYhcGI6pc6e9wsN1dhOqQWyBmts0m3p6pdpqXn7ZwlacAqKDcOCv3b8OKeGptQQxo6qD7WoR79s6UbQZY324h2pMzdZ8c4tX/Juzs0UAi6V3c5MybSbHf2XzpDGM26mVX40q3BV+knqi/SIATV+RXJGhaM4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bfnzCE6R; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bfnzCE6R" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-215770613dbso52931945ad.2; Mon, 13 Jan 2025 06:38:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736779102; x=1737383902; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=v2hr3iCsVwpwP1Nzlez7XTECQN7gMZZquvojvDybmoY=; b=bfnzCE6RhkR3mH6HdaywSfC0r2ONa7vLfi4KQ1j0U7zFOFANx1MxyxXEY8+b2v365A N0Jflc1WZJ5hmV7pxrVA+h0Wc3B4SvJg+eRTLCydrRuH166XGrbqi/pIdCLtOu6S6KBZ ukFrNEKme98YWNM0ZwwDxD5uYt7GANZN9cP+XYsbH/yq+pumW00j97fQuU21W6ApcDVx pDviWZ7nTyPyJqiDLf3D4T66TsI+ilZ18QXzZEQwwM4RFcEDf4zQ4LIukp81s7bJBvrv hjoLBcrpiKKgYSjHFa9+VEwcSCj49kOIFpYtjAQDuoA7PXYZRJJ4AKNqB7kGngmJN5Yh ZrsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736779102; x=1737383902; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=v2hr3iCsVwpwP1Nzlez7XTECQN7gMZZquvojvDybmoY=; b=ZGb7oeutrBpcI3FsMnm/H0p9pilZfifLWSJzgwr/OuNQzcyGNJMdCLMAxB710a1pnC 9L356jOPMPxkLZwADFG1psCXKb3IbqCJq9HHjdqxn/Qe1KyGgEifFcF5AXel8wUXG4SU OhymppWKWLDTdS90vUPkSxLk+5zAPqgbs/48mW+/1l93C7vc8eFAA9bNp5GjKXXCDmgO kxJi+9+1L4wEpaqGo20b3+3vf+3sL+M2Fi3EKIRBKrpb8bOpr/ojFWKfGblv5Gis217P 6fBy0poCaUmQgPFcwGLzmS0AC83LRn8SL2NCInhWJQiL4J541Ac/h3tIifY9oybqZgD2 cJ/g== X-Forwarded-Encrypted: i=1; AJvYcCUUkcKgY0Jt9rEXZvt//Aw/Ch8Fw+B7Vy8gTHkhUZ3OzRGkCi4oAMEarH49gJ8YKrdAKauCUmsCioViHySJgElm@vger.kernel.org, AJvYcCUZfygCc3aQo5/TJ3hzGaR7PLbe443xngGTMBz19+Rg8o9zANOHwl6450BZxbKSAx3OIKc=@vger.kernel.org, AJvYcCVAheS3YNo1fhOK1dYOX8rjrPuEvjV7RRkctcgEMFR+t1wAie96d1iZJJey0A0pWxjsP4LPKMX7nvBcHg==@vger.kernel.org, AJvYcCVQ04dilNbo0YfI/FoBBiDoqowcx80Wanqj5MomQP7o6ZS560NmVqvp0d7SBIFFOZGUUolPQwFjHZqz@vger.kernel.org, AJvYcCVikUMBBw8TEmlKxsfNJz7spR89TBbG/y8SFRvv9hwhJAp5utqE12Q/NjVWLmYXzbDnZ+SM/t6MT6G8besHKQU=@vger.kernel.org, AJvYcCWYqpM1we9bZr7ImhMd3jGNr/i6HmKDqc19gtsY8mOhUT6WzMqAEInsyZqvQgi/kd8t4BrB6R8NEkRR@vger.kernel.org, AJvYcCWn40lY4Mp0J1FkGEQTuczwuTQ03xTw5dw3Q94tvYeGjkcUa9lc22XVY8gSJoobh9FG/R5OYbIdgUBDnQ==@vger.kernel.org, AJvYcCXwKgKUFtbKx9gIwMYW8VUdzVEN0Qx/uHLQKD7G2lSZN0VV7ke4WU0i2jhqb6WhR3h8s2nJIa/V5fsa2mJZ@vger.kernel.org X-Gm-Message-State: AOJu0YxBvfjf6k+w4tDwlDXknTMQGdIT9ZknNLLIcxUzb2ICeWgdvMxm FU+57/D5559/niDPMOQvKyYEcoT9VJyLJejg6kUlEm5XAM12PrIIUy+hLNF5VUQ= X-Gm-Gg: ASbGnctQvqa46xG5wbMDI2KXyG2NPSF3+8As7mSu9u3XhI6X4atEBA6NHV2owX1JusW h+Fe5t2rV2H37qTG1Ult7+/2boJanPYv7zPsMtwg4WWRa24gWw6JJua/3se39Qf1yOCkmCU1xqy sVASfHPm1DkNKez12Q1VCCjKK6kwS3JFHFvyjFVynoIyIARb/LsQ3RAsUKdnYav3swBxCnqJS3R lLNKb1Ek/BACPXsJ+MXP0u4VEGmpE7B30g9INyfiVt9i54= X-Google-Smtp-Source: AGHT+IGv14RrhPbpKFC9/J2BufZTu7MOaWM0c1rsX2Y4WR5iS1cGRY2j7eRCHAjKSVADaNJCQQybTw== X-Received: by 2002:a17:902:f685:b0:215:b473:1dc9 with SMTP id d9443c01a7336-21a83fdf10fmr312977815ad.46.1736779101666; Mon, 13 Jan 2025 06:38:21 -0800 (PST) Received: from ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f155e00sm54328715ad.103.2025.01.13.06.38.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 06:38:21 -0800 (PST) From: Xiao Liang To: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Kuniyuki Iwashima , Jakub Kicinski Cc: "David S. Miller" , David Ahern , Eric Dumazet , Paolo Abeni , Andrew Lunn , Simon Horman , Shuah Khan , Donald Hunter , Alexander Aring , Stefan Schmidt , Miquel Raynal , Steffen Klassert , Herbert Xu , linux-rdma@vger.kernel.org, linux-can@vger.kernel.org, osmocom-net-gprs@lists.osmocom.org, bpf@vger.kernel.org, linux-ppp@vger.kernel.org, wireguard@lists.zx2c4.com, linux-wireless@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org, bridge@lists.linux.dev, linux-wpan@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v8 05/11] net: ip_tunnel: Use link netns in newlink() of rtnl_link_ops Date: Mon, 13 Jan 2025 22:37:13 +0800 Message-ID: <20250113143719.7948-6-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250113143719.7948-1-shaw.leon@gmail.com> References: <20250113143719.7948-1-shaw.leon@gmail.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When link_net is set, use it as link netns instead of dev_net(). This prepares for rtnetlink core to create device in target netns directly, in which case the two namespaces may be different. Convert common ip_tunnel_newlink() to accept an extra link netns argument. Don't overwrite ip_tunnel.net in ip_tunnel_init(). Signed-off-by: Xiao Liang --- include/net/ip_tunnels.h | 5 +++-- net/ipv4/ip_gre.c | 8 +++++--- net/ipv4/ip_tunnel.c | 10 ++++++---- net/ipv4/ip_vti.c | 3 ++- net/ipv4/ipip.c | 3 ++- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h index 1aa31bdb2b31..ae1f2dda4533 100644 --- a/include/net/ip_tunnels.h +++ b/include/net/ip_tunnels.h @@ -406,8 +406,9 @@ int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb, bool log_ecn_error); int ip_tunnel_changelink(struct net_device *dev, struct nlattr *tb[], struct ip_tunnel_parm_kern *p, __u32 fwmark); -int ip_tunnel_newlink(struct net_device *dev, struct nlattr *tb[], - struct ip_tunnel_parm_kern *p, __u32 fwmark); +int ip_tunnel_newlink(struct net *net, struct net_device *dev, + struct nlattr *tb[], struct ip_tunnel_parm_kern *p, + __u32 fwmark); void ip_tunnel_setup(struct net_device *dev, unsigned int net_id); bool ip_tunnel_netlink_encap_parms(struct nlattr *data[], diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c index 4e8c310769ad..51113e981229 100644 --- a/net/ipv4/ip_gre.c +++ b/net/ipv4/ip_gre.c @@ -1409,7 +1409,8 @@ static int ipgre_newlink(struct net_device *dev, err = ipgre_netlink_parms(dev, data, tb, &p, &fwmark); if (err < 0) return err; - return ip_tunnel_newlink(dev, tb, &p, fwmark); + return ip_tunnel_newlink(params->link_net ? : dev_net(dev), dev, tb, &p, + fwmark); } static int erspan_newlink(struct net_device *dev, @@ -1429,7 +1430,8 @@ static int erspan_newlink(struct net_device *dev, err = erspan_netlink_parms(dev, data, tb, &p, &fwmark); if (err) return err; - return ip_tunnel_newlink(dev, tb, &p, fwmark); + return ip_tunnel_newlink(params->link_net ? : dev_net(dev), dev, tb, &p, + fwmark); } static int ipgre_changelink(struct net_device *dev, struct nlattr *tb[], @@ -1703,7 +1705,7 @@ struct net_device *gretap_fb_dev_create(struct net *net, const char *name, struct ip_tunnel *t; int err; struct rtnl_newlink_params params = { - .net = net, + .src_net = net, .tb = tb, }; diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c index 09b73acf037a..618a50d5c0c2 100644 --- a/net/ipv4/ip_tunnel.c +++ b/net/ipv4/ip_tunnel.c @@ -1213,11 +1213,11 @@ void ip_tunnel_delete_nets(struct list_head *net_list, unsigned int id, } EXPORT_SYMBOL_GPL(ip_tunnel_delete_nets); -int ip_tunnel_newlink(struct net_device *dev, struct nlattr *tb[], - struct ip_tunnel_parm_kern *p, __u32 fwmark) +int ip_tunnel_newlink(struct net *net, struct net_device *dev, + struct nlattr *tb[], struct ip_tunnel_parm_kern *p, + __u32 fwmark) { struct ip_tunnel *nt; - struct net *net = dev_net(dev); struct ip_tunnel_net *itn; int mtu; int err; @@ -1326,7 +1326,9 @@ int ip_tunnel_init(struct net_device *dev) } tunnel->dev = dev; - tunnel->net = dev_net(dev); + if (!tunnel->net) + tunnel->net = dev_net(dev); + strscpy(tunnel->parms.name, dev->name); iph->version = 4; iph->ihl = 5; diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c index b901bee03e6d..159b4473290e 100644 --- a/net/ipv4/ip_vti.c +++ b/net/ipv4/ip_vti.c @@ -585,7 +585,8 @@ static int vti_newlink(struct net_device *dev, __u32 fwmark = 0; vti_netlink_parms(data, &parms, &fwmark); - return ip_tunnel_newlink(dev, tb, &parms, fwmark); + return ip_tunnel_newlink(params->link_net ? : dev_net(dev), dev, tb, + &parms, fwmark); } static int vti_changelink(struct net_device *dev, struct nlattr *tb[], diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c index a8b844bcfc64..bab0bf90c908 100644 --- a/net/ipv4/ipip.c +++ b/net/ipv4/ipip.c @@ -455,7 +455,8 @@ static int ipip_newlink(struct net_device *dev, } ipip_netlink_parms(data, &p, &t->collect_md, &fwmark); - return ip_tunnel_newlink(dev, tb, &p, fwmark); + return ip_tunnel_newlink(params->link_net ? : dev_net(dev), dev, tb, &p, + fwmark); } static int ipip_changelink(struct net_device *dev, struct nlattr *tb[], From patchwork Mon Jan 13 14:37:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Liang X-Patchwork-Id: 13937455 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.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 8DB501FBBE7; Mon, 13 Jan 2025 14:38:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736779113; cv=none; b=Rc6aiS2f9BbG6zeWhWjQY8qJVcwuOkInTaU6lHfJ+8u2gOODr7IP9gzwjCOyfv2FB5MhaWRD2ke6F5RIJZ4qIgcU0KFdjo+ZEwuGE9iDATCZ3faMSh8HCh4Sem8ZuMaVWoE02T8cxTsjY35US/Hy4KjmFcW69sw2mnWKGd7GRZw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736779113; c=relaxed/simple; bh=qOvo+dmmY9xTW22wFfsBEPAG2fg1C/WbopyDpEjHwQk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BjxcYfXN50uy4MikRaDtOvW6c9PuB7jjWnfYAcsrAY3sgJrW9uoMrOKbARh398dm1g09hTsGZke2o8Nj3Ga200p8Ll3/j97Q6J+fDjCuU+lwYw4NZD6fMDAdHBJZT5LWvMmZCpOhGnu3M/5MqZ08SR2aP9x1FkFTmrxiCKv7stk= 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=lxJjbIaz; arc=none smtp.client-ip=209.85.214.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="lxJjbIaz" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-21644aca3a0so95912875ad.3; Mon, 13 Jan 2025 06:38:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736779110; x=1737383910; 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=oQWEflIxWDAik4fl9hhH1GQo7B+/kKhdJ5eqx3FBJEo=; b=lxJjbIazpY+Euu2X9WBo4kT2Gq3whr/QnYh/QmXrORbRzOJVGFKVpGakcUSZwqUglh 7FpGKnD6SUgzK+vlOMJ7402AKxx22ITrskQPOl3/Zcko5Z+FgCOHom0OdjiBrYuFUx3q nLjI1ug/2xpLdOYK22tuxkg1t2RQolhsLtA3tupgRCvbAZN1MYk6fYrkyk8vSVRIfxAn UR9cGR5lnAv3E8r3xCJUqcS8QqwW0a+Dqt+9YBQz3MKh0aRC+Bd4Trmfcz68CGQkbgDt MD+Isusm3tKROXmWU5QXgcq3j2H+yyKKeKI+ptGn2MAsHfpp+y0nCEXOvzqSc718tHX6 VcPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736779110; x=1737383910; 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=oQWEflIxWDAik4fl9hhH1GQo7B+/kKhdJ5eqx3FBJEo=; b=bGFTAV1CA1XXkIIJrv2Q8cLFgrZnPC62a9VL/JjwtKg8UvVXvZt6+HOaKfFrZp8/WL sEh1LWJOo5cWYZ8uXUPJFoPz/fp09+fD6q/6hOCSBeS2uPkmi0iKfK95I5BRj20GsCDF lspPnDAsLbVkztS+OJcFQX4MN7b+kB4nmFEGOjfR2IFFAcZdQF36xtBz2jqezXROAD+r YeNwXuQDZi+n+B0un6ZogLXi5xrbeCEwUCzUUXoanzU/jIb1gYv7zTh9iOb+nSztchdg nL5m4J1qPXQzPcDFsx8qHvNpHFl1zhPjEtULHj37xsD6EW7ikpceR0No4rA49C5RQht3 71iw== X-Forwarded-Encrypted: i=1; AJvYcCUUI9DaqrWmq5I49t/OXT4pkpqVhB2hXpeq2wWhQI8CtUDsvgyAANMbqRQQ+pxQR5ik8C7pxWYQK6bOiQ==@vger.kernel.org, AJvYcCUpqNHuKMo1CzWL2bI9olTUZKHL5ugtnnmXz0QLnIjlSTHgg8LiWxmu8jd/FOxfj5DAHvhCeKpA3BzpLhtp2PsI@vger.kernel.org, AJvYcCV2CsT64O5ae1MgNvePE1mfbVGXK9b+WPn0LGdTAOdsaNzfdBaAsea1uUSkIDT6RtNDl9493al8AuSo@vger.kernel.org, AJvYcCV3i2RhrOy6c/e8jdz3E/a6tnQQJpalKNWYiokNL0kNHqq72sCjx3nfLf+2J1nFz6y/5KZ7CbB8uPyz@vger.kernel.org, AJvYcCVmOMjXhngDyD+UHP0UyMDqj0gHQ+H3wcXbtZ+YBqIp5AD4+d0eRLcHV+xSB7Xz9JYbAI1gOF3xWm6HEVpw3oE=@vger.kernel.org, AJvYcCVmafoBu9NkTyrl7IekQLEdRQiqdAVWxWMsvAh1iQbAnNJO7xqD8yvvdgzGcbNn6Pm/gprGAlcPVpPk+se+@vger.kernel.org, AJvYcCWtp5eN+PIVV4w0vlaQqrNc7YTz5pTm0OtfT8GOnOQb/7y1YkW6AaQbseSFFlgYDIlCCBc=@vger.kernel.org, AJvYcCX9OpC4iGLkQn3YbpObmgo4d35BsGondm53/xHEGdTpbfA447uY04NVw0/AuYXmEQyaZUFczjjXpSpPxg==@vger.kernel.org X-Gm-Message-State: AOJu0YyLOPkeSKFSUsdgTAjJDPHCzLgZjrtL+sfF/iM9nRYszzpo44MX SUrq97epAzeZxvDGyehBZP82iNjFDqMXDLknHAnLxmZwV7UBWSmMDL1C/zRbpbY= X-Gm-Gg: ASbGncvn4g4AhmXH75yZIlK6SXaw7DC90AGtvuYpl0tXom9b590z5TsY6CicgWeiher nt3ORubtQMNkmO+9pxbgRMIsN2uqKgSCl1nqw+IR2R4AQZOrLSA1AHZgW9umnGp9UUyJZUNT/z5 zLuqO3YjpzRlfx16wmmJ2WSQ04Jy7kYqi4OzYhPuVmSEbhF2AQheYAY5o77jUr8+PXrM7+g22UB hljLpI+l0uWuQQ0uRS6iAUJLwVNsX/vSB1TizNB6Ke2viU= X-Google-Smtp-Source: AGHT+IH2EwVnyCLc0IdhYURoHcqSq8a7l1rdTlos+W9PilaFrNaXj6haYBmin4OcYsiFKO0gg5hkKA== X-Received: by 2002:a17:902:dac6:b0:216:4a8a:2665 with SMTP id d9443c01a7336-21a84012a17mr321236845ad.50.1736779110291; Mon, 13 Jan 2025 06:38:30 -0800 (PST) Received: from ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f155e00sm54328715ad.103.2025.01.13.06.38.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 06:38:29 -0800 (PST) From: Xiao Liang To: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Kuniyuki Iwashima , Jakub Kicinski Cc: "David S. Miller" , David Ahern , Eric Dumazet , Paolo Abeni , Andrew Lunn , Simon Horman , Shuah Khan , Donald Hunter , Alexander Aring , Stefan Schmidt , Miquel Raynal , Steffen Klassert , Herbert Xu , linux-rdma@vger.kernel.org, linux-can@vger.kernel.org, osmocom-net-gprs@lists.osmocom.org, bpf@vger.kernel.org, linux-ppp@vger.kernel.org, wireguard@lists.zx2c4.com, linux-wireless@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org, bridge@lists.linux.dev, linux-wpan@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v8 06/11] net: ipv6: Use link netns in newlink() of rtnl_link_ops Date: Mon, 13 Jan 2025 22:37:14 +0800 Message-ID: <20250113143719.7948-7-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250113143719.7948-1-shaw.leon@gmail.com> References: <20250113143719.7948-1-shaw.leon@gmail.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When link_net is set, use it as link netns instead of dev_net(). This prepares for rtnetlink core to create device in target netns directly, in which case the two namespaces may be different. 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 | 20 ++++++++++---------- net/ipv6/ip6_tunnel.c | 13 ++++++++----- net/ipv6/ip6_vti.c | 10 ++++++---- net/ipv6/sit.c | 11 +++++++---- 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c index 863852abe8ea..108600dc716f 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) @@ -2009,11 +2011,10 @@ static int ip6gre_newlink(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + struct net *net = params->link_net ? : dev_net(dev); struct ip6_tnl *nt = netdev_priv(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; int err; @@ -2028,7 +2029,7 @@ static int ip6gre_newlink(struct net_device *dev, 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); @@ -2248,11 +2249,10 @@ static int ip6erspan_newlink(struct net_device *dev, struct rtnl_newlink_params *params, struct netlink_ext_ack *extack) { + struct net *net = params->link_net ? : dev_net(dev); struct ip6_tnl *nt = netdev_priv(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; int err; @@ -2268,7 +2268,7 @@ static int ip6erspan_newlink(struct net_device *dev, 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 54b843d20870..2438dc627e02 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) @@ -2008,13 +2008,16 @@ static int ip6_tnl_newlink(struct net_device *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 993f85aeb882..4aa1e7821951 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; @@ -1002,13 +1002,15 @@ static int vti6_newlink(struct net_device *dev, struct netlink_ext_ack *extack) { 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 e2bd52cabdee..e870271ed04a 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); @@ -1556,15 +1557,17 @@ static int ipip6_newlink(struct net_device *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 Mon Jan 13 14:37:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Liang X-Patchwork-Id: 13937456 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 018542297E4; Mon, 13 Jan 2025 14:38:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736779121; cv=none; b=hcWNhBJ50+b793ORx1yvkQ8P3lUHohk6XKkt31kq+fXFkwXFA5pGOd5rpUt0//P3SkYS2uCnzH9GcWpURp4w+xfvPYaCP3SAWS9Edf09pdHh+IGPA3lwqW+DgwvirVWoPYZy3T6ImW76mlBjpDMvB7qcFJ/VbfztRARCZn3BLjA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736779121; c=relaxed/simple; bh=pUkeHC9Duzkf0b0cEfL+7VFfzV63XchEu8lpcFtp5IM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VWHRq0QpzV7O04Ual9WFIS/PoNAveX6eEVNKpZc+ri4inhzE/NykvC5rSvWl64bM3ffwihFnncgxphM4j/Xahla/+32oRBP/z4RXkCuUlsOGZ2UsL3kS9OMRGjFO82ohpluSqzClRXzF84DtZKuwtHMkySKrjRI/ex06wNOLeoY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VaSxtuw4; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VaSxtuw4" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-2163b0c09afso78936185ad.0; Mon, 13 Jan 2025 06:38:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736779119; x=1737383919; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=n79rk6b+8xqMmWjuAyko0er+FR6QjAQIxOU32J9enis=; b=VaSxtuw4+z5YRbznyJGw57orxt8BaN3nxucZFYOcb+Y3/QVE0tI8u/ZJQGfq8p+Sr2 PS0okpJa55NqGwhL0nlZRUFM3OGX3R/u706zsyz2pyMEE9gI+6TB6bRFmybILuwmbLfv O4O5jtdANwtUPEyu1Mc/X4x0h8eOCK8uALgITZ6VPz38p//1XmOziXZktyCNiQhLsX7n a2jEopYN71A/0VotmmAaqjJ20NMlKIGAYhbJhIKMiNdiJgsGTcN/yX/8f4MaclrpudCz IFMkBNCtzCUc0B6Cct+mIrfMZ+/JXzCmr0kDNHKYi1GSP5gGOA/CMB2STSXumj4W4Fl5 QPpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736779119; x=1737383919; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=n79rk6b+8xqMmWjuAyko0er+FR6QjAQIxOU32J9enis=; b=GAtxwVagYJhdu5NQJptnnl8JWYwtUB3JuayEKl/5K3QHZLMz8g2UngkIaQUAjwjwBV XK22HPE0k9RHaXBaIFqs5xt3JTRde7l1Cl9xJ3LhkLfD0AFIXxmZ3E87iZlJknRWQu2F lJaMMMeApkpxDKwE3WHlM/6Xb+ooyoyRzgs2yIHi5xAhe4vbqm0tj1v2Kik+i/0VAuHf LOy2UOgE7vAutn/fp55fmy7A7GwJiFgfcDEjwxxYWsDGhaC7sW/oBUPSd0SUC89pcHsI B1QFDYCjB4ibalYex5w/nATeKCSKyuzUk8+RfErt18+GitqgiOD1ZNyQtCv6JNPPy9Ym ld+w== X-Forwarded-Encrypted: i=1; AJvYcCUCbUiyI3cH9cq4Cixx6+sqBlbMSIbycN+fdQrTzyM0ooKI3gIclMrn6H07XbZ52yvJO84QLMS1s6So@vger.kernel.org, AJvYcCV4pmqQiRPJCnhqXviQsPnuJZ+GvbgqCUJF7x9r6GRq0t5P2LOP8udeB0+c7vxxg+FKZqMG+Fz9S64K7i/V@vger.kernel.org, AJvYcCVS5jvkhKBCwnAls71IPTfGysYXt/x/rN4MFBjPqqyo/UAyt+0D3dHqLzfwQLJkr/rj/bc=@vger.kernel.org, AJvYcCVVOxQ4BcD4ntjNICscuQTeVlp+IzLCtUosyGfSCo2czcQQRbbh9VFaLjWEseIP0KxD1NMGrOI5hZXoHA==@vger.kernel.org, AJvYcCVjcXD1+RteH69G6E2RW2D9NZGRSpZpzf6Y/Ui9OY5AJH6EP7v0S8olQ06fx6dyBKf/ORTLtHF3SDqQXUYPEFM=@vger.kernel.org, AJvYcCWO/vteSDdRT/Cosz2r63xXrey1auG3PyL0486xWn5fjOfml1p86umoVOcx5UEfp75fAc7f3pPF3Usx2g==@vger.kernel.org, AJvYcCXWCeC6y7B0vNC1et/d7HHuiNam1aJvImFRAbDYb50IXWfqo5H49tDJbfky0VLhPTdu/yoUkrdI2Vq2@vger.kernel.org, AJvYcCXgURTHVA4jcLrra0TqDsmFD/XidEFxjkGh+XE6X2ZlimrE5J3Jrlah/LOdukzkIz/zlxjp+xqR7/zVI7TT3hy4@vger.kernel.org X-Gm-Message-State: AOJu0YxsaPijT23PtLu0DtlB2NIXrDYLmVGqUWKbrcY1jIdGGg1tUpMV lnmedXOkBgOF9bC5ddUMNuxeiTKETmQkgitJpqPdVArUrI+a6kZikN22ZifdmcE= X-Gm-Gg: ASbGnctRMkCw3yARvgvAdAGN21gClc6EnQo2pkY44L9WyOoJ6NapuAW7seen1ydpgkF eKI5cy5qEz1VdddKAceE3eVytxshK8SmUBmOsVaEy+WzPr3rzUwQ800jrsm/bdn83HsDYlmKlWV Vr9fua2wVG2Pe54r1vLHcWhZoEAAUaN54wCoE9CAfZocKoDcTumarYaqIdklqrhuAZz32Gb5T8m a5VAQ8ahIc13yxuTXYy8X0DSWxKjJqhKev953uaQ24qfLg= X-Google-Smtp-Source: AGHT+IGazeu03SiYco1yjo+DeQUEtizAzSGgMZznFsd/ItXTJBGhLqoPfMkABloEPy5ZTJeLHULJqw== X-Received: by 2002:a17:902:cecd:b0:215:6995:1ef3 with SMTP id d9443c01a7336-21a83f3469cmr286693405ad.3.1736779118671; Mon, 13 Jan 2025 06:38:38 -0800 (PST) Received: from ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f155e00sm54328715ad.103.2025.01.13.06.38.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 06:38:38 -0800 (PST) From: Xiao Liang To: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Kuniyuki Iwashima , Jakub Kicinski Cc: "David S. Miller" , David Ahern , Eric Dumazet , Paolo Abeni , Andrew Lunn , Simon Horman , Shuah Khan , Donald Hunter , Alexander Aring , Stefan Schmidt , Miquel Raynal , Steffen Klassert , Herbert Xu , linux-rdma@vger.kernel.org, linux-can@vger.kernel.org, osmocom-net-gprs@lists.osmocom.org, bpf@vger.kernel.org, linux-ppp@vger.kernel.org, wireguard@lists.zx2c4.com, linux-wireless@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org, bridge@lists.linux.dev, linux-wpan@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v8 07/11] net: xfrm: Use link netns in newlink() of rtnl_link_ops Date: Mon, 13 Jan 2025 22:37:15 +0800 Message-ID: <20250113143719.7948-8-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250113143719.7948-1-shaw.leon@gmail.com> References: <20250113143719.7948-1-shaw.leon@gmail.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When link_net is set, use it as link netns instead of dev_net(). This prepares for rtnetlink core to create device in target netns directly, in which case the two namespaces may be different. Signed-off-by: Xiao Liang --- net/xfrm/xfrm_interface_core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/net/xfrm/xfrm_interface_core.c b/net/xfrm/xfrm_interface_core.c index b7ac558025d5..b87a5c950833 100644 --- a/net/xfrm/xfrm_interface_core.c +++ b/net/xfrm/xfrm_interface_core.c @@ -242,10 +242,9 @@ static void xfrmi_dev_free(struct net_device *dev) gro_cells_destroy(&xi->gro_cells); } -static int xfrmi_create(struct net_device *dev) +static int xfrmi_create(struct net *net, struct net_device *dev) { struct xfrm_if *xi = netdev_priv(dev); - struct net *net = dev_net(dev); struct xfrmi_net *xfrmn = net_generic(net, xfrmi_net_id); int err; @@ -819,11 +818,12 @@ static int xfrmi_newlink(struct net_device *dev, struct netlink_ext_ack *extack) { struct nlattr **data = params->data; - struct net *net = dev_net(dev); struct xfrm_if_parms p = {}; struct xfrm_if *xi; + struct net *net; int err; + net = params->link_net ? : dev_net(dev); xfrmi_netlink_parms(data, &p); if (p.collect_md) { struct xfrmi_net *xfrmn = net_generic(net, xfrmi_net_id); @@ -852,7 +852,7 @@ static int xfrmi_newlink(struct net_device *dev, xi->net = net; xi->dev = dev; - err = xfrmi_create(dev); + err = xfrmi_create(net, dev); return err; } From patchwork Mon Jan 13 14:37:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Liang X-Patchwork-Id: 13937457 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 5030B22C9FC; Mon, 13 Jan 2025 14:38:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736779129; cv=none; b=cNSBwrY2EWiUJRaVUhDY+G5FAhrTzvDu6w4u7liCuk44O3ZDws2rXxdYVkvi3tbPuh2ntEgOXqmkG7J6y6XsernJI09zDX75ywaz6Bkv0UYX+PvcjV3V2rzdBSak4k0UX3IUjU6EK1fpq2TeejWxLGl5FKsphRHMlEwJRBDAdC8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736779129; c=relaxed/simple; bh=3ZFVoGehuDwl/mWPg6mYnMbYtzRE432EuJk5jze9RMo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YR5xzFB0AnW5DDqFx+hOLHX67ZjAoziTLBXVtSHS2/Sp+vF03uOQihqeUxrQHY+p3tWdTRghkbvYgPp6PTM8Qq5T1EK1alCqcBIWbC8c26ceJJbnGxzyEN/4Ybh3g1YuM2GlaMxwDrEo31R9sllu8MwqCT9+drbSn0cGrJYnnhg= 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=kAze0crh; arc=none smtp.client-ip=209.85.214.182 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="kAze0crh" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-21628b3fe7dso73483805ad.3; Mon, 13 Jan 2025 06:38:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736779127; x=1737383927; 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=O0itpuEZRuaRQ33kirP60JpiMAPNyz5teegcwQ5xuJQ=; b=kAze0crhPHvwQAVQFM8UNrhQ0ibbf1uXbP64MVxUHrah/2OHgSsiMw9kXhYZJmYMP1 UZYDO0lG9DMzbgkZ2e/H/y0n/F0rolVDQFLyOJVKmGjtHeWidoScBr9TEZrVmRr+L7/e rx+7I5m6inLXU84tDT4nvJ8JC68BxNZfJAm+Mnf0H7Ip1v7N/oFjjgQOSiQ1cR4pZRsI C6Ixd/Qeyip3S5Iu2Joidpo/it/nDmEsea6MEuR3OQMrVDehp5TVQyTyVQqVZBpD/5aL vdmbLUr4Y4VQ5mXjwU9Cr5gG26BG1p5Rc1FpLXpYjs5NKkJemmemgT1HYThU/XpC2aL7 k2BQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736779127; x=1737383927; 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=O0itpuEZRuaRQ33kirP60JpiMAPNyz5teegcwQ5xuJQ=; b=C4t2TN+DPVcf/J2kX6ZFprOZ6O5uELqYPlog1gubdgSlsZO+S1JGwl/mdnPbsVt28S vFTR8GVEj2hQVPIGiLzZXNQMf2FX4GG6dlvPBhI3YVspz4ftgQ9VX9WDrRMt+rlNDZNB PSMHfK1oQvZrNch+uISIOkwljDA+UcD5xDAfA7jChvGTu6NyODqmozGCDmHK/PXgP/jA FhESTYtcZ8/PkkeIJkuaGoMBn9F7rgwi9IMVEP6YVUuazTqnLm9FlbdZthbWeO2O8v87 7XiA5/buQ//CnQRwTip9BeSpWFoi+gngRwQRqgK+KQuuLhnnicJg20grf/nMzVg5q73N GnLg== X-Forwarded-Encrypted: i=1; AJvYcCUCiiOLAO/FS02ytrsuch3SXkBqSliI7Lo75Lr44lDP7oLBYzrxNfccEQkV6n1WKjdRQEhBIuJPIy52ZA==@vger.kernel.org, AJvYcCUL60OTZgoiXQ0SYSgKGlj4Nrq5OqzGCHcbsan1ULfkx+/irqu28AUw6g5BVVf6GFn/jENLRlpfgfI4KmIrdt8=@vger.kernel.org, AJvYcCURT8a9zzWxt9a03WxqJKKzen539BwJGgKWW9anSjvaXRvRlk+hYUfABx7SRsu8XfPpkdCKe9RQQYWJwmuY@vger.kernel.org, AJvYcCUZPVnH2946ieuZX5/IVeaoQDvRtGD3HP6aG8K4ojrxmWKTv7shvohEuOmq5BNilWkrwMOlgvFvoXPl@vger.kernel.org, AJvYcCVWXgPL/7opb/T2oz4UdzubVeOHhSI+pquZHOZIgG8j8hQzpJo4RlcrKhf1lL58jnExkJI=@vger.kernel.org, AJvYcCWHsI2laDEuhxsbgEC8/X73TLWsY5EXbKtv3sWOGc6fA+IO7ogy76wffl4QUJqyCq3uYfa4DP81Vvc+z/s1fgwx@vger.kernel.org, AJvYcCWV4rA8ZPYq+nsj9syLVBtitCDEHUnRolnPpWUPmtp9ZTwW14pQ+XjCf3P/a+8jjnNTsF8QYpoIdBKx@vger.kernel.org, AJvYcCXNBFMo+azk8yJgWyV+41/Kl5CC85VG57GRH5LltK9zRkNW0cJONgM7M2dLd6+JfCroGq2N48u0Y8M61Q==@vger.kernel.org X-Gm-Message-State: AOJu0YxojYaXwnRTGZlp6/dtdj1XeSqRO7670wKI3urNFTEwyynuEIt8 udkBzu/JWeIjfuGFAzG54XTiyH9ofTt683c0xki7bo+1CKNfJHIYDCEtOyOvovg= X-Gm-Gg: ASbGncvJyLqavOxyZdtfwZSEn4e47Y5leUIQuA7eSUkg95gzUoe3qWZJY0veXUHA3zy KYOkT+ZKEm3zfNsi24r2QsxYZ1ER6IYtag16ux++kA5d43k4l7u3xTJwN7s5/ZyhRfoPa1+Rx/M FkCGI4Cnv2VJDN1T5aTHdOUiF6NokcAUGIy4GKvE60IDUBLBJEvEVrK/HF+NKtnW7XaW+IUPYbM JwqlJs9cd46LHdS3uWo2Ef1RoL0Spq2w1vnZ24/Eh3MEEk= X-Google-Smtp-Source: AGHT+IF46BIJsHmY25FQQjjhe3rRKluIF8yEXaDZgFjxpJ6wghwfrMVhniqYlndXdS242mt6yFdpoQ== X-Received: by 2002:a17:903:230d:b0:215:cbbf:8926 with SMTP id d9443c01a7336-21a83fb0da4mr356224215ad.35.1736779127243; Mon, 13 Jan 2025 06:38:47 -0800 (PST) Received: from ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f155e00sm54328715ad.103.2025.01.13.06.38.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 06:38:46 -0800 (PST) From: Xiao Liang To: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Kuniyuki Iwashima , Jakub Kicinski Cc: "David S. Miller" , David Ahern , Eric Dumazet , Paolo Abeni , Andrew Lunn , Simon Horman , Shuah Khan , Donald Hunter , Alexander Aring , Stefan Schmidt , Miquel Raynal , Steffen Klassert , Herbert Xu , linux-rdma@vger.kernel.org, linux-can@vger.kernel.org, osmocom-net-gprs@lists.osmocom.org, bpf@vger.kernel.org, linux-ppp@vger.kernel.org, wireguard@lists.zx2c4.com, linux-wireless@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org, bridge@lists.linux.dev, linux-wpan@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v8 08/11] rtnetlink: Remove "net" from newlink params Date: Mon, 13 Jan 2025 22:37:16 +0800 Message-ID: <20250113143719.7948-9-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250113143719.7948-1-shaw.leon@gmail.com> References: <20250113143719.7948-1-shaw.leon@gmail.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 00c086ca0c11..dd51240431b8 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 @@ -80,7 +79,6 @@ static inline int rtnl_msg_family(const struct nlmsghdr *nlh) * @data: IFLA_INFO_DATA attributes */ 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 7ff5e96f6ba7..cce5bcd1f257 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -3767,7 +3767,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, @@ -3794,11 +3793,6 @@ static int rtnl_newlink_create(struct sk_buff *skb, struct ifinfomsg *ifm, dev->ifindex = ifm->ifi_index; - if (link_net) - params.net = link_net; - if (peer_net) - params.net = peer_net; - if (ops->newlink) err = ops->newlink(dev, ¶ms, extack); else From patchwork Mon Jan 13 14:37:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Liang X-Patchwork-Id: 13937458 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E0AE922DFBB; Mon, 13 Jan 2025 14:38:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736779138; cv=none; b=ADzK7oEC8EknPnFYpxqKP5YTAiQrfzA1BPRr6Ue/D968sOZ4Vc/Lb73dcuMTbNSOPYyDBkvgZMWJ2eoBl/OY+lMm+g2o87RsWCja+xrQyyBTDgkUJy+H5UrstjVTk9Gz+yJwaKDOYo0RR/fXomuILTp1FZgPGekzNNOcP5e58bw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736779138; c=relaxed/simple; bh=HRgkD5FKjFgLgWVxBNT3gyl1M0RycbLvrFOZUB35tkQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Td++9PxjjmlCjNRnktdJ9PfYP/ec198sa5tkhTbe8w9BPY5oLGstcX4JhPK+qYlI8EijRt5M9140EzXgObwhg/h1H98fHdVHe5UwIn88vnhK6JLep0huV5iDyxsajXDePUi9wcp0Wz5g2wkN+Z0F3piQCYPYOb0HkuKVDEUCJvM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=TCymOuVN; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TCymOuVN" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-2164b662090so72494875ad.1; Mon, 13 Jan 2025 06:38:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736779136; x=1737383936; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3RwrUezkHV4Bxso8Lan3H8PNeHkallTCdG4JVNGo1S0=; b=TCymOuVNtub+RoSE/q4/jI7nJDy2ZTafd4gGusYP1GD4bB0XE8b5fqgX4mjn3nUp+P vtvKnWDy/FTUsILLdgeCGUcRTGnbuJ79Qw3e2HEXwMi5cXXcPU6v7UPLZ6OuxyU+BnC0 5CEailZ12Ufq3Y4PjnQQ4ccHc5Lh7JzpwX/98C3tYSiDR/NdzGdKlhcmEgPWhChFBPj9 YrfAWUl9nWlspKF08eJaTz1QLwUFnfTDdNmm4L0D/VlkgZJfns7P8x6hhNMnPJolM+/e +ARHlADeagomj5phE8nsBLzr/a/Xg0HJ2+ZR41EWOqAiow9Ja4gCdHe9cNGclldV3pwJ aLEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736779136; x=1737383936; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3RwrUezkHV4Bxso8Lan3H8PNeHkallTCdG4JVNGo1S0=; b=WnviK/ZcJIFKatA1O4q/t0C0s52kmuVHnHCsY8u+AODeXEGIW2tu8FLBiESJ80BumF gW/TNUFgW4HlbuJoyhmq0c4unehs7dBucZiZ6mIHL3iitt9rGkScHwY9yYv4LDIRn7t6 6E5bU0cabahRTR/vKHhLWKhit0tKQ5QXqJGegbaCqeUlAWpJ0IhEWAnKu9iNGw1x6yLo fJUtJTFX9EA9GIkmT2vIVyFjdf1SlQ2cxUL1T3SgiNWusevcxCpKFwZGlg9IdWdHVjuy v5TWeJha7lTlGBGmY5x2f8HD6fUL5/sNBuE7VxFUNjnM0jbQwNXqYMx1wVQZVnfSTNoq nakg== X-Forwarded-Encrypted: i=1; AJvYcCU3kPIFp32L68EAjgtaZ82+hHKbwN8Bc/g0T39e5/loGLgNSa4imobz41uqdH5O2JiTHYaF6F7tJ+Ke@vger.kernel.org, AJvYcCU97xC8iLU9PbPoqk5nZXyXjtjr5Ruv2VkRBfj5LhjhJWhdORCrAuPl5rKZJ+Qt2trpSUjcS57iSSlJ@vger.kernel.org, AJvYcCUXgPW1rjteQ7WOIGWs9R1PVlCXYUXF4p7/3tuihuUHKr5zd84Sj0l0C70c54Inzjp5KW+4NAXBo6PXopZ/PTA=@vger.kernel.org, AJvYcCWXfSjICMyvOKRjSGgmK6sup0SRjrxwAN/l2EJ58rRokct2GPZRg/3zdYz58GUU9Un9pCE3+CvU09DHIw==@vger.kernel.org, AJvYcCWac8ybgMS3OkRLE56avFYqOuW3/O4+VtD2DcScckmVo5pbfk6gjQrO69h9TqFt5EGm/Qo=@vger.kernel.org, AJvYcCWxBKoabvtBkqs/KHwhYwzTrALQlw0x7+m4Zvi5ONOlg1UZEI6YB/rbcIc7ibp3q3xmbO7BnJkP6h8dTA==@vger.kernel.org, AJvYcCX1l2+pgVaXvtEaCcoPKstIQPpMSkbwGAtPSnayailoNW5rNd3+7f84M92jZyVZCCYvqCcCDbEOkhSuzBcE@vger.kernel.org, AJvYcCXj9zMBVBs6IZOrfdyNuavH5zO4qOTtK/cq+3jQYUIpIZ6e0OH+R9EHQ7+wD+MTzMN1q994oZD9zKDOHLYpgdC2@vger.kernel.org X-Gm-Message-State: AOJu0YzhLtCiD4ayWXm+QiQs1uZYiG/4hC4crhh46QdpoyQDgiVWgg/L zCIS41OOAQUhSytwE6U+5aic0BSeHMcJwqKobeyP3D1s8eaP9DNoQFnrSIyst3Q= X-Gm-Gg: ASbGncsmZuvyHUSquy6otKQY8/7Od6oxNvHHnfeA/c4h9KGtqrLeN5ijlV3oZQEf5yu t22GLf7IvwM84dH8KQVKWA5DZy1SaVjUmdQCn7PJrsHiz6DTE+MsycRJwDD15zm19rAz3ssVPNb lcXaGpQKvtNMTkngDyXKHE8KrR8B6EYKNAUoibvzcx0osquVlMDDxO5Vsd8rYQp1YKduUYcYlFh qVOcxHhvAYZ0lIk7hnGQm50TQHcfMi6IKjZaXHCnYCUarU= X-Google-Smtp-Source: AGHT+IHt1nCTDh10fBQS9NHgK/oOky2VtiRHLWbePcQNxSAsFYQfmLDkyg61R0c+C95BGg+IP2F6xw== X-Received: by 2002:a17:903:18a:b0:216:4a06:e87a with SMTP id d9443c01a7336-21a83fc7640mr358427785ad.40.1736779135888; Mon, 13 Jan 2025 06:38:55 -0800 (PST) Received: from ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f155e00sm54328715ad.103.2025.01.13.06.38.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 06:38:55 -0800 (PST) From: Xiao Liang To: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Kuniyuki Iwashima , Jakub Kicinski Cc: "David S. Miller" , David Ahern , Eric Dumazet , Paolo Abeni , Andrew Lunn , Simon Horman , Shuah Khan , Donald Hunter , Alexander Aring , Stefan Schmidt , Miquel Raynal , Steffen Klassert , Herbert Xu , linux-rdma@vger.kernel.org, linux-can@vger.kernel.org, osmocom-net-gprs@lists.osmocom.org, bpf@vger.kernel.org, linux-ppp@vger.kernel.org, wireguard@lists.zx2c4.com, linux-wireless@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org, bridge@lists.linux.dev, linux-wpan@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v8 09/11] rtnetlink: Create link directly in target net namespace Date: Mon, 13 Jan 2025 22:37:17 +0800 Message-ID: <20250113143719.7948-10-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250113143719.7948-1-shaw.leon@gmail.com> References: <20250113143719.7948-1-shaw.leon@gmail.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Make rtnl_newlink_create() create device in target namespace directly. Avoid extra netns change when link netns is provided. Device drivers has been converted to be aware of link netns, that is not assuming device netns is and link netns is the same when ops->newlink() is called. Signed-off-by: Xiao Liang --- net/core/rtnetlink.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index cce5bcd1f257..65f09ab616b5 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -3784,8 +3784,8 @@ static int rtnl_newlink_create(struct sk_buff *skb, struct ifinfomsg *ifm, name_assign_type = NET_NAME_ENUM; } - dev = rtnl_create_link(link_net ? : tgt_net, ifname, - name_assign_type, ops, tb, extack); + dev = rtnl_create_link(tgt_net, ifname, name_assign_type, ops, tb, + extack); if (IS_ERR(dev)) { err = PTR_ERR(dev); goto out; @@ -3805,11 +3805,6 @@ static int rtnl_newlink_create(struct sk_buff *skb, struct ifinfomsg *ifm, err = rtnl_configure_link(dev, ifm, portid, nlh); if (err < 0) goto out_unregister; - if (link_net) { - err = dev_change_net_namespace(dev, tgt_net, ifname); - if (err < 0) - goto out_unregister; - } if (tb[IFLA_MASTER]) { err = do_set_master(dev, nla_get_u32(tb[IFLA_MASTER]), extack); if (err) From patchwork Mon Jan 13 14:37:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Liang X-Patchwork-Id: 13937459 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.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 AA1D122F85B; Mon, 13 Jan 2025 14:39:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736779150; cv=none; b=b78+wc98x13NzAHukQDgpPUcCqfX/qYsBmdNz9oo3OvU3u6UT/wnIph76+1rdE3kLGTiwY1cQDPtrzDpPdTacgW9sWFd6EbEgYMkY4YMjBb4hHAdYFErDg8fpEnq3o5nXIz2FNq6LXcyboJDMO6cS8rEmK0vhOE2apl4sA5vZo8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736779150; c=relaxed/simple; bh=PdyhCxIiCvxYyD0kNCUPOuthJbFGoqxPJVmAtqTiJvU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R9E/x05jq27mX1dPGXdr0+MhDSTzx46lyRzfc+AK7vTHgF290t2w236lK1R10DgrboUdK24saQjona5/rkkB97AClEhy/JPHD73mC1pIU9Nf+0FVOTE8xWJKiuWykICjv/Wt+HhDwgmY/Vt75WuyGuxHwUWPM06tnh92dyS256E= 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=e3Ot6lW+; arc=none smtp.client-ip=209.85.214.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="e3Ot6lW+" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-21634338cfdso59145665ad.2; Mon, 13 Jan 2025 06:39:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736779144; x=1737383944; 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=e3Ot6lW+8joJAi0eKlVl2nVNUGLesEBz2Q0hc/J1rXj80ispWBadpyxATfOYlbyKgc 64dwTybb5bkNi2lMF+kLX5ybhABUg1+AO4xUhZFV/JiZgOIiy+TvzPz49PhcpddWeX4+ XMOOiPm8FWHTfCMcxYk+J/NcptoFdEbDt94Xn41Ep/04yvOzmFk8CUrSORF36wClb6Pf sXwwSv9EIeGtZ/OsCAVo7AMRvD16e0AaYqpwWDGQr8oY9AJfN98fyy31C2Wx4FeJFWWH +T8ROylJ1ys9beZfvCkB8I9lEROsHJZSEV7psafWdW1snJUKvH4O3RdNa6np5pbHwi7A gLIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736779144; x=1737383944; 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=V4cqOI8PVc2KHat+2POyCU3fwnxTSLkh4XU9oqLlyYP7CeDFa2dRajVN9s6na8V0bx GHjLHf/5vwCzqXj17SSBfNkJLoRHTp5fiOXmd6+RXTyDbUs1w01btc5OscvudRggZIpU Hln1+jD/m0fRJ014S6g50qOakn5WWJQUip2yg95Syj5DAztcJAIbNjNSmgYu0ydwnrIu L+CIQNkEO9eW6GA9PGcU1aJfuJ2NF08h3l71D3IniFG17nUUZCAOadgH8xXpC/hpVt4k MesWhWsZC2rLrRe9y994jzG/R1OvNiP+StXiES1Je0TYxgcG1rrv29FIRmR+dkQcn1vj QBww== X-Forwarded-Encrypted: i=1; AJvYcCViUcUc6rMeGMWChzr+hpxO4LvQxkBzmXB7eTjPUkCpErbfNJuuWaX/ZJgzAROR7+A2hAJJ+xo+HQSbBWf3r0A=@vger.kernel.org, AJvYcCWTwNurXeqsXteB8zhgAsAOM54/8RUK6YPizfNt44r/+rUbrp9WeY3wd954XQYv8IiwbojSoYEk0g/G2g==@vger.kernel.org, AJvYcCWtuKvjtmSHHiyyeutdDcdiksUfKsmIZv6garbXW9EfDYxEghkI+1PSR6vPUQw2A8iQEwmVlRUui/iOrngtNYsW@vger.kernel.org, AJvYcCXAj3IwuLZg5JYLq1eV3Z2mQndBoNsCsyTD0LK+D2/upLl5CiU+V9RH/waydv5i6lHX0LY=@vger.kernel.org, AJvYcCXCg60Buj/SFbAemV6oub/tQT7Wsakg9Fzy5s6OvbWk1g3cVHAp7kDJVE0eEcX5WXLvso4KW1jAJOaF@vger.kernel.org, AJvYcCXaVsVXz/GCKF3P2ChX5fLnZjVATTD6YsQYIG0vgfCy/18hp31v0mOvTE2Q4SzLI+fvVB1dHAlbyDp8@vger.kernel.org, AJvYcCXk0vvtQkYH8NR10zOadZn0ShG/51m5uvUtz83DZQbv6tjzi5wDrSm31IQBRKIsbDabTz4yRMUThMSCcg==@vger.kernel.org, AJvYcCXvtRLLsrshGs1p3SnRHhL0x9qTdZhiTVyHfPbnNnZi6oRAfaDR+r9ZwtL0FuktWQ6ByaAWWXtgyP81ip3x@vger.kernel.org X-Gm-Message-State: AOJu0YyN5FIvWUob2CC8Gg6gyoQQjv0aqwl/2ksHjDbc9jyEGgosf0fD PhEyUUGrKmzl6YzOPrG3IOTAoHO6ovqlQw/6jxkwlOk/VeIFiwoDxBt9Pn/8Dl4= X-Gm-Gg: ASbGncu1WIfjx1pz+RaF00QwJVpHoHRer7icV/6t31i6Q169qHGyM4Lw+hbzaEiqsNH RqYAewCqmxLFRQ4XtNG9Bkl+bw6OUPVwHQ9X643kn1ZmmqXqprzvyTmAZgSgCF6wso4jddI4NLu +Iq+wyPLekztmU4L8u4kIn/sMVLVFdgZPgmPtOPjmmcefPCMyKiHN89ukjbnsZPzsjYUMr2V9th dCuXRC7XStW+9Twjr9i2DyxzhJWy+f2RN6aYgCtLbsThxs= X-Google-Smtp-Source: AGHT+IEL9Q/TeE8X83a4D73J5c4BnqISbL2nsMzkDnt4Xq2JHmNtTfGl7cYLX08uLNv4xfpjIcH6KQ== X-Received: by 2002:a17:902:f685:b0:216:5002:7341 with SMTP id d9443c01a7336-21a83fde2bcmr322676685ad.44.1736779144551; Mon, 13 Jan 2025 06:39:04 -0800 (PST) Received: from ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f155e00sm54328715ad.103.2025.01.13.06.38.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 06:39:04 -0800 (PST) From: Xiao Liang To: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Kuniyuki Iwashima , Jakub Kicinski Cc: "David S. Miller" , David Ahern , Eric Dumazet , Paolo Abeni , Andrew Lunn , Simon Horman , Shuah Khan , Donald Hunter , Alexander Aring , Stefan Schmidt , Miquel Raynal , Steffen Klassert , Herbert Xu , linux-rdma@vger.kernel.org, linux-can@vger.kernel.org, osmocom-net-gprs@lists.osmocom.org, bpf@vger.kernel.org, linux-ppp@vger.kernel.org, wireguard@lists.zx2c4.com, linux-wireless@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org, bridge@lists.linux.dev, linux-wpan@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v8 10/11] selftests: net: Add python context manager for netns entering Date: Mon, 13 Jan 2025 22:37:18 +0800 Message-ID: <20250113143719.7948-11-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250113143719.7948-1-shaw.leon@gmail.com> References: <20250113143719.7948-1-shaw.leon@gmail.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Mon Jan 13 14:37:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Liang X-Patchwork-Id: 13937509 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C44622DFB1; Mon, 13 Jan 2025 14:39:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736779156; cv=none; b=sBNJGu8C+OFoEtVvyJ7hsQ0etH12VvX+5ykHpHNvcjxqQK4ceJhkBHYtwR4LbLHqWUBpQKQ9nxtwWMvMWMZwBm49UwFj8Vwwe6y1EfH9WKtxjrCW6eWZXOAcz53D2Ctv9NdiNvCgJDjQ6V0/5iCM4Vh1y/0tW3cC+n4mpPwwe54= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736779156; c=relaxed/simple; bh=0G+WJHelzbbjtgv/Zbgactw+yzF4V+X8MJldF12Uf7A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BOLWsJS5luNWaQ+/zuM/zTvfqBrZuPwxp5NB/Lrr4Ayks0T6L4MlWQh8bm1D7YCaxHP/MEem8HuToVskqs/rUEsWUg7gYFFaepO9cKzGReRsFE2Yz7nGG9HZxnm41LZAmdmmecRefsJqxIDcEcp966o6LFN93uCL3HJCUbu/VP4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mdhV9hqD; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mdhV9hqD" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-21644aca3a0so95936325ad.3; Mon, 13 Jan 2025 06:39:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736779153; x=1737383953; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=R0TVXDX/Oq9IB0mhgmi61TXIFVtPNPu1PWKjPd5bzuM=; b=mdhV9hqDkGVkVHMv0B5JnL14GjXjp3LSB6fFUzLsJUGCasBB8mLgesFEOKv28jfDQd Dzv9tytKyUQmeNmr0+wcbcXOgQNMFfYqZUI5zSj9chuix98ydumZFVItYR7h3Smk8JY6 qy9WYM4CWnIklxZUKa2JhV5aXokm3Al7xOQSm7mWYdVmiVV+1TJqPaoICAo+SL/hCtu0 CxxPKId7EHV4QmxfhygiXApf3kS57jsAH/+Sd0XgB2iliWc223bWim26um12wtE/LfMD w+VpxgfWK0BuRYPqQC8P0mCE8sevD/v8WCBPHiUMxbyMtMZNi945f2zAWPCU0dClTA+z 5OkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736779153; x=1737383953; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=R0TVXDX/Oq9IB0mhgmi61TXIFVtPNPu1PWKjPd5bzuM=; b=WiuFY5ERx4fZpmkVLLqT3P0vHJpVZTD4HhV2mAT1D0QBAnwulvqAvaNRcn64O5blyc hDj4RpT+Plp04Pu7UlmXy4MjtAGn2kNUQ61hmsC/OCSzVaA4s5Ze1zVwqwn5qvfsgWpr Pfr78T+22PAEgiES06BHBq9kn31SQTsW7eVc8hshLjM0qcpJDgoGEu6NpGdTdFMpU5Zz D7MVUMDRqz63KPY1fgKYHlrduGQiLzSYH08AUovaad12NMUc7EQcHF2plZ0ltC3c+d0v 5p7Nz9b1ZICM4g6+cjkFfwU/c+izLfUAGhSLB8/1nqZV7jB5nwJx0ya24+p9abalJ2d0 HuNA== X-Forwarded-Encrypted: i=1; AJvYcCUFLHbYOydfU9es94NceemO6MeaBLSuau8MGS8Q5YQESD11JXXOC6rSc+YvLCR3Sm/AtRsdSlk2ET7xLVFg@vger.kernel.org, AJvYcCUH1F2mkybZW4CxDUuGB3TjgjLWxQydaIAE9tOJaQOi7MkoP/SfNHUdxjdW4qpAQUVoGNoa+FGzyN/GUKDUC/4D@vger.kernel.org, AJvYcCWTd2MAO6ANCPBs8qvzHuKtQr7/4ogS81msGHChhwaaOHylmBnmZEfpzWj/C2B3Wto1KaHxpg6R1mv90w==@vger.kernel.org, AJvYcCWjqDRNJI/jmkdmeioMn0CMfVjTK0VRKBw6M//Z3e7KCOGNSoK7rJiRJvIhJLX+FS4hekz2ZHpKtPMf+Q==@vger.kernel.org, AJvYcCWtBh8hPHYqbJoqQIYIihjXOAyYSagAbJi018tUytgJ7p/OowWk5/IwCB84dXwLc0vdo7Aw1uGolxVcuC44rE4=@vger.kernel.org, AJvYcCX/B+yT7GmPsoczL3aqi1Ex3PWFXFf2fwhq0bQr9Ju83Cme6A1xfCrGJsjdfbl4JhOGr4U67PP41/T+@vger.kernel.org, AJvYcCXGoICj+Ow8nY1RV5ZEW8Ggph/NaOfyzM7/vU//PECyYsVQnZIZ/FLkNup8ASnFgz7cdPCzfdCMSLy/@vger.kernel.org, AJvYcCXHOCpOX4LkVkZd5kinYzLin1oVXQ0qV5luP8ZG8OoSBCU0QLSE5VkZEBxMETIKIrOTGOU=@vger.kernel.org X-Gm-Message-State: AOJu0YxfpaCXHld9uVlEVWr3bQ3IJQ4VPT89um+69Bp60rvdb1FGnt1J A/LqcgXWNaulD7HtHYQnzs/aYAYG83MQONpWAhkwBKdmTun6Ax1ojdA0tyVvWqw= X-Gm-Gg: ASbGncuuf7feJL582A2xBsiBfUhssO5EqfS1JSB43mvXNmmx5ZE2+FugdrD+meMcQy0 33I/DELTcM7BVkf37+aQxv9+BqRj2JU3OJUY6JhCzGjyfDWPvV8irsFxYCT60fQmyU+E8bDA9ra vlNzm+eqjvcN7it1Hxz9q53DPLxrfNgFSWfJvXCLf9PCehp/DfP3Mw5peDu/iWVk0CTkhJDix8V kotEJlHrksrYu7h3Sa+jyQNyZBqRrI7UO0oddpCDHCTBzg= X-Google-Smtp-Source: AGHT+IFt4cEJz+p42bYm31EfJt3Zb0JLb+qW+6vXHsT58zE4AWUF4ed/u79zsBlznytyW2KBQMyVfw== X-Received: by 2002:a17:902:d511:b0:215:6489:cfbf with SMTP id d9443c01a7336-21a83f48cc0mr313835205ad.11.1736779153175; Mon, 13 Jan 2025 06:39:13 -0800 (PST) Received: from ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f155e00sm54328715ad.103.2025.01.13.06.39.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 06:39:12 -0800 (PST) From: Xiao Liang To: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Kuniyuki Iwashima , Jakub Kicinski Cc: "David S. Miller" , David Ahern , Eric Dumazet , Paolo Abeni , Andrew Lunn , Simon Horman , Shuah Khan , Donald Hunter , Alexander Aring , Stefan Schmidt , Miquel Raynal , Steffen Klassert , Herbert Xu , linux-rdma@vger.kernel.org, linux-can@vger.kernel.org, osmocom-net-gprs@lists.osmocom.org, bpf@vger.kernel.org, linux-ppp@vger.kernel.org, wireguard@lists.zx2c4.com, linux-wireless@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org, bridge@lists.linux.dev, linux-wpan@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v8 11/11] selftests: net: Add test cases for link and peer netns Date: Mon, 13 Jan 2025 22:37:19 +0800 Message-ID: <20250113143719.7948-12-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250113143719.7948-1-shaw.leon@gmail.com> References: <20250113143719.7948-1-shaw.leon@gmail.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 - Add test for creating link in another netns when a link of the same name and ifindex exists in current netns. - Add test to verify that link is created in target netns directly - no link new/del events should be generated in link netns or current netns. - Add test cases to verify that link-netns is set as expected for various drivers and combination of namespace-related parameters. Signed-off-by: Xiao Liang --- tools/testing/selftests/net/Makefile | 1 + tools/testing/selftests/net/config | 5 + tools/testing/selftests/net/link_netns.py | 141 ++++++++++++++++++++++ tools/testing/selftests/net/netns-name.sh | 10 ++ 4 files changed, 157 insertions(+) create mode 100755 tools/testing/selftests/net/link_netns.py diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile index 73ee88d6b043..df07a38f884f 100644 --- a/tools/testing/selftests/net/Makefile +++ b/tools/testing/selftests/net/Makefile @@ -35,6 +35,7 @@ TEST_PROGS += cmsg_so_mark.sh TEST_PROGS += cmsg_so_priority.sh TEST_PROGS += cmsg_time.sh cmsg_ipv6.sh TEST_PROGS += netns-name.sh +TEST_PROGS += link_netns.py TEST_PROGS += nl_netdev.py TEST_PROGS += srv6_end_dt46_l3vpn_test.sh TEST_PROGS += srv6_end_dt4_l3vpn_test.sh diff --git a/tools/testing/selftests/net/config b/tools/testing/selftests/net/config index 5b9baf708950..ab55270669ec 100644 --- a/tools/testing/selftests/net/config +++ b/tools/testing/selftests/net/config @@ -107,3 +107,8 @@ CONFIG_XFRM_INTERFACE=m CONFIG_XFRM_USER=m CONFIG_IP_NF_MATCH_RPFILTER=m CONFIG_IP6_NF_MATCH_RPFILTER=m +CONFIG_IPVLAN=m +CONFIG_CAN=m +CONFIG_CAN_DEV=m +CONFIG_CAN_VXCAN=m +CONFIG_NETKIT=y diff --git a/tools/testing/selftests/net/link_netns.py b/tools/testing/selftests/net/link_netns.py new file mode 100755 index 000000000000..aab043c59d69 --- /dev/null +++ b/tools/testing/selftests/net/link_netns.py @@ -0,0 +1,141 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +import time + +from lib.py import ksft_run, ksft_exit, ksft_true +from lib.py import ip +from lib.py import NetNS, NetNSEnter +from lib.py import RtnlFamily + + +LINK_NETNSID = 100 + + +def test_event() -> None: + with NetNS() as ns1, NetNS() as ns2: + with NetNSEnter(str(ns2)): + rtnl = RtnlFamily() + + rtnl.ntf_subscribe("rtnlgrp-link") + + ip(f"netns set {ns2} {LINK_NETNSID}", ns=str(ns1)) + ip(f"link add netns {ns1} link-netnsid {LINK_NETNSID} dummy1 type dummy") + ip(f"link add netns {ns1} dummy2 type dummy", ns=str(ns2)) + + ip("link del dummy1", ns=str(ns1)) + ip("link del dummy2", ns=str(ns1)) + + time.sleep(1) + rtnl.check_ntf() + ksft_true(rtnl.async_msg_queue.empty(), + "Received unexpected link notification") + + +def validate_link_netns(netns, ifname, link_netnsid) -> bool: + link_info = ip(f"-d link show dev {ifname}", ns=netns, json=True) + if not link_info: + return False + return link_info[0].get("link_netnsid") == link_netnsid + + +def test_link_net() -> None: + configs = [ + # type, common args, type args, fallback to dev_net + ("ipvlan", "link dummy1", "", False), + ("macsec", "link dummy1", "", False), + ("macvlan", "link dummy1", "", False), + ("macvtap", "link dummy1", "", False), + ("vlan", "link dummy1", "id 100", False), + ("gre", "", "local 192.0.2.1", True), + ("vti", "", "local 192.0.2.1", True), + ("ipip", "", "local 192.0.2.1", True), + ("ip6gre", "", "local 2001:db8::1", True), + ("ip6tnl", "", "local 2001:db8::1", True), + ("vti6", "", "local 2001:db8::1", True), + ("sit", "", "local 192.0.2.1", True), + ("xfrm", "", "if_id 1", True), + ] + + with NetNS() as ns1, NetNS() as ns2, NetNS() as ns3: + net1, net2, net3 = str(ns1), str(ns2), str(ns3) + + # prepare link netnsid and a dummy link needed by certain drivers + ip(f"netns set {net3} {LINK_NETNSID}", ns=str(net2)) + ip("link add dummy1 type dummy", ns=net3) + + cases = [ + # source, "netns", "link-netns", expected link-netns + (net3, None, None, None, None), + (net3, net2, None, None, LINK_NETNSID), + (net2, None, net3, LINK_NETNSID, LINK_NETNSID), + (net1, net2, net3, LINK_NETNSID, LINK_NETNSID), + ] + + for src_net, netns, link_netns, exp1, exp2 in cases: + tgt_net = netns or src_net + for typ, cargs, targs, fb_dev_net in configs: + cmd = "link add" + if netns: + cmd += f" netns {netns}" + if link_netns: + cmd += f" link-netns {link_netns}" + cmd += f" {cargs} foo type {typ} {targs}" + ip(cmd, ns=src_net) + if fb_dev_net: + ksft_true(validate_link_netns(tgt_net, "foo", exp1), + f"{typ} link_netns validation failed") + else: + ksft_true(validate_link_netns(tgt_net, "foo", exp2), + f"{typ} link_netns validation failed") + ip(f"link del foo", ns=tgt_net) + + +def test_peer_net() -> None: + types = [ + "vxcan", + "netkit", + "veth", + ] + + with NetNS() as ns1, NetNS() as ns2, NetNS() as ns3, NetNS() as ns4: + net1, net2, net3, net4 = str(ns1), str(ns2), str(ns3), str(ns4) + + ip(f"netns set {net3} {LINK_NETNSID}", ns=str(net2)) + + cases = [ + # source, "netns", "link-netns", "peer netns", expected + (net1, None, None, None, None), + (net1, net2, None, None, None), + (net2, None, net3, None, LINK_NETNSID), + (net1, net2, net3, None, None), + (net2, None, None, net3, LINK_NETNSID), + (net1, net2, None, net3, LINK_NETNSID), + (net2, None, net2, net3, LINK_NETNSID), + (net1, net2, net4, net3, LINK_NETNSID), + ] + + for src_net, netns, link_netns, peer_netns, exp in cases: + tgt_net = netns or src_net + for typ in types: + cmd = "link add" + if netns: + cmd += f" netns {netns}" + if link_netns: + cmd += f" link-netns {link_netns}" + cmd += f" foo type {typ}" + if peer_netns: + cmd += f" peer netns {peer_netns}" + ip(cmd, ns=src_net) + ksft_true(validate_link_netns(tgt_net, "foo", exp), + f"{typ} peer_netns validation failed") + ip(f"link del foo", ns=tgt_net) + + +def main() -> None: + ksft_run([test_event, test_link_net, test_peer_net]) + ksft_exit() + + +if __name__ == "__main__": + main() diff --git a/tools/testing/selftests/net/netns-name.sh b/tools/testing/selftests/net/netns-name.sh index 6974474c26f3..0be1905d1f2f 100755 --- a/tools/testing/selftests/net/netns-name.sh +++ b/tools/testing/selftests/net/netns-name.sh @@ -78,6 +78,16 @@ ip -netns $NS link show dev $ALT_NAME 2> /dev/null && fail "Can still find alt-name after move" ip -netns $test_ns link del $DEV || fail +# +# Test no conflict of the same name/ifindex in different netns +# +ip -netns $NS link add name $DEV index 100 type dummy || fail +ip -netns $NS link add netns $test_ns name $DEV index 100 type dummy || + fail "Can create in netns without moving" +ip -netns $test_ns link show dev $DEV >> /dev/null || fail "Device not found" +ip -netns $NS link del $DEV || fail +ip -netns $test_ns link del $DEV || fail + echo -ne "$(basename $0) \t\t\t\t" if [ $RET_CODE -eq 0 ]; then echo "[ OK ]"