1717package com .cloud .network ;
1818
1919import com .cloud .agent .api .routing .DnsMasqConfigCommand ;
20- import com .cloud .agent .api .to .DnsmasqTO ;
20+ import com .cloud .agent .api .to .DhcpTO ;
2121import org .apache .log4j .Logger ;
2222
2323import java .util .Arrays ;
@@ -74,11 +74,10 @@ public class DnsMasqConfigurator {
7474 "dhcp-option=6,router_ip,external_dns\n " ,
7575 "dhcp-optsfile=/etc/dhcpopts.txt\n " ,
7676
77-
7877 };
7978
8079 public String [] generateConfiguration (DnsMasqConfigCommand dnsMasqconfigcmd ) {
81- List <DnsmasqTO > dnsmasqTOs = dnsMasqconfigcmd .getIps ();
80+ List <DhcpTO > dhcpTOs = dnsMasqconfigcmd .getIps ();
8281 List <String > dnsMasqconf = Arrays .asList (Dnsmasq_config );
8382 String range ="" ;
8483 String gateway ="" ;
@@ -95,15 +94,42 @@ public String[] generateConfiguration(DnsMasqConfigCommand dnsMasqconfigcmd) {
9594 dns_external = dns_external + "*" ;
9695 dns_external = dns_external .replace (",*" ,"" );
9796 int i =0 ;
98- for (; i < dnsmasqTOs .size (); i ++) {
99- range =range + "dhcp-range=set:range" +i +"," +dnsmasqTOs .get (i ).getStartIpOfSubnet ()+",static\n " ;
100- gateway =gateway +"dhcp-option=tag:range" +i +",3," +dnsmasqTOs .get (i ).getGateway ()+"\n " ;
101- netmask =netmask +"dhcp-option=tag:range" +i +",1," +dnsmasqTOs .get (i ).getNetmask ()+"\n " ;
102- dnsServers =dnsServers +"dhcp-option=tag:range" +i +",6," +dnsmasqTOs .get (i ).getRouterIp ()+"," +dns_external +"\n " ;
97+ for (; i < dhcpTOs .size (); i ++) {
98+ range =range + "dhcp-range=set:range" +i +"," + dhcpTOs .get (i ).getStartIpOfSubnet ()+",static\n " ;
99+ gateway =gateway +"dhcp-option=tag:range" +i +",3," + dhcpTOs .get (i ).getGateway ()+"\n " ;
100+ netmask =netmask +"dhcp-option=tag:range" +i +",1," + dhcpTOs .get (i ).getNetmask ()+"\n " ;
101+ if (!dnsMasqconfigcmd .isDnsProvided ()) {
102+ dnsServers = dnsServers +"dhcp-option=tag:range" +i +",6," +dns_external +"\n " ;
103+ }
104+ else {
105+ dnsServers =dnsServers +"dhcp-option=tag:range" +i +",6," + dhcpTOs .get (i ).getRouterIp ()+"," +dns_external +"\n " ;
106+ }
107+
103108 }
104- dnsMasqconf .set (12 , "domain=" +domain +"\n " );
105- dnsMasqconf .set (14 , "domain=" +domain +"\n " );
106- dnsMasqconf .set (16 ,"domain=" +domain +"\n " );
109+ String domain_suffix = dnsMasqconfigcmd .getDomainSuffix ();
110+
111+ if (domain != null ) {
112+ if (domain_suffix != null ) {
113+
114+ dnsMasqconf .get (5 ).replace (" local=/cs1cloud.internal/" ," local=/" +domain +"/" );
115+ dnsMasqconf .set (12 , "domain=" +domain_suffix +domain +"\n " );
116+ dnsMasqconf .set (14 , "domain=" +domain_suffix +domain +"\n " );
117+ dnsMasqconf .set (16 ,"domain=" +domain_suffix +domain +"\n " );
118+ } else {
119+ dnsMasqconf .get (5 ).replace (" local=/cs1cloud.internal/" ," local=/" +domain +"/" );
120+ dnsMasqconf .set (12 , "domain=" +domain +"\n " );
121+ dnsMasqconf .set (14 , "domain=" +domain +"\n " );
122+ dnsMasqconf .set (16 ,"domain=" +domain +"\n " );
123+ }
124+ }
125+ ///if no domain is specified. this happens when dns service is not provided by the virtualrouter.
126+ else {
127+ dnsMasqconf .get (5 ).replace (" local=/cs1cloud.internal/" ," local=/" +domain +"/" );
128+ dnsMasqconf .set (12 , "domain=" +"cloudnine.internal\n " );
129+ dnsMasqconf .set (14 , "domain=" +"cloudnine.internal\n " );
130+ dnsMasqconf .set (16 ,"domain=" +"cloudnine.internal\n " );
131+ }
132+
107133 dnsMasqconf .set (18 , range );
108134 dnsMasqconf .set (22 , gateway );
109135 dnsMasqconf .set (23 , netmask );
0 commit comments