From patchwork Wed Oct 23 02:31:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Liang X-Patchwork-Id: 13846319 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-oo1-f42.google.com (mail-oo1-f42.google.com [209.85.161.42]) (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 8BD0C5FB8D for ; Wed, 23 Oct 2024 02:32:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729650736; cv=none; b=Dgdm+vR46lA7/0pnwv1ouPan07ZtXPmYJ0Zw5cZOUGe7KUFCOKEEUZVwO0Nzuqzil/OtRiv9cB9wrwoP1/j0j382gQ3xHLhHW2LVISri9mjOC30+D/FAf9gVXxItwb3Bq7W35tpL9tDAnVNXoS26WsW+0ry6Sa1i6HCOg58wpQk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729650736; c=relaxed/simple; bh=fc2NOfta+FSn1SOHQi2N2meCboovslY0zPfdlwGpmp8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kK+DqVVVGYLAw4ytkbN9YlZcsdZ51CZdFkeWE+mkQt9prsAJ2IEkZp+PC12UIsiHINVnG3adEaM5qxqC/EzCIxjOtVqMaCuAf43xUH+Bdya3FO6cmhp+jfD9SeIWs6ClNlvPPuu16zMaC9TZzp/LnP4YFhc9U1oNtEMraAcyhM4= 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=SH4k0FJj; arc=none smtp.client-ip=209.85.161.42 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="SH4k0FJj" Received: by mail-oo1-f42.google.com with SMTP id 006d021491bc7-5ebc1af8f10so1313431eaf.2 for ; Tue, 22 Oct 2024 19:32:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729650734; x=1730255534; 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=aI6AWkQNI/okCcU8bkSh5OZLcAKrZZzAC/ATARuWBuI=; b=SH4k0FJjyDs1owIrMuiUJsspsLhC2M6W1lFvj/wAh+FZo9uFsM5kmA3M+hsdrgapX2 yOKzMWLusucsjS3SfLLgvySbuT+o3D+foLASSgjpojoUBg5NGAIxYZJ8rdGOVCiw6Joq vQEcEtE6njg5joPVeWwRBpfUU61BenIwEcU5JiQf2jqu3cCaKXii5hQwlC7jt9lPZzmK kqAcjVtNtKCSkKJTpVSaOKLMVvkTmThABsNByAQAEv/sZg0pTvU3uOHxOj6GcFfgKx0V oAERqu7E78rMLnL+5E7AwsOw6dPs9mLwkk7O5DdmSjDRm2ze9CCvtwmtppl/jtGvumAe VjnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729650734; x=1730255534; 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=aI6AWkQNI/okCcU8bkSh5OZLcAKrZZzAC/ATARuWBuI=; b=W1cOBrJlFH3reYoSCsJUWOc0n1zsQA6D7QOLIzbUn3iHaHEGIFae/yndR+trRbUJGU Q4Sm5au87JXIqy22hol8cwJ1GXtL3lPQC/xjX62uAaQ89GW3qaq01G/nhZ0JD5A4s1f4 c1tQatZE9ha/xygQ8GeJe+2oIyWZhHKUzy4xzrfl2jJiGiA7pOGbaSHfctNzkCNMe6Zt Ns/BfKZBL0DePKuq7q7FCRbThN/SonWFDgpbJIMS1MRRRv4m9dA1fTDjrWVsyoNrgsS+ WFTII834q8XONyd1dlH/MwE5Hkzm6Fts2v3p+T40jFUvigC95yMSL1m3MccZQ6ICokrm K3DQ== X-Gm-Message-State: AOJu0Yz4DZZFiVOXpUOp27R4BAx4GxW9Zck58otfF9ZzDmZAlEjToUpj JwOv4uBYDgQL2D1fWMYXRVEIgfhqW27Yt6LNHZKl4O6Fli1BbOPzn7LZpj2AkBk= X-Google-Smtp-Source: AGHT+IH2P29vbbMfuRgBLG5crsf6VPpcy+ecoc2b1iEqq1lRrHU/7klqffQ5YntPOLxhcmlolHgn7A== X-Received: by 2002:a05:6870:b409:b0:288:59d3:2a03 with SMTP id 586e51a60fabf-28ccb9f79cemr1331637fac.39.1729650734194; Tue, 22 Oct 2024 19:32:14 -0700 (PDT) Received: from nova-ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7eaea9386e5sm4972284a12.0.2024.10.22.19.32.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 19:32:12 -0700 (PDT) From: Xiao Liang To: netdev@vger.kernel.org Cc: "David S. Miller" , David Ahern , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Kuniyuki Iwashima , Ido Schimmel Subject: [PATCH net-next 1/5] rtnetlink: Lookup device in target netns when creating link Date: Wed, 23 Oct 2024 10:31:42 +0800 Message-ID: <20241023023146.372653-2-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241023023146.372653-1-shaw.leon@gmail.com> References: <20241023023146.372653-1-shaw.leon@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org When creating link, lookup for existing device in target net namespace instead of current one. For example, two links created by: # ip link add dummy1 type dummy # ip link add netns ns1 dummy1 type dummy should have no conflict since they are in different namespaces. Signed-off-by: Xiao Liang --- net/core/rtnetlink.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 194a81e5f608..ff8d25acfc00 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -3733,20 +3733,24 @@ 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 ? tgt_net : net; + ifm = nlmsg_data(nlh); if (ifm->ifi_index > 0) { link_specified = true; - dev = __dev_get_by_index(net, ifm->ifi_index); + dev = __dev_get_by_index(device_net, ifm->ifi_index); } else if (ifm->ifi_index < 0) { NL_SET_ERR_MSG(extack, "ifindex can't be negative"); return -EINVAL; } else if (tb[IFLA_IFNAME] || tb[IFLA_ALT_IFNAME]) { link_specified = true; - dev = rtnl_dev_get(net, tb); + dev = rtnl_dev_get(device_net, tb); } else { link_specified = false; dev = NULL; From patchwork Wed Oct 23 02:31:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Liang X-Patchwork-Id: 13846320 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ot1-f45.google.com (mail-ot1-f45.google.com [209.85.210.45]) (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 753718289A for ; Wed, 23 Oct 2024 02:32:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729650741; cv=none; b=iTJarkEhLA1mREaoE2llPIYzj1jcOwshzlVja3VGGrHO8q35SpYBmz5AW9bEDoVVOKA3cDyfZ8xU8mLkKyETN5CoW3ttQ1Ei4SZcgYXuYuBUfpX80EOu+Cmw6RksKG/qi2YNZyfzk63v/voejyBiMM6j23bnpn6JPc7sMnk+/Yw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729650741; c=relaxed/simple; bh=z41vDWpbYePdTd0mhv3d1zCU5AqlJoE2kQemUoZg2LY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l77RqZb8H/SmkvvNuyBOadwOVgCINj5DkiYp7C768EDOy00en/XuuVE+KK+pbpCOkE9lIAjU/TjRu6Tt/ilqBGo1i/FC1XPElQwut7Mcz3Sy5vPgnynRzP1asYfSs3rxsifNO5RYpc9gp2oHKwxtjrnNQd6SEv2Z8e27iUqC4KM= 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=AIVAKFCj; arc=none smtp.client-ip=209.85.210.45 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="AIVAKFCj" Received: by mail-ot1-f45.google.com with SMTP id 46e09a7af769-7181b86a749so2000326a34.3 for ; Tue, 22 Oct 2024 19:32:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729650737; x=1730255537; 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=MVqrAYudBHADfRNQe+vlD7YTXBuMXBYKujpwwARcSME=; b=AIVAKFCjAJzEC/XDo/BwuNDn71cXMdqFORpGJxGZJYZSuliBaI2kdh9BfiUyX5CVjA KEH+uH/tgogO66V1hDCEWoKtUYX+sk2ZFlWDJZOUq/qfzeqHFtc0V1GBaAd1Y0KbNFCr GaAPUsNMxSJdE/u09CeFr7cQEPvsvh0fs1ie43zhLw9MZTgKHnbYwW8QmAbRTF1HExCN ocKNE4WLr+Ja2wnUCymOW3Nsm47J7qRJcVDDEli6BQLt9LvVjyLfmM5YQsTf8PVQ7oS8 YxVgZGLnPZOwiAR0O9m1ZrmlWUzPoqjy1dvZNCmUgbG8R/WRHlDIqffTZCQJvQnWNGU6 lKJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729650737; x=1730255537; 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=MVqrAYudBHADfRNQe+vlD7YTXBuMXBYKujpwwARcSME=; b=rYiHvEU4SHseWqVDPzNnZ8J5SmyX22b6Xsnmg8H3s2txXu0ytn1zV08fKNca9v0aVI D0dYl/P5dmK0hTK+vs6cyDbcsjDMUopCgLoek36uyxzHMnEsWPGO7+gO2FQIxto19ZQk 8a/RFySiw6Nb2CnMs9X8I9sf/DlWLKUy5oqOg3H3VTUFsV/qYgGVdivxGeFdP/tJqi0F G8Aazt5V7PZH1qrWqyyge+XNC7D1RvkYe4+T5qGZFa+B2/5GGrTte+IWZsAhU8oD2J9s lpSY8axTPBK1NnStIAvSdX6YRYwY2LxleTiZsUPuhLPIBQi0hRJ4o8sUUQ29Qn7AnzY/ fi8g== X-Gm-Message-State: AOJu0YzADGt+xQmV2mhe7MI5ILE5+gqsP1UhOgmu5S/DC65dh1ksulM0 vF04VlH9Ewgmd6Q1Z/YrXUrRr+rPTHRTeInQQSqXhW2/6MmgJunsM30GJKMwmy8= X-Google-Smtp-Source: AGHT+IEEy53EhLbM611LaZaiVpr7Vhv8np5U9KKyfV4GHSBXQ0tLWzlzRw69ax12p1INASbhgVNQ5w== X-Received: by 2002:a05:6830:6687:b0:717:fb12:2c2 with SMTP id 46e09a7af769-7184b37e49cmr1211115a34.3.1729650737574; Tue, 22 Oct 2024 19:32:17 -0700 (PDT) Received: from nova-ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7eaea9386e5sm4972284a12.0.2024.10.22.19.32.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 19:32:17 -0700 (PDT) From: Xiao Liang To: netdev@vger.kernel.org Cc: "David S. Miller" , David Ahern , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Kuniyuki Iwashima , Ido Schimmel Subject: [PATCH net-next 2/5] rtnetlink: Add netns_atomic flag in rtnl_link_ops Date: Wed, 23 Oct 2024 10:31:43 +0800 Message-ID: <20241023023146.372653-3-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241023023146.372653-1-shaw.leon@gmail.com> References: <20241023023146.372653-1-shaw.leon@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Currently these two steps are needed to create a net device with IFLA_LINK_NETNSID attr: 1. create and setup the netdev in the link netns with rtnl_create_link() 2. move it to the target netns with dev_change_net_namespace() This has some side effects, including extra ifindex allocation, ifname validation and link notifications in link netns. Add a netns_atomic flag, that if set to true, devices will be created in the target netns directly. Signed-off-by: Xiao Liang --- include/net/rtnetlink.h | 3 +++ net/core/rtnetlink.c | 7 ++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h index e0d9a8eae6b6..59594cef2272 100644 --- a/include/net/rtnetlink.h +++ b/include/net/rtnetlink.h @@ -74,6 +74,8 @@ static inline int rtnl_msg_family(const struct nlmsghdr *nlh) * @srcu: Used internally * @kind: Identifier * @netns_refund: Physical device, move to init_net on netns exit + * @netns_atomic: Device can be created in target netns even when + * link-netns is different, avoiding netns change. * @maxtype: Highest device specific netlink attribute number * @policy: Netlink policy for device specific attribute validation * @validate: Optional validation function for netlink/changelink parameters @@ -115,6 +117,7 @@ struct rtnl_link_ops { void (*setup)(struct net_device *dev); bool netns_refund; + bool netns_atomic; unsigned int maxtype; const struct nla_policy *policy; int (*validate)(struct nlattr *tb[], diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index ff8d25acfc00..99250779d8ba 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -3679,8 +3679,9 @@ static int rtnl_newlink_create(struct sk_buff *skb, struct ifinfomsg *ifm, name_assign_type = NET_NAME_ENUM; } - dev = rtnl_create_link(link_net ? : tgt_net, ifname, - name_assign_type, ops, tb, extack); + dev = rtnl_create_link(!link_net || ops->netns_atomic ? + tgt_net : link_net, ifname, name_assign_type, + ops, tb, extack); if (IS_ERR(dev)) { err = PTR_ERR(dev); goto out; @@ -3700,7 +3701,7 @@ static int rtnl_newlink_create(struct sk_buff *skb, struct ifinfomsg *ifm, err = rtnl_configure_link(dev, ifm, portid, nlh); if (err < 0) goto out_unregister; - if (link_net) { + if (link_net && !ops->netns_atomic) { err = dev_change_net_namespace(dev, tgt_net, ifname); if (err < 0) goto out_unregister; From patchwork Wed Oct 23 02:31:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Liang X-Patchwork-Id: 13846321 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 253FF8289A for ; Wed, 23 Oct 2024 02:32:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729650745; cv=none; b=DibB2o1qwf9inws31zpQS0/GhcoMaC/Vbj31dLd/obaXh97CgZP8CsRlGN9RBop11kQbSowJV3Pq1f0eFSocx07N6iralFaXa3mEQLkETnw7nTns3ZnHByYdKJQxlTe6KciFU/0mZs/+t++yRXw+Fw8RKsEoFU/He1cyGiisgKA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729650745; c=relaxed/simple; bh=msjLdmI7eZv6iOp/4R6FDEdaIwsy+STZb5PQIgx6BqQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LX6dE2eHa4gZSjsTikNSxJCF5I+g2zAPgFDeYLvnDSZovEVJqStRITFUNz5othNOZUWvJ1bqeRStuyLXqVKR7vCM11KbmJdTwOc0wefjSwoEQtQW9h1V5oeJvyv8Jo7AgFmVBoAC7+TYQlZicufOIrqUQcGH2RbAe0rOSrcBuIs= 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=CqdvGl1W; arc=none smtp.client-ip=209.85.215.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CqdvGl1W" Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-7d916b6a73aso4011029a12.1 for ; Tue, 22 Oct 2024 19:32:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729650743; x=1730255543; 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=TAI1ERJNMU7DRNqtWoqCKDb9xZyhLsX5eDa0lA+o94s=; b=CqdvGl1Wm06jEeuLd4jJRYPotugEPgHezCUU4UO85lOhi3ePvklnMeTQ3YTg52OUaA SsuN9Wd7NDknshU/q9xp/EOyyydeUButN8WMDmV3PdK6asva59JsBfl8pLAC9BfKdRfh qzbzaurGDzhJdQwPnZMa+lBnT/0GyGKWAL/WHUUX5YcqkZoAq2rH8lDbSpqSlfufr8q/ H82vqbtQ98Hddyq4PLaLDAwTak8IE0HITCpCju01wsMEM9gwFyoYw5uYGYf4PdZALR5w e6w38XsnT67d72vBH7eMnGWrXbObB2klIL5xTp2CnOarLZnFrukUyIOQY+02YNESOutB 2N6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729650743; x=1730255543; 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=TAI1ERJNMU7DRNqtWoqCKDb9xZyhLsX5eDa0lA+o94s=; b=rJcH/OX2Uda4sSRRXOvCBy/1mem2mOUrpmpo8u4I5M7YEQbAREo3n5DRKu12oX1hLG rPyLo5a/vzTd3Tr8gx90te7CsFX24GGlB1MpIFO6KfpzRpzpjKs6rM+zfRP8xLHAnLql oRay0Hq+EH/EzIFwjUJH+XO/yL9yKjG7N0zFwIVRSedyWcb1fkm5nmLIb4kHu/YSWXSe +Gs7O24kP3N5+eWcg+b4hTZCzfubdBo/4+OCA2aSAEjX5FzWvdPjUsUSAxL360cbXdhl h9I+VQvrwT9pi7gf1pNSNQwSd1FEw1bu0gTTAvggMZhkpelEo1QwenD8zBj+SwRcngeH pxAQ== X-Gm-Message-State: AOJu0YwhrGzIDJwcEoE+SkTz0Nh/hWJ2unX/rcu8coLeeWfEPL6Dh+eO SABuwpyjLr8g4io95czaGPZGni6cIU9K4jQ0A2lRhVVGjra/E/Pa9FqcEqHD2yg= X-Google-Smtp-Source: AGHT+IGgDUxT06z/1wez874znvjqRL3hC/Z4QWu68IJiSKAbMKm97o/LowxynpbSRGB128obd7poAg== X-Received: by 2002:a05:6a21:3511:b0:1d8:a4f7:67ae with SMTP id adf61e73a8af0-1d978b243d0mr1243739637.17.1729650743029; Tue, 22 Oct 2024 19:32:23 -0700 (PDT) Received: from nova-ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7eaea9386e5sm4972284a12.0.2024.10.22.19.32.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 19:32:21 -0700 (PDT) From: Xiao Liang To: netdev@vger.kernel.org Cc: "David S. Miller" , David Ahern , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Kuniyuki Iwashima , Ido Schimmel Subject: [PATCH net-next 3/5] net: ip_tunnel: Build flow in underlay net namespace Date: Wed, 23 Oct 2024 10:31:44 +0800 Message-ID: <20241023023146.372653-4-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241023023146.372653-1-shaw.leon@gmail.com> References: <20241023023146.372653-1-shaw.leon@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Build IPv4 flow in underlay net namespace, where encapsulated packets are routed. Signed-off-by: Xiao Liang --- net/ipv4/ip_tunnel.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c index d591c73e2c0e..09ee39e7b617 100644 --- a/net/ipv4/ip_tunnel.c +++ b/net/ipv4/ip_tunnel.c @@ -294,7 +294,7 @@ static int ip_tunnel_bind_dev(struct net_device *dev) ip_tunnel_init_flow(&fl4, iph->protocol, iph->daddr, iph->saddr, tunnel->parms.o_key, - iph->tos & INET_DSCP_MASK, dev_net(dev), + iph->tos & INET_DSCP_MASK, tunnel->net, tunnel->parms.link, tunnel->fwmark, 0, 0); rt = ip_route_output_key(tunnel->net, &fl4); @@ -611,7 +611,7 @@ void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev, } ip_tunnel_init_flow(&fl4, proto, key->u.ipv4.dst, key->u.ipv4.src, tunnel_id_to_key32(key->tun_id), - tos & INET_DSCP_MASK, dev_net(dev), 0, skb->mark, + tos & INET_DSCP_MASK, tunnel->net, 0, skb->mark, skb_get_hash(skb), key->flow_flags); if (!tunnel_hlen) @@ -774,7 +774,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev, ip_tunnel_init_flow(&fl4, protocol, dst, tnl_params->saddr, tunnel->parms.o_key, tos & INET_DSCP_MASK, - dev_net(dev), READ_ONCE(tunnel->parms.link), + tunnel->net, READ_ONCE(tunnel->parms.link), tunnel->fwmark, skb_get_hash(skb), 0); if (ip_tunnel_encap(skb, &tunnel->encap, &protocol, &fl4) < 0) From patchwork Wed Oct 23 02:31:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Liang X-Patchwork-Id: 13846322 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-oi1-f169.google.com (mail-oi1-f169.google.com [209.85.167.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 75E1C3F9CC for ; Wed, 23 Oct 2024 02:32:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729650749; cv=none; b=baA+1Zv1KXg0cwiLr1L28BI0YBS4MOnXJgJcy0Jxip7k0VFaNzaSlydzYg51o3TgFO22/+V5zEjs+eGPNke/yzs/mewwwYiR8z/XBCwigW5aSm9pM4pn7XtYbeK83GUJ+Mu5a7B/exNAHYTS7Sd9nZ+GjsttUCxANKpw+Xx0uII= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729650749; c=relaxed/simple; bh=vUMNMxZeLiPPmCS3W4GeXXclEDK3xSpLBVzYEtOvUfY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pjNK9fyGWQNyRpqngFft7rHCkV5nmtUuQMBv8uEbgOyYHf5IZDejeD8aaPfPIeCm2rOGfFFqqgZlnliSMgsXX0WM6w8QyEKnJiVQuz/+U9MGKz3g51D5R5qyfOqOk6rLsIATL95ywzm2xqrPajMtJ04qCzTBqoavXzDYif0jiSQ= 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=jRxKwYib; arc=none smtp.client-ip=209.85.167.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="jRxKwYib" Received: by mail-oi1-f169.google.com with SMTP id 5614622812f47-3e6104701ffso1813436b6e.0 for ; Tue, 22 Oct 2024 19:32:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729650747; x=1730255547; 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=LUkTGTHxwSN6/nyZbXQLzBNsHbN79gfD6AzC8ONj3r0=; b=jRxKwYibwrMMyPcrYmyTkyHUOHyQqh56H/kdEDQY5ADgZmvFNyLvcewM2LnjggZ8Fw TPGDkHGx3TjKj/R1KC9w8QUBrbaP1aJf4OqDDZckWG8mGSG5qyMwWcfQkXORpLmI7Qvj va6kgP94WJ2IBg0Ig4DtmUXGxtZ/quCMJcGa1/booyqa6H2HC/O2avJ0mrg1/tJGL6gF 7IeObdVaGsUZZ7517OBE37esWk6mkh2H7DYbjAMKdQ1YcY4tmNiFeEbmoOq4yWnWO54f lrmR9QYXzQJdeVMHhJtuHy+tJFrjdSxoL6LrcoykeaZ0wjeWT7X0ATL3wu6bhnylSohf asJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729650747; x=1730255547; 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=LUkTGTHxwSN6/nyZbXQLzBNsHbN79gfD6AzC8ONj3r0=; b=IJtBFMdjEGeQYySV4uncIQMXCDGwt4SgtMzX75wWfmJRKx5d88GmeiZ3HXFHUv6NL9 WSQ2ceyjIHmRpYZoDu34AdXEl9hY5Mrk3Meat1GI/6PXjJPTYti4nzFBkp34EYjOut4g 4goDFakFNRtAlTQN4LK0UidTPaHniS01uQhZuUi9G5EfSL6PsT2IuzcAIH5nXkAVrTfb sg5zFwAXPqo9RN5FDJVE4KdbIff79W9G8c04aVHfKwplmiOXDZA5oPmp8K56nBEQyG5F 28cb9wCywepapp6oyoRoXRDv8v8y8XRNuD5+lLzVOlQ/95b4uuFaXCbz6HHoi26g7y1g 5bPQ== X-Gm-Message-State: AOJu0YzTFXrOCb4QZSU2efqmncVImGS+t9wS2RVYqmDcoRvhb+BLPfwq r72JZ8u7eVcAtxYzyCbVwE+Tz4gg4PUQmB/efSWTyX/9YJeAgoSy7m+Jr4ovKmk= X-Google-Smtp-Source: AGHT+IEGVuRSKCodWbj0u/pengCPqZPQ10WHWc2Qvm8NCV4PBB39xtgIQGWWN+V7cn8BeOiE4CV4sw== X-Received: by 2002:a05:6808:23cb:b0:3e6:86d:ec11 with SMTP id 5614622812f47-3e6244e6ccbmr1078910b6e.9.1729650746696; Tue, 22 Oct 2024 19:32:26 -0700 (PDT) Received: from nova-ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7eaea9386e5sm4972284a12.0.2024.10.22.19.32.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 19:32:26 -0700 (PDT) From: Xiao Liang To: netdev@vger.kernel.org Cc: "David S. Miller" , David Ahern , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Kuniyuki Iwashima , Ido Schimmel Subject: [PATCH net-next 4/5] net: ip_tunnel: Add source netns support for newlink Date: Wed, 23 Oct 2024 10:31:45 +0800 Message-ID: <20241023023146.372653-5-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241023023146.372653-1-shaw.leon@gmail.com> References: <20241023023146.372653-1-shaw.leon@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Add ip_tunnel_newlink_net() that accepts src_net parameter, which is passed from newlink() of RTNL ops, and use it as tunnel source netns. Signed-off-by: Xiao Liang --- include/net/ip_tunnels.h | 3 +++ net/ipv4/ip_tunnel.c | 21 +++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h index 4e4f9e24c9c1..67f56440e72a 100644 --- a/include/net/ip_tunnels.h +++ b/include/net/ip_tunnels.h @@ -408,6 +408,9 @@ int ip_tunnel_changelink(struct net_device *dev, struct nlattr *tb[], struct ip_tunnel_parm_kern *p, __u32 fwmark); int ip_tunnel_newlink(struct net_device *dev, struct nlattr *tb[], struct ip_tunnel_parm_kern *p, __u32 fwmark); +int ip_tunnel_newlink_net(struct net *src_net, struct net_device *dev, + struct nlattr *tb[], struct ip_tunnel_parm_kern *p, + __u32 fwmark); void ip_tunnel_setup(struct net_device *dev, unsigned int net_id); bool ip_tunnel_netlink_encap_parms(struct nlattr *data[], diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c index 09ee39e7b617..91d54ebe09c7 100644 --- a/net/ipv4/ip_tunnel.c +++ b/net/ipv4/ip_tunnel.c @@ -1213,17 +1213,17 @@ void ip_tunnel_delete_nets(struct list_head *net_list, unsigned int id, } EXPORT_SYMBOL_GPL(ip_tunnel_delete_nets); -int ip_tunnel_newlink(struct net_device *dev, struct nlattr *tb[], - struct ip_tunnel_parm_kern *p, __u32 fwmark) +int ip_tunnel_newlink_net(struct net *src_net, struct net_device *dev, + struct nlattr *tb[], struct ip_tunnel_parm_kern *p, + __u32 fwmark) { struct ip_tunnel *nt; - struct net *net = dev_net(dev); struct ip_tunnel_net *itn; int mtu; int err; nt = netdev_priv(dev); - itn = net_generic(net, nt->ip_tnl_net_id); + itn = net_generic(src_net, nt->ip_tnl_net_id); if (nt->collect_md) { if (rtnl_dereference(itn->collect_md_tun)) @@ -1233,7 +1233,7 @@ int ip_tunnel_newlink(struct net_device *dev, struct nlattr *tb[], return -EEXIST; } - nt->net = net; + nt->net = src_net; nt->parms = *p; nt->fwmark = fwmark; err = register_netdevice(dev); @@ -1265,6 +1265,13 @@ int ip_tunnel_newlink(struct net_device *dev, struct nlattr *tb[], err_register_netdevice: return err; } +EXPORT_SYMBOL_GPL(ip_tunnel_newlink_net); + +int ip_tunnel_newlink(struct net_device *dev, struct nlattr *tb[], + struct ip_tunnel_parm_kern *p, __u32 fwmark) +{ + return ip_tunnel_newlink_net(dev_net(dev), dev, tb, p, fwmark); +} EXPORT_SYMBOL_GPL(ip_tunnel_newlink); int ip_tunnel_changelink(struct net_device *dev, struct nlattr *tb[], @@ -1326,7 +1333,9 @@ int ip_tunnel_init(struct net_device *dev) } tunnel->dev = dev; - tunnel->net = dev_net(dev); + if (!tunnel->net) + tunnel->net = dev_net(dev); + strscpy(tunnel->parms.name, dev->name); iph->version = 4; iph->ihl = 5; From patchwork Wed Oct 23 02:31:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Liang X-Patchwork-Id: 13846323 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-oi1-f169.google.com (mail-oi1-f169.google.com [209.85.167.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 D3E7377111 for ; Wed, 23 Oct 2024 02:32:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729650754; cv=none; b=MnyVmlACv/jUuz7WzDVczbBoHkzVQxPHmAhKm7zHGOwCQf/Q3QfasNqFiztwZ/sgRCM04YWOA9bjAHADQ9upMo415eUAdJC507dBMhifui5IbH9R+bIhRkFd/0CgCOZLgHeptRIpR5NqhYAYoLGHSAjyjOq+N+R0S2gOrSuMIO4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729650754; c=relaxed/simple; bh=DP+FtCvuMIZd6/BnGy3YHcmGQRT1aA22G7G7QoSQE1o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MNewyHCVoA6psLa7IU4k7Ze6IWuPhDk/VxXM5vGAGpoCVeLfSNJS1eNWGluZDSfqFvJBkwJj9ZQ9dDzxyo4bmPjkhv/O6P+0x8pfaxrm3GNkBxyTfuD8doJXl65BG95nGmImLZiXzHg4NO9aMYBANQaBu8jIFV3uh9P7GnrLuvI= 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=Jj4RARWE; arc=none smtp.client-ip=209.85.167.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="Jj4RARWE" Received: by mail-oi1-f169.google.com with SMTP id 5614622812f47-3e5fb8a4e53so2782010b6e.1 for ; Tue, 22 Oct 2024 19:32:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729650751; x=1730255551; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gClAoFe1h5U+0NiA7Nj6o2YtRc1W3/sr4TmNeojvSXo=; b=Jj4RARWEYR3eiI8IGHOGUvyM4Dq3yJmsCu3/8qlaGcyXoTtWVBszx2YRXOz0qwSUEN nhWkCRTnzGLZjBiloBn/JfN4mjOqg3LvHyj56QLT0w+otNbaKRScul66RR99CHhjFQrX V7Itro/7wvnjronHp2U9cb7PjD+O77urKQpsJEKS0IDI7doa7/ej4RFX7i63UNesFbPJ 0jzvZwCjeFmpfr6dbUfb8eMcx0M5s8Yd3V5vPYwXS+zX1Z6zb52MD8lKQ7463E5CgFRo FkSFoDuIVgvh9+iW1GaeExpchDVAtY9nJOgTyAY+hNtwoa03sEVzBOf3U17dzftg/I7l ZZ0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729650751; x=1730255551; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gClAoFe1h5U+0NiA7Nj6o2YtRc1W3/sr4TmNeojvSXo=; b=DvHDzr+gFSQNvLvhDCVEmA89Yw9dIa8QeDQWO3GvXdITUJE0J0eLNMs+zc8Ow8FPUT oYYyD6DNcBNk6qGZPaFcSuRp7Fy4fux6z30v7OyIYFtAnF8b/MK77RAZzcrYNmhkajX2 2Sv/W5ZHA+CATtVazChFI4ciLky6bzq2HM4Ax1EG0l/JEMjrs0mb1iTCpgvVbk96VLfn HHQGqS9meQrIYwLFM83tZXuVs+7F9NXo/u76DyBN57Yfb+U9XnTAWrwh3Aba2+ftE8rs ckADiDDHVow7pfgp/vrFZ36lGM3aeGeg9SyMScKEzeOT96dqQ/Oj/3lgnnXqQn5ETUQX NZaA== X-Gm-Message-State: AOJu0YxTp+ZQ/gjMgGuW9hh2O1GFRpglNhM/nymhPZaiBzLdEcaX1za0 Xx4fp0GMoDWgNW1y4QhkWvWkFm1lVco+PwueQa4JP4bk6I7jhJYXUQQCMzwYWgQ= X-Google-Smtp-Source: AGHT+IEDXGuR/QEPREdt6ljh433KApel17rJl+AQJ4xZnzLcKZC+KIqP7n3RCpZgE0bkrw4FTqIZ2w== X-Received: by 2002:a05:6808:2395:b0:3e6:77d:2ea1 with SMTP id 5614622812f47-3e6245d4c65mr922602b6e.45.1729650751239; Tue, 22 Oct 2024 19:32:31 -0700 (PDT) Received: from nova-ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7eaea9386e5sm4972284a12.0.2024.10.22.19.32.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 19:32:29 -0700 (PDT) From: Xiao Liang To: netdev@vger.kernel.org Cc: "David S. Miller" , David Ahern , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Kuniyuki Iwashima , Ido Schimmel Subject: [PATCH net-next 5/5] net: ip_gre: Add netns_atomic module parameter Date: Wed, 23 Oct 2024 10:31:46 +0800 Message-ID: <20241023023146.372653-6-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241023023146.372653-1-shaw.leon@gmail.com> References: <20241023023146.372653-1-shaw.leon@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org If set to true, create device in target netns (when different from link-netns) without netns change, and use current netns as link-netns if not specified explicitly. Signed-off-by: Xiao Liang --- net/ipv4/ip_gre.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c index f1f31ebfc793..6ef7e98e4620 100644 --- a/net/ipv4/ip_gre.c +++ b/net/ipv4/ip_gre.c @@ -107,6 +107,11 @@ static bool log_ecn_error = true; module_param(log_ecn_error, bool, 0644); MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN"); +static bool netns_atomic; +module_param(netns_atomic, bool, 0444); +MODULE_PARM_DESC(netns_atomic, + "Create tunnel in target net namespace directly and use current net namespace as link-netns by default"); + static struct rtnl_link_ops ipgre_link_ops __read_mostly; static const struct header_ops ipgre_header_ops; @@ -1393,6 +1398,7 @@ static int ipgre_newlink(struct net *src_net, struct net_device *dev, struct nlattr *tb[], struct nlattr *data[], struct netlink_ext_ack *extack) { + struct net *link_net = netns_atomic ? src_net : dev_net(dev); struct ip_tunnel_parm_kern p; __u32 fwmark = 0; int err; @@ -1404,13 +1410,14 @@ static int ipgre_newlink(struct net *src_net, struct net_device *dev, err = ipgre_netlink_parms(dev, data, tb, &p, &fwmark); if (err < 0) return err; - return ip_tunnel_newlink(dev, tb, &p, fwmark); + return ip_tunnel_newlink_net(link_net, dev, tb, &p, fwmark); } static int erspan_newlink(struct net *src_net, struct net_device *dev, struct nlattr *tb[], struct nlattr *data[], struct netlink_ext_ack *extack) { + struct net *link_net = netns_atomic ? src_net : dev_net(dev); struct ip_tunnel_parm_kern p; __u32 fwmark = 0; int err; @@ -1422,7 +1429,7 @@ static int erspan_newlink(struct net *src_net, struct net_device *dev, err = erspan_netlink_parms(dev, data, tb, &p, &fwmark); if (err) return err; - return ip_tunnel_newlink(dev, tb, &p, fwmark); + return ip_tunnel_newlink_net(link_net, dev, tb, &p, fwmark); } static int ipgre_changelink(struct net_device *dev, struct nlattr *tb[], @@ -1777,6 +1784,10 @@ static int __init ipgre_init(void) pr_info("GRE over IPv4 tunneling driver\n"); + ipgre_link_ops.netns_atomic = netns_atomic; + ipgre_tap_ops.netns_atomic = netns_atomic; + erspan_link_ops.netns_atomic = netns_atomic; + err = register_pernet_device(&ipgre_net_ops); if (err < 0) return err;