From 309bebc9b3eccc48c8d58e91dd39c5ebba4ed1e2 Mon Sep 17 00:00:00 2001 From: Yuan Liu Date: Mon, 8 Aug 2016 18:00:37 -0700 Subject: [PATCH 1/2] lkl: add lkl_mount_fs A lot of configs have to be done through /proc. Having it can make it easier Signed-off-by: Yuan Liu --- tools/lkl/include/lkl.h | 7 +++++++ tools/lkl/lib/dbg.c | 27 ++++--------------------- tools/lkl/lib/fs.c | 40 ++++++++++++++++++++++--------------- tools/lkl/lib/hijack/init.c | 35 +++----------------------------- 4 files changed, 38 insertions(+), 71 deletions(-) diff --git a/tools/lkl/include/lkl.h b/tools/lkl/include/lkl.h index c77f2d9a8635fa..67a26d832092a7 100644 --- a/tools/lkl/include/lkl.h +++ b/tools/lkl/include/lkl.h @@ -369,6 +369,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 diff --git a/tools/lkl/lib/dbg.c b/tools/lkl/lib/dbg.c index 077311f1be68e8..70dcec7254c908 100644 --- a/tools/lkl/lib/dbg.c +++ b/tools/lkl/lib/dbg.c @@ -143,8 +143,7 @@ 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."); @@ -152,27 +151,9 @@ static void mount() { } 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() { diff --git a/tools/lkl/lib/fs.c b/tools/lkl/lib/fs.c index c0d9f1c2a16b3f..866059f8f24c5d 100644 --- a/tools/lkl/lib/fs.c +++ b/tools/lkl/lib/fs.c @@ -2,38 +2,46 @@ #include #include -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) diff --git a/tools/lkl/lib/hijack/init.c b/tools/lkl/lib/hijack/init.c index 97bf29cdee9304..155b5621eeb6c7 100644 --- a/tools/lkl/lib/hijack/init.c +++ b/tools/lkl/lib/hijack/init.c @@ -137,35 +137,6 @@ 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; @@ -173,12 +144,12 @@ static void mount_cmds_exec(char *_cmds, int (*callback)(char*)) 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); @@ -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); From 255bfc83b75c5753bdb9c30865e9f5f6ff6a28f5 Mon Sep 17 00:00:00 2001 From: Yuan Liu Date: Tue, 9 Aug 2016 15:35:23 -0700 Subject: [PATCH 2/2] lkl: Fix ipv6 netperf failure ipv6 address is in state tentative until Duplicate Address Detection (DAD) is done. So netperf can't get the correct ip address on LKL startup. Fixed by waiting for netlink msg Signed-off-by: Yuan Liu --- tools/lkl/include/lkl.h | 1 + tools/lkl/lib/hijack/init.c | 6 +- tools/lkl/lib/net.c | 330 +++++++++++++++++++++++++-------- tools/lkl/tests/hijack-test.sh | 21 ++- tools/lkl/tests/run_netperf.sh | 6 +- 5 files changed, 267 insertions(+), 97 deletions(-) diff --git a/tools/lkl/include/lkl.h b/tools/lkl/include/lkl.h index 67a26d832092a7..139f3081e8da7c 100644 --- a/tools/lkl/include/lkl.h +++ b/tools/lkl/include/lkl.h @@ -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) diff --git a/tools/lkl/lib/hijack/init.c b/tools/lkl/lib/hijack/init.c index 155b5621eeb6c7..304ae27eb0bf2e 100644 --- a/tools/lkl/lib/hijack/init.c +++ b/tools/lkl/lib/hijack/init.c @@ -388,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)); diff --git a/tools/lkl/lib/net.c b/tools/lkl/lib/net.c index b075acc96f9526..52860c41b3d115 100644 --- a/tools/lkl/lib/net.c +++ b/tools/lkl/lib/net.c @@ -143,27 +143,6 @@ int lkl_set_ipv4_gateway(unsigned int addr) return err; } -int lkl_if_set_ipv6(int ifindex, void* addr, unsigned int netprefix_len) -{ - struct lkl_in6_ifreq ifr6; - int err, sock; - - if (netprefix_len >= 128) - return -LKL_EINVAL; - - sock = lkl_sys_socket(LKL_AF_INET6, LKL_SOCK_DGRAM, 0); - if (sock < 0) - return sock; - - memcpy(&ifr6.ifr6_addr.lkl_s6_addr, addr, sizeof(struct lkl_in6_addr)); - ifr6.ifr6_ifindex = ifindex; - ifr6.ifr6_prefixlen = netprefix_len; - - err = lkl_sys_ioctl(sock, LKL_SIOCSIFADDR, (long)&ifr6); - lkl_sys_close(sock); - return err; -} - int lkl_set_ipv6_gateway(void* addr) { int err, sock; @@ -197,30 +176,121 @@ int lkl_netdev_get_ifindex(int id) return ret < 0 ? ret : ifr.lkl_ifr_ifindex; } -// Copied from iproute2/lib/libnetlink.c -static unsigned int seq = 0; -static int rtnl_talk(int fd, struct lkl_nlmsghdr *n) +static int netlink_sock(unsigned int groups) { - int status; - struct lkl_nlmsghdr *h; - struct lkl_sockaddr_nl nladdr = {.nl_family = LKL_AF_NETLINK}; - struct lkl_iovec iov = {.iov_base = (void *)n, .iov_len = n->nlmsg_len}; - struct lkl_user_msghdr msg = { - .msg_name = &nladdr, - .msg_namelen = sizeof(nladdr), - .msg_iov = &iov, - .msg_iovlen = 1, - }; - char buf[32768] = {}; + struct lkl_sockaddr_nl la; + int fd, err; - n->nlmsg_seq = seq; - n->nlmsg_flags |= LKL_NLM_F_ACK; + fd = lkl_sys_socket(LKL_AF_NETLINK, LKL_SOCK_DGRAM, LKL_NETLINK_ROUTE); + if (fd < 0) + return fd; - status = lkl_sys_sendmsg(fd, &msg, 0); - if (status < 0) { - lkl_perror("Cannot talk to rtnetlink", status); + memset(&la, 0, sizeof(la)); + la.nl_family = LKL_AF_NETLINK; + la.nl_groups = groups; + err = lkl_sys_bind(fd, (struct lkl_sockaddr *)&la, sizeof(la)); + if (err < 0) + return err; + + return fd; +} + +static int parse_rtattr(struct lkl_rtattr *tb[], int max, + struct lkl_rtattr *rta, int len) +{ + unsigned short type; + + memset(tb, 0, sizeof(struct lkl_rtattr *) * (max + 1)); + while (LKL_RTA_OK(rta, len)) { + type = rta->rta_type; + if ((type <= max) && (!tb[type])) + tb[type] = rta; + rta = LKL_RTA_NEXT(rta, len); + } + if (len) + lkl_printf( "!!!Deficit %d, rta_len=%d\n", len, + rta->rta_len); + return 0; +} + +struct addr_filter { + unsigned int ifindex; + void *addr; +}; + +static unsigned int get_ifa_flags(struct lkl_ifaddrmsg *ifa, + struct lkl_rtattr *ifa_flags_attr) +{ + return ifa_flags_attr ? *(unsigned int *)LKL_RTA_DATA(ifa_flags_attr) : + ifa->ifa_flags; +} + +/* returns: + * 0 - dad succeed. + * -1 - dad failed or other error. + * 1 - should wait for new msg. + */ +static int check_ipv6_dad(struct lkl_sockaddr_nl *nladdr, + struct lkl_nlmsghdr *n, void *arg) +{ + struct addr_filter *filter = arg; + struct lkl_ifaddrmsg *ifa = LKL_NLMSG_DATA(n); + struct lkl_rtattr *rta_tb[LKL_IFA_MAX+1]; + unsigned int ifa_flags; + int len = n->nlmsg_len; + + if (n->nlmsg_type != LKL_RTM_NEWADDR) + return 1; + + len -= LKL_NLMSG_LENGTH(sizeof(*ifa)); + if (len < 0) { + lkl_printf( "BUG: wrong nlmsg len %d\n", len); + return -1; + } + + parse_rtattr(rta_tb, LKL_IFA_MAX, LKL_IFA_RTA(ifa), + n->nlmsg_len - LKL_NLMSG_LENGTH(sizeof(*ifa))); + + ifa_flags = get_ifa_flags(ifa, rta_tb[LKL_IFA_FLAGS]); + + if (ifa->ifa_index != filter->ifindex) + return 1; + if (ifa->ifa_family != LKL_AF_INET6) + return 1; + + if (!rta_tb[LKL_IFA_LOCAL]) + rta_tb[LKL_IFA_LOCAL] = rta_tb[LKL_IFA_ADDRESS]; + + if (!rta_tb[LKL_IFA_LOCAL] || + (filter->addr && memcmp(LKL_RTA_DATA(rta_tb[LKL_IFA_LOCAL]), + filter->addr, 16))) { + return 1; + } + if (ifa_flags & LKL_IFA_F_DADFAILED) { + lkl_printf( "IPV6 DAD failed.\n"); return -1; } + if (!(ifa_flags & LKL_IFA_F_TENTATIVE)) + return 0; + return 1; +} + +/* Copied from iproute2/lib/ */ +static int rtnl_listen(int fd, int (*handler)(struct lkl_sockaddr_nl *nladdr, + struct lkl_nlmsghdr *, void *), + void *arg) +{ + int status; + struct lkl_nlmsghdr *h; + struct lkl_sockaddr_nl nladdr = { .nl_family = LKL_AF_NETLINK }; + struct lkl_iovec iov; + struct lkl_user_msghdr msg = { + .msg_name = &nladdr, + .msg_namelen = sizeof(nladdr), + .msg_iov = &iov, + .msg_iovlen = 1, + }; + char buf[16384]; iov.iov_base = buf; while (1) { @@ -230,100 +300,197 @@ static int rtnl_talk(int fd, struct lkl_nlmsghdr *n) if (status < 0) { if (status == -LKL_EINTR || status == -LKL_EAGAIN) continue; - lkl_perror("netlink receive error \n", status); + lkl_printf( "netlink receive error %s (%d)\n", + lkl_strerror(status), status); + if (status == -LKL_ENOBUFS) + continue; return status; } if (status == 0) { - fprintf(stderr, "EOF on netlink\n"); + lkl_printf( "EOF on netlink\n"); return -1; } if (msg.msg_namelen != sizeof(nladdr)) { - fprintf(stderr, "sender address length == %d\n", + lkl_printf( "Sender address length == %d\n", msg.msg_namelen); return -1; } - for (h = (struct lkl_nlmsghdr *)buf; status >= (int)sizeof(*h);) { + + for (h = (struct lkl_nlmsghdr *)buf; + (unsigned int)status >= sizeof(*h);) { + int err; int len = h->nlmsg_len; int l = len - sizeof(*h); if (l < 0 || len > status) { if (msg.msg_flags & LKL_MSG_TRUNC) { - fprintf(stderr, "Truncated message\n"); + lkl_printf( "Truncated message\n"); return -1; } - fprintf(stderr, "!!!malformed message: len=%d\n", + lkl_printf( "!!!malformed message: len=%d\n", len); return -1; } - if (nladdr.nl_pid != 0 || h->nlmsg_seq != seq++) { - /* Don't forget to skip that message. */ - status -= LKL_NLMSG_ALIGN(len); - h = (struct lkl_nlmsghdr *)((char *)h + - LKL_NLMSG_ALIGN(len)); - continue; - } - if (h->nlmsg_type == LKL_NLMSG_ERROR) { - struct lkl_nlmsgerr *err = - (struct lkl_nlmsgerr *)LKL_NLMSG_DATA(h); - if (l < (int)sizeof(struct lkl_nlmsgerr)) { - fprintf(stderr, "ERROR truncated\n"); - } else if (!err->error) { - return 0; - } - fprintf(stderr, "RTNETLINK answers: %s\n", - strerror(-err->error)); - return -1; - } - - fprintf(stderr, "Unexpected reply!!!\n"); + err = handler(&nladdr, h, arg); + if (err <= 0) + return err; status -= LKL_NLMSG_ALIGN(len); h = (struct lkl_nlmsghdr *)((char *)h + - LKL_NLMSG_ALIGN(len)); + LKL_NLMSG_ALIGN(len)); } - if (msg.msg_flags & LKL_MSG_TRUNC) { - fprintf(stderr, "Message truncated\n"); + lkl_printf( "Message truncated\n"); continue; } - if (status) { - fprintf(stderr, "!!!Remnant of size %d\n", status); + lkl_printf( "!!!Remnant of size %d\n", status); return -1; } } } +static int wait_ipv6(int ifindex, void *addr) +{ + struct addr_filter filter = {.ifindex = ifindex, .addr = addr}; + int fd, ret; + struct { + struct lkl_nlmsghdr nlmsg_info; + struct lkl_ifaddrmsg ifaddrmsg_info; + } req; + + fd = netlink_sock(1 << (LKL_RTNLGRP_IPV6_IFADDR - 1)); + if (fd < 0) + return fd; + + memset(&req, 0, sizeof(req)); + req.nlmsg_info.nlmsg_len = + LKL_NLMSG_LENGTH(sizeof(struct lkl_ifaddrmsg)); + req.nlmsg_info.nlmsg_flags = LKL_NLM_F_REQUEST | LKL_NLM_F_DUMP; + req.nlmsg_info.nlmsg_type = LKL_RTM_GETADDR; + req.ifaddrmsg_info.ifa_family = LKL_AF_INET6; + req.ifaddrmsg_info.ifa_index = ifindex; + ret = lkl_sys_send(fd, &req, req.nlmsg_info.nlmsg_len, 0); + if (ret < 0) { + lkl_perror("lkl_sys_send", ret); + return ret; + } + ret = rtnl_listen(fd, check_ipv6_dad, (void *)&filter); + lkl_sys_close(fd); + return ret; +} + +int lkl_if_set_ipv6(int ifindex, void *addr, unsigned int netprefix_len) +{ + struct lkl_in6_ifreq ifr6; + int err, sock; + + if (netprefix_len >= 128) + return -LKL_EINVAL; + + sock = lkl_sys_socket(LKL_AF_INET6, LKL_SOCK_DGRAM, 0); + if (sock < 0) + return sock; + + memcpy(&ifr6.ifr6_addr.lkl_s6_addr, addr, sizeof(struct lkl_in6_addr)); + ifr6.ifr6_ifindex = ifindex; + ifr6.ifr6_prefixlen = netprefix_len; + + err = lkl_sys_ioctl(sock, LKL_SIOCSIFADDR, (long)&ifr6); + lkl_sys_close(sock); + if (err) + return err; + + err = wait_ipv6(ifindex, addr); + return err; +} + +/* returns: + * 0 - succeed. + * -1 - error. + * 1 - should wait for new msg. + */ +static int check_error(struct lkl_sockaddr_nl *nladdr, struct lkl_nlmsghdr *n, + void *arg) +{ + unsigned int s = *(unsigned int *)arg; + + if (nladdr->nl_pid != 0 || n->nlmsg_seq != s) { + /* Don't forget to skip that message. */ + return 1; + } + + if (n->nlmsg_type == LKL_NLMSG_ERROR) { + struct lkl_nlmsgerr *err = + (struct lkl_nlmsgerr *)LKL_NLMSG_DATA(n); + int l = n->nlmsg_len - sizeof(*n); + + if (l < (int)sizeof(struct lkl_nlmsgerr)) + lkl_printf( "ERROR truncated\n"); + else if (!err->error) + return 0; + + lkl_printf( "RTNETLINK answers: %s\n", + strerror(-err->error)); + return -1; + } + lkl_printf( "Unexpected reply!!!\n"); + return -1; +} + +static unsigned int seq; +static int rtnl_talk(int fd, struct lkl_nlmsghdr *n) +{ + int status; + struct lkl_sockaddr_nl nladdr = {.nl_family = LKL_AF_NETLINK}; + struct lkl_iovec iov = {.iov_base = (void *)n, .iov_len = n->nlmsg_len}; + struct lkl_user_msghdr msg = { + .msg_name = &nladdr, + .msg_namelen = sizeof(nladdr), + .msg_iov = &iov, + .msg_iovlen = 1, + }; + + n->nlmsg_seq = seq; + n->nlmsg_flags |= LKL_NLM_F_ACK; + + status = lkl_sys_sendmsg(fd, &msg, 0); + if (status < 0) { + lkl_perror("Cannot talk to rtnetlink", status); + return status; + } + + status = rtnl_listen(fd, check_error, (void *)&seq); + seq++; + return status; +} + int lkl_add_neighbor(int ifindex, int af, void* ip, void* mac) { - struct lkl_sockaddr_nl la; struct { struct lkl_nlmsghdr n; struct lkl_ndmsg r; char buf[1024]; } req2; - int err, addr_sz, fd; + int err, addr_sz; int ndmsglen = LKL_NLMSG_LENGTH(sizeof(struct lkl_ndmsg)); struct lkl_rtattr *dstattr; + int fd; if (af == LKL_AF_INET) addr_sz = 4; else if (af == LKL_AF_INET6) addr_sz = 16; else { - fprintf(stderr, "Bad address family: %d\n", af); + lkl_printf( "Bad address family: %d\n", af); return -1; } - fd = lkl_sys_socket(LKL_AF_NETLINK, LKL_SOCK_DGRAM, LKL_NETLINK_ROUTE); + + fd = netlink_sock(0); if (fd < 0) return fd; - memset(&la, 0, sizeof(la)); - la.nl_family = LKL_AF_NETLINK; - err = lkl_sys_bind(fd, (struct lkl_sockaddr *)&la, sizeof(la)); - if (err < 0) goto exit; - memset(&req2, 0, sizeof(req2)); // create the IP attribute @@ -353,7 +520,6 @@ int lkl_add_neighbor(int ifindex, int af, void* ip, void* mac) err = rtnl_talk(fd, &req2.n); -exit: lkl_sys_close(fd); return err; } diff --git a/tools/lkl/tests/hijack-test.sh b/tools/lkl/tests/hijack-test.sh index c9c9b0910e12b8..866cb1fa012563 100755 --- a/tools/lkl/tests/hijack-test.sh +++ b/tools/lkl/tests/hijack-test.sh @@ -68,24 +68,24 @@ export LKL_HIJACK_NET_IFPARAMS=lkl_ptt0 export LKL_HIJACK_NET_IP=192.168.13.2 export LKL_HIJACK_NET_NETMASK_LEN=24 export LKL_HIJACK_NET_GATEWAY=192.168.13.1 -export LKL_HIJACK_NET_IPV6=2001:db8:0:f102::2 +export LKL_HIJACK_NET_IPV6=fc03::2 export LKL_HIJACK_NET_NETMASK6_LEN=64 -export LKL_HIJACK_NET_GATEWAY6=2001:db8:0:f102::1 +export LKL_HIJACK_NET_GATEWAY6=fc03::1 # Set up the TAP device we'd like to use sudo ip tuntap del dev lkl_ptt0 mode tap || true sudo ip tuntap add dev lkl_ptt0 mode tap user $USER sudo ip link set dev lkl_ptt0 up sudo ip addr add dev lkl_ptt0 192.168.13.1/24 -sudo ip -6 addr add dev lkl_ptt0 2001:db8:0:f102::1/64 +sudo ip -6 addr add dev lkl_ptt0 fc03::1/64 # Make sure our device has the addresses we expect addr=$(LKL_HIJACK_DEBUG=1\ - LKL_HIJACK_NET_MAC="aa:bb:cc:dd:ee:ff" ${hijack_script} ip addr) + LKL_HIJACK_NET_MAC="aa:bb:cc:dd:ee:ff" ${hijack_script} ip addr) echo "$addr" | grep eth0 echo "$addr" | grep 192.168.13.2 echo "$addr" | grep "aa:bb:cc:dd:ee:ff" -echo "$addr" | grep "2001:db8:0:f102::2" +echo "$addr" | grep "fc03::2" ! echo "$addr" | grep "WARN: failed to free" # Copy ping so we're allowed to run it under LKL @@ -94,18 +94,18 @@ cp `which ping6` . # Make sure we can ping the host from inside LKL ${hijack_script} ./ping 192.168.13.1 -c 1 -${hijack_script} ./ping6 2001:db8:0:f102::1 -c 10 +${hijack_script} ./ping6 fc03::1 -c 1 rm ./ping ./ping6 # Now let's check that the host can see LKL. -sudo ip -6 neigh del 2001:db8:0:f102::2 dev lkl_ptt0 +sudo ip -6 neigh del fc03::2 dev lkl_ptt0 sudo ip neigh del 192.168.13.2 dev lkl_ptt0 sudo ping -i 0.01 -c 65 192.168.13.2 & -sudo ping6 -i 0.01 -c 65 2001:db8:0:f102::2 & +sudo ping6 -i 0.01 -c 65 fc03::2 & ${hijack_script} sleep 3 # add neighbor entries -ans=$(LKL_HIJACK_NET_NEIGHBOR="192.168.13.100|12:34:56:78:9a:bc;2001:db8:0:f102::100|12:34:56:78:9a:be"\ +ans=$(LKL_HIJACK_NET_NEIGHBOR="192.168.13.100|12:34:56:78:9a:bc;fc03::100|12:34:56:78:9a:be"\ ${hijack_script} ip neighbor show) || true echo "$ans" | tail -n 15 | grep "12:34:56:78:9a:bc" echo "$ans" | tail -n 15 | grep "12:34:56:78:9a:be" @@ -116,7 +116,7 @@ echo "$ans" | tail -n 15 | grep "192.168.13.1" # gateway v6 ans=$(${hijack_script} ip -6 route show) || true -echo "$ans" | tail -n 15 | grep "2001:db8:0:f102::1" +echo "$ans" | tail -n 15 | grep "fc03::1" # LKL_VIRTIO_NET_F_HOST_TSO4 && LKL_VIRTIO_NET_F_GUEST_TSO4 # LKL_VIRTIO_NET_F_CSUM && LKL_VIRTIO_NET_F_GUEST_CSUM @@ -127,6 +127,7 @@ LKL_HIJACK_OFFLOAD=0x883 sh ${script_dir}/run_netperf.sh 192.168.13.1 1 0 TCP_MA # LKL_VIRTIO_NET_F_CSUM && LKL_VIRTIO_NET_F_GUEST_CSUM LKL_HIJACK_OFFLOAD=0x8803 sh ${script_dir}/run_netperf.sh 192.168.13.1 1 0 TCP_MAERTS sh ${script_dir}/run_netperf.sh 192.168.13.1 1 0 TCP_RR +sh ${script_dir}/run_netperf.sh fc03::1 1 0 TCP_STREAM echo "== VDE tests ==" if [ ! -x "$(which vde_switch)" ]; then diff --git a/tools/lkl/tests/run_netperf.sh b/tools/lkl/tests/run_netperf.sh index fb7e1fbb98d091..570555ed5689db 100644 --- a/tools/lkl/tests/run_netperf.sh +++ b/tools/lkl/tests/run_netperf.sh @@ -77,6 +77,8 @@ then export LKL_HIJACK_NET_IFPARAMS=lkl_ptt0 export LKL_HIJACK_NET_IP=192.168.13.2 export LKL_HIJACK_NET_NETMASK_LEN=24 + export LKL_HIJACK_NET_IPV6=fc03::2 + export LKL_HIJACK_NET_NETMASK6_LEN=64 sudo ip tuntap del dev $LKL_HIJACK_NET_IFPARAMS mode tap || true sudo ip tuntap add dev $LKL_HIJACK_NET_IFPARAMS mode tap user $USER @@ -86,10 +88,10 @@ then trap clean_with_tap EXIT fi -sudo netserver -L $host_ip +sudo netserver echo NUM=$num_runs, TEST=$test_name, TASKSET=$use_taskset for i in `seq $num_runs`; do echo Test: $i - $taskset_cmd ${hijack_script} netperf -L $LKL_HIJACK_NET_IP -H $host_ip -t $test_name -l $test_len + $taskset_cmd ${hijack_script} netperf -H $host_ip -t $test_name -l $test_len done