Set server ip and mtu

This commit is contained in:
Bjorn Andersson 2006-06-11 15:24:20 +00:00
parent c83d6d6983
commit d15c72c29c
2 changed files with 31 additions and 12 deletions

View File

@ -108,18 +108,21 @@ extern char *__progname;
static void static void
usage() { 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); exit(2);
} }
static void static void
help() { help() {
printf("iodine IP over DNS tunneling server\n"); printf("iodine IP over DNS tunneling server\n");
printf("Usage: %s [-v] [-h] [-f] [-u user] [-t chrootdir] " printf("Usage: %s [-v] [-h] [-f] [-u user] [-t chrootdir] [-m mtu] "
"topdomain\n", __progname); "tunnel_ip topdomain\n", __progname);
printf(" -f to keep running in foreground\n"); printf(" -f to keep running in foreground\n");
printf(" -u name to drop privileges and run as user 'name'\n"); printf(" -u name to drop privileges and run as user 'name'\n");
printf(" -t dir to chroot to directory dir\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); exit(0);
} }
@ -140,12 +143,15 @@ main(int argc, char **argv)
char *newroot; char *newroot;
char *username; char *username;
int foreground; int foreground;
int mtu;
struct passwd *pw; struct passwd *pw;
username = NULL; username = NULL;
newroot = NULL;
foreground = 0; foreground = 0;
mtu = 1024;
while ((choice = getopt(argc, argv, "vfhu:t:")) != -1) { while ((choice = getopt(argc, argv, "vfhu:t:m:")) != -1) {
switch(choice) { switch(choice) {
case 'v': case 'v':
version(); version();
@ -162,6 +168,9 @@ main(int argc, char **argv)
case 't': case 't':
newroot = optarg; newroot = optarg;
break; break;
case 'm':
mtu = atoi(optarg);
break;
default: default:
usage(); usage();
break; break;
@ -176,7 +185,7 @@ main(int argc, char **argv)
usage(); usage();
} }
if (argc != 1) if (argc != 2)
usage(); usage();
if (username) { if (username) {
@ -187,9 +196,16 @@ main(int argc, char **argv)
} }
} }
if ((tun_fd = open_tun()) == -1) 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; goto cleanup1;
if ((dnsd_fd = open_dnsd(argv[0])) == -1) if ((dnsd_fd = open_dnsd(argv[1])) == -1)
goto cleanup2; goto cleanup2;
@ -220,6 +236,7 @@ cleanup2:
close_dnsd(dnsd_fd); close_dnsd(dnsd_fd);
cleanup1: cleanup1:
close_tun(tun_fd); close_tun(tun_fd);
cleanup0:
return 0; return 0;
} }

12
tun.c
View File

@ -31,7 +31,7 @@
#define TUN_MAX_TRY 50 #define TUN_MAX_TRY 50
char *tun_device = NULL; char *tun_device = NULL;
char *if_device = NULL; char *if_name = NULL;
#ifdef LINUX #ifdef LINUX
@ -63,7 +63,7 @@ open_tun()
if (ioctl(tun_fd, TUNSETIFF, (void *) &ifreq) != -1) { if (ioctl(tun_fd, TUNSETIFF, (void *) &ifreq) != -1) {
printf("Opened %s\n", ifreq.ifr_name); printf("Opened %s\n", ifreq.ifr_name);
if_device = strdup(ifreq.ifr_name); if_name = strdup(ifreq.ifr_name);
return tun_fd; return tun_fd;
} }
@ -98,7 +98,7 @@ open_tun()
if ((tun_fd = open(tun_name, O_RDWR)) >= 0) { if ((tun_fd = open(tun_name, O_RDWR)) >= 0) {
printf("Opened %s\n", tun_name); printf("Opened %s\n", tun_name);
if_device = strdup(tun_name); if_name = strdup(tun_name);
return tun_fd; return tun_fd;
} }
@ -158,7 +158,7 @@ tun_setip(const char *ip)
if (inet_addr(ip) != 0) { if (inet_addr(ip) != 0) {
snprintf(cmdline, sizeof(cmdline), snprintf(cmdline, sizeof(cmdline),
"/sbin/ifconfig %s %s netmask 255.255.255.0", "/sbin/ifconfig %s %s netmask 255.255.255.0",
tun_device, if_name,
ip); ip);
#ifndef LINUX #ifndef LINUX
int r; int r;
@ -173,6 +173,7 @@ tun_setip(const char *ip)
} }
#endif #endif
printf("Setting IP of %s to %s\n", if_name, ip);
return system(cmdline); return system(cmdline);
} }
@ -187,9 +188,10 @@ tun_setmtu(const int mtu)
if (mtu > 200 && mtu < 1500) { if (mtu > 200 && mtu < 1500) {
snprintf(cmdline, sizeof(cmdline), snprintf(cmdline, sizeof(cmdline),
"/sbin/ifconfig %s mtu %d", "/sbin/ifconfig %s mtu %d",
tun_device, if_name,
mtu); mtu);
printf("Setting MTU of %s to %d\n", if_name, mtu);
return system(cmdline); return system(cmdline);
} }