Skip to content

Commit

Permalink
executor: create netdevsim device
Browse files Browse the repository at this point in the history
Create testing netdevsim instance with 4 ports.

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
  • Loading branch information
jpirko authored and dvyukov committed Oct 25, 2019
1 parent d01bb02 commit 5b49e1f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions executor/common_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,14 @@ static void initialize_tun(void)
#define DEV_IPV6 "fe80::%02x"
#define DEV_MAC 0x00aaaaaaaaaa

static void netdevsim_add(unsigned int addr, unsigned int port_count)
{
char buf[16];

sprintf(buf, "%u %u", addr, port_count);
write_file("/sys/bus/netdevsim/new_device", buf);
}

// We test in a separate namespace, which does not have any network devices initially (even lo).
// Create/up as many as we can.
static void initialize_netdevices(void)
Expand Down Expand Up @@ -570,6 +578,8 @@ static void initialize_netdevices(void)
netlink_device_change(sock, "hsr_slave_0", true, 0, 0, 0);
netlink_device_change(sock, "hsr_slave_1", true, 0, 0, 0);

netdevsim_add((int)procid, 4);

for (i = 0; i < sizeof(devices) / (sizeof(devices[0])); i++) {
// Assign some unique address to devices. Some devices won't up without this.
// Shift addresses by 10 because 0 subnet address can mean special things.
Expand Down
10 changes: 10 additions & 0 deletions pkg/csource/generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -1451,6 +1451,14 @@ static void initialize_tun(void)
#define DEV_IPV4 "172.20.20.%d"
#define DEV_IPV6 "fe80::%02x"
#define DEV_MAC 0x00aaaaaaaaaa
static void netdevsim_add(unsigned int addr, unsigned int port_count)
{
char buf[16];
sprintf(buf, "%u %u", addr, port_count);
write_file("/sys/bus/netdevsim/new_device", buf);
}
static void initialize_netdevices(void)
{
#if SYZ_EXECUTOR
Expand Down Expand Up @@ -1541,6 +1549,8 @@ static void initialize_netdevices(void)
netlink_device_change(sock, "hsr_slave_0", true, 0, 0, 0);
netlink_device_change(sock, "hsr_slave_1", true, 0, 0, 0);
netdevsim_add((int)procid, 4);
for (i = 0; i < sizeof(devices) / (sizeof(devices[0])); i++) {
char addr[32];
sprintf(addr, DEV_IPV4, i + 10);
Expand Down

0 comments on commit 5b49e1f

Please sign in to comment.