From patchwork Wed Feb 28 23:22:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13576129 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f175.google.com (mail-yw1-f175.google.com [209.85.128.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 6859513D306 for ; Wed, 28 Feb 2024 23:22:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709162579; cv=none; b=qltmkZB4k79/vohwsAOS0fD3/VqKPUf2ArivVhuu5PY4zQXVeOpEuEk/Nlb/TqfI0TywAzLMs/fGQnV68CDxFR97DYfzbZzlSm627ze+EqDCLuJdW7FZ3+h8vGgKMglMhTfWuErA9CTd9wrxSLGjPXUfGzRgNDUMc5FmMTX+Aws= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709162579; c=relaxed/simple; bh=y1S2eetl14xWG3tddS2FMiEcu4pRLxGLIJD7nUZduQI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DfPb65xL1qs6eJpCZu9RzCk+L5sM1cTiEdDcQXZDJcSXKxr3D/Eac6W3/H734lV88WCYkGu72gDBUK7keWVs/ddJvxfUbkoxIZrx5i3yCo3H711Dc3wlO5yY93b7V0+gcAl6yU3SJV73Y5BWvJCd/EpefrmQeT6piyN5ieqkv2o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=davidwei.uk; spf=none smtp.mailfrom=davidwei.uk; dkim=pass (2048-bit key) header.d=davidwei-uk.20230601.gappssmtp.com header.i=@davidwei-uk.20230601.gappssmtp.com header.b=SeS7lGYT; arc=none smtp.client-ip=209.85.128.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=davidwei.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=davidwei.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=davidwei-uk.20230601.gappssmtp.com header.i=@davidwei-uk.20230601.gappssmtp.com header.b="SeS7lGYT" Received: by mail-yw1-f175.google.com with SMTP id 00721157ae682-608e0b87594so3055817b3.1 for ; Wed, 28 Feb 2024 15:22:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1709162576; x=1709767376; 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=LEoci8r9fYh9X8Ih0f8ErkspCwERkY2nhtYsuarWoIs=; b=SeS7lGYTDE4wSMSylMbin+yUqEKCT2iNbVNp7MOPBQ5xsaDOvHzdPTZZkqcREAdZGT XKwAE3H4CPXbKfAxPiBtcpHKNC0t2vAZuKQ6mB7v6KUxz/76gVZMt4Io4Uwp6u4WXvSm LM7umvByWkZLLdJyILSTAnp2Xb6tdB8J/WruxV7IorfNcCOGqR7DyG9VEID3bRQTUufP q00Ej51BPiM+d7d5nezEJ9tM97IL1nDbCm5YS0wHcUlX9CMYYvC8Ef2zQJ9TxTnOSwWH 1O+ru8teTpW0AvkPQ3MWihIAsXbTMg3R00zRDeibU9Vw+uCuHlJ882OHD5Sw7EaavIjt 4f0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709162576; x=1709767376; 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=LEoci8r9fYh9X8Ih0f8ErkspCwERkY2nhtYsuarWoIs=; b=Eco4Cu4kBsXdwsM/i8FQiIV1zIUQCBONKKhWDX9oCN7dlLennd0xyVn86gD+32P3UL gDuNwEeLg42g1rCUDDJn9JtFDA0dGgsWh3TCpm5A9MFW2RNfRpNPEnI7F21+Zh+hBwFR 7Oa+9UyIoLpugQI068IhZnbWwRkHPTcLhivSzzfjT/za0QHqeQCbzckDHgbGVPbjrKaM oD0e/zV57MVouh1iiqugzpQwDuQKnM7YYAgAfzXaeiIN+OF9hl2is2gjNETGvxTUIORX dBof7NU5lCxhrYkOJvaiYBu1irkRliQV2g1fJk4l86ZqnP+UFLPHbichDLhBa0w8hpoR jbLw== X-Forwarded-Encrypted: i=1; AJvYcCVzyBZurdcInQuMi1Ps0Sd0I9Dh6Nghicv4wdJ3ImlLJR1h6T3SMjcyyN7p2Q8FPEl2KyzRlDjlHdZfngYO56XNSwIf5qXU X-Gm-Message-State: AOJu0YxI3g0MsIW5bLc+/saMxa32EF0WWhcK/WRzu1+QPUO70SAwDRxl 2LSzFbhcMg6ItFph7kykZeLlfpZiq/CVtshWblhM0jjEqzn+/pim7rauGLccwZo= X-Google-Smtp-Source: AGHT+IEWlCaGFOxfnYNme0k/rb+Q4cZUqLCOgslY6A2UP+lO1rwExTCZM94ijFoPwM3leW7RaYlq7g== X-Received: by 2002:a81:4742:0:b0:608:af6:afa4 with SMTP id u63-20020a814742000000b006080af6afa4mr507087ywa.39.1709162576393; Wed, 28 Feb 2024 15:22:56 -0800 (PST) Received: from localhost (fwdproxy-prn-116.fbsv.net. [2a03:2880:ff:74::face:b00c]) by smtp.gmail.com with ESMTPSA id d10-20020a81e90a000000b006095684c480sm29190ywm.30.2024.02.28.15.22.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 15:22:56 -0800 (PST) From: David Wei To: Jakub Kicinski , Jiri Pirko , Sabrina Dubroca , maciek@machnikowski.net, horms@kernel.org, netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Paolo Abeni Subject: [PATCH v14 1/5] netdevsim: allow two netdevsim ports to be connected Date: Wed, 28 Feb 2024 15:22:49 -0800 Message-ID: <20240228232253.2875900-2-dw@davidwei.uk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240228232253.2875900-1-dw@davidwei.uk> References: <20240228232253.2875900-1-dw@davidwei.uk> 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 two netdevsim bus attribute to sysfs: /sys/bus/netdevsim/link_device /sys/bus/netdevsim/unlink_device Writing "A M B N" to link_device will link netdevsim M in netnsid A with netdevsim N in netnsid B. Writing "A M" to unlink_device will unlink netdevsim M in netnsid A from its peer, if any. rtnl_lock is taken to ensure nothing changes during the linking. Signed-off-by: David Wei Reviewed-by: Maciek Machnikowski --- drivers/net/netdevsim/bus.c | 145 ++++++++++++++++++++++++++++++ drivers/net/netdevsim/netdev.c | 10 +++ drivers/net/netdevsim/netdevsim.h | 2 + 3 files changed, 157 insertions(+) diff --git a/drivers/net/netdevsim/bus.c b/drivers/net/netdevsim/bus.c index 0c5aff63d242..64c0cdd31bf8 100644 --- a/drivers/net/netdevsim/bus.c +++ b/drivers/net/netdevsim/bus.c @@ -232,9 +232,154 @@ del_device_store(const struct bus_type *bus, const char *buf, size_t count) } static BUS_ATTR_WO(del_device); +static ssize_t link_device_store(const struct bus_type *bus, const char *buf, size_t count) +{ + struct netdevsim *nsim_a, *nsim_b, *peer; + struct net_device *dev_a, *dev_b; + unsigned int ifidx_a, ifidx_b; + int netnsfd_a, netnsfd_b, err; + struct net *ns_a, *ns_b; + + err = sscanf(buf, "%d:%u %d:%u", &netnsfd_a, &ifidx_a, &netnsfd_b, + &ifidx_b); + if (err != 4) { + pr_err("Format for linking two devices is \"netnsfd_a:ifidx_a netnsfd_b:ifidx_b\" (int uint int uint).\n"); + return -EINVAL; + } + + ns_a = get_net_ns_by_fd(netnsfd_a); + if (IS_ERR(ns_a)) { + pr_err("Could not find netns with fd: %d\n", netnsfd_a); + return -EINVAL; + } + + ns_b = get_net_ns_by_fd(netnsfd_b); + if (IS_ERR(ns_b)) { + pr_err("Could not find netns with fd: %d\n", netnsfd_b); + put_net(ns_a); + return -EINVAL; + } + + err = -EINVAL; + rtnl_lock(); + dev_a = __dev_get_by_index(ns_a, ifidx_a); + if (!dev_a) { + pr_err("Could not find device with ifindex %u in netnsfd %d\n", + ifidx_a, netnsfd_a); + goto out_err; + } + + if (!netdev_is_nsim(dev_a)) { + pr_err("Device with ifindex %u in netnsfd %d is not a netdevsim\n", + ifidx_a, netnsfd_a); + goto out_err; + } + + dev_b = __dev_get_by_index(ns_b, ifidx_b); + if (!dev_b) { + pr_err("Could not find device with ifindex %u in netnsfd %d\n", + ifidx_b, netnsfd_b); + goto out_err; + } + + if (!netdev_is_nsim(dev_b)) { + pr_err("Device with ifindex %u in netnsfd %d is not a netdevsim\n", + ifidx_b, netnsfd_b); + goto out_err; + } + + if (dev_a == dev_b) { + pr_err("Cannot link a netdevsim to itself\n"); + goto out_err; + } + + err = -EBUSY; + nsim_a = netdev_priv(dev_a); + peer = rtnl_dereference(nsim_a->peer); + if (peer) { + pr_err("Netdevsim %d:%u is already linked\n", netnsfd_a, + ifidx_a); + goto out_err; + } + + nsim_b = netdev_priv(dev_b); + peer = rtnl_dereference(nsim_b->peer); + if (peer) { + pr_err("Netdevsim %d:%u is already linked\n", netnsfd_b, + ifidx_b); + goto out_err; + } + + err = 0; + rcu_assign_pointer(nsim_a->peer, nsim_b); + rcu_assign_pointer(nsim_b->peer, nsim_a); + +out_err: + put_net(ns_b); + put_net(ns_a); + rtnl_unlock(); + + return !err ? count : err; +} +static BUS_ATTR_WO(link_device); + +static ssize_t unlink_device_store(const struct bus_type *bus, const char *buf, size_t count) +{ + struct netdevsim *nsim, *peer; + struct net_device *dev; + unsigned int ifidx; + int netnsfd, err; + struct net *ns; + + err = sscanf(buf, "%u:%u", &netnsfd, &ifidx); + if (err != 2) { + pr_err("Format for unlinking a device is \"netnsfd:ifidx\" (int uint).\n"); + return -EINVAL; + } + + ns = get_net_ns_by_fd(netnsfd); + if (IS_ERR(ns)) { + pr_err("Could not find netns with fd: %d\n", netnsfd); + return -EINVAL; + } + + err = -EINVAL; + rtnl_lock(); + dev = __dev_get_by_index(ns, ifidx); + if (!dev) { + pr_err("Could not find device with ifindex %u in netnsfd %d\n", + ifidx, netnsfd); + goto out_put_netns; + } + + if (!netdev_is_nsim(dev)) { + pr_err("Device with ifindex %u in netnsfd %d is not a netdevsim\n", + ifidx, netnsfd); + goto out_put_netns; + } + + nsim = netdev_priv(dev); + peer = rtnl_dereference(nsim->peer); + if (!peer) + goto out_put_netns; + + err = 0; + RCU_INIT_POINTER(nsim->peer, NULL); + RCU_INIT_POINTER(peer->peer, NULL); + +out_put_netns: + put_net(ns); + rtnl_unlock(); + + return !err ? count : err; +} +static BUS_ATTR_WO(unlink_device); + static struct attribute *nsim_bus_attrs[] = { &bus_attr_new_device.attr, &bus_attr_del_device.attr, + &bus_attr_link_device.attr, + &bus_attr_unlink_device.attr, NULL }; ATTRIBUTE_GROUPS(nsim_bus); diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c index 77e8250282a5..9063f4f2971b 100644 --- a/drivers/net/netdevsim/netdev.c +++ b/drivers/net/netdevsim/netdev.c @@ -413,8 +413,13 @@ nsim_create(struct nsim_dev *nsim_dev, struct nsim_dev_port *nsim_dev_port) void nsim_destroy(struct netdevsim *ns) { struct net_device *dev = ns->netdev; + struct netdevsim *peer; rtnl_lock(); + peer = rtnl_dereference(ns->peer); + if (peer) + RCU_INIT_POINTER(peer->peer, NULL); + RCU_INIT_POINTER(ns->peer, NULL); unregister_netdevice(dev); if (nsim_dev_port_is_pf(ns->nsim_dev_port)) { nsim_macsec_teardown(ns); @@ -427,6 +432,11 @@ void nsim_destroy(struct netdevsim *ns) free_netdev(dev); } +bool netdev_is_nsim(struct net_device *dev) +{ + return dev->netdev_ops == &nsim_netdev_ops; +} + static int nsim_validate(struct nlattr *tb[], struct nlattr *data[], struct netlink_ext_ack *extack) { diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h index 028c825b86db..c8b45b0d955e 100644 --- a/drivers/net/netdevsim/netdevsim.h +++ b/drivers/net/netdevsim/netdevsim.h @@ -125,11 +125,13 @@ struct netdevsim { } udp_ports; struct nsim_ethtool ethtool; + struct netdevsim __rcu *peer; }; struct netdevsim * nsim_create(struct nsim_dev *nsim_dev, struct nsim_dev_port *nsim_dev_port); void nsim_destroy(struct netdevsim *ns); +bool netdev_is_nsim(struct net_device *dev); void nsim_ethtool_init(struct netdevsim *ns); From patchwork Wed Feb 28 23:22:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13576130 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f178.google.com (mail-yw1-f178.google.com [209.85.128.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 B70DC72901 for ; Wed, 28 Feb 2024 23:22:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709162580; cv=none; b=gsky292SxTHJc0/iYFsZoQY2qm85RxJSC+JaVJPYV1C3FpexbInngQeNpBTvCP0o6+tkRN2cL1YnSi6eK61pR1Y1bVRAn5oN2W7GnAB2dP13YStEPIc6qZYywtdXKVOM3sXsmE/aAHZMSW4cQEMokGy66laoe7dP1Uh+NW8rwpo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709162580; c=relaxed/simple; bh=+3sq9lfVb5ZFktgaFs9T5aQVerTPpfw47fVxMi66gv0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SelLMqNaUJAbWb/xnvtSzc9ftOqNpQHTZwXYKX6Nx5L2A1u1MOUfCa1XuT08EG1qOexaxB5KKkr/OlFfGt5wKwvdCjhgW9hWYpTqk+EUYgAcAvlGo9JAjaM8rqa5mp3Hmbiy5s2rjJ91N8WJw7CkzE3x1ufTo3CLKtq8+HOyXE0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=davidwei.uk; spf=none smtp.mailfrom=davidwei.uk; dkim=pass (2048-bit key) header.d=davidwei-uk.20230601.gappssmtp.com header.i=@davidwei-uk.20230601.gappssmtp.com header.b=aLkQgCw7; arc=none smtp.client-ip=209.85.128.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=davidwei.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=davidwei.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=davidwei-uk.20230601.gappssmtp.com header.i=@davidwei-uk.20230601.gappssmtp.com header.b="aLkQgCw7" Received: by mail-yw1-f178.google.com with SMTP id 00721157ae682-608e3530941so3397117b3.1 for ; Wed, 28 Feb 2024 15:22:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1709162578; x=1709767378; 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=F6IAN7c925VSRxOVMZAdo+DB7DtBwZEdQgiiRGMzVDQ=; b=aLkQgCw7o56IRNaJF8TLs2AqhodAw2dq+5sczDjjaAtNegwp6MAJA5I/73z7xkIadV ar+4XegPPRh3BENQsukxnSj8R/t0HyFNr+PULr3MCBqY2GGl7Wu3tWvB6AD9rwaWOKX4 /jge9rWn4MZ5zMW1cd7hEerO1ZADoASkESNMepx7rhwSz1gEoZ7/SHZazXb7iY+kUaYw l63W2hGSBJnmi9DnWIQs5+puff7RWKJfaUs2CravCIjbfvtYpXT7x6O97yRY4c1psaEu H3SFz69ya6UiCvOg+qcBOmKXaCijhZbqkRJbxFY9+0rVr1L7HgQok8+XB5AtybOqBBY7 nqLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709162578; x=1709767378; 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=F6IAN7c925VSRxOVMZAdo+DB7DtBwZEdQgiiRGMzVDQ=; b=plCHVxHsspGDomWC7WecPc8iL9aSB9nj6AGA1XEhGx+d7djcT2pqkduMMok4gmSq2j nxCJ2INDDO0jE4d3Kx6//ZdJAiT3/VDl8XK0J0itD3JD3d1mfgYI6jukeZsMQe0g5GQ2 WrboHNaHnoTaXHvqmc8fw5f7+wxTRoWoEbTL4dBXhDNu32MJOS99sy3DtqRQ+PXB/pmB IVVmdTnb29+sObf/yatWOjx6FgvVkkbV2UoayoqsPMFJI9mqNiSyHayX4RL73b6tqfCt R9qc4k9V9ZKE8dG3QkD7QdKLba5jYE0Hnzo0qfxjKX4GYXv7g7BZ/U58ZBuZl32LAeJz zX3Q== X-Forwarded-Encrypted: i=1; AJvYcCVW9PzC4U+sG/zeQMiQed3o3Da9cDTi2rU/pQIHcc8b66ALo5lucBLNqoNcThyAb99SEwRQfYtnAHhTG4Bjqhjh0UUkokwC X-Gm-Message-State: AOJu0YzXWx9Lq1k6TSwetM0Vc7oOPU/7+mNe8TUcru4bUu3hr65WHUMb fpzD75m8AZ+l/dPqukmMagC5nxUYw+mpQtJqorjK73StQ7BKTpm45uoGLpAjRXk= X-Google-Smtp-Source: AGHT+IH7ZoVYh/UQ/uavJdvPDIydc6N55caF51UVuqCxCHB8L26v/tsCJdoa26rgE8yZs5LZGKKDhQ== X-Received: by 2002:a25:bc88:0:b0:dcd:2aa3:d744 with SMTP id e8-20020a25bc88000000b00dcd2aa3d744mr752770ybk.17.1709162577780; Wed, 28 Feb 2024 15:22:57 -0800 (PST) Received: from localhost (fwdproxy-prn-119.fbsv.net. [2a03:2880:ff:77::face:b00c]) by smtp.gmail.com with ESMTPSA id t17-20020a252d11000000b00dcbce4abc32sm14351ybt.36.2024.02.28.15.22.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 15:22:57 -0800 (PST) From: David Wei To: Jakub Kicinski , Jiri Pirko , Sabrina Dubroca , maciek@machnikowski.net, horms@kernel.org, netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Paolo Abeni Subject: [PATCH v14 2/5] netdevsim: forward skbs from one connected port to another Date: Wed, 28 Feb 2024 15:22:50 -0800 Message-ID: <20240228232253.2875900-3-dw@davidwei.uk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240228232253.2875900-1-dw@davidwei.uk> References: <20240228232253.2875900-1-dw@davidwei.uk> 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 Forward skbs sent from one netdevsim port to its connected netdevsim port using dev_forward_skb, in a spirit similar to veth. Add a tx_dropped variable to struct netdevsim, tracking the number of skbs that could not be forwarded using dev_forward_skb(). The xmit() function accessing the peer ptr is protected by an RCU read critical section. The rcu_read_lock() is functionally redundant as since v5.0 all softirqs are implicitly RCU read critical sections; but it is useful for human readers. If another CPU is concurrently in nsim_destroy(), then it will first set the peer ptr to NULL. This does not affect any existing readers that dereferenced a non-NULL peer. Then, in unregister_netdevice(), there is a synchronize_rcu() before the netdev is actually unregistered and freed. This ensures that any readers i.e. xmit() that got a non-NULL peer will complete before the netdev is freed. Any readers after the RCU_INIT_POINTER() but before synchronize_rcu() will dereference NULL, making it safe. The codepath to nsim_destroy() and nsim_create() takes both the newly added nsim_dev_list_lock and rtnl_lock. This makes it safe with concurrent calls to linking two netdevsims together. Signed-off-by: David Wei Reviewed-by: Maciek Machnikowski --- drivers/net/netdevsim/netdev.c | 27 ++++++++++++++++++++++----- drivers/net/netdevsim/netdevsim.h | 1 + 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c index 9063f4f2971b..c3f3fda5fdc0 100644 --- a/drivers/net/netdevsim/netdev.c +++ b/drivers/net/netdevsim/netdev.c @@ -29,18 +29,35 @@ static netdev_tx_t nsim_start_xmit(struct sk_buff *skb, struct net_device *dev) { struct netdevsim *ns = netdev_priv(dev); + unsigned int len = skb->len; + struct netdevsim *peer_ns; + rcu_read_lock(); if (!nsim_ipsec_tx(ns, skb)) - goto out; + goto out_drop_free; + peer_ns = rcu_dereference(ns->peer); + if (!peer_ns) + goto out_drop_free; + + skb_tx_timestamp(skb); + if (unlikely(dev_forward_skb(peer_ns->netdev, skb) == NET_RX_DROP)) + goto out_drop_cnt; + + rcu_read_unlock(); u64_stats_update_begin(&ns->syncp); ns->tx_packets++; - ns->tx_bytes += skb->len; + ns->tx_bytes += len; u64_stats_update_end(&ns->syncp); + return NETDEV_TX_OK; -out: +out_drop_free: dev_kfree_skb(skb); - +out_drop_cnt: + rcu_read_unlock(); + u64_stats_update_begin(&ns->syncp); + ns->tx_dropped++; + u64_stats_update_end(&ns->syncp); return NETDEV_TX_OK; } @@ -70,6 +87,7 @@ nsim_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) start = u64_stats_fetch_begin(&ns->syncp); stats->tx_bytes = ns->tx_bytes; stats->tx_packets = ns->tx_packets; + stats->tx_dropped = ns->tx_dropped; } while (u64_stats_fetch_retry(&ns->syncp, start)); } @@ -302,7 +320,6 @@ static void nsim_setup(struct net_device *dev) eth_hw_addr_random(dev); dev->tx_queue_len = 0; - dev->flags |= IFF_NOARP; dev->flags &= ~IFF_MULTICAST; dev->priv_flags |= IFF_LIVE_ADDR_CHANGE | IFF_NO_QUEUE; diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h index c8b45b0d955e..553c4b9b4f63 100644 --- a/drivers/net/netdevsim/netdevsim.h +++ b/drivers/net/netdevsim/netdevsim.h @@ -98,6 +98,7 @@ struct netdevsim { u64 tx_packets; u64 tx_bytes; + u64 tx_dropped; struct u64_stats_sync syncp; struct nsim_bus_dev *nsim_bus_dev; From patchwork Wed Feb 28 23:22:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13576131 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f175.google.com (mail-yw1-f175.google.com [209.85.128.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 435C472925 for ; Wed, 28 Feb 2024 23:22:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709162581; cv=none; b=czX2xxhBbP3stjqKrIQpyvaXjk1nfBEXg3Ae2wCrwpERfpGWhESbt5wepQjY4oOeApX3W65a2ot13kbQkrP9kkDWsJWTgxYSXxuwiX7bET15+3nKI7pLpEA2PM46jVfvn7dGjcbUdnyGhCisGAwL2tqYvUofK9IdsF6tCKC7dtg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709162581; c=relaxed/simple; bh=d2HppGWJaQa66JR1Fk24YetPh6Z/upq86bTQP4nNA/E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PgsMBfMIMCTY8hexnJSw3SFYZuWNlS+lIc3BaDgaWJ4JnjD3lGsLb0iU1s2MnqokeQUuXN7vIhdAtphADQEsVjhLCdQ6tNeTtzx1o3xy8W1z2ZQn0RVbB2IXTXiLpl3Ju7KQ33ZoSUvEJGCJ/uhbfwBL9LPmQ39FQK7Dp9bdwyo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=davidwei.uk; spf=none smtp.mailfrom=davidwei.uk; dkim=pass (2048-bit key) header.d=davidwei-uk.20230601.gappssmtp.com header.i=@davidwei-uk.20230601.gappssmtp.com header.b=L13RgYxO; arc=none smtp.client-ip=209.85.128.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=davidwei.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=davidwei.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=davidwei-uk.20230601.gappssmtp.com header.i=@davidwei-uk.20230601.gappssmtp.com header.b="L13RgYxO" Received: by mail-yw1-f175.google.com with SMTP id 00721157ae682-607eefeea90so2905487b3.1 for ; Wed, 28 Feb 2024 15:22:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1709162579; x=1709767379; 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=9o/qfEe7PEuAJOpg929dSRy3Fc9j1BX3q2xBprmXfn0=; b=L13RgYxOiHR1njsVDPlGRQP+ZfFUzMpJCsw5aCkWEyog8SMuHz/9aT1tUNA+Ss7fEm ZpRvsGS9mtht9YUx4QypDQ8fMK+X6PQqnzPxVLFzPld094UEF+dIgM2jAfRtvuBTUVoR emU1dox4cFmyqdHFp+pO+We5WN7t4aC8qS8xp+EggGKBGvOlOdjL54Wqyf4nJi0qDX7k tyMcL7OUqBG0G97VmvcRMnN14jy/qLdX2KvkNjRx05h4+0WwPD7xkagYy4B+nV6S4ZjN tsbMq+/Ubu74VF8D0759LjO7AE3s6LWGWJ6MDyC3Zi3/L6AxhQUChRhODcSTEdSWkPqq vHVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709162579; x=1709767379; 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=9o/qfEe7PEuAJOpg929dSRy3Fc9j1BX3q2xBprmXfn0=; b=XJtKVMh3mOK1oobG4NTyaqQji02JcYhWb9qsfCzHKcb972zWdgXFQNDtTonjPeLCSB LeOckqXHgcAUs2Zg65tzwX57HPgU6iYzRyTkAbGmnlT1jJZq4rJnmq7gQZvG2mJxb0Bk MHT2Zni1Kbmp+yLEwk1NaiDeRcmKJF5W8OJAm5SMxhuOz2X/rY0BHeLfwyi+R5IHUUHw gix0YFpH2wdp23D0PyA5C71uumIhmms/W5khmPU9jDFZhH+sgNF2aAXVBlA31gI6gjRP iQgHxSyiNnmDynS3+RCoMlocSHq72WGa4R9XbXxX9G49vw0O2qZAqmOfAMSwBGIZj4th ICYg== X-Forwarded-Encrypted: i=1; AJvYcCWUtrEcD0qsZaM6CzOZ3YvBzJCTTS6yLNqOmAxlqHK2edKEQjfZyL2KJocqiVmdrw38dCLlKw+BJpQ0rhhDPhzUA9YFuURm X-Gm-Message-State: AOJu0YzAIxezhQg9gixe3S3xFMH2Dt4eCyssANIzH18m75fKzR3rTtsY Ln59nH54WC7uN4MxPFULQp3ozEq692LOpITowjC7Bfu/tanzB6AyIc2xe/DRpxI= X-Google-Smtp-Source: AGHT+IHnQQffD6GzCU1pgzYuo1NA4cjXVJRbUV9u8ZxvGons4Thrd9fsGuP/Q083lPIPI+E9KNeDAA== X-Received: by 2002:a81:a145:0:b0:609:531:8550 with SMTP id y66-20020a81a145000000b0060905318550mr147985ywg.21.1709162579182; Wed, 28 Feb 2024 15:22:59 -0800 (PST) Received: from localhost (fwdproxy-prn-011.fbsv.net. [2a03:2880:ff:b::face:b00c]) by smtp.gmail.com with ESMTPSA id b3-20020a81bc43000000b006086a467647sm29595ywl.56.2024.02.28.15.22.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 15:22:59 -0800 (PST) From: David Wei To: Jakub Kicinski , Jiri Pirko , Sabrina Dubroca , maciek@machnikowski.net, horms@kernel.org, netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Paolo Abeni Subject: [PATCH v14 3/5] netdevsim: add ndo_get_iflink() implementation Date: Wed, 28 Feb 2024 15:22:51 -0800 Message-ID: <20240228232253.2875900-4-dw@davidwei.uk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240228232253.2875900-1-dw@davidwei.uk> References: <20240228232253.2875900-1-dw@davidwei.uk> 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 an implementation for ndo_get_iflink() in netdevsim that shows the ifindex of the linked peer, if any. Signed-off-by: David Wei Reviewed-by: Maciek Machnikowski --- drivers/net/netdevsim/netdev.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c index c3f3fda5fdc0..8330bc0bcb7e 100644 --- a/drivers/net/netdevsim/netdev.c +++ b/drivers/net/netdevsim/netdev.c @@ -283,6 +283,21 @@ nsim_set_features(struct net_device *dev, netdev_features_t features) return 0; } +static int nsim_get_iflink(const struct net_device *dev) +{ + struct netdevsim *nsim, *peer; + int iflink; + + nsim = netdev_priv(dev); + + rcu_read_lock(); + peer = rcu_dereference(nsim->peer); + iflink = peer ? READ_ONCE(peer->netdev->ifindex) : 0; + rcu_read_unlock(); + + return iflink; +} + static const struct net_device_ops nsim_netdev_ops = { .ndo_start_xmit = nsim_start_xmit, .ndo_set_rx_mode = nsim_set_rx_mode, @@ -300,6 +315,7 @@ static const struct net_device_ops nsim_netdev_ops = { .ndo_set_vf_rss_query_en = nsim_set_vf_rss_query_en, .ndo_setup_tc = nsim_setup_tc, .ndo_set_features = nsim_set_features, + .ndo_get_iflink = nsim_get_iflink, .ndo_bpf = nsim_bpf, }; From patchwork Wed Feb 28 23:22:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13576132 Received: from mail-yw1-f181.google.com (mail-yw1-f181.google.com [209.85.128.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 9C8CF72901 for ; Wed, 28 Feb 2024 23:23:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709162583; cv=none; b=ffKoc2f8zlJIBOC6nwMlgBnSFO1CTqFjbipKD0w1EyHmUUnKibdt3R5nGy1vruEJZBdXgkzvdI5seA8qjcaTsF24N9wPmN5zGmq5RYPuQ056PXhdxkBN55Cfw9XW2z/8jJs+I+3nShQsb4qlHfjZ/Xt0yiLSH6izumlo35CNzIw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709162583; c=relaxed/simple; bh=Y1jPRwRoyMNF0suvjMjHZLxamIH5AlPcRacyY9MnFBo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lUU3T+ioIvTrS6RPM+WKsUJa9L6kDBnBO4YlF0UPjuzHfUhFhlfOoWMtN/fXUbuiOmDoNWLg4AzzzVdnr2kJm8ikHSHr75kduX+ZzCNPxr39ctjFOi2u1+Q6PTC5Tl8qVxRfrUPki0QI/OEWzByQeAme/mmM3q7G0qihDPAHop8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=davidwei.uk; spf=none smtp.mailfrom=davidwei.uk; dkim=pass (2048-bit key) header.d=davidwei-uk.20230601.gappssmtp.com header.i=@davidwei-uk.20230601.gappssmtp.com header.b=Eb3dvQzS; arc=none smtp.client-ip=209.85.128.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=davidwei.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=davidwei.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=davidwei-uk.20230601.gappssmtp.com header.i=@davidwei-uk.20230601.gappssmtp.com header.b="Eb3dvQzS" Received: by mail-yw1-f181.google.com with SMTP id 00721157ae682-608959cfcbfso3792527b3.3 for ; Wed, 28 Feb 2024 15:23:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1709162580; x=1709767380; 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=3q5XYN7tzbVmTzEuBgAB1tZATSLFQ1CSVWIFAsyXioE=; b=Eb3dvQzShbBxNl6bh4zcT7xaJQHLDqoa0uSPaBqNYt8KkhoJ0hLro83IXU87jLKN/p A1Mdyk5/NrGhJ6eiDb8xd7QQnOclf63MpC14gQLJx5WpBuzIhQb+wiNON+tpsQCVPOiN Iw+rXShCk4IvzEbVooVGdpESiHZzlxK/ZhQNY3cd2rf2yBwdiefGDCdz2fO/80NO8j+j moXHESsvKWTPtncsccrhLfKiEXV6nuJk5JZ5EghVmcgtCLaBE/yNS+B7R8IBvrwQggNU ryfRqYbE8sCj2h5iW09dAI0IiMwVbYE/3TWumBNihjkZeiyxy6JFSumyfEt6qz0tID5g VLHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709162580; x=1709767380; 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=3q5XYN7tzbVmTzEuBgAB1tZATSLFQ1CSVWIFAsyXioE=; b=HATte9Ffbysc2wF5Z+ZXbflG2O/QPJheroj1iC5Bgb8gglD8JxKcQlg9NaXQiaRhQB FPGoUh8u4g5E5V53lm0A3AqowGj7hRE8mweX0k1ZfKNx75YdJzsvPcapqdyb5AAQB6Ss 7duQFkn32MHbY+ZOmXT7mzqf4dHbc7r1dqNZfYbOJ49RMClhBadOmZWvu5dDauiclI38 d2j+32mhLuoMl6QMOkWe74hRUflV2AIcT5M1Cq5vSef6/TYzoeFkGpUDFebCNyIhDF7w rXrPRgsyZvTG+4kOCL6XlrBkK0/g4Jni2dCvj2C1bTKMTIVabfu1NaTnn8A+YgtN4CkI G8iw== X-Forwarded-Encrypted: i=1; AJvYcCWaNB3N2jb2IErLrlx0yYF90W/ZaJY1lNEwdM5fBsVyMcTcxP44YRCG7XJmdFAkakcaX7JqrqckYRDm0zp7KbFZqjoeFyvm X-Gm-Message-State: AOJu0YxDpR6rCjkHqHJZkirMmst1ezRkjZRGh6Ayzj0Z9a5HtKe/Q4v2 LTH7R2nNz4S4t30/17xt2bn0LDuroYmv/uIMvbnOnvPVTJ7/LRfpeS1s8lInHs0= X-Google-Smtp-Source: AGHT+IFdGc5iS069dwBDm1PLYqqaF5i6QrAzF03v+YWYq0DDd/glzzKKdhBarMVa+A54wABREGgOyA== X-Received: by 2002:a0d:ed04:0:b0:608:20fe:dc28 with SMTP id w4-20020a0ded04000000b0060820fedc28mr588799ywe.37.1709162580632; Wed, 28 Feb 2024 15:23:00 -0800 (PST) Received: from localhost (fwdproxy-prn-023.fbsv.net. [2a03:2880:ff:17::face:b00c]) by smtp.gmail.com with ESMTPSA id t125-20020a818383000000b005ff846d1f1dsm25808ywf.134.2024.02.28.15.23.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 15:23:00 -0800 (PST) From: David Wei To: Jakub Kicinski , Jiri Pirko , Sabrina Dubroca , maciek@machnikowski.net, horms@kernel.org, netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Paolo Abeni Subject: [PATCH v14 4/5] netdevsim: add selftest for forwarding skb between connected ports Date: Wed, 28 Feb 2024 15:22:52 -0800 Message-ID: <20240228232253.2875900-5-dw@davidwei.uk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240228232253.2875900-1-dw@davidwei.uk> References: <20240228232253.2875900-1-dw@davidwei.uk> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Connect two netdevsim ports in different namespaces together, then send packets between them using socat. Signed-off-by: David Wei Reviewed-by: Maciek Machnikowski --- .../selftests/drivers/net/netdevsim/Makefile | 1 + .../selftests/drivers/net/netdevsim/peer.sh | 143 ++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100755 tools/testing/selftests/drivers/net/netdevsim/peer.sh diff --git a/tools/testing/selftests/drivers/net/netdevsim/Makefile b/tools/testing/selftests/drivers/net/netdevsim/Makefile index 7a29a05bea8b..5bace0b7fb57 100644 --- a/tools/testing/selftests/drivers/net/netdevsim/Makefile +++ b/tools/testing/selftests/drivers/net/netdevsim/Makefile @@ -10,6 +10,7 @@ TEST_PROGS = devlink.sh \ fib.sh \ hw_stats_l3.sh \ nexthop.sh \ + peer.sh \ psample.sh \ tc-mq-visibility.sh \ udp_tunnel_nic.sh \ diff --git a/tools/testing/selftests/drivers/net/netdevsim/peer.sh b/tools/testing/selftests/drivers/net/netdevsim/peer.sh new file mode 100755 index 000000000000..aed62d9e6c0a --- /dev/null +++ b/tools/testing/selftests/drivers/net/netdevsim/peer.sh @@ -0,0 +1,143 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-only + +source ../../../net/net_helper.sh + +NSIM_DEV_1_ID=$((256 + RANDOM % 256)) +NSIM_DEV_1_SYS=/sys/bus/netdevsim/devices/netdevsim$NSIM_DEV_1_ID +NSIM_DEV_2_ID=$((512 + RANDOM % 256)) +NSIM_DEV_2_SYS=/sys/bus/netdevsim/devices/netdevsim$NSIM_DEV_2_ID + +NSIM_DEV_SYS_NEW=/sys/bus/netdevsim/new_device +NSIM_DEV_SYS_DEL=/sys/bus/netdevsim/del_device +NSIM_DEV_SYS_LINK=/sys/bus/netdevsim/link_device +NSIM_DEV_SYS_UNLINK=/sys/bus/netdevsim/unlink_device + +socat_check() +{ + if [ ! -x "$(command -v socat)" ]; then + echo "socat command not found. Skipping test" + return 1 + fi + + return 0 +} + +setup_ns() +{ + set -e + ip netns add nssv + ip netns add nscl + + NSIM_DEV_1_NAME=$(find $NSIM_DEV_1_SYS/net -maxdepth 1 -type d ! \ + -path $NSIM_DEV_1_SYS/net -exec basename {} \;) + NSIM_DEV_2_NAME=$(find $NSIM_DEV_2_SYS/net -maxdepth 1 -type d ! \ + -path $NSIM_DEV_2_SYS/net -exec basename {} \;) + + ip link set $NSIM_DEV_1_NAME netns nssv + ip link set $NSIM_DEV_2_NAME netns nscl + + ip netns exec nssv ip addr add '192.168.1.1/24' dev $NSIM_DEV_1_NAME + ip netns exec nscl ip addr add '192.168.1.2/24' dev $NSIM_DEV_2_NAME + + ip netns exec nssv ip link set dev $NSIM_DEV_1_NAME up + ip netns exec nscl ip link set dev $NSIM_DEV_2_NAME up + set +e +} + +cleanup_ns() +{ + ip netns del nscl + ip netns del nssv +} + +### +### Code start +### + +socat_check || exit 4 + +modprobe netdevsim + +# linking + +echo $NSIM_DEV_1_ID > $NSIM_DEV_SYS_NEW +echo $NSIM_DEV_2_ID > $NSIM_DEV_SYS_NEW +udevadm settle + +setup_ns + +NSIM_DEV_1_FD=$((256 + RANDOM % 256)) +exec {NSIM_DEV_1_FD} $NSIM_DEV_SYS_LINK 2>/dev/null +if [ $? -eq 0 ]; then + echo "linking with non-existent netdevsim should fail" + cleanup_ns + exit 1 +fi + +echo "$NSIM_DEV_1_FD:$NSIM_DEV_1_IFIDX 2000:$NSIM_DEV_2_IFIDX" > $NSIM_DEV_SYS_LINK 2>/dev/null +if [ $? -eq 0 ]; then + echo "linking with non-existent netnsid should fail" + cleanup_ns + exit 1 +fi + +echo "$NSIM_DEV_1_FD:$NSIM_DEV_1_IFIDX $NSIM_DEV_1_FD:$NSIM_DEV_1_IFIDX" > $NSIM_DEV_SYS_LINK 2>/dev/null +if [ $? -eq 0 ]; then + echo "linking with self should fail" + cleanup_ns + exit 1 +fi + +echo "$NSIM_DEV_1_FD:$NSIM_DEV_1_IFIDX $NSIM_DEV_2_FD:$NSIM_DEV_2_IFIDX" > $NSIM_DEV_SYS_LINK +if [ $? -ne 0 ]; then + echo "linking netdevsim1 with netdevsim2 should succeed" + cleanup_ns + exit 1 +fi + +# argument error checking + +echo "$NSIM_DEV_1_FD:$NSIM_DEV_1_IFIDX $NSIM_DEV_2_FD:a" > $NSIM_DEV_SYS_LINK 2>/dev/null +if [ $? -eq 0 ]; then + echo "invalid arg should fail" + cleanup_ns + exit 1 +fi + +# send/recv packets + +tmp_file=$(mktemp) +ip netns exec nssv socat TCP-LISTEN:1234,fork $tmp_file & +pid=$! +res=0 + +wait_local_port_listen nssv 1234 tcp + +echo "HI" | ip netns exec nscl socat STDIN TCP:192.168.1.1:1234 + +count=$(cat $tmp_file | wc -c) +if [[ $count -ne 3 ]]; then + echo "expected 3 bytes, got $count" + res=1 +fi + +echo "$NSIM_DEV_1_FD:$NSIM_DEV_1_IFIDX" > $NSIM_DEV_SYS_UNLINK + +echo $NSIM_DEV_2_ID > $NSIM_DEV_SYS_DEL + +kill $pid +echo $NSIM_DEV_1_ID > $NSIM_DEV_SYS_DEL + +cleanup_ns + +modprobe -r netdevsim + +exit $res From patchwork Wed Feb 28 23:22:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13576133 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f178.google.com (mail-yw1-f178.google.com [209.85.128.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 DDCB172938 for ; Wed, 28 Feb 2024 23:23:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709162585; cv=none; b=CHhxHY/YcBfb0Qxvi0t9J4UbQVCAKxLWko3o3wpMWNsKuHLe+IqIxCik/BMa/ZS5Ky/9nUE51yyo7T2xC0756W9OCFSmcLPzU2u2STymX7tkJuq0DIoSTc1xij2mrElKljqhSMtpPq3hvMEDc1TmFcODiCya/ggdrJ6yIG4C4cw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709162585; c=relaxed/simple; bh=gWzmDNpH4ymuh/z0FtOSGtL1rvV/ao8PcM2prYv6Y5Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KVVfNCLOW8YQ1yhBxO+N+XJSYIsljOhJgLs4jqduB0YJne9j74BP2l7FIm5PaXz6dWrroaAxGhBaeCos7LXSAftwV8lp6kyRWnJGK641jpUt7hSzEPVVf1oMPjeQ1/HWprCgBlpPReD/9QtZlQ6OF3tNXnwza4pMGA79OmGytcM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=davidwei.uk; spf=none smtp.mailfrom=davidwei.uk; dkim=pass (2048-bit key) header.d=davidwei-uk.20230601.gappssmtp.com header.i=@davidwei-uk.20230601.gappssmtp.com header.b=nGmpc4XD; arc=none smtp.client-ip=209.85.128.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=davidwei.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=davidwei.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=davidwei-uk.20230601.gappssmtp.com header.i=@davidwei-uk.20230601.gappssmtp.com header.b="nGmpc4XD" Received: by mail-yw1-f178.google.com with SMTP id 00721157ae682-607bfa4c913so3422847b3.3 for ; Wed, 28 Feb 2024 15:23:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1709162582; x=1709767382; 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=BUXTQwpf8JAkFjPlBQzq5/ttlnpw3bhhsVqVvNgnTM0=; b=nGmpc4XDsk5Ja9En50/Y+g1YlkYOzKDAYUUP8y9bZjgp6aTfEB7OPdzlXh16hrY3TH T+sqG/A092ygqShIFd1JJ0HU+Vcb2b14gPlB9HRyFpUcorYDeBINEriltVWCIqK4xxqK 1jcNY0zbZbhQ1GvnXbvqgwksb4tL2R5/CajX5oLAKUzO1DgkuUanXuL8hRiIRNpgKUOT SUkWq+cfOxshJU1PtGTkMTZvCAhX+HI0TAjrFqHmYeLvj9Gcax9ifwSZ1RJnZTAyGFsj Yno3u0UAbbHGONINSgLHGor1/GEPTANpe0V11rmxN7xsUzvR4ziye/P4P7qcASUcKrL2 5nXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709162582; x=1709767382; 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=BUXTQwpf8JAkFjPlBQzq5/ttlnpw3bhhsVqVvNgnTM0=; b=Y0CX8X36NC3iXV8LrmYyMEtmn5EecIqwPyv6OQMbaOl3pSCFZD9gmrD/zfVgqUNzil KMtxQkZZ9HHlg5t4rmq4MVLAW/blb3AbEM1bSEpwQcwOE2a6vunWKKysWQqn8pRn9+7G qm5tcC61Ddl/w1eybpKG0fi1Scf+97a4AlS3U1NSbscZQrwBrLv/PTqBaLjSNXoEiQUx h4CPeLGvM5cVmhamTfmKrfl6CuVBtnoyJ81F1AxAe9H3UAsg6D+xUgrx/1LXuGO+c84o ord3s7TbMhx0H3r21r55htRhNvPg65UPQGWNiXAXFi90jEnK6NRcJjzoF9CrONYXlYIa 8WyA== X-Forwarded-Encrypted: i=1; AJvYcCW2ItgWE7z3w+r7JxuO+eYNExsaAOGpZpKWMeXYRvbJLfB7/Nd1Tmhzp/avEdrKRTb3XuinMU65ObFS/5ShK95PaZnC851w X-Gm-Message-State: AOJu0YxXafLtm254HuzUbpDG4/Cgcsd/ofN78iXPuWM36m/MrckpkiUn fxICYmTIQ5LZqUYFoymK3aOrjslgWxVqmeuy86t/yLIVtlHqywnp2JYtuFKNEKQ= X-Google-Smtp-Source: AGHT+IELWkpUghELm1lyMVKivm0RqxtoSTDbvVieqEJ+k0VG/HUMFe9+EWEIRvneJ3ba1nj4JfwlVA== X-Received: by 2002:a0d:d48f:0:b0:608:b64a:1517 with SMTP id w137-20020a0dd48f000000b00608b64a1517mr553680ywd.19.1709162582010; Wed, 28 Feb 2024 15:23:02 -0800 (PST) Received: from localhost (fwdproxy-prn-016.fbsv.net. [2a03:2880:ff:10::face:b00c]) by smtp.gmail.com with ESMTPSA id n17-20020a81eb11000000b0060487d30610sm29625ywm.45.2024.02.28.15.23.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 15:23:01 -0800 (PST) From: David Wei To: Jakub Kicinski , Jiri Pirko , Sabrina Dubroca , maciek@machnikowski.net, horms@kernel.org, netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Paolo Abeni Subject: [PATCH v14 5/5] netdevsim: fix rtnetlink.sh selftest Date: Wed, 28 Feb 2024 15:22:53 -0800 Message-ID: <20240228232253.2875900-6-dw@davidwei.uk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240228232253.2875900-1-dw@davidwei.uk> References: <20240228232253.2875900-1-dw@davidwei.uk> 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 I cleared IFF_NOARP flag from netdevsim dev->flags in order to support skb forwarding. This breaks the rtnetlink.sh selftest kci_test_ipsec_offload() test because ipsec does not connect to peers it cannot transmit to. Fix the issue by adding a neigh entry manually. ipsec_offload test now successfully pass. Signed-off-by: David Wei --- tools/testing/selftests/net/rtnetlink.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testing/selftests/net/rtnetlink.sh b/tools/testing/selftests/net/rtnetlink.sh index 874a2952aa8e..bdf6f10d0558 100755 --- a/tools/testing/selftests/net/rtnetlink.sh +++ b/tools/testing/selftests/net/rtnetlink.sh @@ -801,6 +801,8 @@ kci_test_ipsec_offload() end_test "FAIL: ipsec_offload SA offload missing from list output" fi + # we didn't create a peer, make sure we can Tx + ip neigh add $dstip dev $dev lladdr 00:11:22:33:44:55 # use ping to exercise the Tx path ping -I $dev -c 3 -W 1 -i 0 $dstip >/dev/null