]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Move last last extending into it's own option so we can use the last lease
authorRoy Marples <roy@marples.name>
Sat, 30 Apr 2016 07:30:40 +0000 (07:30 +0000)
committerRoy Marples <roy@marples.name>
Sat, 30 Apr 2016 07:30:40 +0000 (07:30 +0000)
in a RFC compliant or incompliant way by choice.

dhcp.c
dhcpcd.8.in
if-options.c
if-options.h

diff --git a/dhcp.c b/dhcp.c
index 15fba78850d8af4d3c8cf8b96ceb499e0a02f183..03f822d176480ac8bc0efcbec94420148ae210e3 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
@@ -1850,7 +1850,7 @@ dhcp_expire(void *arg)
        struct interface *ifp = arg;
 
        logger(ifp->ctx, LOG_ERR, "%s: DHCP lease expired", ifp->name);
-       if (ifp->options->options & DHCPCD_LASTLEASE) {
+       if (ifp->options->options & DHCPCD_LASTLEASE_EXTEND) {
                if (dhcp_leaseextend(ifp) == 0)
                        return;
                logger(ifp->ctx, LOG_ERR, "%s: dhcp_leaseextend: %m",
@@ -2185,7 +2185,9 @@ dhcp_lastlease(void *arg)
        if (ifp->ctx->options & DHCPCD_FORKED)
                return;
        state->interval = 0;
-       if (dhcp_leaseextend(ifp) == -1) {
+       if (ifp->options->options & DHCPCD_LASTLEASE_EXTEND &&
+           dhcp_leaseextend(ifp) == -1)
+       {
                logger(ifp->ctx, LOG_ERR, "%s: dhcp_leaseextend: %m",
                    ifp->name);
                dhcp_expire(ifp);
@@ -3409,7 +3411,7 @@ dhcp_start1(void *arg)
                                free(state->offer);
                                state->offer = NULL;
                        }
-               } else if (!(ifo->options & DHCPCD_LASTLEASE) &&
+               } else if (!(ifo->options & DHCPCD_LASTLEASE_EXTEND) &&
                    state->lease.leasetime != ~0U &&
                    stat(state->leasefile, &st) == 0)
                {
@@ -3470,6 +3472,11 @@ dhcp_start(struct interface *ifp)
        if (!(ifp->options->options & DHCPCD_IPV4))
                return;
 
+       /* If we violate RFC2131 section 3.7 then require ARP
+        * to detect if any other client wants our address. */
+       if (ifp->options->options & DHCPCD_LASTLEASE_EXTEND)
+               ifp->options->options |= DHCPCD_ARP;
+
        /* No point in delaying a static configuration */
        if (ifp->options->options & DHCPCD_STATIC ||
            !(ifp->options->options & DHCPCD_INITIAL_DELAY))
index a72502a5ab884ff469e262be4ae350ac6cdccecc..6772968e8bb81416b60467055423b5aee5a34ef1 100644 (file)
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd April 27, 2016
+.Dd April 30, 2016
 .Dt DHCPCD 8
 .Os
 .Sh NAME
@@ -268,9 +268,12 @@ If
 .Nm
 cannot obtain a lease, then try to use the last lease acquired for the
 interface.
-If the
-.Fl p, Fl Fl persistent
-option is not given then the lease is used if it hasn't expired.
+.It Fl Fl lastleaseextend
+Same as the above, but he lease will be retained even if it expires.
+.Nm
+will give it up if any other host tries to claim it for their own via ARP.
+This is does violate RFC2131 section 3.7 which states the lease should be
+dropped once it has expired.
 .It Fl e , Fl Fl env Ar value
 Push
 .Ar value
index 75d381d8f21955c903e7df954eb528b5c22a4c98..6b2052bbfa19b10a22c3ad9ca4a06f9ac34450fe 100644 (file)
 #define O_DEFINEND             O_BASE + 43
 #define O_NODELAY              O_BASE + 44
 #define O_INFORM6              O_BASE + 45
+#define O_LASTLEASE_EXTEND     O_BASE + 46
 
 const struct option cf_options[] = {
        {"background",      no_argument,       NULL, 'b'},
@@ -198,6 +199,7 @@ const struct option cf_options[] = {
        {"bootp",           no_argument,       NULL, O_BOOTP},
        {"nodelay",         no_argument,       NULL, O_NODELAY},
        {"noup",            no_argument,       NULL, O_NOUP},
+       {"lastleaseextend", no_argument,       NULL, O_LASTLEASE_EXTEND},
        {NULL,              0,                 NULL, '\0'}
 };
 
@@ -2086,6 +2088,9 @@ err_sla:
        case O_NODELAY:
                ifo->options &= ~DHCPCD_INITIAL_DELAY;
                break;
+       case O_LASTLEASE_EXTEND:
+               ifo->options |= DHCPCD_LASTLEASE | DHCPCD_LASTLEASE_EXTEND;
+               break;
        default:
                return 0;
        }
index 9d825569d4317329b4a46c68901d014c786c4b5f..a0be326a5bf5eb62d418694ff5a96ff1e6c8ef68 100644 (file)
 #define DHCPCD_RTM_PPID                        (1ULL << 53)
 #define DHCPCD_IPV6RA_AUTOCONF         (1ULL << 54)
 #define DHCPCD_ROUTER_HOST_ROUTE_WARNED        (1ULL << 55)
-// unassigned  (1ULL << 56)
+#define DHCPCD_LASTLEASE_EXTEND                (1ULL << 56)
 #define DHCPCD_BOOTP                   (1ULL << 57)
 #define DHCPCD_INITIAL_DELAY           (1ULL << 58)
 #define DHCPCD_PRINT_PIDFILE           (1ULL << 59)