Skip to content

Commit

Permalink
fix the issue #2. default mac addr is filled by eth_random_addr()
Browse files Browse the repository at this point in the history
  • Loading branch information
upa committed Nov 25, 2014
1 parent 3b87a2f commit 74b7b7d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions arch/sim/nuse-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
10 changes: 10 additions & 0 deletions arch/sim/nuse.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <linux/sched.h> /* struct task_struct */
#include <uapi/linux/route.h> /* struct rtentry */
#include <linux/netdevice.h>
#include <linux/etherdevice.h> /* eth_random_addr() */
#include <linux/inetdevice.h>
#include <net/route.h>
#include <net/ipconfig.h> /* ip_route_iotcl() */
Expand Down Expand Up @@ -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);

Expand Down
5 changes: 3 additions & 2 deletions nuse.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 74b7b7d

Please sign in to comment.