* new tuntap interface. Interface name can be acquired via TUNGETIFF ioctl.
*/
+#include <config.h>
#include <sys/un.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-#include <errno.h>
#include <unistd.h>
+#include <errno.h>
#include <sys/socket.h>
#include <linux/if.h>
#include <linux/if_tun.h>
-#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;
while(((rv = recvmsg(fd, &msg, 0)) == -1) && errno == EINTR);
if (rv == -1) {
+ perror("recvmsg");
return -1;
}
if(!rv) {
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;
}
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));
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);