Skip to content

Commit

Permalink
Merge pull request torvalds#197 from liuyuan10/ipv6
Browse files Browse the repository at this point in the history
 lkl: Fix ipv6 netperf failure
  • Loading branch information
Octavian Purdila authored Aug 14, 2016
2 parents e99de6d + 255bfc8 commit 7826756
Show file tree
Hide file tree
Showing 7 changed files with 305 additions and 168 deletions.
8 changes: 8 additions & 0 deletions tools/lkl/include/lkl.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ int lkl_set_ipv4_gateway(unsigned int addr);

/**
* lkl_if_set_ipv6 - set IPv6 address on interface
* must be called after interface is up.
*
* @ifindex - the ifindex of the interface
* @addr - 16-byte IPv6 address (i.e., struct in6_addr)
Expand Down Expand Up @@ -369,6 +370,13 @@ void lkl_register_dbg_handler();
*/
int lkl_add_neighbor(int ifindex, int af, void* addr, void* mac);

/**
* lkl_mount_fs - mount a file system type like proc, sys
* @fstype - file system type. e.g. proc, sys
* @returns - 0 on success. 1 if it's already mounted. negative on failure.
*/
int lkl_mount_fs(char *fstype);

#ifdef __cplusplus
}
#endif
Expand Down
27 changes: 4 additions & 23 deletions tools/lkl/lib/dbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,36 +143,17 @@ static void cd() {

static void mount() {
char* fstype;
char dir[MAX_BUF] = "/";
int flags = 0, ret = 0;
int ret = 0;

if (argc != 1) {
fprintf(stderr, "%s\n", "One argument is needed.");
return;
}

fstype = argv[0];
strncat(dir, fstype, MAX_BUF - 1);

/* Create with regular umask */
ret = lkl_sys_mkdir(dir, 0xff);
if (ret) {
fprintf(stderr, "mount mkdir %s: %s\n", dir,
lkl_strerror(ret));
return;
}

ret = lkl_sys_mount(dir, dir, fstype, flags, NULL);
if (ret) {
fprintf(stderr, "mount mount %s as %s: %s\n",
dir, fstype, strerror(ret));
ret = lkl_sys_rmdir(dir);
if (ret) {
fprintf(stderr, "mount rmdir %s: %s\n",
dir, strerror(ret));
}
return;
}
ret = lkl_mount_fs(fstype);
if (ret == 1)
fprintf(stderr, "%s is already mounted.\n", fstype);
}

static void cat() {
Expand Down
40 changes: 24 additions & 16 deletions tools/lkl/lib/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,46 @@
#include <string.h>
#include <lkl_host.h>

long lkl_mount_sysfs(void)
#define MAX_FSTYPE_LEN 50
int lkl_mount_fs(char *fstype)
{
long ret;
static int sysfs_mounted;
char dir[MAX_FSTYPE_LEN+2] = "/";
int flags = 0, ret = 0;

if (sysfs_mounted)
return 0;
strncat(dir, fstype, MAX_FSTYPE_LEN);

ret = lkl_sys_mkdir("/sys", 0700);
if (ret)
/* Create with regular umask */
ret = lkl_sys_mkdir(dir, 0xff);
if (ret && ret != -LKL_EEXIST) {
lkl_perror("mount_fs mkdir", ret);
return ret;
}

ret = lkl_sys_mount("none", "sys", "sysfs", 0, NULL);

if (ret == 0)
sysfs_mounted = 1;
/* We have no use for nonzero flags right now */
ret = lkl_sys_mount("none", dir, fstype, flags, NULL);
if (ret && ret != -LKL_EBUSY) {
lkl_sys_rmdir(dir);
return ret;
}

return ret;
if (ret == -LKL_EBUSY)
return 1;
return 0;
}

static long get_virtio_blkdev(int disk_id)
{
char sysfs_path[] = "/sys/block/vda/dev";
char sysfs_path[] = "/sysfs/block/vda/dev";
char buf[16] = { 0, };
long fd, ret;
int major, minor;

ret = lkl_mount_sysfs();
if (ret)

ret = lkl_mount_fs("sysfs");
if (ret < 0)
return ret;

sysfs_path[strlen("/sys/block/vd")] += disk_id;
sysfs_path[strlen("/sysfs/block/vd")] += disk_id;

fd = lkl_sys_open(sysfs_path, LKL_O_RDONLY, 0);
if (fd < 0)
Expand Down
41 changes: 6 additions & 35 deletions tools/lkl/lib/hijack/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,48 +137,19 @@ static int dump_file(char *path)
return 0;
}

/* For simplicity, if we want to mount a filesystem of a particular
* type, we'll create a directory under / with the name of the type;
* e.g. we'll have our sysfs as /sysfs */
static int mount_fs(char *fstype)
{
char dir[MAX_FSTYPE_LEN] = "/";
int flags = 0, ret = 0;

strncat(dir, fstype, MAX_FSTYPE_LEN - 1);

/* Create with regular umask */
ret = lkl_sys_mkdir(dir, 0xff);
if (ret) {
fprintf(stderr, "mount_fs mkdir %s: %s\n", dir,
lkl_strerror(ret));
return -1;
}

/* We have no use for nonzero flags right now */
ret = lkl_sys_mount(dir, dir, fstype, flags, NULL);
if (ret) {
fprintf(stderr, "mount_fs mount %s as %s: %s\n",
dir, fstype, strerror(ret));
return -1;
}

return 0;
}

static void mount_cmds_exec(char *_cmds, int (*callback)(char*))
{
char *saveptr = NULL, *token;
int ret = 0;
char *cmds = strdup(_cmds);
token = strtok_r(cmds, ",", &saveptr);

while (token && !ret) {
while (token && ret >= 0) {
ret = callback(token);
token = strtok_r(NULL, ",", &saveptr);
}

if (ret)
if (ret < 0)
fprintf(stderr, "mount_cmds_exec: failed parsing %s\n", _cmds);

free(cmds);
Expand Down Expand Up @@ -417,13 +388,13 @@ hijack_init(void)
}

if (nd_ifindex >= 0 && ipv6 && netmask6_len) {
char addr[16];
struct in6_addr addr;
unsigned int pflen = atoi(netmask6_len);

if (inet_pton(AF_INET6, ipv6, addr) != 1) {
if (inet_pton(AF_INET6, ipv6, &addr) != 1) {
fprintf(stderr, "Invalid ipv6 addr: %s\n", ipv6);
} else {
ret = lkl_if_set_ipv6(nd_ifindex, addr, pflen);
ret = lkl_if_set_ipv6(nd_ifindex, &addr, pflen);
if (ret < 0)
fprintf(stderr, "failed to set IPv6address: %s\n",
lkl_strerror(ret));
Expand All @@ -444,7 +415,7 @@ hijack_init(void)
}

if (mount)
mount_cmds_exec(mount, mount_fs);
mount_cmds_exec(mount, lkl_mount_fs);

if (nd_ifindex >=0 && neigh_entries)
add_neighbor(nd_ifindex, neigh_entries);
Expand Down
Loading

0 comments on commit 7826756

Please sign in to comment.