Skip to content

Commit 514cf64

Browse files
jpirkodavem330
authored andcommitted
netdevsim: generate random switch id instead of using dev id
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>
1 parent d514f41 commit 514cf64

3 files changed

Lines changed: 5 additions & 2 deletions

File tree

‎drivers/net/netdevsim/dev.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include <linux/debugfs.h>
1919
#include <linux/device.h>
20+
#include <linux/random.h>
2021
#include <linux/rtnetlink.h>
2122
#include <net/devlink.h>
2223

@@ -204,6 +205,8 @@ static struct nsim_dev *nsim_dev_create(struct nsim_bus_dev *nsim_bus_dev)
204205
return ERR_PTR(-ENOMEM);
205206
nsim_dev = devlink_priv(devlink);
206207
nsim_dev->nsim_bus_dev = nsim_bus_dev;
208+
nsim_dev->switch_id.id_len = sizeof(nsim_dev->switch_id.id);
209+
get_random_bytes(nsim_dev->switch_id.id, nsim_dev->switch_id.id_len);
207210

208211
nsim_dev->fib_data = nsim_fib_create();
209212
if (IS_ERR(nsim_dev->fib_data)) {

‎drivers/net/netdevsim/netdev.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ static int nsim_get_port_parent_id(struct net_device *dev,
3232
{
3333
struct netdevsim *ns = netdev_priv(dev);
3434

35-
ppid->id_len = sizeof(ns->nsim_dev->nsim_bus_dev->dev.id);
36-
memcpy(&ppid->id, &ns->nsim_dev->nsim_bus_dev->dev.id, ppid->id_len);
35+
memcpy(ppid, &ns->nsim_dev->switch_id, sizeof(*ppid));
3736
return 0;
3837
}
3938

‎drivers/net/netdevsim/netdevsim.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ struct nsim_dev {
141141
u32 prog_id_gen;
142142
struct list_head bpf_bound_progs;
143143
struct list_head bpf_bound_maps;
144+
struct netdev_phys_item_id switch_id;
144145
};
145146

146147
struct nsim_dev *

0 commit comments

Comments
 (0)