]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
DHCP: If root fs is network mounted, enable last lease extend
authorRoy Marples <roy@marples.name>
Fri, 6 Sep 2019 11:52:22 +0000 (12:52 +0100)
committerRoy Marples <roy@marples.name>
Fri, 6 Sep 2019 11:52:22 +0000 (12:52 +0100)
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.

src/common.c
src/common.h
src/dhcpcd.c

index 838b4887eff837425b8e4f95761c7a1e8fd8583b..8b45a30709c586c6a6a969c262a86dceee01f02e 100644 (file)
@@ -26,6 +26,8 @@
  * SUCH DAMAGE.
  */
 
+#include <sys/statvfs.h>
+
 #include <ctype.h>
 #include <errno.h>
 #include <stdio.h>
@@ -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
+}
index 301c8869b5451dda850fb3e69871d840deb50810..4e8bcdead667a67b1a5ef7fd091d035837996533 100644 (file)
@@ -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
index 6d361e49a3760deb34331b465a3d56e502a41b21..f944d9e67998b948dadcec181161ca8e72feb8a0 100644 (file)
@@ -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