diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-12-08 23:52:28 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-12-08 23:52:28 +0100 |
commit | b3b4397734e2845d9fa0f994550dc960ad1900d1 (patch) | |
tree | b8f3b3b6aaa18f5ec4c15a8dc1f6d12978fd5def | |
parent | 6b6099a630510cab290a6115ebf4100e630cd497 (diff) | |
download | fastd-b3b4397734e2845d9fa0f994550dc960ad1900d1.tar fastd-b3b4397734e2845d9fa0f994550dc960ad1900d1.zip |
Only try to set MTU when it isn't correct
This allows fastd to run completely without root privileges when the TUN/TAP
device is pre-created
-rw-r--r-- | src/fastd.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/fastd.c b/src/fastd.c index 3b8531f..af9ba6e 100644 --- a/src/fastd.c +++ b/src/fastd.c @@ -308,9 +308,14 @@ static void init_tuntap(fastd_context *ctx) { if (ctl_sock < 0) exit_errno(ctx, "socket"); - ifr.ifr_mtu = ctx->conf->mtu; - if (ioctl(ctl_sock, SIOCSIFMTU, &ifr) < 0) - exit_errno(ctx, "SIOCSIFMTU ioctl failed"); + if (ioctl(ctl_sock, SIOCGIFMTU, &ifr) < 0) + exit_errno(ctx, "SIOCGIFMTU ioctl failed"); + + if (ifr.ifr_mtu != ctx->conf->mtu) { + ifr.ifr_mtu = ctx->conf->mtu; + if (ioctl(ctl_sock, SIOCSIFMTU, &ifr) < 0) + exit_errno(ctx, "SIOCSIFMTU ioctl failed"); + } if (close(ctl_sock)) pr_error_errno(ctx, "close"); |