shithub: riscv

Download patch

ref: abc5a66c566e217f8683b6a105860ad05709d541
parent: fed50d79d38881437639f3189b4a99aee93daa9a
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Wed Apr 8 19:37:38 EDT 2020

9bootpxe: continues the war against random DHCPv6 DUIDs

Some UEFI implementations use random UUID based DUID instead of
ethernet address, but use ethernet derived link-local addresses.
So extract the MAC from our IPv6 address.

--- a/sys/src/boot/efi/pxe.c
+++ b/sys/src/boot/efi/pxe.c
@@ -367,6 +367,7 @@
 	char *x;
 	int opt;
 	int len;
+	uint type;
 
 	memset(mymac, 0, sizeof(mymac));
 	memset(serverip, 0, sizeof(serverip));
@@ -389,7 +390,15 @@
 			break;
 		switch(opt){
 		case 1:	/* Client DUID */
-			memmove(mymac, p+len-6, 6);
+			if(len < 4+6)
+				break;
+			type = p[0]<<24 | p[1]<<16 | p[2]<<8 | p[3];
+			switch(type){
+			case 0x00010001:
+			case 0x00030001:
+				memmove(mymac, p+len-6, 6);
+				break;
+			}
 			break;
 		case 59: /* Boot File URL */
 			for(x = (char*)p; x < (char*)p+len; x++){
@@ -401,6 +410,21 @@
 			break;
 		}
 		p += len;
+	}
+
+	/*
+	 * some UEFI implementations use random UUID based DUID instead of
+	 * ethernet address, but use ethernet derived link-local addresses.
+	 * so extract the MAC from our IPv6 address.
+	 */
+	if((mymac[0]|mymac[1]|mymac[2]|mymac[3]|mymac[4]|mymac[5]) == 0){
+		p = pxe->Mode->StationIp;
+		mymac[0] = p[8] ^ 2;
+		mymac[1] = p[9];
+		mymac[2] = p[10];
+		mymac[3] = p[13];
+		mymac[4] = p[14];
+		mymac[5] = p[15];
 	}
 }