[Dnsmasq-discuss] Enable dnsmasq to return addresses of multiple tftp servers in cycle

Sushil Agrawal sushil_agrawal at hotmail.com
Sat Jun 18 17:52:23 BST 2011



Hi All,

The attached patch enables dnsmasq(8) to return the ip addresses
of multiple tftp servers (for pxe boot) having a single alias
name (thru the /etc/hosts) in round robin fashion.

We have a virtual environment where there are some managed hosts
running kvm hypervisor and some > 150  virtual machines
carved out of these hosts. All these virtual machines are thin
clients which boot of the net using pxe. The arrangement is such
that all of these machines boot at the same time and in order to
balance the load on the tftp server, we planned to have multiple
tftp servers (on these managed hosts themselves) running.

dnsmasq currently returns only one address for tftp server
which it finds in the dhcp-boot option in the dnsmasq.conf
file. Although there is a provision for specifying the
tftp server name there but it is not used. We made
use of this name as an alias for multiple tftp servers
(using /etc/hosts) and then return the resolved addresses
one by one in cycle.

The function cache_find_by_name() already takes care
of all this and all we had to do was to just call
it in dhcp_reply() to get one address and return
that as tftp address.

If the tftp server address is specified in the dhcp-boot
option then that address is returned always. If address
is not specified and name is specified then this cyclic
stuff is done. This solution is working for us and hope it
will be useful to others.


Following is the patch (also attached) based on
dnsmasq-2.57:

................................................................

--- dnsmasq-2.57.origg/src/rfc2131.c    2011-02-17 21:00:15.000000000 +0530
+++ dnsmasq-2.57/src/rfc2131.c    2011-06-18 17:48:59.000000000 +0530
@@ -829,8 +829,23 @@
              and set discovery_control = 8 */
           if (boot)
             {
-              if (boot->next_server.s_addr)
+              if (boot->next_server.s_addr) {
             mess->siaddr = boot->next_server;
+              } else if (boot->sname) {
+
+                /*
+                 * If the pxe server name is given in the conf then
+                 * cycle thru its addresses.
+                 */
+
+                struct crec *crecp;
+                time_t now = dnsmasq_time();
+                crecp = cache_find_by_name(NULL, boot->sname, now,
+                               F_DHCP | F_HOSTS);
+                if (crecp) {
+                    mess->siaddr = *(struct in_addr*)&crecp->addr;
+                }
+              }
               
               if (boot->file)
             strncpy((char *)mess->file, boot->file, sizeof(mess->file)-1);
@@ -2222,8 +2237,23 @@
         strncpy((char *)mess->file, boot->file, sizeof(mess->file)-1);
     }
       
-      if (boot->next_server.s_addr)
+      if (boot->next_server.s_addr) {
     mess->siaddr = boot->next_server;
+      } else if (boot->sname) {
+
+        /*
+         * If the pxe server name is given in the conf then
+         * cycle thru its addresses.
+         */
+
+        struct crec *crecp;
+          time_t now = dnsmasq_time();
+        crecp = cache_find_by_name(NULL, boot->sname, now,
+                       F_DHCP | F_HOSTS);
+        if (crecp) {
+            mess->siaddr = *(struct in_addr*)&crecp->addr;
+        }
+      }
     }
   else
     /* Use the values of the relevant options if no dhcp-boot given and
................................................................

Sushil.


 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/attachments/20110618/251b570e/attachment.htm 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: diff.txt
Url: http://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/attachments/20110618/251b570e/attachment.txt 


More information about the Dnsmasq-discuss mailing list