[Dnsmasq-discuss] [PATCH] Enable netboot of raspberry pi (DHCP)

Lluís Batlle i Rossell viric at viric.name
Fri Jan 3 10:40:43 UTC 2025


Hello,

here is a patch I used to be able to netboot Raspberry Pi (2B in my case).
Their bootcode.bin expects a proxy DHCP like for PXE, but it doesn't want a
filename+sname/tftp_name to fetch a file, but instead it requests DHCP
Option 66 (TFTP Server) to try to download a wide set of files.

Regards,
Lluís.
-------------- next part --------------
diff --git a/src/rfc2131.c b/src/rfc2131.c
index 68834ea..f3eec95 100644
--- a/src/rfc2131.c
+++ b/src/rfc2131.c
@@ -855,6 +855,13 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index,
   /* Can have setting to ignore the client ID for a particular MAC address or hostname */
   if (have_config(config, CONFIG_NOCLID))
     clid = NULL;
+  
+  if ((opt = option_find(mess, sz, OPTION_REQUESTED_OPTIONS, 0)))
+    {
+      req_options = (unsigned char *)daemon->dhcp_buff2;
+      memcpy(req_options, option_ptr(opt, 0), option_len(opt));
+      req_options[option_len(opt)] = OPTION_END;
+    }
           
   /* Check if client is PXE client. */
   if (daemon->enable_pxe &&
@@ -991,10 +998,27 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index,
 		      if (boot->next_server.s_addr) 
 			mess->siaddr = boot->next_server;
 		      else if (boot->tftp_sname) 
-			mess->siaddr = a_record_from_hosts(boot->tftp_sname, now);
-		      
+		        {
+			  if (!option_bool(OPT_NO_OVERRIDE) &&
+				  req_options && 
+				  in_list(req_options, OPTION_SNAME))
+			      option_put_string(mess, end, OPTION_SNAME, boot->tftp_sname, 1);
+			  else
+			    {
+			      mess->siaddr = a_record_from_hosts(boot->tftp_sname, now);
+			      safe_strncpy((char *)mess->sname, boot->tftp_sname, sizeof(mess->sname));
+			    }
+		        }
+
 		      if (boot->file)
-			safe_strncpy((char *)mess->file, boot->file, sizeof(mess->file));
+		        {
+			  if (!option_bool(OPT_NO_OVERRIDE) &&
+				  req_options && 
+				  in_list(req_options, OPTION_FILENAME))
+			      option_put_string(mess, end, OPTION_FILENAME, boot->file, 1);
+			  else
+			      safe_strncpy((char *)mess->file, boot->file, sizeof(mess->file));
+			}
 		    }
 		  
 		  option_put(mess, end, OPTION_MESSAGE_TYPE, 1, 
@@ -1020,13 +1044,6 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index,
   if ((context->flags & CONTEXT_PROXY) || pxe)
     return 0;
   
-  if ((opt = option_find(mess, sz, OPTION_REQUESTED_OPTIONS, 0)))
-    {
-      req_options = (unsigned char *)daemon->dhcp_buff2;
-      memcpy(req_options, option_ptr(opt, 0), option_len(opt));
-      req_options[option_len(opt)] = OPTION_END;
-    }
-  
   switch (mess_type)
     {
     case DHCPDECLINE:


More information about the Dnsmasq-discuss mailing list