I had a box that was installed in 2012 and got a dhcp lease:

$ cat /var/db/dhclient.leases.em0                                  
lease {
  interface "em0";
  fixed-address 172.16.1.5;
  filename "openbsd.0";
  option subnet-mask 255.255.255.0;
  option routers 172.16.1.1;
  option domain-name-servers 8.8.8.8;
  option domain-name "example.com";
  option broadcast-address 172.16.1.255;
  option dhcp-lease-time 6000;
  option dhcp-message-type 5;
  option dhcp-server-identifier 172.16.1.1;
  renew 1 2012/1/16 21:17:31;
  rebind 1 2012/1/16 21:55:01;
  expire 1 2012/1/16 22:07:31;
}

It never ran dhclient after that.

In frontend.c we try to parse "option epoch", but this old file does not
have that. time_t epoch is never initialized in that case and by pure chance
i actually got unwind to use that lease:

$ unwindctl status  
selected             type status
       *         recursor validating
           dhcp forwarder validating
         static forwarder validating

Here is a diff: initialize epoch and lease_time to 0.

ok?

sorry i'm also fixing withespace and comments here, the only real change is

-       time_t   epoch, lease_time, now;
+       time_t   epoch = 0, lease_time = 0, now;


(benno_unwind_dhcp_lease.diff)

diff --git sbin/unwind/frontend.c sbin/unwind/frontend.c
index fef79a78c4c..2946ff00782 100644
--- sbin/unwind/frontend.c
+++ sbin/unwind/frontend.c
@@ -853,12 +853,12 @@ rtmget_default(void)
 void
 parse_dhcp_lease(int fd)
 {
-       FILE    *f;
-       char    *line = NULL, *cur_ns = NULL, *ns = NULL;
-       size_t   linesize = 0;
-       ssize_t  linelen;
-       time_t   epoch, lease_time, now;
-       char **tok, *toks[4], *p;
+       FILE     *f;
+       char     *line = NULL, *cur_ns = NULL, *ns = NULL;
+       size_t    linesize = 0;
+       ssize_t   linelen;
+       time_t    epoch = 0, lease_time = 0, now;
+       char    **tok, *toks[4], *p;
 
        if((f = fdopen(fd, "r")) == NULL) {
                log_warn("cannot read dhcp lease");
@@ -900,8 +900,8 @@ parse_dhcp_lease(int fd)
                        if (epoch + lease_time > now ) {
                                free(ns);
                                ns = cur_ns;
-                               //log_debug("ns: %s, lease_time: %lld, epoch: "
-                               //    "%lld\n", cur_ns, lease_time, epoch);
+                               /* log_debug("ns: %s, lease_time: %lld, epoch: "
+                                  "%lld", cur_ns, lease_time, epoch); */
                        } else /* expired lease */
                                free(cur_ns);
                }

Reply via email to