From 68f0f6ed2996ee7ff5a02ba366bb5cb39c3610d3 Mon Sep 17 00:00:00 2001 From: Ryo Nakamura Date: Fri, 14 Nov 2014 00:44:40 +0900 Subject: [PATCH 1/4] add nuse-config.c and cleanup nuse.c . All env variables are removed and collected to nuse.conf specified by NUSECONF=nuse.conf --- arch/sim/Makefile | 4 +- arch/sim/nuse-config.c | 250 +++++++++++++++++++++++++++++++++++++++++ arch/sim/nuse-config.h | 53 +++++++++ arch/sim/nuse.c | 224 +++++++++++++++--------------------- arch/sim/sim-device.c | 10 +- nuse.conf | 22 ++++ 6 files changed, 422 insertions(+), 141 deletions(-) create mode 100644 arch/sim/nuse-config.c create mode 100644 arch/sim/nuse-config.h create mode 100644 nuse.conf diff --git a/arch/sim/Makefile b/arch/sim/Makefile index 3d06a8bdbec2..1ce106dd6815 100644 --- a/arch/sim/Makefile +++ b/arch/sim/Makefile @@ -17,8 +17,8 @@ tap_yes=nuse-vif-tap.c tap_no= NUSE_SRC=\ -nuse.c nuse-fiber.c nuse-vif.c nuse-poll.c \ -nuse-vif-rawsock.c nuse-glue.c nuse-hostcalls.c \ +nuse.c nuse-fiber.c nuse-vif.c nuse-poll.c \ +nuse-vif-rawsock.c nuse-glue.c nuse-hostcalls.c nuse-config.c\ $(netmap_$(NETMAP)) $(tap_$(TAP)) SIM_SRC=\ diff --git a/arch/sim/nuse-config.c b/arch/sim/nuse-config.c new file mode 100644 index 000000000000..ef9bb07c2e0d --- /dev/null +++ b/arch/sim/nuse-config.c @@ -0,0 +1,250 @@ + +#include +#include +#include +#include "nuse-config.h" + +typedef unsigned int uint32_t; + +/* sdlib.h */ +extern void *malloc (size_t size); +extern void free (void * ptr); + + +/* ipaddress config */ +typedef uint32_t in_addr_t; +extern in_addr_t inet_addr (const char * cp); + + + +static int +strsplit (char * str, char ** args, int max) +{ + int argc; + char * c; + + for (argc = 0, c = str; *c == ' ' || *c == '\t' || *c == '\n'; c++); + while (*c && argc < max) { + args[argc++] = c; + while (*c && *c > ' ') c++; + while (*c && *c <= ' ') *c++ = '\0'; + } + + return argc; +} + +static int +nuse_config_parse_interface (char * line, FILE * fp, struct nuse_config * cf) +{ + int ret; + char buf[1024], *p, * args[2]; + struct nuse_vif_config * vifcf; + struct sockaddr_in * sin; + + memset (buf, 0, sizeof (buf)); + + vifcf = (struct nuse_vif_config *) + malloc (sizeof (struct nuse_vif_config)); + + memset (vifcf, 0, sizeof (struct nuse_vif_config)); + vifcf->type = NUSE_VIF_RAWSOCK; // default + + strsplit (line, args, sizeof (args)); + + strncpy (vifcf->ifname, args[1], IFNAMSIZ); + + while ((p = fgets (buf, sizeof (buf), fp)) != NULL) { + + ret = strsplit (buf, args, sizeof (args)); + + if (ret == 0) { + /* no item in the line */ + break; + } + + if (strncmp (args[0], "address", 7) == 0) { + strncpy (vifcf->address, args[1], NUSE_ADDR_STRLEN); + } + if (strncmp (args[0], "netmask", 7) == 0) { + strncpy (vifcf->netmask, args[1], NUSE_ADDR_STRLEN); + } + if (strncmp (args[0], "macaddr", 7) == 0) { + strncpy (vifcf->macaddr, args[1], NUSE_MACADDR_STRLEN); + } + if (strncmp (args[0], "viftype", 7) == 0) { + if (strncmp (args[1], "RAW", 3) == 0) { + vifcf->type = NUSE_VIF_RAWSOCK; + } else if (strncmp (args[1], "NETMAP", 6) == 0) { + vifcf->type = NUSE_VIF_NETMAP; + } else if (strncmp (args[1], "TAP", 3) == 0) { + vifcf->type = NUSE_VIF_TAP; + } else { + printf ("invalid vif type %s\n", args[1]); + return 0; + } + } + } + + if (!p) { + printf ("Config error for interface %s\n", vifcf->ifname); + free (vifcf); + return 0; + } + + /* setup ifreq */ + sin = (struct sockaddr_in *)&vifcf->ifr_vif_addr.ifr_addr; + sin->sin_family = AF_INET; + sin->sin_addr.s_addr = inet_addr (vifcf->address); + + sin = (struct sockaddr_in *)&vifcf->ifr_vif_mask.ifr_netmask; + sin->sin_family = AF_INET; + sin->sin_addr.s_addr = inet_addr (vifcf->netmask); + + /* XXX: ifname attached to nuse process is same as host stck */ + strncpy (vifcf->ifr_vif_addr.ifr_name, vifcf->ifname, IFNAMSIZ); + strncpy (vifcf->ifr_vif_mask.ifr_name, vifcf->ifname, IFNAMSIZ); + + /* reassemble mac address */ + if (sscanf (vifcf->macaddr, "%u:%u:%u:%u:%u:%u", + (unsigned int *)&vifcf->mac[0], + (unsigned int *)&vifcf->mac[1], + (unsigned int *)&vifcf->mac[2], + (unsigned int *)&vifcf->mac[3], + (unsigned int *)&vifcf->mac[4], + (unsigned int *)&vifcf->mac[5]) < 1) { + printf ("failed to parse mac address %s\n", vifcf->macaddr); + free (vifcf); + return 0; + } + + cf->vifs[cf->vif_cnt++] = vifcf; + + return 1; +} + +static int +nuse_config_parse_route (char * line, FILE * fp, struct nuse_config * cf) +{ + int ret, net, mask, gate; + char buf[1024], * p, * args[2]; + struct nuse_route_config * rtcf; + struct sockaddr_in * sin; + + net = 0; + mask = 0; + gate = 0; + + memset (buf, 0, sizeof (buf)); + + rtcf = (struct nuse_route_config *) + malloc (sizeof (struct nuse_route_config)); + + while ((p = fgets (buf, sizeof (buf), fp)) != NULL) { + + ret = strsplit (buf, args, sizeof (args)); + + if (ret == 0) { + /* no item in the line */ + break; + } + + if (strncmp (args[0], "network", 7) == 0) { + strncpy (rtcf->network, args[1], NUSE_ADDR_STRLEN); + net = 1; + } + if (strncmp (args[0], "netmask", 7) == 0) { + strncpy (rtcf->netmask, args[1], NUSE_ADDR_STRLEN); + mask = 1; + } + if (strncmp (args[0], "gateway", 7) == 0) { + strncpy (rtcf->gateway, args[1], NUSE_ADDR_STRLEN); + gate = 1; + } + + if (net && mask && gate) + break; + } + + if (!p) { + printf ("Config error for route entry\n"); + free (rtcf); + return 0; + } + + if (!net) + printf ("network is not configured !\n"); + if (!mask) + printf ("netmask is not configured !\n"); + if (!gate) + printf ("netmask is not configured !\n"); + + if (!net || !mask || !gate) + return 0; + + /* setup rtentry */ + sin = (struct sockaddr_in *)&rtcf->route.rt_dst; + sin->sin_family = AF_INET; + sin->sin_addr.s_addr = inet_addr (rtcf->network); + + sin = (struct sockaddr_in *) &rtcf->route.rt_genmask; + sin->sin_family = AF_INET; + sin->sin_addr.s_addr = inet_addr (rtcf->netmask); + + sin = (struct sockaddr_in *) &rtcf->route.rt_gateway; + sin->sin_family = AF_INET; + sin->sin_addr.s_addr = inet_addr (rtcf->gateway); + + rtcf->route.rt_flags = RTF_UP | RTF_GATEWAY; + rtcf->route.rt_metric = 0; + + cf->routes[cf->route_cnt++] = rtcf; + + return 1; +} + + +int +nuse_config_parse (struct nuse_config * cf, char * cfname) +{ + FILE * fp; + int ret; + char buf[1024]; + + memset (cf, 0, sizeof (struct nuse_config)); + + if ((fp = fopen (cfname, "r")) == NULL) { + perror ("fopen"); + return 0; + } + + while (fgets (buf, sizeof (buf), fp) != NULL) { + if (strncmp (buf, "interface ", 10) == 0) { + ret = nuse_config_parse_interface (buf, fp, cf); + } else if (strncmp (buf, "route", 5) == 0) { + ret = nuse_config_parse_route (buf, fp, cf); + } + if (!ret) + break; + } + + fclose (fp); + + return ret; +} + +void +nuse_config_free (struct nuse_config * cf) +{ + int n; + + for (n = 0; n < cf->vif_cnt; n++) { + free (cf->vifs[n]); + } + + for (n = 0; n < cf->route_cnt; n++) { + free (cf->routes[n]); + } + + return; +} + diff --git a/arch/sim/nuse-config.h b/arch/sim/nuse-config.h new file mode 100644 index 000000000000..3dc384deaf75 --- /dev/null +++ b/arch/sim/nuse-config.h @@ -0,0 +1,53 @@ + +#ifndef _NUSE_CONFIG_H_ +#define _NUSE_CONFIG_H_ + +#include +#include +#include "nuse-vif.h" + + +#define NUSE_VIF_MAX 16 +#define NUSE_ROUTE_MAX 16 +#define NUSE_ADDR_STRLEN 16 +#define NUSE_MACADDR_STRLEN 20 + + +struct nuse_vif_config { + char ifname[IFNAMSIZ]; + char address[NUSE_ADDR_STRLEN]; + char netmask[NUSE_ADDR_STRLEN]; + char macaddr[NUSE_MACADDR_STRLEN]; + + enum viftype type; + + u_char mac[ETH_ALEN]; + + struct ifreq ifr_vif_addr; + struct ifreq ifr_vif_mask; +}; + +struct nuse_route_config { + char network[NUSE_ADDR_STRLEN]; + char netmask[NUSE_ADDR_STRLEN]; + char gateway[NUSE_ADDR_STRLEN]; + + struct rtentry route; +}; + +struct nuse_config { + int vif_cnt, route_cnt; + struct nuse_vif_config * vifs[NUSE_VIF_MAX]; + struct nuse_route_config * routes[NUSE_ROUTE_MAX]; +}; + + +/* open cfname and return struct nuse_config */ +int nuse_config_parse (struct nuse_config * cf, char * cfname); + +/* free cf->nuse_vif_config and cf->nuse_route_config */ +void nuse_config_free (struct nuse_config * cf); + + + +#endif /* _NUSE_CONFIG_H_ */ diff --git a/arch/sim/nuse.c b/arch/sim/nuse.c index 9a1bd4e6d55d..31d46603b4b6 100644 --- a/arch/sim/nuse.c +++ b/arch/sim/nuse.c @@ -13,6 +13,8 @@ #include "nuse.h" #include "nuse-hostcalls.h" #include "sim.h" +#include "nuse-config.h" + int kptr_restrict __read_mostly; extern struct socket *g_fd_table[1024]; @@ -24,7 +26,8 @@ extern void sim_softirq_wakeup (void); extern void sim_update_jiffies (void); extern struct SimTask *sim_task_create (void *private, unsigned long pid); extern void *sim_dev_get_private (struct SimDevice *); -extern struct SimDevice *sim_dev_create (void *priv, enum SimDevFlags flags); +extern struct SimDevice *sim_dev_create (char * ifname, + void *priv, enum SimDevFlags flags); extern void sim_dev_set_address (struct SimDevice *dev, unsigned char buffer[6]); @@ -44,6 +47,9 @@ extern void ether_setup(struct net_device *dev); typedef uint32_t in_addr_t; extern in_addr_t inet_addr(const char *cp); +/* ip_rt_ioctl */ +extern int ip_rt_ioctl(struct net*net, unsigned int cmd, void __user * arg); + int sim_vprintf (const char *str, va_list args) { @@ -268,104 +274,73 @@ void sim_signal_raised (struct SimTask *task, int sig) return; } -unsigned char hwaddr_base[6] = {0,0,0,0,0,0x01}; - void -nuse_netdev_create (const char *ifname, int ifindex) +nuse_netdev_create (struct nuse_vif_config * vifcf) { + /* create net_device for nuse process from nuse_vif_config */ + int err; - char ifnamebuf[IFNAMSIZ]; - char *ifv4addr, *nusevif, *defaultrt; + struct nuse_vif * vif; struct ifreq ifr; - struct sockaddr_in *sin; - enum viftype type = NUSE_VIF_RAWSOCK; /* default: raw socket */ - - sprintf (ifnamebuf, "nuse-%s", ifname); - if (!(ifv4addr = getenv (ifnamebuf))) - { - /* skipped */ - return; - } - if ((nusevif = getenv ("NUSEVIF"))) - { - if (strncmp (nusevif, "RAW", 3) == 0) - type = NUSE_VIF_RAWSOCK; - else if (strncmp (nusevif, "NETMAP", 6) == 0) - type = NUSE_VIF_NETMAP; - else if (strncmp (nusevif, "TAP", 3) == 0) - type = NUSE_VIF_TAP; - } - - struct nuse_vif *vif = nuse_vif_create (type, ifname); - if (!vif) - { +#ifdef DEBUG + printf ("create vif\n"); + printf ("vif name = %s\n", vifcf->ifname); + printf ("address = %s\n", vifcf->address); + printf ("netmask = %s\n", vifcf->netmask); + printf ("macaddr = %s\n", vifcf->macaddr); + printf ("type = %d\n", vifcf->type); +#endif + + vif = nuse_vif_create (vifcf->type, vifcf->ifname); + if (!vif) { sim_printf ("vif create error\n"); sim_assert (0); - return; - } + } + + /* create new new_device */ + struct SimDevice * dev = sim_dev_create (vifcf->ifname, vif, 0); - /* create new net_device (sim%d FIXME: nuse%d). */ - struct SimDevice *dev = sim_dev_create (vif, 0); /* assign new hw address */ - hwaddr_base[4] = getpid (); - sim_dev_set_address (dev, hwaddr_base); - hwaddr_base[5]++; - ether_setup ((struct net_device *)dev); - - - sin = (struct sockaddr_in *)&ifr.ifr_addr; - printf ("assign nuse interface %s IPv4 address %s\n", ifnamebuf, ifv4addr); - sin->sin_family = AF_INET; - sin->sin_addr.s_addr = inet_addr (ifv4addr); - sprintf (ifr.ifr_name, "sim%d", ifindex - 2); - err = devinet_ioctl (&init_net, SIOCSIFADDR, &ifr); - if (err) - { - sim_printf ("err devinet_ioctl for assign address %d\n", err); - } - - /* IFF_UP */ - memset (&ifr, 0, sizeof (struct ifreq)); - ifr.ifr_flags = IFF_UP; - sprintf (ifr.ifr_name, "sim%d", ifindex - 2); - err = devinet_ioctl (&init_net, SIOCSIFFLAGS, &ifr); - if (err) - { - sim_printf ("err devinet_ioctl %d\n", err); - } + sim_dev_set_address (dev, vifcf->mac); + ether_setup ((struct net_device *) dev); - /* set default route */ - if ((defaultrt = getenv ("DEFAULTROUTE"))) { - struct rtentry rt; - memset (&rt, 0, sizeof (rt)); + /* assign IPv4 address */ + + /* XXX: ifr_name is already fileed by nuse_config_parse_interface, + I don't know why, but vifcf->ifr_vif_addr.ifr_name is NULL in here. */ + strcpy (vifcf->ifr_vif_addr.ifr_name, vifcf->ifname); - sin = (struct sockaddr_in *) &rt.rt_gateway; - sin->sin_family = AF_INET; - sin->sin_addr.s_addr = inet_addr (defaultrt); - - sin = (struct sockaddr_in *) &rt.rt_dst; - sin->sin_family = AF_INET; - sin->sin_addr.s_addr = INADDR_ANY; - - sin = (struct sockaddr_in *) &rt.rt_genmask; - sin->sin_family = AF_INET; - sin->sin_addr.s_addr = INADDR_ANY; + err = devinet_ioctl (&init_net, SIOCSIFADDR, &vifcf->ifr_vif_addr); + if (err) { + perror ("devinet_ioctl"); + printf ("err devinet_ioctl for assign address %s for %s,%s %d\n", + vifcf->address, vifcf->ifname, vifcf->ifr_vif_addr.ifr_name, err); + } - rt.rt_flags = RTF_UP | RTF_GATEWAY; - rt.rt_metric = 0; + /* set netmask */ + err = devinet_ioctl (&init_net, SIOCSIFNETMASK, &vifcf->ifr_vif_mask); + if (err) { + perror ("devinet_ioctl"); + printf ("err devinet_ioctl for assign netmask %s for %s,%s %d\n", + vifcf->netmask, vifcf->ifname, vifcf->ifr_vif_mask.ifr_name, err); + } - err = ip_rt_ioctl (&init_net, SIOCADDRT, &rt); - if (err) - { - sim_printf ("err devinet_ioctl for default route %s %d\n", - defaultrt, err); - } + /* IFF_UP */ + memset (&ifr, 0, sizeof (ifr)); + ifr.ifr_flags = IFF_UP; + strncpy (ifr.ifr_name, vifcf->ifname, IFNAMSIZ); + + err = devinet_ioctl (&init_net, SIOCSIFFLAGS, &ifr); + if (err) { + perror ("devinet_ioctl"); + printf ("err devinet_ioctl to set ifup dev %s %d\n", vifcf->ifname, err); } /* wait for packets */ - void *fiber = nuse_fiber_new (&nuse_netdev_rx_trampoline, dev, 1 << 16, "NET_RX"); + void *fiber = nuse_fiber_new (&nuse_netdev_rx_trampoline, dev, + 1 << 16, "NET_RX"); struct SimTask *task = NULL; task = sim_task_create (fiber, getpid ()); list_add_tail_rcu (&task->head, &g_task_lists); @@ -374,67 +349,28 @@ nuse_netdev_create (const char *ifname, int ifindex) return; } -void -nuse_netdevs_create (void) -{ - char buf[1024]; - struct ifconf ifc; - struct ifreq *ifr; - int sock; - int nifs; - int i; - - sock = host_socket (AF_INET, SOCK_DGRAM, 0); - if (sock < 0) - { - perror("socket"); - return; - } - - ifc.ifc_len = sizeof (buf); - ifc.ifc_buf = buf; - if(host_ioctl (sock, SIOCGIFCONF, &ifc) < 0) - { - perror ("ioctl(SIOCGIFCONF)"); - return; - } - - ifr = ifc.ifc_req; - nifs = ifc.ifc_len / sizeof(struct ifreq); - for (i = 0; i < nifs; i++) - { - struct ifreq *item = &ifr[i]; - - if (strncmp (item->ifr_name, "lo", 2) == 0) - { - continue; - } - - nuse_netdev_create (item->ifr_name, item->ifr_ifindex); - } - host_close (sock); - return; -} void -nuse_netdevs_create2 (void) +nuse_route_install (struct nuse_route_config * rtcf) { - char * ifname; + int err; - ifname = getenv ("NUSEDEV"); - if (!ifname) { - printf ("interface name does not specified\n"); - return; - } + err = ip_rt_ioctl (&init_net, SIOCADDRT, &rtcf->route); + if (err) { + sim_printf ("err ip_rt_ioctl to add route to %s via %s %d\n", + rtcf->network, rtcf->gateway, err); + } - nuse_netdev_create (ifname, 2); - return; + return; } - void __attribute__((constructor)) nuse_init (void) { + int n; + char * config; + struct nuse_config cf; + nuse_set_affinity (); nuse_hijack_init (); @@ -467,6 +403,24 @@ nuse_init (void) /* create descriptor table */ memset (g_fd_table, 0, sizeof (g_fd_table)); - /* create netdev sim%s corresponding to underlying netdevs */ - nuse_netdevs_create2 (); + /* read and parse a config file */ + if ((config = getenv ("NUSECONF")) == NULL) { + printf ("config file is not specified\n"); + sim_assert (0); + } + + if (!nuse_config_parse (&cf, config)) { + printf ("parse config file failed\n"); + sim_assert (0); + } + + /* create netdevs specified by config file */ + for (n = 0; n < cf.vif_cnt; n++) { + nuse_netdev_create (cf.vifs[n]); + } + + /* setup route entries */ + for (n = 0; n < cf.route_cnt; n++) { + nuse_route_install (cf.routes[n]); + } } diff --git a/arch/sim/sim-device.c b/arch/sim/sim-device.c index 81a1cd0169e7..730881a6e54e 100644 --- a/arch/sim/sim-device.c +++ b/arch/sim/sim-device.c @@ -68,11 +68,13 @@ static void sim_dev_setup(struct net_device *dev) } -struct SimDevice *sim_dev_create (void *priv, enum SimDevFlags flags) +struct SimDevice *sim_dev_create (char * ifname, void *priv, + enum SimDevFlags flags) { - struct SimDevice *dev = (struct SimDevice *)alloc_netdev(sizeof(struct SimDevice), - "sim%d", NET_NAME_UNKNOWN, - &sim_dev_setup); + struct SimDevice *dev = + (struct SimDevice *)alloc_netdev(sizeof(struct SimDevice), + ifname, NET_NAME_UNKNOWN, + &sim_dev_setup); if (flags & SIM_DEV_NOARP) { dev->dev.flags |= IFF_NOARP; diff --git a/nuse.conf b/nuse.conf new file mode 100644 index 000000000000..9a15056781fc --- /dev/null +++ b/nuse.conf @@ -0,0 +1,22 @@ + + +interface eth0 + address 192.168.0.10 + netmask 255.255.255.0 + macaddr 00:01:01:01:01:01 + viftype TAP + +interface p1p1 + address 172.16.0.1 + netmask 255.255.255.0 + macaddr 00:01:01:01:01:02 + +route + network 172.16.1.0 + netmask 255.255.255.0 + gateway 172.16.0.2 + +route + network 0.0.0.0 + netmask 0.0.0.0 + gateway 192.168.0.1 From 6ff2aed13b84895d0943d8247632b5a6a3439656 Mon Sep 17 00:00:00 2001 From: Ryo Nakamura Date: Fri, 14 Nov 2014 16:39:20 +0900 Subject: [PATCH 2/4] support comment out on nuse.conf --- arch/sim/nuse-config.c | 8 ++++++++ nuse.conf | 11 ++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/arch/sim/nuse-config.c b/arch/sim/nuse-config.c index ef9bb07c2e0d..6d533332ca10 100644 --- a/arch/sim/nuse-config.c +++ b/arch/sim/nuse-config.c @@ -57,6 +57,10 @@ nuse_config_parse_interface (char * line, FILE * fp, struct nuse_config * cf) ret = strsplit (buf, args, sizeof (args)); + /* comment out */ + if (args[0][0] == '#') + continue; + if (ret == 0) { /* no item in the line */ break; @@ -148,6 +152,10 @@ nuse_config_parse_route (char * line, FILE * fp, struct nuse_config * cf) break; } + /* comment out */ + if (args[0][0] == '#') + continue; + if (strncmp (args[0], "network", 7) == 0) { strncpy (rtcf->network, args[1], NUSE_ADDR_STRLEN); net = 1; diff --git a/nuse.conf b/nuse.conf index 9a15056781fc..b432ba516d14 100644 --- a/nuse.conf +++ b/nuse.conf @@ -1,16 +1,25 @@ +# +# nuse.conf +# # at fornt means comment aout. - +# Interface definition. +# Default viftype is RAWSOCK, and default of other vlaues are 0 fill. interface eth0 address 192.168.0.10 netmask 255.255.255.0 macaddr 00:01:01:01:01:01 viftype TAP +# viftype RAW and NETMAP requires that an interface name must be same as +# a physical interface of host stack. interface p1p1 address 172.16.0.1 netmask 255.255.255.0 macaddr 00:01:01:01:01:02 + +# route entry definition. +# 'network', 'netmask' and 'gateway' are REQUIRED. route network 172.16.1.0 netmask 255.255.255.0 From cb0a6f98057ac62e5f83ed4633130f3594551bfd Mon Sep 17 00:00:00 2001 From: Ryo Nakamura Date: Fri, 14 Nov 2014 16:47:22 +0900 Subject: [PATCH 3/4] update README.md for nuse.conf --- README.md | 57 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index f0e4223dd1cd..81fa860a2abb 100644 --- a/README.md +++ b/README.md @@ -26,45 +26,48 @@ you should see libnuse-linux.so. ## Run -Then, a wrapper script called **nuse** takes your application running with NUSE. +At 1st, please write a configuration file for nuse **nuse.conf**. +Example of nuse.conf is shown below. ``` - sudo NUSEDEV=eth0 nuse-eth0=192.168.209.39 ./nuse ping 192.168.209.1 -``` +# Interface definition. +interface eth0 + address 192.168.0.10 + netmask 255.255.255.0 + macaddr 00:01:01:01:01:01 + viftype TAP -where an environmental variable **nuse-(interface name)** indicates an IPv4 address for an interface under NUSE, instead of host OS's one. +interface p1p1 + address 172.16.0.1 + netmask 255.255.255.0 + macaddr 00:01:01:01:01:02 -and if you want to use netmap for network i/o, specify **NUSEVIF=NETMAP** as an env variable. The default interface will be raw socket based network i/o. +# route entry definition. -``` - sudo NUSEVIF=NETMAP NUSEDEV=eth0 nuse-eth0=192.168.209.39 ./nuse ping 192.168.209.1 +route + network 0.0.0.0 + netmask 0.0.0.0 + gateway 192.168.0.1 ``` -And if you want to use tun/tap driver for network i/o, **NUSEVIF=TAP** is offered. When NUSEVIF is TAP, a name of interface attached to a nuse process is not restricted to existing interface names of host stack. +When viftype is TAP, the interface name attached to nuse process is +not restricted to be same as physical interfaces of host +stack. However, viftype RAW and NETMAP requires that an interface name +must be same as a physical interface of host stack. -``` - sudo NUSEVIF=TAP NUSEDEV=eth0 nuse-eth0=192.168.209.39 ./nuse ping 192.168.209.1 - - ~ host stack ~ - ifconfig nuse-eth0 - nuse-eth0 Link encap:Ethernet HWaddr d6:d6:86:74:bf:5e - inet6 addr: fe80::d4d6:86ff:fe74:bf5e/64 Scope:Link - UP BROADCAST RUNNING MTU:1500 Metric:1 - RX packets:11 errors:0 dropped:0 overruns:0 frame:0 - TX packets:8 errors:0 dropped:0 overruns:0 carrier:0 - collisions:0 txqueuelen:500 - RX bytes:462 (462.0 B) TX bytes:648 (648.0 B) -``` +The default interface will be raw socket based network i/o. + + +Then, a wrapper script called **nuse** takes your application running with NUSE. -How to set default route of nuse process. ``` - sudo NUSEVIF=TAP NUSEDEV=eth0 nuse-eth0=192.168.0.10 DEFAULTROUTE=192.168.0.1 ./nuse ping 172.16.0.1 + sudo NUSECONF=nuse.conf ./nuse ping 172.16.0.2 ``` And, iperf ``` - sudo NUSEDEV=eth0 nuse-eth0=192.168.209.39 ./nuse iperf -c 192.168.209.1 -u + sudo NUSECONF=nuse.conf ./nuse iperf -c 192.168.209.1 -u ``` should just work fine ! @@ -72,6 +75,6 @@ should just work fine ! since the LD_PRELOAD with sudo technique requires additional copy and permission changes to the library, the script will automatically conduct such an operation. ## Tested platform -Fedora 19 64bits -Ubuntu 13.04 64bits -Ubuntu 14.04 64bits +- Fedora 19 64bits +- Ubuntu 13.04 64bits +- Ubuntu 14.04 64bits From efc976bba83cff6293a0be9177d7af7487b3bfc9 Mon Sep 17 00:00:00 2001 From: Ryo Nakamura Date: Fri, 14 Nov 2014 16:48:27 +0900 Subject: [PATCH 4/4] fix README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 81fa860a2abb..543aa0003dea 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,6 @@ interface p1p1 macaddr 00:01:01:01:01:02 # route entry definition. - route network 0.0.0.0 netmask 0.0.0.0