git://git.onelab.eu
/
sliver-openvswitch.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix warning
[sliver-openvswitch.git]
/
lib
/
tunalloc.c
diff --git
a/lib/tunalloc.c
b/lib/tunalloc.c
index
12c2a70
..
b2484b9
100644
(file)
--- a/
lib/tunalloc.c
+++ b/
lib/tunalloc.c
@@
-6,29
+6,33
@@
* new tuntap interface. Interface name can be acquired via TUNGETIFF ioctl.
*/
* 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 <sys/un.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-#include <errno.h>
#include <unistd.h>
#include <unistd.h>
+#include <errno.h>
#include <sys/socket.h>
#include <linux/if.h>
#include <linux/if_tun.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. */
/* 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;
{
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;
/* 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) {
while(((rv = recvmsg(fd, &msg, 0)) == -1) && errno == EINTR);
if (rv == -1) {
+ perror("recvmsg");
return -1;
}
if(!rv) {
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) {
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 -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) {
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));
}
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) {
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);
}
remotefd = receive_vif_fd(control_fd, if_name);