X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Ftunalloc.c;h=b2484b9e4b01b0d3a9ba5069bc4068ca9d4a60ef;hb=3ba9c6a5a5468626dcfeb1f9a750bb0efc8c6a7a;hp=12c2a70e27accd15353b5b125a2f83914f0da1e4;hpb=1e3f34c7693bcabae8e443ac1b246680ef9b60e2;p=sliver-openvswitch.git diff --git a/lib/tunalloc.c b/lib/tunalloc.c index 12c2a70e2..b2484b9e4 100644 --- a/lib/tunalloc.c +++ b/lib/tunalloc.c @@ -6,29 +6,33 @@ * new tuntap interface. Interface name can be acquired via TUNGETIFF ioctl. */ +#include #include #include #include #include -#include #include +#include #include #include #include -#include "tunalloc.h" +#define VSYS_TUNTAP "/vsys/fd_tuntap.control" + -#define VSYS_TUNTAP "/var/run/pl-ovs.control" +int tun_alloc(int iftype, char *if_name); /* Reads vif FD from "fd", writes interface name to vif_name, and returns vif FD. * vif_name should be IFNAMSIZ chars long. */ -static int receive_vif_fd(int fd, char *vif_name) +static +int receive_vif_fd(int fd, char *vif_name) { struct msghdr msg; struct iovec iov; int rv; size_t ccmsg[CMSG_SPACE(sizeof(int)) / sizeof(size_t)]; struct cmsghdr *cmsg; + unsigned char *data; /* Use IOV to read interface name */ iov.iov_base = vif_name; @@ -45,6 +49,7 @@ static int receive_vif_fd(int fd, char *vif_name) while(((rv = recvmsg(fd, &msg, 0)) == -1) && errno == EINTR); if (rv == -1) { + perror("recvmsg"); return -1; } if(!rv) { @@ -54,9 +59,12 @@ static int receive_vif_fd(int fd, char *vif_name) cmsg = CMSG_FIRSTHDR(&msg); if (!cmsg->cmsg_type == SCM_RIGHTS) { + fprintf(stderr, "got control message of unknown type %d\n", + cmsg->cmsg_type); return -1; } - return *(int*)CMSG_DATA(cmsg); + data = CMSG_DATA(cmsg); + return *(int*)data; } @@ -68,7 +76,8 @@ int tun_alloc(int iftype, char *if_name) control_fd = socket(AF_UNIX, SOCK_STREAM, 0); if (control_fd == -1) { - return -1; + perror("Could not create UNIX socket\n"); + exit(-1); } memset(&addr, 0, sizeof(struct sockaddr_un)); @@ -79,7 +88,14 @@ int tun_alloc(int iftype, char *if_name) if (connect(control_fd, (struct sockaddr *) &addr, sizeof(struct sockaddr_un)) == -1) { - return -1; + perror("Could not connect to Vsys control socket"); + exit(-1); + } + + /* passing type param */ + if (send(control_fd, &iftype, sizeof(iftype), 0) != sizeof(iftype)) { + perror("Could not send paramater to Vsys control socket"); + exit(-1); } remotefd = receive_vif_fd(control_fd, if_name);