From patchwork Thu Feb 22 05:08:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13566757 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.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 E439553AC for ; Thu, 22 Feb 2024 05:08:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708578525; cv=none; b=S3akyygA2OyJXwGPIvpcBCeGhoIjCqwt6ULqtyDr8sz2PwFYdu/7EznuRwMQwRDzmKhm0zxk6sPec4Ioe9ov4CcEZU4Dl+Se6Cs3uspeczEHIZtpI8yWWMyxi6EmMWboxFrGKpBMRByRICAckV/s740yOx0RPM151obD0goZcwM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708578525; c=relaxed/simple; bh=8zlsgHn01/nTBoGvTvVbQPv/D/gUieZwvJy7J3dtx6c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Rzdy1GLQY3FAkNK0ma9L3sBR4tCJ4JpwrMBACcebljmLNlgSEF53ubx7eZQGco9EXuWkT0P6WHUB2cQmglSSZGLjaMJRkBCKb5tt3vNsOfpYeGfH6CpI3xE+UlGm9oxgHZFaSF4e6lmaaQD+JpuJO5QX3lkVbajf2etQkt+huXA= 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=2p8XIf6n; arc=none smtp.client-ip=209.85.210.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="2p8XIf6n" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-6e3ffafa708so4660249b3a.1 for ; Wed, 21 Feb 2024 21:08:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1708578523; x=1709183323; 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=cdfR7zWvyTebUkxzjTusqS23eJLm6NJsG7DbC2Ao9DQ=; b=2p8XIf6nX9YNnGd+eAvAvsEKo85JV1FIbsUVsd6hYy6IS1r9yKybsxBr6QkQW+Fs9q yUgpPJ1eiL0V3Mu/QAjw1cGfucOMt/dV9Kxz39iFiuL5UD1lWAlpshUcS5EVZeRwPcT8 b29Jsv5yvtxS0X0Gttm8IGiMPYYe0kAeXHXWlsH7q1vPoNDvAPLY3op1vuxjGPlUsG1H pH2PijjDrL1BxinAgDygSrlBGFDep7K+UuWSQq94GWC/AEppK19jr6di/EnRTzi7vtrs OMa0jUjIEEJsr8/VCkbkcAB27RsyHA/qaSzT0+t2WF5kCwmhbqiqHltd5WM6yPtPFkOC 9DnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708578523; x=1709183323; 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=cdfR7zWvyTebUkxzjTusqS23eJLm6NJsG7DbC2Ao9DQ=; b=kkAVcJ+S74LqIGj98AMHL7bTuN7ksvk6xmtDDl4qPFwJBqQ4qO7Bh3ZXvTWAjESosx R8BTD1WAYRgIFhSMfvkXJDSqjQDvxeVg2xMAUzKj5qTKQQLpAxmpk4pdS2xpZU5tlfGH dIMDodI3olAC78lLTPuvN5+Fvzk/la5H2zoEqti2rJQG6H20RCkBJE/6PqxdyoW7c+W+ x8UWLmj5DKd3YeqgOd4JgZ8021lpFreVK7gffXWrVR8ww0c09Fzk/CUDA0j1YAwy59lr e94vZbEuiz34mpGr3sgt3fc+8RO+Ea/t3C/mVZdjbQlcN0cjFKq5t1ssiODXg31CpaZ2 2mjw== X-Forwarded-Encrypted: i=1; AJvYcCURS7O1ik1UJ3cRrZ8YKyUKJ3cIDoGX6kjjAy9op/HGWiJc0GuSyoP8jtC9ufl1s4uanrYnczvj9VgQuT5c5VQhNwcTGVC+ X-Gm-Message-State: AOJu0Ywn4ByVeaEV6KlGYLMs1tjEkqVtxhqlfWWMnPeE3WT15zzCH7AQ zx24Ih/dYyqdsY+dkDWdUofoHCGeolCISKOvIWhYy9j34hOvrmNrTaj09Zqu3VL9JYpVsqwPoqO f X-Google-Smtp-Source: AGHT+IFWTBusrNRHO5IBjDNrAobRHNtcJceBeZebbEbJgeh9YHQ++csfKWiDgiztjw7Ngy9JnER5wg== X-Received: by 2002:aa7:8b47:0:b0:6e1:3ab9:614c with SMTP id i7-20020aa78b47000000b006e13ab9614cmr17397524pfd.16.1708578523245; Wed, 21 Feb 2024 21:08:43 -0800 (PST) Received: from localhost (fwdproxy-prn-014.fbsv.net. [2a03:2880:ff:e::face:b00c]) by smtp.gmail.com with ESMTPSA id z16-20020a62d110000000b006e38ea2e058sm9219777pfg.164.2024.02.21.21.08.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 21:08:42 -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 net-next v13 1/4] netdevsim: allow two netdevsim ports to be connected Date: Wed, 21 Feb 2024 21:08:37 -0800 Message-Id: <20240222050840.362799-2-dw@davidwei.uk> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240222050840.362799-1-dw@davidwei.uk> References: <20240222050840.362799-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 --- drivers/net/netdevsim/bus.c | 135 ++++++++++++++++++++++++++++++ drivers/net/netdevsim/netdev.c | 10 +++ drivers/net/netdevsim/netdevsim.h | 2 + 3 files changed, 147 insertions(+) diff --git a/drivers/net/netdevsim/bus.c b/drivers/net/netdevsim/bus.c index 0c5aff63d242..202fa35716db 100644 --- a/drivers/net/netdevsim/bus.c +++ b/drivers/net/netdevsim/bus.c @@ -232,9 +232,144 @@ 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 = 0; + 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; + } + + 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; + } + + err = 0; + nsim = netdev_priv(dev); + peer = rtnl_dereference(nsim->peer); + if (!peer) + goto out_put_netns; + + 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 Thu Feb 22 05:08:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13566758 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 458994C8A for ; Thu, 22 Feb 2024 05:08:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708578526; cv=none; b=GlS0kpIth85ej3Bbj2Y467WQYFyyPQd+TpSChkCmcMXOBvIxkA5XCn/PwmLNFI48kN+kEgIXrhAfIsKxgUVQdqmBJkTxwVa+5LNUCOrkJjedWtX+d1kPKT+ob+2r1qp+p516lScdzY/LWaiXKqjUm8jRSTb6W7JmAX/NwGN/2Rc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708578526; c=relaxed/simple; bh=WuVQ9tyy4qXVzj8fg5jT1T8KjKLN2WSR7176fQweBTk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NjdNMfHweLe1ThqQJyWnnyOtZz6x06EcxTIbWq5l9dlYyKEFUq89wumSJIteBKGmRX+5EgseUENlCynoJ3s/W0VquSSXhVNcHIBmt8lYEHPRol64ldFeOagLro4/Ylmg/SQTqneFg86K3XRRb4Olw7NU0hlLmsnBzWNq+6gR9uE= 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=NJLx7Joz; arc=none smtp.client-ip=209.85.214.173 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="NJLx7Joz" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1d934c8f8f7so70046065ad.2 for ; Wed, 21 Feb 2024 21:08:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1708578524; x=1709183324; 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=PVNOE9NzOpHv+S2/C5c0rGW7n1qxuHkxnBJNavNR7kw=; b=NJLx7Joztro5XviN021gh5Ar0innpxwXkRtKeEaGWg8Mqb5u2yQFp7DGtXUFtwnzDq QFV6ndzVE/SahJ4aa7aFGuxMV+WNUUEGTYpa1dky77De1iXqCwswz1J1wlmCSUYO9yt7 2uBerQtYgkfxHYUM2azGPXRFRUNxnegXss/6mCWYg6WMAg3G+c04ThoT5+nTjm5Mg7y2 1HeDvjlrgK01WpoOy9o7qXe3UKXQhS6seQsZJYpqiogNlpTRL7A2lAgqpk7o1UiEzEmB Xlwo8LAf/3+C7MSEdrml1+1P+//JTA2pbh261U/79RmuE0swQLEhuhTdsLi8SDWp97xi I91A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708578524; x=1709183324; 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=PVNOE9NzOpHv+S2/C5c0rGW7n1qxuHkxnBJNavNR7kw=; b=cbDtB+3ScM60qMvA50cpEZFYF0MsIRpAJExlWpJFFXBffiSaiCFkPYh9Uzrn9K6oar u3xHsN+FxjoWW7wFcw+rRRZ5ANn8/oHWu7XTO6eNXklqN0aQ3Jvvtg9ghEIK83ehnSBn Rf4vz1hPIK/09Qbf0QYTtvL6JEJs811uMeyGs1zZlnYTuW1DQrRzc/Wl7DGWLtVVTag4 EDjYjOMqZMuzVChkh6Ow97e2wNJ7l8MD9PrA/9Z5KxAvqygUVi87iU1iDrolFhO6MRBe Uxp1jY2glJ+muwSRMN8E1SDal3la6PnjmbykXAvcXGL8jjFTnJfeoJEIUn27STGSBu0u JPOw== X-Forwarded-Encrypted: i=1; AJvYcCVlfS0elnqkL2DwJh3JJXvnjiaYxS99KMh/sFHUfGaVqrpaZKBY2GJfpwrriXh5rT2d67xZt2EotEanJyq1rsUpQTnTubRb X-Gm-Message-State: AOJu0Yw3vHuUV/KK6nQInnp1ARJPmJImWQOimwk6/3ItmipnB4YZTQxH AZRyHbWHVWxc4YB6oBTrhMR+w8iC8wYhR6NvPWiqSFlU0hptm67KzJoioDvIxbT++xS7XLH5OZE H X-Google-Smtp-Source: AGHT+IEzhoI6LKlAev/iJAdJ6+AUdBSvh7br44RBQgAoinytCvh1L5tzOM7x3rulz5tHkzE5d4klVw== X-Received: by 2002:a17:902:c246:b0:1db:d256:932d with SMTP id 6-20020a170902c24600b001dbd256932dmr11747999plg.10.1708578524317; Wed, 21 Feb 2024 21:08:44 -0800 (PST) Received: from localhost (fwdproxy-prn-005.fbsv.net. [2a03:2880:ff:5::face:b00c]) by smtp.gmail.com with ESMTPSA id bd5-20020a170902830500b001dc0cb0413fsm4911895plb.155.2024.02.21.21.08.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 21:08:44 -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 net-next v13 2/4] netdevsim: forward skbs from one connected port to another Date: Wed, 21 Feb 2024 21:08:38 -0800 Message-Id: <20240222050840.362799-3-dw@davidwei.uk> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240222050840.362799-1-dw@davidwei.uk> References: <20240222050840.362799-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 --- drivers/net/netdevsim/netdev.c | 30 +++++++++++++++++++++++++----- drivers/net/netdevsim/netdevsim.h | 1 + 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c index 9063f4f2971b..d151859fa2c0 100644 --- a/drivers/net/netdevsim/netdev.c +++ b/drivers/net/netdevsim/netdev.c @@ -29,19 +29,39 @@ 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; + int ret = NETDEV_TX_OK; if (!nsim_ipsec_tx(ns, skb)) goto out; + rcu_read_lock(); + peer_ns = rcu_dereference(ns->peer); + if (!peer_ns) { + dev_kfree_skb(skb); + goto out_stats; + } + + skb_tx_timestamp(skb); + if (unlikely(dev_forward_skb(peer_ns->netdev, skb) == NET_RX_DROP)) + ret = NET_XMIT_DROP; + +out_stats: + rcu_read_unlock(); u64_stats_update_begin(&ns->syncp); - ns->tx_packets++; - ns->tx_bytes += skb->len; + if (ret == NET_XMIT_DROP) { + ns->tx_dropped++; + } else { + ns->tx_packets++; + ns->tx_bytes += len; + } u64_stats_update_end(&ns->syncp); + return ret; out: dev_kfree_skb(skb); - - return NETDEV_TX_OK; + return ret; } static void nsim_set_rx_mode(struct net_device *dev) @@ -70,6 +90,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 +323,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 Thu Feb 22 05:08:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13566759 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 515577490 for ; Thu, 22 Feb 2024 05:08:46 +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=1708578527; cv=none; b=EGXEOKvauGHjlmESaDhblFwphz6nQWf3E/MUnAx1c87ueMQeCu9vKAN9j6ADIGh2AAkMtvbvtKG9xjg7MPKa/hSomC7T17J+JmFEisPucOL+HD8zDGmXFD4Kl4IZ7FwLxFD3gOfEKDTrDGdsN4EqP/sRw6poC04HB2XukOdspwI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708578527; c=relaxed/simple; bh=YOPWX+M5ZqiUEJjsvcl0SVqwqZv37soDMbhqOvMVvaA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ahByYJ6UEyovbSc15pQtXRlZjsbkVjAix8rkcYMEbbZkXKFOqi+LHSLKuhg8cvHVQBSv5lJVxHRnUePbAzdLOrst52UXOYtR6P1XbE3HLDz7ykMuU7U99eqzLoKgppaw68TLmORdqvRClcmCyiE3OP1e63e06069PHIi3RGkAOU= 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=qAj9ky5+; arc=none smtp.client-ip=209.85.215.176 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="qAj9ky5+" Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-5d8b70b39efso5749391a12.0 for ; Wed, 21 Feb 2024 21:08:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1708578525; x=1709183325; 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=xg6mAe8Th7HkYfWnh5XTzJrsh0pJe46nLGrfe+y89ZE=; b=qAj9ky5+jo0jiq89y3/qm3uIbgKRcaQqz4h20vbw5nMP2NLtOSPdjUK+Fu+KRusHTi 9MdLYP+BbMNbNZ/+/RuwWwWY3OwVZnqK8iovdf6N9CZkZWu0Yf021bUVFoA3mZ432+Wv GG3ohG0Z2fSyFkxovmj1kPLXjZXF9ef+FHxf922BJ5/1tJSf9GAVpy5tYjadNSwxqbeg x8iy/fthe5gaZGjKEAKvpWnDm5/chHfsB8B6p0cNJa4Hvtc5aefcuQ6Ox4744JIb4aAU KUhUX3dOze3bZMd0B+jiesM6HQt7MVrZZTpXqmLabyr6shyYWiaYtBh4KMPC4cvHquFw cD3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708578525; x=1709183325; 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=xg6mAe8Th7HkYfWnh5XTzJrsh0pJe46nLGrfe+y89ZE=; b=H0fkceDeE0QBiEwh6l1YsgoBTV7GMwuvGJDFkY4pN55DHI3Iz6XzFmAMMFIEk2xWtr SXo/Yu91wYgrf6AscnbYh2iH9m+8/q7cOkHIU4uEFo0ySrGm2KajQ4T5xaO5VtTKHIoi 6prpPZENn96ERamuPKMur68IdJnB4GDYpdU5LxJCLfc7OPoMCpuPUquY6M0fW1BzRnYI jLlMZ7JGoOc+iCmhzMdh02/2F/NMARoyquaE9O/daIlYuRtQX2H23ovpOx6g0cdjUZrH Ad03UJrkiqERz1A/Iv4SkkPiACZkCzGYvK8WiGekfPDezlyxLoa+FHpVP7YpIwnX+QtQ VfvA== X-Forwarded-Encrypted: i=1; AJvYcCVrAB0P1L4VAoQ99zDbcwmGx/o1+FDYwb8+tUh8MsZH0QlZQicUskmZAZWjhz8VFgUu1+vdbSRCxvlQuUneZyujrjAA5Uvd X-Gm-Message-State: AOJu0YxjkLQPwRob2d6BiGaki1jXm8fWv5LBVMi5DJB5myCC0T9c2U/a b2/7k5LQCe8hcRnqpuH8a7N5Klm4TgZEZSAUwuUybgu5/lfiOROIIMVMWjQUs2k= X-Google-Smtp-Source: AGHT+IG4sEOeJd1OGBe5p19rylQG18tMPXSYhI9LNEtG5ef21mGuott/NpnEllvIYPfGMrmNnVfhhg== X-Received: by 2002:a05:6a21:1014:b0:1a0:c950:9eb6 with SMTP id nk20-20020a056a21101400b001a0c9509eb6mr3051270pzb.27.1708578525323; Wed, 21 Feb 2024 21:08:45 -0800 (PST) Received: from localhost (fwdproxy-prn-008.fbsv.net. [2a03:2880:ff:8::face:b00c]) by smtp.gmail.com with ESMTPSA id b15-20020a170902d50f00b001d9aa663282sm8946416plg.266.2024.02.21.21.08.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 21:08:45 -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 net-next v13 3/4] netdevsim: add selftest for forwarding skb between connected ports Date: Wed, 21 Feb 2024 21:08:39 -0800 Message-Id: <20240222050840.362799-4-dw@davidwei.uk> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240222050840.362799-1-dw@davidwei.uk> References: <20240222050840.362799-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 Connect two netdevsim ports in different namespaces together, then send packets between them using socat. Signed-off-by: David Wei --- .../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 Thu Feb 22 05:08:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13566760 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-il1-f179.google.com (mail-il1-f179.google.com [209.85.166.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 5AEF279F9 for ; Thu, 22 Feb 2024 05:08:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708578530; cv=none; b=KHLCJ0AURoGxtq0CJELgoDAanuTciwPvAWjtkWrP44F3QPnmfTh4WY3CjCDojsoVGIqYsVmUgUwvysTUof4MnLayzktz83szErfvP9Up+rMekmbq6oReRLMOZSQKuDfbHF3Yx8PWC9Iga5iZneT1LfBdjj4K0q1eWVV/UP+qswA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708578530; c=relaxed/simple; bh=CurFviOw4itoUtMNe+SZx2bpR/RLLa/WZSwhPDY8PZY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ThI60OrnOtDlOOE4urF70l+cNqcB6FAmTx9w901AvbH1eV5EwrlYaIy20uY23P08mJn6M2XwVfBJA0jMozqmZhiV15ZIE5vqaUDs2AUMhAs6g8Z8sT4tQbJmO7yK/3yVp2Zjy9UEiPgMKJGM+Hsb+3tFbpSJhDau+btAd54WkNc= 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=mMo6qVO3; arc=none smtp.client-ip=209.85.166.179 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="mMo6qVO3" Received: by mail-il1-f179.google.com with SMTP id e9e14a558f8ab-36517cfd690so4013275ab.2 for ; Wed, 21 Feb 2024 21:08:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1708578526; x=1709183326; 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=t9USVVGat00F5jJQj+wUn/U8TMoSCdZw7GREj2Omev8=; b=mMo6qVO36xYJ5Y9UGefp9ARdKc9hlY5/RhFCK10CBbyutb7ukHh7yOcbFhduokx+of JZ5VJNU7sD0xrLyu/hZ4wYQHoHTTEUVyeIzsO/MY1ffVhZ+Rm90bfTnJykUSbyzxnxp+ W19Dwu+RvNkYN7aBApzrm93PPqYssOuKYItXBR05e/voLkKETK4NOxQ5mkWjlalBUwGi 5NXZ9yp232wCzSRr5MxwAaKUr9ZVfuHuO30Yuvqig33yZTT/QGCSwhTSgc/1192TB0rf LEFgNwrKiu3z2bHnrykToqR+kegkADcFjHwYW+S38bWOHAJiyIU1IMxJk33lVK8CmGzq Ug3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708578526; x=1709183326; 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=t9USVVGat00F5jJQj+wUn/U8TMoSCdZw7GREj2Omev8=; b=eMpKRqjEUja1gAG8bhWRCmpNpU0oKDDwJV3JejC0D+Zcdq96/vZy5DP8smgwhR1nbJ W3sQBCfrug0YQrMv/bJdCn5tZ21shhNGI2X/u9f8HEfLq4mV5PCqcs33cjCXNNlJYdEL LJ3RQsM3JGGGUaMCNMzWBGYd/DQ78KEazKbPoTxfjT5zkbHcgYMdPcj7Rej82H02XXTJ wlooEaf08yg1zeARJrdS+WSGvFElflzKTQvzLcCgri8ONkXf+ETXGjrk1bkoKE+oatM5 FyYeAUrpb+7gMPbdFrhRBcJ9J90cflpTc3/08FK3dmUswVdUpu4vBZTqH4Ja7uRogKv4 cmcQ== X-Forwarded-Encrypted: i=1; AJvYcCWkbEzIXb5IKSJZvXsx7v7FC+f307q6VxoLMvbuAZj4TROPikCxCwoo/QmKNmvrXMvT07T5v9R2YCFf4iRc8Q8OtX8YGg74 X-Gm-Message-State: AOJu0YwC5JCBzpIz3ODAJ1HsQCQf9Zupj6SAELsJt5+JaNBczwy3eSN9 3BdWm0pGfBhXJ+yZu8IACEN6lfb41IULMT+dnwgXFAGbyvClLDg/gd/Exql0YII= X-Google-Smtp-Source: AGHT+IFKR4PUttuWoh69U5XDCWvToR6hffbetROxwoSdmdrykF8LZrcVc3cVwgwQm+Lggo+rPa6Xzw== X-Received: by 2002:a92:ce03:0:b0:364:ff2d:8989 with SMTP id b3-20020a92ce03000000b00364ff2d8989mr17030890ilo.31.1708578526531; Wed, 21 Feb 2024 21:08:46 -0800 (PST) Received: from localhost (fwdproxy-prn-118.fbsv.net. [2a03:2880:ff:76::face:b00c]) by smtp.gmail.com with ESMTPSA id 6-20020a631946000000b005dc4806ad7dsm9376754pgz.40.2024.02.21.21.08.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 21:08:46 -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 net-next v13 4/4] netdevsim: fix rtnetlink.sh selftest Date: Wed, 21 Feb 2024 21:08:40 -0800 Message-Id: <20240222050840.362799-5-dw@davidwei.uk> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240222050840.362799-1-dw@davidwei.uk> References: <20240222050840.362799-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