diff --git a/arch/sim/nuse-config.c b/arch/sim/nuse-config.c index 34500ed45dcd..1d1f5a872cfe 100644 --- a/arch/sim/nuse-config.c +++ b/arch/sim/nuse-config.c @@ -40,6 +40,7 @@ nuse_config_parse_interface(char *line, FILE *fp, struct nuse_config *cf) memset(vifcf, 0, sizeof(struct nuse_vif_config)); vifcf->type = NUSE_VIF_RAWSOCK; /* default */ + strcpy(vifcf->macaddr, "00:00:00:00:00:00"); /* means random */ strsplit(line, args, sizeof(args)); diff --git a/arch/sim/nuse.c b/arch/sim/nuse.c index 3b10044f49af..bdd4b010d0ad 100644 --- a/arch/sim/nuse.c +++ b/arch/sim/nuse.c @@ -4,6 +4,7 @@ #include /* struct task_struct */ #include /* struct rtentry */ #include +#include /* eth_random_addr() */ #include #include #include /* ip_route_iotcl() */ @@ -288,6 +289,15 @@ nuse_netdev_create(struct nuse_vif_config *vifcf) struct SimDevice *dev = sim_dev_create(vifcf->ifname, vif, 0); /* assign new hw address */ + if (vifcf->mac[0] == 0 && vifcf->mac[1] == 0 && vifcf->mac[2] == 0 && + vifcf->mac[3] == 0 && vifcf->mac[4] == 0 && vifcf->mac[5] == 0) { + eth_random_addr(vifcf->mac); + ((struct net_device *)dev)->addr_assign_type = NET_ADDR_RANDOM; + printf("mac address for %s is randomized ", vifcf->ifname); + printf("%02x:%02x:%02x:%02x:%02x:%02x\n", + vifcf->mac[0], vifcf->mac[1], vifcf->mac[2], + vifcf->mac[3], vifcf->mac[4], vifcf->mac[5]); + } sim_dev_set_address(dev, vifcf->mac); ether_setup((struct net_device *)dev); diff --git a/nuse.conf b/nuse.conf index 9a15056781fc..282462735621 100644 --- a/nuse.conf +++ b/nuse.conf @@ -3,13 +3,14 @@ interface eth0 address 192.168.0.10 netmask 255.255.255.0 - macaddr 00:01:01:01:01:01 +# if macaddr is not specified, random mac addr is used. viftype TAP interface p1p1 address 172.16.0.1 netmask 255.255.255.0 - macaddr 00:01:01:01:01:02 + macaddr 00:01:01:01:01:01 +# if viftype is not specified, defualt raw socket is used. route network 172.16.1.0