From b3b4397734e2845d9fa0f994550dc960ad1900d1 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 8 Dec 2012 23:52:28 +0100 Subject: 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 --- src/fastd.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/fastd.c') 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"); -- cgit v1.2.3