netdevsim: generate random switch id instead of using dev id
authorJiri Pirko <jiri@mellanox.com>
Thu, 25 Apr 2019 13:59:51 +0000 (15:59 +0200)
committerDavid S. Miller <davem@davemloft.net>
Fri, 26 Apr 2019 05:52:02 +0000 (01:52 -0400)
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>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/netdevsim/dev.c
drivers/net/netdevsim/netdev.c
drivers/net/netdevsim/netdevsim.h

index 93abd0b6c1f922d9118938277f1e688ee4c09cca..98a56d8bdcece26ba9b7ec83e3c15982e875bd68 100644 (file)
@@ -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)) {
index c5f4bbb9716f8b636beae74b6c88fdab1dfe9230..9b4310e20129d07d820647c6bad2c824c81bb35b 100644 (file)
@@ -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;
 }
 
index 4ef44a9538db20a1acc33322d65269e6b045608f..17639c7c903276789f47c9ed984f4b23fbd6cd37 100644 (file)
@@ -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 *