Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions arch/lkl/include/uapi/asm/syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ struct ustat {
#define SOCK_DCCP 6
#define SOCK_PACKET 10

#define MSG_TRUNC 0x20

/* avoid colision with system headers defines */
#define sa_handler sa_handler
#define st_atime st_atime
Expand Down
15 changes: 13 additions & 2 deletions tools/lkl/include/lkl.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,17 +245,28 @@ int lkl_set_ipv6_gateway(void* addr);
*/
struct lkl_netdev;

/**
* lkl_netdev_args - arguments to lkl_netdev_add
* @mac - optional MAC address for the device
* @offload - offload bits for the device
*/
struct lkl_netdev_args {
void *mac;
unsigned int offload;
};

/**
* lkl_netdev_add - add a new network device
*
* Must be called before calling lkl_start_kernel.
*
* @nd - the network device host handle
* @mac - optional MAC address for the device
* @args - arguments that configs the netdev. Can be NULL
* @returns a network device id (0 is valid) or a strictly negative value in
* case of error
*/
int lkl_netdev_add(struct lkl_netdev *nd, void *mac, int offload);

int lkl_netdev_add(struct lkl_netdev *nd, struct lkl_netdev_args* args);

/**
* lkl_netdevs_remove - destroy all network devices
Expand Down
9 changes: 7 additions & 2 deletions tools/lkl/lib/hijack/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ hijack_init(void)
char *debug = getenv("LKL_HIJACK_DEBUG");
char *mount = getenv("LKL_HIJACK_MOUNT");
struct lkl_netdev *nd = NULL;
struct lkl_netdev_args nd_args;
char *neigh_entries = getenv("LKL_HIJACK_NET_NEIGHBOR");
/* single_cpu mode:
* 0: Don't pin to single CPU (default).
Expand All @@ -253,6 +254,7 @@ hijack_init(void)
char *offload1 = getenv("LKL_HIJACK_OFFLOAD");
int offload = 0;

memset(&nd_args, 0, sizeof(struct lkl_netdev_args));
if (!debug) {
lkl_host_ops.print = NULL;
} else {
Expand Down Expand Up @@ -297,6 +299,7 @@ hijack_init(void)
" please use LKL_HIJACK_NET_IFTYPE and "
"LKL_HIJACK_NET_IFPARAMS instead.\n");
nd = lkl_netdev_tap_create(tap, offload);
nd_args.offload = offload;
}

if (!nd && iftype && ifparams) {
Expand Down Expand Up @@ -327,11 +330,13 @@ hijack_init(void)
fprintf(stderr, "failed to parse mac\n");
return;
} else if (ret > 0) {
ret = lkl_netdev_add(nd, mac, offload);
nd_args.mac = mac;
} else {
ret = lkl_netdev_add(nd, NULL, offload);
nd_args.mac = NULL;
}

ret = lkl_netdev_add(nd, &nd_args);

if (ret < 0) {
fprintf(stderr, "failed to add netdev: %s\n",
lkl_strerror(ret));
Expand Down
2 changes: 0 additions & 2 deletions tools/lkl/lib/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,6 @@ int lkl_netdev_get_ifindex(int id)
return ret < 0 ? ret : ifr.lkl_ifr_ifindex;
}

#define LKL_MSG_TRUNC 0x20

// Copied from iproute2/lib/libnetlink.c
static unsigned int seq = 0;
static int rtnl_talk(int fd, struct lkl_nlmsghdr *n)
Expand Down
16 changes: 9 additions & 7 deletions tools/lkl/lib/virtio_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ static struct lkl_mutex **init_queue_locks(int num_queues)
return ret;
}

int lkl_netdev_add(struct lkl_netdev *nd, void *mac, int offload)
int lkl_netdev_add(struct lkl_netdev *nd, struct lkl_netdev_args* args)
{
struct virtio_net_dev *dev;
int ret = -LKL_ENOMEM;
Expand All @@ -214,9 +214,14 @@ int lkl_netdev_add(struct lkl_netdev *nd, void *mac, int offload)
memset(dev, 0, sizeof(*dev));

dev->dev.device_id = LKL_VIRTIO_ID_NET;
if (mac)
dev->dev.device_features |= BIT(LKL_VIRTIO_NET_F_MAC);
dev->dev.device_features |= offload;
if (args) {
if (args->mac) {
dev->dev.device_features |= BIT(LKL_VIRTIO_NET_F_MAC);
memcpy(dev->config.mac, args->mac, LKL_ETH_ALEN);
}
dev->dev.device_features |= args->offload;

}
dev->dev.config_data = &dev->config;
dev->dev.config_len = sizeof(dev->config);
dev->dev.ops = &net_ops;
Expand All @@ -227,9 +232,6 @@ int lkl_netdev_add(struct lkl_netdev *nd, void *mac, int offload)
if (!dev->queue_locks)
goto out_free;

if (mac)
memcpy(dev->config.mac, mac, LKL_ETH_ALEN);

dev->rx_poll.event = LKL_DEV_NET_POLL_RX;
dev->rx_poll.dev = dev;

Expand Down
2 changes: 2 additions & 0 deletions tools/lkl/lib/virtio_net_linux_fdnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ struct lkl_netdev_linux_fdnet *lkl_register_netdev_linux_fdnet(int fd)
return NULL;
}

memset(nd, 0, sizeof(struct lkl_netdev_linux_fdnet));

nd->fd = fd;
/* Making them edge-triggered to save CPU. */
nd->epoll_rx_fd = create_epoll_fd(nd->fd, EPOLLIN | EPOLLPRI | EPOLLET);
Expand Down
2 changes: 1 addition & 1 deletion tools/lkl/tests/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ int test_netdev_add(char *str, int len)
if (!netdev)
goto out;

ret = lkl_netdev_add((struct lkl_netdev *)netdev, NULL, 0);
ret = lkl_netdev_add((struct lkl_netdev *)netdev, NULL);
if (ret < 0)
goto out;

Expand Down
2 changes: 1 addition & 1 deletion tools/lkl/tests/net-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ static int test_net_init(int argc, char **argv)
return -1;
}

ret = lkl_netdev_add(nd, NULL, 0);
ret = lkl_netdev_add(nd, NULL);
if (ret < 0) {
fprintf(stderr, "failed to add netdev: %s\n",
lkl_strerror(ret));
Expand Down