Blame SOURCES/dnsmasq-2.79-alternative-lease.patch

085fce
From 268080fc19990711a1d1e1acd68a50aa2f6cb5fb Mon Sep 17 00:00:00 2001
085fce
From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= <pemensik@redhat.com>
085fce
Date: Fri, 17 Sep 2021 20:12:21 +0200
085fce
Subject: [PATCH] Offer alternative DHCPv6 address if requested is taken
085fce
085fce
In some cases multiple requests might arrive from single DUID. It may
085fce
happen just one address is offered to different IAID requests. When
085fce
the first request confirms lease, another would be offered alternative
085fce
address instead of address in use error.
085fce
085fce
Includes check on such Rapid commit equivalents and returns NotOnLink
085fce
error, required by RFC 8145, if requested address were not on any
085fce
supported prefix.
085fce
---
085fce
 src/rfc3315.c | 39 ++++++++++++++++++++++++++++-----------
085fce
 1 file changed, 28 insertions(+), 11 deletions(-)
085fce
085fce
diff --git a/src/rfc3315.c b/src/rfc3315.c
085fce
index 5c2ff97..d1534ad 100644
085fce
--- a/src/rfc3315.c
085fce
+++ b/src/rfc3315.c
085fce
@@ -614,7 +614,7 @@ static int dhcp6_no_relay(struct state *state, int msg_type, void *inbuff, size_
085fce
       
085fce
     case DHCP6SOLICIT:
085fce
       {
085fce
-      	int address_assigned = 0;
085fce
+	int address_assigned = 0, ia_invalid = 0;
085fce
 	/* tags without all prefix-class tags */
085fce
 	struct dhcp_netid *solicit_tags;
085fce
 	struct dhcp_context *c;
085fce
@@ -697,6 +697,8 @@ static int dhcp6_no_relay(struct state *state, int msg_type, void *inbuff, size_
085fce
 		    get_context_tag(state, c);
085fce
 		    address_assigned = 1;
085fce
 		  }
085fce
+		else
085fce
+		  ia_invalid++;
085fce
 	      }
085fce
 	    
085fce
 	    /* Suggest configured address(es) */
085fce
@@ -782,11 +784,26 @@ static int dhcp6_no_relay(struct state *state, int msg_type, void *inbuff, size_
085fce
 	    tagif = add_options(state, 0);
085fce
 	  }
085fce
 	else
085fce
-	  { 
085fce
+	  {
085fce
+	    char *errmsg;
085fce
 	    /* no address, return error */
085fce
 	    o1 = new_opt6(OPTION6_STATUS_CODE);
085fce
-	    put_opt6_short(DHCP6NOADDRS);
085fce
-	    put_opt6_string(_("no addresses available"));
085fce
+	    if (state->lease_allocate && ia_invalid)
085fce
+	      {
085fce
+		/* RFC 8415, Section 18.3.2:
085fce
+		   If any of the prefixes of the included addresses are not
085fce
+		   appropriate for the link to which the client is connected,
085fce
+		   the server MUST return the IA to the client with a Status
085fce
+		   Code option with the value NotOnLink. */
085fce
+		put_opt6_short(DHCP6NOTONLINK);
085fce
+		errmsg = _("not on link");
085fce
+	      }
085fce
+	    else
085fce
+	      {
085fce
+		put_opt6_short(DHCP6NOADDRS);
085fce
+		errmsg = _("no addresses available");
085fce
+	      }
085fce
+	    put_opt6_string(errmsg);
085fce
 	    end_opt6(o1);
085fce
 
085fce
 	    /* Some clients will ask repeatedly when we're not giving
085fce
@@ -795,7 +812,7 @@ static int dhcp6_no_relay(struct state *state, int msg_type, void *inbuff, size_
085fce
 	    for (c = state->context; c; c = c->current)
085fce
 	      if (!(c->flags & CONTEXT_RA_STATELESS))
085fce
 		{
085fce
-		  log6_packet(state, state->lease_allocate ? "DHCPREPLY" : "DHCPADVERTISE", NULL, _("no addresses available"));
085fce
+		  log6_packet(state, state->lease_allocate ? "DHCPREPLY" : "DHCPADVERTISE", NULL, errmsg);
085fce
 		  break;
085fce
 		}
085fce
 	  }
085fce
@@ -831,7 +848,7 @@ static int dhcp6_no_relay(struct state *state, int msg_type, void *inbuff, size_
085fce
 		 /* If we get a request with an IA_*A without addresses, treat it exactly like
085fce
 		    a SOLICT with rapid commit set. */
085fce
 		 save_counter(start);
085fce
-		 goto request_no_address; 
085fce
+		 goto request_no_address;
085fce
 	       }
085fce
 
085fce
 	    o = build_ia(state, &t1cntr);
085fce
@@ -861,11 +878,11 @@ static int dhcp6_no_relay(struct state *state, int msg_type, void *inbuff, size_
085fce
 		      }
085fce
 		    else if (!check_address(state, &req_addr))
085fce
 		      {
085fce
-			/* Address leased to another DUID/IAID */
085fce
-			o1 = new_opt6(OPTION6_STATUS_CODE);
085fce
-			put_opt6_short(DHCP6UNSPEC);
085fce
-			put_opt6_string(_("address in use"));
085fce
-			end_opt6(o1);
085fce
+			/* Address leased to another DUID/IAID.
085fce
+			   Find another address for the client, treat it exactly like
085fce
+			   a SOLICT with rapid commit set. */
085fce
+			save_counter(start);
085fce
+			goto request_no_address;
085fce
 		      } 
085fce
 		    else 
085fce
 		      {
085fce
-- 
085fce
2.31.1
085fce