Blame SOURCES/0013-DHCPv6-over-PPP-support-626514.patch

df4638
From 234747fbfd6c6429619ba843713d5b39fb4a513d Mon Sep 17 00:00:00 2001
df4638
From: Pavel Zhukov <pzhukov@redhat.com>
df4638
Date: Thu, 21 Feb 2019 10:33:06 +0100
df4638
Subject: [PATCH 13/26] DHCPv6 over PPP support (#626514)
df4638
Cc: pzhukov@redhat.com
df4638
df4638
---
df4638
 client/dhc6.c     |  3 ++-
df4638
 client/dhclient.c | 17 ++++++++++++++---
df4638
 common/bpf.c      | 16 ++++++++++++++++
df4638
 common/lpf.c      | 16 ++++++++++++++++
df4638
 includes/dhcp.h   |  2 ++
df4638
 includes/dhcpd.h  |  2 +-
df4638
 server/dhcpv6.c   |  3 +++
df4638
 7 files changed, 54 insertions(+), 5 deletions(-)
df4638
df4638
diff --git a/client/dhc6.c b/client/dhc6.c
df4638
index 16a0838..3171828 100644
df4638
--- a/client/dhc6.c
df4638
+++ b/client/dhc6.c
df4638
@@ -5744,7 +5744,8 @@ make_client6_options(struct client_state *client, struct option_state **op,
df4638
 	 */
df4638
 	if ((oc = lookup_option(&dhcpv6_universe, *op,
df4638
 				D6O_CLIENTID)) == NULL) {
df4638
-		if (!option_cache(&oc, &default_duid, NULL, clientid_option,
df4638
+		if (default_duid.len == 0 ||
df4638
+		    !option_cache(&oc, &default_duid, NULL, clientid_option,
df4638
 				  MDL))
df4638
 			log_fatal("Failure assembling a DUID.");
df4638
 
df4638
diff --git a/client/dhclient.c b/client/dhclient.c
df4638
index 5d3f5bc..301132c 100644
df4638
--- a/client/dhclient.c
df4638
+++ b/client/dhclient.c
df4638
@@ -1202,8 +1202,8 @@ main(int argc, char **argv) {
df4638
 			if (default_duid.buffer != NULL)
df4638
 				data_string_forget(&default_duid, MDL);
df4638
 
df4638
-			form_duid(&default_duid, MDL);
df4638
-			write_duid(&default_duid);
df4638
+			if (form_duid(&default_duid, MDL) == ISC_R_SUCCESS)
df4638
+				write_duid(&default_duid);
df4638
 		}
df4638
 	}
df4638
 
df4638
@@ -3956,7 +3956,7 @@ write_options(struct client_state *client, struct option_state *options,
df4638
  * is not how it is intended.  Upcoming rearchitecting the client should
df4638
  * address this "one daemon model."
df4638
  */
df4638
-void
df4638
+isc_result_t
df4638
 form_duid(struct data_string *duid, const char *file, int line)
df4638
 {
df4638
 	struct interface_info *ip;
df4638
@@ -3969,6 +3969,15 @@ form_duid(struct data_string *duid, const char *file, int line)
df4638
 	if (ip == NULL)
df4638
 		log_fatal("Impossible condition at %s:%d.", MDL);
df4638
 
df4638
+	while (ip && ip->hw_address.hbuf[0] == HTYPE_RESERVED) {
df4638
+		/* Try the other interfaces */
df4638
+		log_debug("Cannot form default DUID from interface %s.", ip->name);
df4638
+		ip = ip->next;
df4638
+	}
df4638
+	if (ip == NULL) {
df4638
+		return ISC_R_UNEXPECTED;
df4638
+	}
df4638
+
df4638
 	if ((ip->hw_address.hlen == 0) ||
df4638
 	    (ip->hw_address.hlen > sizeof(ip->hw_address.hbuf)))
df4638
 		log_fatal("Impossible hardware address length at %s:%d.", MDL);
df4638
@@ -4014,6 +4023,8 @@ form_duid(struct data_string *duid, const char *file, int line)
df4638
 		log_info("Created duid %s.", str);
df4638
 		dfree(str, MDL);
df4638
 	}
df4638
+	
df4638
+	return ISC_R_SUCCESS;
df4638
 }
df4638
 
df4638
 /* Write the default DUID to the lease store. */
df4638
diff --git a/common/bpf.c b/common/bpf.c
df4638
index 67b6d64..ffbd09a 100644
df4638
--- a/common/bpf.c
df4638
+++ b/common/bpf.c
df4638
@@ -650,6 +650,22 @@ get_hw_addr(const char *name, struct hardware *hw) {
df4638
                         memcpy(&hw->hbuf[1], LLADDR(sa), sa->sdl_alen);
df4638
                         break;
df4638
 #endif /* IFT_FDDI */
df4638
+#if defined(IFT_PPP)
df4638
+                case IFT_PPP:
df4638
+                        if (local_family != AF_INET6)
df4638
+                             log_fatal("Unsupported device type %d for \"%s\"",
df4638
+                                        sa->sdl_type, name);
df4638
+                        hw->hlen = 0;
df4638
+                        hw->hbuf[0] = HTYPE_RESERVED;
df4638
+                        /* 0xdeadbeef should never occur on the wire,
df4638
+                         *  and is a signature that something went wrong.
df4638
+                         */
df4638
+                        hw->hbuf[1] = 0xde;
df4638
+                        hw->hbuf[2] = 0xad;
df4638
+                        hw->hbuf[3] = 0xbe;
df4638
+                        hw->hbuf[4] = 0xef;
df4638
+                        break;
df4638
+#endif
df4638
                 default:
df4638
                         log_fatal("Unsupported device type %d for \"%s\"",
df4638
                                   sa->sdl_type, name);
df4638
diff --git a/common/lpf.c b/common/lpf.c
df4638
index 82a279b..b0ed01c 100644
df4638
--- a/common/lpf.c
df4638
+++ b/common/lpf.c
df4638
@@ -563,6 +563,22 @@ get_hw_addr(const char *name, struct hardware *hw) {
df4638
 			hw->hbuf[0] = HTYPE_FDDI;
df4638
 			memcpy(&hw->hbuf[1], sa->sa_data, 6);
df4638
 			break;
df4638
+#if defined(ARPHRD_PPP)
df4638
+		case ARPHRD_PPP:
df4638
+			if (local_family != AF_INET6)
df4638
+				log_fatal("Unsupported device type %d for \"%s\"",
df4638
+				           sa->sa_family, name);
df4638
+			hw->hlen = 0;
df4638
+			hw->hbuf[0] = HTYPE_RESERVED;
df4638
+			/* 0xdeadbeef should never occur on the wire,
df4638
+			 * and is a signature that something went wrong.
df4638
+			 */
df4638
+			hw->hbuf[1] = 0xde;
df4638
+			hw->hbuf[2] = 0xad;
df4638
+			hw->hbuf[3] = 0xbe;
df4638
+			hw->hbuf[4] = 0xef;
df4638
+			break;
df4638
+#endif
df4638
 		default:
df4638
 			log_fatal("Unsupported device type %ld for \"%s\"",
df4638
 				  (long int)sa->sa_family, name);
df4638
diff --git a/includes/dhcp.h b/includes/dhcp.h
df4638
index 95bf539..4cc547a 100644
df4638
--- a/includes/dhcp.h
df4638
+++ b/includes/dhcp.h
df4638
@@ -80,6 +80,8 @@ struct dhcp_packet {
df4638
 					 * is no standard for this so we
df4638
 					 * just steal a type            */
df4638
 
df4638
+#define HTYPE_RESERVED	0		/* RFC 5494 */
df4638
+
df4638
 /* Magic cookie validating dhcp options field (and bootp vendor
df4638
    extensions field). */
df4638
 #define DHCP_OPTIONS_COOKIE	"\143\202\123\143"
df4638
diff --git a/includes/dhcpd.h b/includes/dhcpd.h
df4638
index 2ac39ae..faa9251 100644
df4638
--- a/includes/dhcpd.h
df4638
+++ b/includes/dhcpd.h
df4638
@@ -3051,7 +3051,7 @@ void client_dns_remove(struct client_state *client, struct iaddr *addr);
df4638
 
df4638
 void dhcpv4_client_assignments(void);
df4638
 void dhcpv6_client_assignments(void);
df4638
-void form_duid(struct data_string *duid, const char *file, int line);
df4638
+isc_result_t form_duid(struct data_string *duid, const char *file, int line);
df4638
 
df4638
 void dhcp4o6_start(void);
df4638
 
df4638
diff --git a/server/dhcpv6.c b/server/dhcpv6.c
df4638
index a7110f9..c5ce7e8 100644
df4638
--- a/server/dhcpv6.c
df4638
+++ b/server/dhcpv6.c
df4638
@@ -482,6 +482,9 @@ generate_new_server_duid(void) {
df4638
 		if (p->hw_address.hlen > 0) {
df4638
 			break;
df4638
 		}
df4638
+		if (p->next == NULL && p->hw_address.hbuf[0] == HTYPE_RESERVED) {
df4638
+			log_error("Can not generate DUID from interfaces which do not have hardware addresses, please configure server-duid!");
df4638
+		}
df4638
 	}
df4638
 	if (p == NULL) {
df4638
 		return ISC_R_UNEXPECTED;
df4638
-- 
df4638
2.14.5
df4638