From: Jiri Pirko <jiri@resnulli.us>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, mlxsw@mellanox.com, jakub.kicinski@netronome.com
Subject: [patch net-next rfc 11/15] netdevsim: generate random switch id instead of using dev id
Date: Sat, 13 Apr 2019 18:21:08 +0200 [thread overview]
Message-ID: <20190413162112.8203-12-jiri@resnulli.us> (raw)
In-Reply-To: <20190413162112.8203-1-jiri@resnulli.us>
From: Jiri Pirko <jiri@mellanox.com>
Current implementation of parent_id/switch_id does not follow the
original idea of being unique. The values are "0", "1", etc. Instead of
that, generate 32 random bytes.
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
---
drivers/net/netdevsim/dev.c | 3 +++
drivers/net/netdevsim/netdev.c | 3 +--
drivers/net/netdevsim/netdevsim.h | 1 +
3 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c
index ced32c85dd73..cad96c44f885 100644
--- a/drivers/net/netdevsim/dev.c
+++ b/drivers/net/netdevsim/dev.c
@@ -17,6 +17,7 @@
#include <linux/debugfs.h>
#include <linux/device.h>
+#include <linux/random.h>
#include <linux/rtnetlink.h>
#include <net/devlink.h>
@@ -204,6 +205,8 @@ static struct nsim_dev *nsim_dev_create(struct nsim_bus_dev *nsim_bus_dev)
return ERR_PTR(-ENOMEM);
nsim_dev = devlink_priv(devlink);
nsim_dev->nsim_bus_dev = nsim_bus_dev;
+ nsim_dev->switch_id.id_len = sizeof(nsim_dev->switch_id.id);
+ get_random_bytes(nsim_dev->switch_id.id, nsim_dev->switch_id.id_len);
nsim_dev->fib_data = nsim_fib_create();
if (IS_ERR(nsim_dev->fib_data)) {
diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c
index c5f4bbb9716f..9b4310e20129 100644
--- a/drivers/net/netdevsim/netdev.c
+++ b/drivers/net/netdevsim/netdev.c
@@ -32,8 +32,7 @@ static int nsim_get_port_parent_id(struct net_device *dev,
{
struct netdevsim *ns = netdev_priv(dev);
- ppid->id_len = sizeof(ns->nsim_dev->nsim_bus_dev->dev.id);
- memcpy(&ppid->id, &ns->nsim_dev->nsim_bus_dev->dev.id, ppid->id_len);
+ memcpy(ppid, &ns->nsim_dev->switch_id, sizeof(*ppid));
return 0;
}
diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h
index 5c03d0f6d285..47c596d85519 100644
--- a/drivers/net/netdevsim/netdevsim.h
+++ b/drivers/net/netdevsim/netdevsim.h
@@ -141,6 +141,7 @@ struct nsim_dev {
u32 prog_id_gen;
struct list_head bpf_bound_progs;
struct list_head bpf_bound_maps;
+ struct netdev_phys_item_id switch_id;
};
struct nsim_dev *nsim_dev_create_with_ns(struct nsim_bus_dev *nsim_bus_dev,
--
2.17.2
next prev parent reply other threads:[~2019-04-13 16:21 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-13 16:20 [patch net-next rfc 00/15] netdevsim: impement proper device model Jiri Pirko
2019-04-13 16:20 ` [patch net-next rfc 01/15] netdevsim: move device registration on bus to be done earlier in init Jiri Pirko
2019-04-13 16:20 ` [patch net-next rfc 02/15] netdevsim: create devlink instance per netdevsim instance Jiri Pirko
2019-04-15 2:24 ` David Ahern
2019-04-15 5:41 ` Jiri Pirko
2019-04-15 15:07 ` David Ahern
2019-04-15 15:39 ` Jiri Pirko
2019-04-13 16:21 ` [patch net-next rfc 03/15] netdevsim: rename devlink.c to dev.c to contain per-dev(asic) items Jiri Pirko
2019-04-13 16:21 ` [patch net-next rfc 04/15] netdevsim: put netdevsim bus code into separate file Jiri Pirko
2019-04-14 20:27 ` David Miller
2019-04-15 5:40 ` Jiri Pirko
2019-04-13 16:21 ` [patch net-next rfc 05/15] netdevsim: move device registration and related code to bus.c Jiri Pirko
2019-04-13 16:21 ` [patch net-next rfc 06/15] netdevsim: add stub netdevsim driver implementation Jiri Pirko
2019-04-13 16:21 ` [patch net-next rfc 07/15] netdevsim: use ida for bus device ids Jiri Pirko
2019-04-13 16:21 ` [patch net-next rfc 08/15] netdevsim: add bus attributes to add new and delete devices Jiri Pirko
2019-04-13 16:21 ` [patch net-next rfc 09/15] netdevsim: rename dev_init/exit() functions and make them independent on ns Jiri Pirko
2019-04-13 16:21 ` [patch net-next rfc 10/15] netdevsim: merge sdev into dev Jiri Pirko
2019-04-15 20:49 ` Jakub Kicinski
2019-04-16 8:49 ` Jiri Pirko
2019-04-13 16:21 ` Jiri Pirko [this message]
2019-04-13 16:21 ` [patch net-next rfc 12/15] netdevsim: change debugfs tree topology Jiri Pirko
2019-04-13 16:21 ` [patch net-next rfc 13/15] netdevsim: implement dev probe/remove skeleton with port initialization Jiri Pirko
2019-04-13 16:21 ` [patch net-next rfc 14/15] netdevsim: move netdev creation/destruction to dev probe Jiri Pirko
2019-04-13 16:21 ` [patch net-next rfc 15/15] netdevsim: implement ndo_get_devlink_port Jiri Pirko
2019-04-15 19:27 ` [patch net-next rfc 00/15] netdevsim: impement proper device model Jakub Kicinski
2019-04-16 8:53 ` Jiri Pirko
2019-04-16 17:58 ` Jakub Kicinski
2019-04-16 8:59 ` Jiri Pirko
2019-04-16 18:04 ` Jakub Kicinski
2019-04-18 7:22 ` Jiri Pirko
2019-04-18 17:07 ` Jakub Kicinski
2019-04-19 5:25 ` Jiri Pirko
2019-04-19 21:00 ` Jakub Kicinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190413162112.8203-12-jiri@resnulli.us \
--to=jiri@resnulli.us \
--cc=davem@davemloft.net \
--cc=jakub.kicinski@netronome.com \
--cc=mlxsw@mellanox.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).