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

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