Re: [ipxe-devel] [PATCH 1/3] dhcpv6: Fallback to using DUID-LL for empty UUID

2018-03-01 Thread Michael Brown

On 05/02/18 08:36, Hannes Reinecke wrote:

+/** DHCP unique identifier based on Ethernet Link-layer address (DUID-LL) */
+struct dhcpv6_duid_eth_ll {
+   /** Type */
+   uint16_t type;
+   /** Hardware type: Ethernet */
+   uint16_t hw_type;
+   /** Ethernet link-layer address */
+   uint8_t ll_addr[ETH_ALEN];
+} __attribute__ (( packed ));


This needs to handle link-layer addresses that are not ETH_ALEN bytes 
long, since:



+   memcpy( dhcpv6->client_duid.ll.ll_addr, netdev->ll_addr,
+   ll_protocol->ll_addr_len );


Thanks,

Michael
___
ipxe-devel mailing list
ipxe-devel@lists.ipxe.org
https://lists.ipxe.org/mailman/listinfo.cgi/ipxe-devel


[ipxe-devel] [PATCH 1/3] dhcpv6: Fallback to using DUID-LL for empty UUID

2018-02-05 Thread Hannes Reinecke
If the system UUID is empty we cannot use it as a
DUID for DCHPv6.
So fallback to use DUID-LL in these cases.

Signed-off-by: Hannes Reinecke 
---
 src/core/uuid.c   |  2 ++
 src/include/ipxe/dhcpv6.h | 13 +
 src/include/ipxe/uuid.h   |  2 ++
 src/net/udp/dhcpv6.c  | 28 +---
 4 files changed, 38 insertions(+), 7 deletions(-)

diff --git a/src/core/uuid.c b/src/core/uuid.c
index c43d4216f..c19ff8bf1 100644
--- a/src/core/uuid.c
+++ b/src/core/uuid.c
@@ -34,6 +34,8 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  *
  */
 
+const union uuid null_uuid;
+
 /**
  * Convert UUID to printable string
  *
diff --git a/src/include/ipxe/dhcpv6.h b/src/include/ipxe/dhcpv6.h
index 6e70f7e63..c865fa02a 100644
--- a/src/include/ipxe/dhcpv6.h
+++ b/src/include/ipxe/dhcpv6.h
@@ -11,6 +11,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 
 #include 
 #include 
+#include 
 #include 
 
 /** DHCPv6 server port */
@@ -32,6 +33,16 @@ struct dhcpv6_option {
uint8_t data[0];
 } __attribute__ (( packed ));
 
+/** DHCP unique identifier based on Ethernet Link-layer address (DUID-LL) */
+struct dhcpv6_duid_eth_ll {
+   /** Type */
+   uint16_t type;
+   /** Hardware type: Ethernet */
+   uint16_t hw_type;
+   /** Ethernet link-layer address */
+   uint8_t ll_addr[ETH_ALEN];
+} __attribute__ (( packed ));
+
 /** DHCP unique identifier based on UUID (DUID-UUID) */
 struct dhcpv6_duid_uuid {
/** Type */
@@ -40,6 +51,8 @@ struct dhcpv6_duid_uuid {
union uuid uuid;
 } __attribute__ (( packed ));
 
+/** DHCP unique identifier based on link-layer address (DUID-LL) */
+#define DHCPV6_DUID_LL 3
 /** DHCP unique identifier based on UUID (DUID-UUID) */
 #define DHCPV6_DUID_UUID 4
 
diff --git a/src/include/ipxe/uuid.h b/src/include/ipxe/uuid.h
index 24c46acaf..84675973a 100644
--- a/src/include/ipxe/uuid.h
+++ b/src/include/ipxe/uuid.h
@@ -49,4 +49,6 @@ static inline void uuid_mangle ( union uuid *uuid ) {
 
 extern const char * uuid_ntoa ( const union uuid *uuid );
 
+extern const union uuid null_uuid;
+
 #endif /* _IPXE_UUID_H */
diff --git a/src/net/udp/dhcpv6.c b/src/net/udp/dhcpv6.c
index 253032e4e..090e03130 100644
--- a/src/net/udp/dhcpv6.c
+++ b/src/net/udp/dhcpv6.c
@@ -508,7 +508,11 @@ struct dhcpv6_session {
/** Start time (in ticks) */
unsigned long start;
/** Client DUID */
-   struct dhcpv6_duid_uuid client_duid;
+   union {
+   struct dhcpv6_duid_uuid uuid;
+   struct dhcpv6_duid_eth_ll ll;
+   } client_duid;
+   int client_duid_len;
/** Server DUID, if known */
void *server_duid;
/** Server DUID length */
@@ -627,7 +631,7 @@ static int dhcpv6_tx ( struct dhcpv6_session *dhcpv6 ) {
 
/* Calculate lengths */
client_id_len = ( sizeof ( *client_id ) +
- sizeof ( dhcpv6->client_duid ) );
+ dhcpv6->client_duid_len );
server_id_len = ( dhcpv6->server_duid ? ( sizeof ( *server_id ) +
  dhcpv6->server_duid_len ) :0);
if ( dhcpv6->state->flags & DHCPV6_TX_IA_NA ) {
@@ -662,7 +666,7 @@ static int dhcpv6_tx ( struct dhcpv6_session *dhcpv6 ) {
client_id->header.len = htons ( client_id_len -
sizeof ( client_id->header ) );
memcpy ( client_id->duid, >client_duid,
-sizeof ( dhcpv6->client_duid ) );
+dhcpv6->client_duid_len );
 
/* Construct server identifier, if applicable */
if ( server_id_len ) {
@@ -793,7 +797,7 @@ static int dhcpv6_rx ( struct dhcpv6_session *dhcpv6,
/* Verify client identifier */
if ( ( rc = dhcpv6_check_duid ( , DHCPV6_CLIENT_ID,
>client_duid,
-   sizeof ( dhcpv6->client_duid ) ) ) !=0){
+   dhcpv6->client_duid_len ) ) !=0){
DBGC ( dhcpv6, "DHCPv6 %s received %s without correct client "
   "ID: %s\n", dhcpv6->netdev->name,
   dhcpv6_type_name ( dhcphdr->type ), strerror ( rc ) );
@@ -959,15 +963,25 @@ int start_dhcpv6 ( struct interface *job, struct 
net_device *netdev,
addresses.server.sin6.sin6_port = htons ( DHCPV6_SERVER_PORT );
 
/* Construct client DUID from system UUID */
-   dhcpv6->client_duid.type = htons ( DHCPV6_DUID_UUID );
+   dhcpv6->client_duid_len = sizeof(struct dhcpv6_duid_uuid);
+   dhcpv6->client_duid.uuid.type = htons ( DHCPV6_DUID_UUID );
if ( ( len = fetch_uuid_setting ( NULL, _setting,
- >client_duid.uuid ) ) < 0 ) {
+ >client_duid.uuid.uuid ) ) <= 
0 ) {
rc = len;
DBGC ( dhcpv6, "DHCPv6 %s could not create DUID-UUID: %s\n",