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