From: Roy Marples Date: Fri, 6 Sep 2019 11:52:22 +0000 (+0100) Subject: DHCP: If root fs is network mounted, enable last lease extend X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d68b260c745008426e8411121325b6cf4d038ddd;p=thirdparty%2Fdhcpcd.git DHCP: If root fs is network mounted, enable last lease extend We don't want expiry to unmount the root FS. Also, we don't want a reboot with an expired lease to kill our current assignment either. Only works on NetBSD right now. --- diff --git a/src/common.c b/src/common.c index 838b4887..8b45a307 100644 --- a/src/common.c +++ b/src/common.c @@ -26,6 +26,8 @@ * SUCH DAMAGE. */ +#include + #include #include #include @@ -135,3 +137,18 @@ read_hwaddr_aton(uint8_t **data, const char *path) fclose(fp); return len; } + +int +is_root_local(void) +{ +#ifdef ST_LOCAL + struct statvfs vfs; + + if (statvfs("/", &vfs) == -1) + return -1; + return vfs.f_flag & ST_LOCAL ? 1 : 0; +#else + errno = ENOTSUP; + return -1; +#endif +} diff --git a/src/common.h b/src/common.h index 301c8869..4e8bcdea 100644 --- a/src/common.h +++ b/src/common.h @@ -197,4 +197,5 @@ int get_monotonic(struct timespec *); const char *hwaddr_ntoa(const void *, size_t, char *, size_t); size_t hwaddr_aton(uint8_t *, const char *); size_t read_hwaddr_aton(uint8_t **, const char *); +int is_root_local(void); #endif diff --git a/src/dhcpcd.c b/src/dhcpcd.c index 6d361e49..f944d9e6 100644 --- a/src/dhcpcd.c +++ b/src/dhcpcd.c @@ -590,6 +590,12 @@ configure_interface1(struct interface *ifp) } } #endif + + /* If root is network mounted, we don't want to kill the connection + * if the DHCP server goes the way of the dodo OR dhcpcd is rebooting + * and the lease file has expired. */ + if (is_root_local() == 0) + ifo->options |= DHCPCD_LASTLEASE_EXTEND; } int