summaryrefslogtreecommitdiff
path: root/pfinet
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2013-02-05 00:33:28 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2013-02-05 00:33:28 +0100
commit93932c891eb76fa96f99aea275325c6048b62747 (patch)
treeab46a9335ec660003f2e6ecb5e244ac8cfe7252c /pfinet
parenta4693935b02c509fe029a0653391f8a030e4d615 (diff)
Permit to use a tunnel not in /dev
* pfinet/main.c (find_device): Use basename of NAME for the comparison against "tun" and "dummy". * pfinet/tunnel.c (setup_tunnel_device): Only prepend "/dev/" to tun name if the parameter is not a path.
Diffstat (limited to 'pfinet')
-rw-r--r--pfinet/main.c11
-rw-r--r--pfinet/tunnel.c16
2 files changed, 22 insertions, 5 deletions
diff --git a/pfinet/main.c b/pfinet/main.c
index 7ec1bf1c..01b324df 100644
--- a/pfinet/main.c
+++ b/pfinet/main.c
@@ -174,6 +174,7 @@ error_t
find_device (char *name, struct device **device)
{
struct device *dev = dev_base;
+ char *base_name;
/* Skip loopback interface. */
assert (dev);
@@ -202,9 +203,15 @@ find_device (char *name, struct device **device)
return 0;
}
- if (strncmp(name, "tun", 3) == 0)
+ base_name = strrchr(name, '/');
+ if (base_name)
+ base_name++;
+ else
+ base_name = name;
+
+ if (strncmp(base_name, "tun", 3) == 0)
setup_tunnel_device (name, device);
- else if (strncmp(name, "dummy", 5) == 0)
+ else if (strncmp(base_name, "dummy", 5) == 0)
setup_dummy_device (name, device);
else
setup_ethernet_device (name, device);
diff --git a/pfinet/tunnel.c b/pfinet/tunnel.c
index cf907f59..5d2544b2 100644
--- a/pfinet/tunnel.c
+++ b/pfinet/tunnel.c
@@ -149,6 +149,7 @@ setup_tunnel_device (char *name, struct device **device)
error_t err;
struct tunnel_device *tdev;
struct device *dev;
+ char *base_name;
/* Do global initialization before setting up first tunnel device. */
if (!tunnel_dev)
@@ -165,7 +166,13 @@ setup_tunnel_device (char *name, struct device **device)
*device = dev = &tdev->dev;
- dev->name = strdup (name);
+ base_name = strrchr (name, '/');
+ if (base_name)
+ base_name++;
+ else
+ base_name = name;
+
+ dev->name = strdup (base_name);
dev->priv = tdev;
dev->get_stats = tunnel_get_stats;
@@ -187,8 +194,11 @@ setup_tunnel_device (char *name, struct device **device)
dev_init_buffers (dev);
- /* Setting up the translator at /dev/tunX. */
- asprintf (&tdev->devname, "/dev/%s", tdev->dev.name);
+ if (base_name != name)
+ tdev->devname = strdup (name);
+ else
+ /* Setting up the translator at /dev/tunX. */
+ asprintf (&tdev->devname, "/dev/%s", tdev->dev.name);
tdev->underlying = file_name_lookup (tdev->devname, O_CREAT|O_NOTRANS, 0664);
if (tdev->underlying == MACH_PORT_NULL)