[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <v4zcjfsyv3iffd35wf5hflsjzyug5gwyoartisttyvwt3glufz@5a2ato6hmob2>
Date: Mon, 17 Feb 2025 14:11:48 +0100
From: Jiri Pirko <jiri@...nulli.us>
To: Toke Høiland-Jørgensen <toke@...hat.com>
Cc: Jakub Kicinski <kuba@...nel.org>, Andrew Lunn <andrew+netdev@...n.ch>,
"David S. Miller" <davem@...emloft.net>, Eric Dumazet <edumazet@...gle.com>,
Paolo Abeni <pabeni@...hat.com>, netdev@...r.kernel.org
Subject: Re: [PATCH net-next] net: netdevsim: Support setting dev->perm_addr
Mon, Feb 03, 2025 at 06:21:24PM +0100, toke@...hat.com wrote:
>Network management daemons that match on the device permanent address
>currently have no virtual interface types to test against.
>NetworkManager, in particular, has carried an out of tree patch to set
>the permanent address on netdevsim devices to use in its CI for this
>purpose.
>
>To support this use case, add a debugfs file for netdevsim to set the
>permanent address to an arbitrary value.
>
>Signed-off-by: Toke Høiland-Jørgensen <toke@...hat.com>
>---
> drivers/net/netdevsim/netdev.c | 44 +++++++++++++++++++++++++++++++++++++++
> drivers/net/netdevsim/netdevsim.h | 1 +
> 2 files changed, 45 insertions(+)
>
>diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c
>index 42f247cbdceecbadf27f7090c030aa5bd240c18a..3a7fcc32901c754eadf7d6ea43cd0ddc29586cf9 100644
>--- a/drivers/net/netdevsim/netdev.c
>+++ b/drivers/net/netdevsim/netdev.c
>@@ -782,6 +782,47 @@ static const struct file_operations nsim_qreset_fops = {
> .owner = THIS_MODULE,
> };
>
>+static ssize_t
>+nsim_permaddr_write(struct file *file, const char __user *data,
>+ size_t count, loff_t *ppos)
>+{
>+ struct netdevsim *ns = file->private_data;
>+ u8 eth_addr[ETH_ALEN];
>+ char buf[32];
>+ ssize_t ret;
>+
>+ if (count >= sizeof(buf))
>+ return -EINVAL;
>+ if (copy_from_user(buf, data, count))
>+ return -EFAULT;
>+ buf[count] = '\0';
>+
>+ ret = sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
>+ ð_addr[0], ð_addr[1], ð_addr[2],
>+ ð_addr[3], ð_addr[4], ð_addr[5]);
>+ if (ret != 6)
>+ return -EINVAL;
>+
>+ rtnl_lock();
>+ if (netif_running(ns->netdev)) {
>+ ret = -EBUSY;
>+ goto exit_unlock;
>+ }
>+
>+ memcpy(ns->netdev->perm_addr, eth_addr, sizeof(eth_addr));
>+
>+ ret = count;
>+exit_unlock:
>+ rtnl_unlock();
>+ return ret;
>+}
>+
>+static const struct file_operations nsim_permaddr_fops = {
>+ .open = simple_open,
>+ .write = nsim_permaddr_write,
>+ .owner = THIS_MODULE,
>+};
Well, hwaddr is not a runtime config, it's rather provisioning time
config. I believe the best fit would be to put it to new_device_store()
or new_port_store().
We already implement couple of things there in new_device_store(), like
port count and number of queues.
>+
> static ssize_t
> nsim_pp_hold_read(struct file *file, char __user *data,
> size_t count, loff_t *ppos)
>@@ -997,6 +1038,9 @@ nsim_create(struct nsim_dev *nsim_dev, struct nsim_dev_port *nsim_dev_port)
> ns->qr_dfs = debugfs_create_file("queue_reset", 0200,
> nsim_dev_port->ddir, ns,
> &nsim_qreset_fops);
>+ ns->permaddr_dfs = debugfs_create_file("perm_addr", 0200,
>+ nsim_dev_port->ddir, ns,
>+ &nsim_permaddr_fops);
>
> return ns;
>
>diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h
>index dcf073bc4802e7f7f8c14a2b8d94d24cd31f1f7b..fffec5dbf80759240a323f7c3630c79c5c68faec 100644
>--- a/drivers/net/netdevsim/netdevsim.h
>+++ b/drivers/net/netdevsim/netdevsim.h
>@@ -140,6 +140,7 @@ struct netdevsim {
> struct page *page;
> struct dentry *pp_dfs;
> struct dentry *qr_dfs;
>+ struct dentry *permaddr_dfs;
>
> struct nsim_ethtool ethtool;
> struct netdevsim __rcu *peer;
>
>---
>base-commit: 0ad9617c78acbc71373fb341a6f75d4012b01d69
>change-id: 20250128-netdevsim-perm_addr-5fca47a08157
>
>
Powered by blists - more mailing lists