X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Ftunalloc.c;h=053b4a5cfe71dba75ed4cd12b9c7793fd0365b1a;hb=305b76debf72120672a8ba81d3356b6dccb1da9a;hp=12c2a70e27accd15353b5b125a2f83914f0da1e4;hpb=1e3f34c7693bcabae8e443ac1b246680ef9b60e2;p=sliver-openvswitch.git diff --git a/lib/tunalloc.c b/lib/tunalloc.c index 12c2a70e2..053b4a5cf 100644 --- a/lib/tunalloc.c +++ b/lib/tunalloc.c @@ -6,29 +6,32 @@ * new tuntap interface. Interface name can be acquired via TUNGETIFF ioctl. */ +#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 +48,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 +58,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 +75,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 +87,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);