Warn only when tun_create() fail
This commit is contained in:
@@ -783,8 +783,10 @@ int main (int argc, char **argv)
|
|||||||
|
|
||||||
tun.fd = tun_create(dev, option_is_set(opts, "multiqueue"));
|
tun.fd = tun_create(dev, option_is_set(opts, "multiqueue"));
|
||||||
|
|
||||||
if (tun.fd==-1)
|
if (tun.fd==-1) {
|
||||||
|
gt_log("couldn't create tun device\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
struct blk *blks = calloc(256, sizeof(struct blk));
|
struct blk *blks = calloc(256, sizeof(struct blk));
|
||||||
size_t blk_count = 0;
|
size_t blk_count = 0;
|
||||||
|
|||||||
11
src/tun.c
11
src/tun.c
@@ -35,10 +35,8 @@ static int tun_create_by_name (char *name, size_t size, char *dev_name, int mq)
|
|||||||
{
|
{
|
||||||
int fd = open("/dev/net/tun", O_RDWR);
|
int fd = open("/dev/net/tun", O_RDWR);
|
||||||
|
|
||||||
if (fd==-1) {
|
if (fd==-1)
|
||||||
perror("open /dev/net/tun");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
struct ifreq ifr = {
|
struct ifreq ifr = {
|
||||||
.ifr_flags = IFF_TUN|IFF_NO_PI,
|
.ifr_flags = IFF_TUN|IFF_NO_PI,
|
||||||
@@ -55,7 +53,6 @@ static int tun_create_by_name (char *name, size_t size, char *dev_name, int mq)
|
|||||||
str_cpy(ifr.ifr_name, dev_name, IFNAMSIZ-1);
|
str_cpy(ifr.ifr_name, dev_name, IFNAMSIZ-1);
|
||||||
|
|
||||||
if (ioctl(fd, TUNSETIFF, &ifr)) {
|
if (ioctl(fd, TUNSETIFF, &ifr)) {
|
||||||
perror("ioctl TUNSETIFF");
|
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -69,10 +66,8 @@ static int tun_create_by_id (char *name, size_t size, unsigned id, _unused_ int
|
|||||||
{
|
{
|
||||||
int fd = socket(PF_SYSTEM, SOCK_DGRAM, SYSPROTO_CONTROL);
|
int fd = socket(PF_SYSTEM, SOCK_DGRAM, SYSPROTO_CONTROL);
|
||||||
|
|
||||||
if (fd==-1) {
|
if (fd==-1)
|
||||||
perror("socket");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
struct ctl_info ci;
|
struct ctl_info ci;
|
||||||
|
|
||||||
@@ -80,7 +75,6 @@ static int tun_create_by_id (char *name, size_t size, unsigned id, _unused_ int
|
|||||||
str_cpy(ci.ctl_name, UTUN_CONTROL_NAME, sizeof(ci.ctl_name)-1);
|
str_cpy(ci.ctl_name, UTUN_CONTROL_NAME, sizeof(ci.ctl_name)-1);
|
||||||
|
|
||||||
if (ioctl(fd, CTLIOCGINFO, &ci)) {
|
if (ioctl(fd, CTLIOCGINFO, &ci)) {
|
||||||
perror("ioctl CTLIOCGINFO");
|
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -94,7 +88,6 @@ static int tun_create_by_id (char *name, size_t size, unsigned id, _unused_ int
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (connect(fd, (struct sockaddr *)&sc, sizeof(sc))) {
|
if (connect(fd, (struct sockaddr *)&sc, sizeof(sc))) {
|
||||||
perror("connect");
|
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user