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

Simon Kelley simon at thekelleys.org.uk
Sat Jun 18 22:44:25 BST 2011


Sushil Agrawal <sushil_agrawal at hotmail.com> wrote:

>
>
>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.
>
>
> 		 	   		  _______________________________________________
>Dnsmasq-discuss mailing list
>Dnsmasq-discuss at lists.thekelleys.org.uk
>http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss

This looks like a great idea, but overloading the server name parameter is not correct. That can be used for other things. The correct way to do this is to check if a name is supplied instead of an address in dhcp-boot and act accordingly. That will need some code in options.c and elaboration of the dhcp boot data structure. 

A general observation for patch submitters. I'm much more likely to look kindly on a patch if it includes documentation, ie a patch to the man page.

I'm away from home at the moment, so further action on this may have to wait until next week.

Cheers, 

Simon.



More information about the Dnsmasq-discuss mailing list