Add iface.[ch]
This commit is contained in:
@@ -14,6 +14,8 @@ glorytun_SOURCES = \
|
|||||||
src/option.h \
|
src/option.h \
|
||||||
src/tun.c \
|
src/tun.c \
|
||||||
src/tun.h \
|
src/tun.h \
|
||||||
|
src/iface.c \
|
||||||
|
src/iface.h \
|
||||||
src/db.c \
|
src/db.c \
|
||||||
src/db.h
|
src/db.h
|
||||||
|
|
||||||
|
|||||||
29
src/iface.c
Normal file
29
src/iface.c
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
#include "str.h"
|
||||||
|
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
iface_set_mtu(char *dev_name, int mtu)
|
||||||
|
{
|
||||||
|
struct ifreq ifr = {
|
||||||
|
.ifr_mtu = mtu,
|
||||||
|
};
|
||||||
|
|
||||||
|
str_cpy(ifr.ifr_name, dev_name, IFNAMSIZ - 1);
|
||||||
|
|
||||||
|
int fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
|
|
||||||
|
if (fd == -1)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
int ret = ioctl(fd, SIOCSIFMTU, &ifr);
|
||||||
|
|
||||||
|
int err = errno;
|
||||||
|
close(fd);
|
||||||
|
errno = err;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
3
src/iface.h
Normal file
3
src/iface.h
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
int iface_set_mtu (char *, int);
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
#include "option.h"
|
#include "option.h"
|
||||||
#include "str.h"
|
#include "str.h"
|
||||||
#include "tun.h"
|
#include "tun.h"
|
||||||
|
#include "iface.h"
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
@@ -263,7 +264,7 @@ gt_setup_mtu(struct mud *mud, char *tun_name)
|
|||||||
|
|
||||||
gt_log("setup MTU to %i on interface %s\n", mtu, tun_name);
|
gt_log("setup MTU to %i on interface %s\n", mtu, tun_name);
|
||||||
|
|
||||||
if (tun_set_mtu(tun_name, mtu) == -1)
|
if (iface_set_mtu(tun_name, mtu) == -1)
|
||||||
perror("tun_set_mtu");
|
perror("tun_set_mtu");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
23
src/tun.c
23
src/tun.c
@@ -239,29 +239,6 @@ tun_write(int fd, const void *data, size_t size)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
|
||||||
tun_set_mtu(char *dev_name, int mtu)
|
|
||||||
{
|
|
||||||
struct ifreq ifr = {
|
|
||||||
.ifr_mtu = mtu,
|
|
||||||
};
|
|
||||||
|
|
||||||
str_cpy(ifr.ifr_name, dev_name, IFNAMSIZ - 1);
|
|
||||||
|
|
||||||
int fd = socket(AF_INET, SOCK_DGRAM, 0);
|
|
||||||
|
|
||||||
if (fd == -1)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
int ret = ioctl(fd, SIOCSIFMTU, &ifr);
|
|
||||||
|
|
||||||
int err = errno;
|
|
||||||
close(fd);
|
|
||||||
errno = err;
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
tun_set_persist(int fd, int on)
|
tun_set_persist(int fd, int on)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,5 +3,4 @@
|
|||||||
int tun_create (char *, char **);
|
int tun_create (char *, char **);
|
||||||
int tun_read (int, void *, size_t);
|
int tun_read (int, void *, size_t);
|
||||||
int tun_write (int, const void *, size_t);
|
int tun_write (int, const void *, size_t);
|
||||||
int tun_set_mtu (char *, int);
|
|
||||||
int tun_set_persist (int, int);
|
int tun_set_persist (int, int);
|
||||||
|
|||||||
Reference in New Issue
Block a user