mirror of
https://github.com/yarrick/iodine.git
synced 2024-11-03 06:57:27 +00:00
Set server ip and mtu
This commit is contained in:
parent
c83d6d6983
commit
d15c72c29c
29
iodined.c
29
iodined.c
|
@ -108,18 +108,21 @@ extern char *__progname;
|
|||
|
||||
static void
|
||||
usage() {
|
||||
printf("Usage: %s [-v] [-h] [-f] [-u user] [-t chrootdir] topdomain\n", __progname);
|
||||
printf("Usage: %s [-v] [-h] [-f] [-u user] [-t chrootdir] [-m mtu] "
|
||||
"tunnel_ip topdomain\n", __progname);
|
||||
exit(2);
|
||||
}
|
||||
|
||||
static void
|
||||
help() {
|
||||
printf("iodine IP over DNS tunneling server\n");
|
||||
printf("Usage: %s [-v] [-h] [-f] [-u user] [-t chrootdir] "
|
||||
"topdomain\n", __progname);
|
||||
printf("Usage: %s [-v] [-h] [-f] [-u user] [-t chrootdir] [-m mtu] "
|
||||
"tunnel_ip topdomain\n", __progname);
|
||||
printf(" -f to keep running in foreground\n");
|
||||
printf(" -u name to drop privileges and run as user 'name'\n");
|
||||
printf(" -t dir to chroot to directory dir\n");
|
||||
printf("tunnel_ip is the IP number of the local tunnel interface.\n");
|
||||
printf("topdomain is the FQDN that is delegated to this server.\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
@ -140,12 +143,15 @@ main(int argc, char **argv)
|
|||
char *newroot;
|
||||
char *username;
|
||||
int foreground;
|
||||
int mtu;
|
||||
struct passwd *pw;
|
||||
|
||||
username = NULL;
|
||||
newroot = NULL;
|
||||
foreground = 0;
|
||||
mtu = 1024;
|
||||
|
||||
while ((choice = getopt(argc, argv, "vfhu:t:")) != -1) {
|
||||
while ((choice = getopt(argc, argv, "vfhu:t:m:")) != -1) {
|
||||
switch(choice) {
|
||||
case 'v':
|
||||
version();
|
||||
|
@ -162,6 +168,9 @@ main(int argc, char **argv)
|
|||
case 't':
|
||||
newroot = optarg;
|
||||
break;
|
||||
case 'm':
|
||||
mtu = atoi(optarg);
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
break;
|
||||
|
@ -176,7 +185,7 @@ main(int argc, char **argv)
|
|||
usage();
|
||||
}
|
||||
|
||||
if (argc != 1)
|
||||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
if (username) {
|
||||
|
@ -187,9 +196,16 @@ main(int argc, char **argv)
|
|||
}
|
||||
}
|
||||
|
||||
if (mtu == 0) {
|
||||
printf("Bad MTU given.\n");
|
||||
usage();
|
||||
}
|
||||
|
||||
if ((tun_fd = open_tun()) == -1)
|
||||
goto cleanup0;
|
||||
if (tun_setip(argv[0]) != 0 || tun_setmtu(mtu) != 0)
|
||||
goto cleanup1;
|
||||
if ((dnsd_fd = open_dnsd(argv[0])) == -1)
|
||||
if ((dnsd_fd = open_dnsd(argv[1])) == -1)
|
||||
goto cleanup2;
|
||||
|
||||
|
||||
|
@ -220,6 +236,7 @@ cleanup2:
|
|||
close_dnsd(dnsd_fd);
|
||||
cleanup1:
|
||||
close_tun(tun_fd);
|
||||
cleanup0:
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
12
tun.c
12
tun.c
|
@ -31,7 +31,7 @@
|
|||
#define TUN_MAX_TRY 50
|
||||
|
||||
char *tun_device = NULL;
|
||||
char *if_device = NULL;
|
||||
char *if_name = NULL;
|
||||
|
||||
#ifdef LINUX
|
||||
|
||||
|
@ -63,7 +63,7 @@ open_tun()
|
|||
|
||||
if (ioctl(tun_fd, TUNSETIFF, (void *) &ifreq) != -1) {
|
||||
printf("Opened %s\n", ifreq.ifr_name);
|
||||
if_device = strdup(ifreq.ifr_name);
|
||||
if_name = strdup(ifreq.ifr_name);
|
||||
return tun_fd;
|
||||
}
|
||||
|
||||
|
@ -98,7 +98,7 @@ open_tun()
|
|||
|
||||
if ((tun_fd = open(tun_name, O_RDWR)) >= 0) {
|
||||
printf("Opened %s\n", tun_name);
|
||||
if_device = strdup(tun_name);
|
||||
if_name = strdup(tun_name);
|
||||
return tun_fd;
|
||||
}
|
||||
|
||||
|
@ -158,7 +158,7 @@ tun_setip(const char *ip)
|
|||
if (inet_addr(ip) != 0) {
|
||||
snprintf(cmdline, sizeof(cmdline),
|
||||
"/sbin/ifconfig %s %s netmask 255.255.255.0",
|
||||
tun_device,
|
||||
if_name,
|
||||
ip);
|
||||
#ifndef LINUX
|
||||
int r;
|
||||
|
@ -173,6 +173,7 @@ tun_setip(const char *ip)
|
|||
}
|
||||
#endif
|
||||
|
||||
printf("Setting IP of %s to %s\n", if_name, ip);
|
||||
return system(cmdline);
|
||||
}
|
||||
|
||||
|
@ -187,9 +188,10 @@ tun_setmtu(const int mtu)
|
|||
if (mtu > 200 && mtu < 1500) {
|
||||
snprintf(cmdline, sizeof(cmdline),
|
||||
"/sbin/ifconfig %s mtu %d",
|
||||
tun_device,
|
||||
if_name,
|
||||
mtu);
|
||||
|
||||
printf("Setting MTU of %s to %d\n", if_name, mtu);
|
||||
return system(cmdline);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue