From patchwork Sat Feb 17 05:04:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13561242 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-oa1-f44.google.com (mail-oa1-f44.google.com [209.85.160.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 18EF54A0A for ; Sat, 17 Feb 2024 05:04:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708146263; cv=none; b=KItBzduoSAIAeMlNPAgBn22mtfnvd4yJD7nfOFkNO/eUNjnh+1v8uZs6x5c0uA0QBkRzGmXAWGxoo0cZGCItTeJhEZDe8zkKBuprEIX2dIuylWlKZS2uPEAD80pjY+0+VIcZYEiBQa8j9vIOHF+5lb0Rible5rR57Q+T7GEcp1o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708146263; c=relaxed/simple; bh=PlrDauaSXJsrUEEP+2vAcDcSxafWJS7CE1uKjTQJTgo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SNMiRn7FhahZJLV8Jwy9mhGTniI0ObZ3C/F3TJnEkhMQn3yxrZeLCBn/2+6sAgCg0urVOZDCgTKmh9B4j4ClMIBj0RjPUucB2rowj5bkF1hIhxBLoyl15+Km7tDiHFrpY4cHZ2YUHTEDuwV2qJkFgU3pJL2bMqtivCYLTtIi9SE= 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=mgapmY7j; arc=none smtp.client-ip=209.85.160.44 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="mgapmY7j" Received: by mail-oa1-f44.google.com with SMTP id 586e51a60fabf-204f50f305cso1950600fac.3 for ; Fri, 16 Feb 2024 21:04:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1708146261; x=1708751061; 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=McQEsHhHuU9oKMyDS4+y8U0TmMMTqMmyMgH+jRxqi8g=; b=mgapmY7jLCvLUXi3y82RM444zu0XRdNx384BpflYQi7yPkbIRvxuJ2KhPuZ0lmQS/m f6rDO0gVLCglklonI7q3Es6rIq/chRL8c37BBZxw9HbvT2IBRteXTizHsX2KjGAY64fH Oxj/Jjrr9zty29CBDUgIS1QZv9Sbt2t/cMKv1lx4ZmwnI7LHfZsFoHx9YfAqeuW8GNrb kHhTXWCQ/0R4BUk+9mzNK0mMRMCSFaGUkKH8A/ADgY/c6YVQTLeHlEAbNXT45QbJ0A99 mUkrUtNy2gbem+aceTSLR4nFbudvm+Vv7xVsJ2A6EuAna8YFzwwsjrFpTGfi4ynvdI0k oTiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708146261; x=1708751061; 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=McQEsHhHuU9oKMyDS4+y8U0TmMMTqMmyMgH+jRxqi8g=; b=bpk1Gl+N3cCbNE+TnafjfAzGiiTnqcaY89ZEDZtXP9xkllJg2ielFCYUXQKLKVGBEB cr4OXTzfNlLsIV89R8RkvdN3MDApSzYWBvu6AAK4mFyflkrtZQFIiw4pZ2mOLdV7F5cf 1doTkmxwhef76LZToU50pEgaaAEjBry+nAFvxl3CBzvJX3kw8D/jJsNIt9CjEuZO23s4 Xpfi1HgtdbqAy7olzgYKUacAzim6IImv2njni9eGTfbNIDDu5xvL2o9XhLyDzR3PW/om nd++PgvaUUrgh0xLT+Wqg4GW6hbQkOtTflEDXYPaSzCRGJFFTYgRTI0ZmYUwmig9eywW OLXA== X-Forwarded-Encrypted: i=1; AJvYcCVamdAOfUaipveQFbczhG2yiuw+OaxpKC0OWWVyqRlTkeYtQQAg6F7FcPEbgk+jJlFKSJhv7kP66R60y8ht6pCpD9inyTV0 X-Gm-Message-State: AOJu0YzcPufBq+qQcp6oIF2x+LEmFm/zXarFHprbI8BBOX0/jpwUGiR/ q0SaUYnQYLOp5bsDj7ZPp+zq1heoxTdGriGVozIVhNMdf2sWigIukDicGGl73tY= X-Google-Smtp-Source: AGHT+IHc6e2Mx9sABYHzDGutuoapfmSoQfjpyxjsbraSjdBN3ZMP7LVYAYT3l0GFlP0ar4wQnxvapg== X-Received: by 2002:a05:6870:8a06:b0:219:2d44:5db7 with SMTP id p6-20020a0568708a0600b002192d445db7mr7391692oaq.45.1708146261118; Fri, 16 Feb 2024 21:04:21 -0800 (PST) Received: from localhost (fwdproxy-prn-018.fbsv.net. [2a03:2880:ff:12::face:b00c]) by smtp.gmail.com with ESMTPSA id f2-20020a656282000000b005c662e103a1sm622918pgv.41.2024.02.16.21.04.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 21:04:20 -0800 (PST) From: David Wei To: Jakub Kicinski , Jiri Pirko , Sabrina Dubroca , netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Paolo Abeni Subject: [PATCH net-next v12 1/4] netdevsim: allow two netdevsim ports to be connected Date: Fri, 16 Feb 2024 21:04:15 -0800 Message-Id: <20240217050418.3125504-2-dw@davidwei.uk> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240217050418.3125504-1-dw@davidwei.uk> References: <20240217050418.3125504-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 | 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 aedab1d9623a..438b862cb577 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 Sat Feb 17 05:04:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13561243 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.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 DBA6D1C2B2 for ; Sat, 17 Feb 2024 05:04:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708146264; cv=none; b=fJ9Tl2wQGOBcPyeWrbl+18FltwI43p+EuXt/c3TM3oJs2pa80PWOW09ZekYi8lK7i0DtGbR6Zm5K6pEicdediPnIfwu478fH8XA/FwOb64hvVKoEKoNdfC/2nzOAUz7ybyDZE+DFBRG007oJ9ThxhcmFIujB+Q3XS7uGJrjLh0s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708146264; c=relaxed/simple; bh=WuVQ9tyy4qXVzj8fg5jT1T8KjKLN2WSR7176fQweBTk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KuJuWMKwMpVs2cWrM+W75nNBZDdR1IBrsXZFX6f0+okuIF7aOy21bUSBRvh4gaUYeobEoWYZeGeIUAmnzEi4JKtyGewV6BJsKbNJsg44IqdqXnGbxjrUWNG4HQdlcsTJhxL+0vx9AeL5qycZ3Qp7oGx4mLWRAfM05lK6EqTKOm4= 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=u60yxPNG; arc=none smtp.client-ip=209.85.215.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="u60yxPNG" Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-5cedfc32250so2163600a12.0 for ; Fri, 16 Feb 2024 21:04:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1708146262; x=1708751062; 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=u60yxPNGGiAgo4/Jr5mjmLAFcVthNGBdLdnVZZcW5CEPccWIuzCdjKw7CpXyNG+YYH 2j/vtdb5wZLbnsD5m3XrPsSGLEuhpFaGlfqJDbg0yM6Ke+gbwNwrtV5RtGf9hjiNXMp/ QnAn8DGaDMbnWAHBQ+X2ExeLs4sgsKh1Ir39BleTRujLCfwIApYHxc6z78YRTk1C2gOL P1O4Fqe/ZOiH7Bl4XYo7pub0XCbh4d710pXqkwGhSJUmoZt3msqsH1qioRftKYRVz70T c2SitlLEcYSG0u5dwwun1i5dSyzxwRhkkV2IuB5ANPziUmWFRvzsXtAWZ5qSrcQR1t9H pDtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708146262; x=1708751062; 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=kfty+6hmaV2Fb5345MmazTFRFsAZP6uxN0aWnhLgiUQiEUZQhBULHu56J7X4cl4eqR qLOfNZb1bdNIR3/5E+qmIRZhKrLm4ON4K9J5l4Ec53km+XTWnuAN/bdF8k8KkvKfXzxx PCRK65ljayXBNpKIWhj2i8WvNglDE4qPP7OSVmDqVpLViTzBcGQf/YEhLMkYjXq4lsrB 2JclRL4nUXuNaGpLS3kIHTCZxxUFD2RIRiMz6SGpYeIHjKmGTmnFLfV+5dyPtikWPOti yzJUNk+rV75F8OO6LhvexkfkQa6ZA+PWoMIM0+3vs+5HP92L9+tKSKaGza5SVeQwHjBW Ne2Q== X-Forwarded-Encrypted: i=1; AJvYcCWM5nUUslByr9mDz1pNC6ERZ+P9ZvPQCIG+Wvd8g/4RKxIFpi5WiZmrz/AAF8aQkB+YhmTiVcZ/SHA2HjYCD9kLGE7bWLFZ X-Gm-Message-State: AOJu0YyThEkWNUwCYt/wKU2z4JAoTnUG1H8N2cQ7IZnaaat6EKz2iJbD tsjyOYis6NqJa+PNQfBZn0eZdM0GSlXqeD5ORRS+8CBfwpmdVadE0qcZJ1j4FVo= X-Google-Smtp-Source: AGHT+IE/zDv5gTgvueeCqai2GKPmFMqVjvLyQBvuSmedaqXlH+Zz40BSN4t3E2QmYp+i5NMVHM7tHg== X-Received: by 2002:a05:6a00:2fd1:b0:6db:d2f5:9e28 with SMTP id fn17-20020a056a002fd100b006dbd2f59e28mr6817820pfb.10.1708146262172; Fri, 16 Feb 2024 21:04:22 -0800 (PST) Received: from localhost (fwdproxy-prn-111.fbsv.net. [2a03:2880:ff:6f::face:b00c]) by smtp.gmail.com with ESMTPSA id fj36-20020a056a003a2400b006e04d2be954sm773766pfb.187.2024.02.16.21.04.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 21:04:21 -0800 (PST) From: David Wei To: Jakub Kicinski , Jiri Pirko , Sabrina Dubroca , netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Paolo Abeni Subject: [PATCH net-next v12 2/4] netdevsim: forward skbs from one connected port to another Date: Fri, 16 Feb 2024 21:04:16 -0800 Message-Id: <20240217050418.3125504-3-dw@davidwei.uk> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240217050418.3125504-1-dw@davidwei.uk> References: <20240217050418.3125504-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 | 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 Sat Feb 17 05:04:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13561244 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) (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 148CF1C6BD for ; Sat, 17 Feb 2024 05:04:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708146265; cv=none; b=WkmZixGBOiNcZGfV5KNvc2gWem9ygLAaRVUTj3X76Z1TUKdX/f6gkEmmblh/q0fUs1p2YaHMuJdb0S6xNnfDr/SkAkMyVmkllP13tFvT5NTtUQ3c2LJkoZd/RZv0gnFASPdNdfD8afmx12JwCaX8TvYGrbW7/InJLpDv0uh5TrQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708146265; c=relaxed/simple; bh=0cUVoJTJr3QlY4VeIpHF08NETkkBRKcCVRXoF8XuXsc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UZIt9LBqLQ0d/Zhwpj++NlkWME6P05pzTJDvy9vuvxbqGunZvNgh5QlmHGCgekxbn5UmwjWDhrWhBcA7SzIFE82eR4OUkhsmC1NFQ9JjRRbyTp3+xRt1E2oWEKCvCWlpmCwNY2MGr+4PuDh5RnShf4JAySR2lDudcZZGa7doCGA= 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=QLN0Eihb; arc=none smtp.client-ip=209.85.210.53 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="QLN0Eihb" Received: by mail-ot1-f53.google.com with SMTP id 46e09a7af769-6ddf26eba3cso1837365a34.0 for ; Fri, 16 Feb 2024 21:04:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1708146263; x=1708751063; 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=ofa1RGnWd2lIotrEIt0lDKejuMRo/GrQuejfvweLENM=; b=QLN0EihbNNVvOvRfjAX2dIXdHB2W9hM2Y2xw+tpeiJiETpzaMSAn2aKLgWs7xBc0V1 wzkVhiQks8/pduaJeeSV8UxBW1kVLf8cd9rqqDpCGBaSytIVgD0P1E1Pd/Xt+Z7ew1uc bHScLvTmjQnfThTxYdxC6WVFVkc5WWeLMsG+S1GfyfudN63HWvCGEusVzeJfWnF+iEDj LvNLR8gtMrJSBUcUGw7XHdv86FD3i2YbzvxAoOdXOaaMT80qXSOwh0MoTxCRIQbtIEMu lVtPzii8H2FecFIKOIkEMAVbBvBglktiXUJHmYL8n8HeuSGK7BEp1vikHyESnEJnLsLX JU3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708146263; x=1708751063; 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=ofa1RGnWd2lIotrEIt0lDKejuMRo/GrQuejfvweLENM=; b=FQ7+Yoz+xsbttbd8q1BBqSOVLyvFQW1qMZeFCxeiQIpfi1hJZGOkW3lqJyHvJP9MyV Ya/0FREGOGPrUgWdwsbwFoHqbzd2u1jJ8Nzrm8QDtYkkJA79Wx8cxCqp6KGehoYg1VKj wJryAdn7qFmH9msI27Wpzd+tBn5p5bbiaiaTl0Lp+yUIt8G59q9TntSllwDeyfKrpKRV RCf5DWSDlAzfVpvDXYLRSpQaIrJ/dDFak8AMOMKSVOmmC/p1s49op0zKPt5Q60TSmNK7 kBoHHmPOI95k/n2SUboZHpL2+Fif28jXqCAQi9nPcQeAfYn/32D/3UWsihW6kCMDuNgc kVEw== X-Forwarded-Encrypted: i=1; AJvYcCV2SADO6NRmrJR+mPCXlVoeW8U92lVZGa9XlDAcdcNMWBQt8sA9Seprsx2oRo1cOVQVFrowq2fdeerKKvYsxp5uyhu3eJUI X-Gm-Message-State: AOJu0YzuLwRaJ2u1HDAONfptUQWJtG/QFPALpAPinsNNvxNFntboBsi1 xqL4GQ1qeJgr7WpdpdDrZHhOtFSiSvdCgl4DLfM6Kack8NCVYPGttKw4aNr9AV8= X-Google-Smtp-Source: AGHT+IGYFCGOJJhpaJ9diYN7G1TogjhXQqmW9muo3nKFfifu1OEqsCfo1GWPeXnYA24Qs1ZjQb4vWA== X-Received: by 2002:a05:6358:5925:b0:176:d522:76b4 with SMTP id g37-20020a056358592500b00176d52276b4mr7138428rwf.14.1708146263121; Fri, 16 Feb 2024 21:04:23 -0800 (PST) Received: from localhost (fwdproxy-prn-006.fbsv.net. [2a03:2880:ff:6::face:b00c]) by smtp.gmail.com with ESMTPSA id e25-20020aa78259000000b006e0d44e1bd0sm783967pfn.55.2024.02.16.21.04.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 21:04:22 -0800 (PST) From: David Wei To: Jakub Kicinski , Jiri Pirko , Sabrina Dubroca , netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Paolo Abeni Subject: [PATCH net-next v12 3/4] netdevsim: add selftest for forwarding skb between connected ports Date: Fri, 16 Feb 2024 21:04:17 -0800 Message-Id: <20240217050418.3125504-4-dw@davidwei.uk> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240217050418.3125504-1-dw@davidwei.uk> References: <20240217050418.3125504-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 | 139 ++++++++++++++++++ 2 files changed, 140 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..c3051399c509 --- /dev/null +++ b/tools/testing/selftests/drivers/net/netdevsim/peer.sh @@ -0,0 +1,139 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-only + +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 + +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 Sat Feb 17 05:04:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13561245 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD8C51CAA5 for ; Sat, 17 Feb 2024 05:04:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708146266; cv=none; b=b4kcHMuB2X+qBHHGcWoxVeW9O3wvYHGoizgAPXmH8U1KMqwN/CjZ97mccol6w5pAq1HnOczLCoLntXu1X/ztwwiQds3PyzM6j+aBgwhmHGPkHxyjHwYG6UpCJZOkdpx/4I2iCz8NxSr4Hx5wBS+/QeF4+PFMVR8Ru7ty+bjL4FU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708146266; c=relaxed/simple; bh=8VUFqO7uMyvWoGqPY0is7aeFHyAn4ytK3vcbIsUxFBM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=e686k7Vl7LMtDCFedGe4Nac8wUyuHyDFC4eCH/rjqgkZbu8cO+cTwHcbP9ErI2ehTRdsV8LVqj7+FgAhJ/SvFiQgErk8GSVqB7eMPenA5bumYiIEjhjPnQQi/xc5VKG/kaDulwj9vNpXIIl7gQ9N0785JdIUz0bgmZ83r9xcIJs= 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=IZsqckJS; arc=none smtp.client-ip=209.85.215.182 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="IZsqckJS" Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-5ce6b5e3c4eso1023677a12.2 for ; Fri, 16 Feb 2024 21:04:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1708146264; x=1708751064; 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=15+Wstd0K/tQdqUBE0nxl8MuFaPL4ZsBE+4CamJf2q4=; b=IZsqckJSgqGgDUgC31kTRFRnx/aAzKHGl7PW/f41p4h2PTYy6Rx+DzYD1XwaavHRgz t0W+8qk14Z7sCsT+YRtpjXuvLAMhB8Iosp69Cfi5DAIbxEZlwLcV6EXeBc8ZgFVm8tEl S9TLj57VickXAnL22m7VOsIYMluK5V62TxK62vZW+zrzyH1XShSVaIFBpGU083tFYilv q5Da8jL5GmU8kjt2o2K80Wab/roMQq8FwYUHhkXMyYC6zUAGJe57o48exiuMiDK0Teyu RJhNnLuGgVhlO9UTwwjxb/t8+9N53vePTT5/FvT0Ufi1gJUgbdrPHOv8J5L9P9gKOs5r U2Pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708146264; x=1708751064; 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=15+Wstd0K/tQdqUBE0nxl8MuFaPL4ZsBE+4CamJf2q4=; b=pp/7lrRJr9OXFXgOcWEVEgiMKKWcD/kNMUEVRCDuCs6XN9ELqkqbZlc16XG0y+fQHk xTjKLVUPB+Z0+9/721jrowBZWtWGp8kJRZGmKSWlreNNoXalfir4LB1tyB1B+d7Bwy+Q E00vO1GeHRbAsfeq/V8gFCnFB2HFa1N8cj0aGviBel6tXONEWTpt3Dz36IoZXF/h5y5I /iQ/P7nJimOiWJQ5KcqAI9+ZwAm8EExzoTQgy1Y/9o3O1JHYRHu1iILETQ656kVXzfNz aAnabYvtjb0IIl36qlAWmSbcAhhkA8IvU56VWONWtyfysV8WlxrkVKtymwf9Giv9s9hE 0X9w== X-Forwarded-Encrypted: i=1; AJvYcCXmzueq/z6G2xE+ZYXlLiuc6qU5GDnhTzyCDI8oSKnpL1ZT072iyg2+vX+CGHp/8apMwhY3M0l6R7IaNZuqVSaV71VG3Rzb X-Gm-Message-State: AOJu0YyeK12WQNZcfaQlzuKiKEEmTVh27AeYmuYxdF0j9bzAMJWfQuLz vJXEQ4Gn3LWIRqzxBl1QnoSXWsWz4atfn11E5QxX5cyHNTWAwbJcNDthLWdpG96MvAemcbGMYYE 6rSM= X-Google-Smtp-Source: AGHT+IF9srCvGFY/UGP4ztg0hTzGBQEkKOe0I7iiklOxexzEjVSj6nkd5VwDA24UISFByNCCXRMLPA== X-Received: by 2002:a05:6a20:93aa:b0:1a0:7fa2:305 with SMTP id x42-20020a056a2093aa00b001a07fa20305mr7456614pzh.47.1708146264043; Fri, 16 Feb 2024 21:04:24 -0800 (PST) Received: from localhost (fwdproxy-prn-017.fbsv.net. [2a03:2880:ff:11::face:b00c]) by smtp.gmail.com with ESMTPSA id h3-20020a17090a2ec300b002993743e4a7sm840105pjs.20.2024.02.16.21.04.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 21:04:23 -0800 (PST) From: David Wei To: Jakub Kicinski , Jiri Pirko , Sabrina Dubroca , netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Paolo Abeni Subject: [PATCH net-next v12 4/4] netdevsim: fix rtnetlink.sh selftest Date: Fri, 16 Feb 2024 21:04:18 -0800 Message-Id: <20240217050418.3125504-5-dw@davidwei.uk> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240217050418.3125504-1-dw@davidwei.uk> References: <20240217050418.3125504-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. ❯❯❯ sudo ./rtnetlink.sh PASS: policy routing PASS: route get PASS: preferred_lft addresses have expired PASS: promote_secondaries complete PASS: tc htb hierarchy PASS: gre tunnel endpoint PASS: gretap PASS: ip6gretap PASS: erspan PASS: ip6erspan PASS: bridge setup PASS: ipv6 addrlabel PASS: set ifalias 7a28dcd6-7fc3-4499-9f58-9f85d34eb328 for test-dummy0 FAIL: can't add vrf interface, skipping test FAIL: can't add macsec interface, skipping test FAIL: macsec_offload netdevsim doesn't support MACsec offload PASS: ipsec ./rtnetlink.sh: line 756: echo: write error: No space left on device PASS: ipsec_offload FAIL: bridge fdb get PASS: neigh get PASS: bridge_parent_id PASS: address proto IPv4 PASS: address proto IPv6 PASS: enslave interface in a bond 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