Ticket #19978: dnsmasq

File dnsmasq, 20.5 KB (added by eric_dtw, 3 years ago)

Revised /etc/init.d/dnsmasq for Better IPV6

Line 
1#!/bin/sh /etc/rc.common
2# Revised from OpenWrt.org 6/2015
3#######################################
4
5START=60
6
7USE_PROCD=1
8PROG=/usr/sbin/dnsmasq
9
10DNS_SERVERS=""
11DOMAIN=""
12ADD_LOCAL_DOMAIN=1
13ADD_LOCAL_HOSTNAME=1
14DNSMASQ_DHCP_VER=4
15
16CONFIGFILE="/var/etc/dnsmasq.conf"
17HOSTFILE="/tmp/hosts/dhcp"
18TRUSTANCHORSFILE="/usr/share/dnsmasq/trust-anchors.conf"
19
20#######################################
21
22prettybar() {
23  echo "#######################################" >> $CONFIGFILE
24}
25
26#######################################
27
28xappend() {
29  # dnsmasq.conf uses long command options without "--"
30  local value="$1"
31  echo "${value#--}" >> $CONFIGFILE
32}
33
34#######################################
35
36log_once() {
37  pidof dnsmasq >/dev/null || logger -t dnsmasq "$@"
38}
39
40#######################################
41
42append_bool() {
43  # Check and add boolean (option active if present)
44  local section="$1"
45  local option="$2"
46  local value="$3"
47  local _loctmp
48  config_get_bool _loctmp "$section" "$option" 0
49  [ $_loctmp -gt 0 ] && xappend "$value"
50}
51
52#######################################
53
54append_parm() {
55  # Check and add option with value string assignment
56  local section="$1"
57  local option="$2"
58  local switch="$3"
59  local _loctmp
60  config_get _loctmp "$section" "$option"
61  [ -z "$_loctmp" ] && return 0
62  xappend "$switch=$_loctmp"
63}
64
65#######################################
66
67append_server() {
68  # dnsmasq "server" option in syntax for your private domain (typ. /lan/)
69  # dnsmasq "server" option can also direct domains at specific name servers
70  xappend "--server=$1"
71}
72
73#######################################
74
75append_address() {
76  # explicit DNS "address" override, direct addserver.net to myweb.lan (192.168.1.10)
77  xappend "--address=$1"
78}
79
80#######################################
81
82append_interface() {
83  # tell dnsmasq to listen on interface (default all),
84  # but dnsmasq doesn't do well with VLAN aliases like eth0.1
85  local ifname=$(uci_get_state network "$1" ifname "$1")
86  xappend "--interface=$ifname"
87}
88
89#######################################
90
91append_notinterface() {
92  # ignore dns queries on interface, but again VLAN issue,
93  # and use firewall to block port#53 instead
94  local ifname=$(uci_get_state network "$1" ifname "$1")
95  xappend "--except-interface=$ifname"
96}
97
98#######################################
99
100append_addnhosts() {
101  # Point dnsmasq at other files like /etc/hosts for DNS
102  # Typically, /tmp/hosts/ directory to dump lease files in
103  xappend "--addn-hosts=$1"
104}
105
106#######################################
107
108append_bogusnxdomain() {
109  # Advert. violation of IETF standards to redirect instead of NXDOMAIN
110  # This is the IP4/IP6 violator you want to revert back to NXDOMAIN
111  xappend "--bogus-nxdomain=$1"
112}
113
114#######################################
115
116append_rebind_domain() {
117  log_once "Allowing RFC1918 responses for domain $1"
118  xappend "--rebind-domain-ok=$1"
119}
120
121#######################################
122
123dhcp_calc() {
124  # Apply DHCP4 client start address to subnet base
125  # DNSMASQ does this automatically for DHCP6
126  local ip="$1"
127  local res=0
128  while [ -n "$ip" ]; do
129    part="${ip%%.*}"
130    res="$(($res * 256))"
131    res="$(($res + $part))"
132    [ "${ip%.*}" != "$ip" ] && ip="${ip#*.}" || ip=
133  done
134  echo "$res"
135}
136
137#######################################
138
139dhcp_check() {
140  # Don't serve DHCP4/6 on an interface with self as client
141  local ifname="$1"
142  local stamp="/var/run/dnsmasq.$ifname.dhcp"
143  local rv=0
144
145  # Check done already
146  [ -s "$stamp" ] && return $(cat "$stamp")
147 
148  # Perform check
149  udhcpc -n -q -s /bin/true -t 1 -i "$ifname" >&- && rv=1 || rv=0
150
151  [ $rv -eq 1 ] && logger -t dnsmasq \
152      "found already running DHCP-server on interface '$ifname'" \
153      "refusing to start, use 'option force 1' to override"
154
155  echo $rv > "$stamp"
156  return $rv
157}
158
159#######################################
160
161dhcp_add() {
162  local cfg="$1"
163  local nettag4=""
164  local nettag6=""
165  local dhcp6rng="::"
166 
167  config_get net "$cfg" interface
168  [ -n "$net" ] || return 0
169
170  config_get dhcpv4 "$cfg" dhcpv4
171  [ "$dhcpv4" != "disabled" ] || return 0
172
173  config_get networkid "$cfg" networkid
174  [ -n "$networkid" ] || networkid="$net"
175
176  network_get_subnet subnet "$net" || return 0
177  network_get_device ifname "$net" || return 0
178  network_get_protocol proto "$net" || return 0
179 
180  nettag4="${networkid:+set:${networkid}}"
181  nettag6="${networkid:+set:${networkid}6}"
182 
183  [ "$cachelocal" = "0" ] && network_get_dnsserver dnsserver "$net" && {
184    DNS_SERVERS="$DNS_SERVERS $dnsserver"
185  }
186
187  append_bool "$cfg" ignore "--no-dhcp-interface=$ifname" && return 0
188
189  # Do not support non-static interfaces for now
190  [ static = "$proto" ] || return 0
191
192  # Override interface netmask with dhcp config if applicable
193  config_get netmask "$cfg" netmask "${subnet##*/}"
194
195  #check for an already active dhcp server on the interface, unless 'force' is set
196  config_get_bool force "$cfg" force 0
197  [ $force -gt 0 ] || dhcp_check "$ifname" || return 0
198
199  config_get start "$cfg" start
200  config_get limit "$cfg" limit
201  config_get leasetime "$cfg" leasetime
202  config_get options "$cfg" options
203  config_get_bool dynamicdhcp "$cfg" dynamicdhcp 1
204 
205  # Enter Router Name on Interface for DNS
206  [ $ADD_LOCAL_HOSTNAME -eq 1 ] && {
207    local routername="$(uci_get system @system[0] hostname OpenWrt)"
208    xappend "--interface-name=$routername.$DOMAIN,$ifname"
209    xappend "--interface-name=$routername,$ifname"
210   
211   
212    [ $DNSMASQ_DHCP_VER -eq 6 ] && {
213      xappend "--interface-name=ipv4.$routername.$DOMAIN,$ifname/4"
214      xappend "--interface-name=ipv6.$routername.$DOMAIN,$ifname/6"
215    }
216  }
217 
218  # Construct DHCP4 range on subnet (odd, dnsmasq does this for DHCP6 automatically)
219  leasetime="${leasetime:-12h}"
220  start="$(dhcp_calc "${start:-100}")"
221  limit="${limit:-150}"
222 
223  [ "$limit" -gt 0 ] && limit=$((limit-1))
224  eval "$(ipcalc.sh "${subnet%%/*}" $netmask $start $limit)"
225 
226  [ "$dynamicdhcp" = "0" ] && END="static"
227 
228  xappend "--dhcp-range=$nettag4,$START,$END,$NETMASK,$leasetime${options:+ $options}"
229 
230  # DHCP6 if you want it 
231  config_get dhcpv6 "$cfg" dhcpv6
232  config_get ra "$cfg" ra
233  config_get ra_management "$cfg" ra_management
234  config_get ra_preference "$cfg" ra_preference
235 
236  # DNSMASQ DHCP6 will automatically construct prefix::device in random order
237  [ "$dynamicdhcp" = "0" ] && dhcp6rng="::,static" || dhcp6rng="::1000,::ffff"
238 
239  if [ $DNSMASQ_DHCP_VER -eq 6 ]; then
240    if [ "$ra" == "server" ]; then
241      if [ "$dhcpv6" == "server" ]; then
242        case $ra_management in
243        0)
244          # SLACC with DCHP only for extended data
245          xappend "--dhcp-range=$nettag6,::,constructor:$ifname,ra-stateless,ra-names"
246          ;;
247        2)
248          # DHCP only
249          xappend "--dhcp-range=$nettag6,$dhcp6rng,constructor:$ifname,$leasetime"
250          ;;
251        *)
252          # default) DHCP and SLACC
253          xappend "--dhcp-range=$nettag6,$dhcp6rng,constructor:$ifname,slaac,ra-names,$leasetime"
254          ;;
255        esac
256       
257      else
258        xappend "--dhcp-range=$nettag6,::,constructor:$ifname,ra-only,ra-names"
259      fi
260     
261      xappend "--ra-param=$ifname,${ra_preference:-medium},300,3600"
262    fi
263  fi
264 
265  # Other Options
266  dhcp_option_add "$cfg" "$networkid"
267 
268  echo >> $CONFIGFILE
269}
270
271#######################################
272
273dhcp_host_add() {
274  local cfg="$1"
275  local nettag4=""
276  local nettag6=""
277 
278  config_get_bool force "$cfg" force 0
279  config_get networkid "$cfg" networkid
280  config_get name "$cfg" name
281  config_get ip "$cfg" ip
282  config_get hostid "$cfg" hostid
283  config_get_bool dns "$cfg" dns 0
284  config_get mac "$cfg" mac
285  config_get duid "$cfg" duid
286  config_get tag "$cfg" tag
287  config_get_bool broadcast "$cfg" broadcast 0
288 
289 
290  [ -n "$networkid" ] && dhcp_option_add "$cfg" "$networkid" "$force"
291
292  [ -n "$ip" -o -n "$name" ] || return 0
293 
294  [ "$dns" = "1" -a -n "$ip" -a -n "$name" ] && {
295    echo "$ip $name${DOMAIN:+.$DOMAIN}" >> $HOSTFILE
296  }
297
298  if [ -n "$mac" ]; then
299    # --dhcp-host=00:20:e0:3b:13:af,192.168.0.199,lap
300    macs=""
301    for m in $mac; do append macs "$m" ","; done
302  else
303    # --dhcp-host=lap,192.168.0.199
304    [ -n "$name" ] || return 0
305    macs="$name"
306    name=""
307  fi
308
309  [ "$broadcast" = "0" ] && broadcast=
310
311  nettag4="${networkid:+,tag:${networkid}}"
312  nettag6="${networkid:+,tag:${networkid}6}"
313 
314  xappend "--dhcp-host=$macs$nettag4${broadcast:+,set:needs-broadcast}${tag:+,set:$tag}${ip:+,$ip}${name:+,$name}"
315 
316  if [ $DNSMASQ_DHCP_VER -eq 6 ]; then
317    xappend "--dhcp-host=${duid:+id:$duid}$nettag6${hostid:+,[$hostid]}${name:+,$name}"
318  fi
319 
320  echo >> $CONFIGFILE
321}
322
323#######################################
324
325dhcp_subscrid_add() {
326  local cfg="$1"
327
328  config_get networkid "$cfg" networkid
329  [ -n "$networkid" ] || return 0
330
331  config_get subscriberid "$cfg" subscriberid
332  [ -n "$subscriberid" ] || return 0
333
334  xappend "--dhcp-subscrid=set:$networkid,$subscriberid"
335
336  config_get_bool force "$cfg" force 0
337
338  dhcp_option_add "$cfg" "$networkid" "$force"
339}
340
341#######################################
342
343dhcp_remoteid_add() {
344  local cfg="$1"
345
346  config_get networkid "$cfg" networkid
347  [ -n "$networkid" ] || return 0
348
349  config_get remoteid "$cfg" remoteid
350  [ -n "$remoteid" ] || return 0
351
352  xappend "--dhcp-remoteid=set:$networkid,$remoteid"
353
354  config_get_bool force "$cfg" force 0
355
356  dhcp_option_add "$cfg" "$networkid" "$force"
357}
358
359#######################################
360
361dhcp_circuitid_add() {
362  local cfg="$1"
363
364  config_get networkid "$cfg" networkid
365  [ -n "$networkid" ] || return 0
366
367  config_get circuitid "$cfg" circuitid
368  [ -n "$circuitid" ] || return 0
369
370  xappend "--dhcp-circuitid=set:$networkid,$circuitid"
371
372  config_get_bool force "$cfg" force 0
373
374  dhcp_option_add "$cfg" "$networkid" "$force"
375}
376
377#######################################
378
379dhcp_userclass_add() {
380  local cfg="$1"
381
382  config_get networkid "$cfg" networkid
383  [ -n "$networkid" ] || return 0
384
385  config_get userclass "$cfg" userclass
386  [ -n "$userclass" ] || return 0
387
388  xappend "--dhcp-userclass=set:$networkid,$userclass"
389
390  config_get_bool force "$cfg" force 0
391
392  dhcp_option_add "$cfg" "$networkid" "$force"
393}
394
395#######################################
396
397dhcp_vendorclass_add() {
398  local cfg="$1"
399
400  config_get networkid "$cfg" networkid
401  [ -n "$networkid" ] || return 0
402
403  config_get vendorclass "$cfg" vendorclass
404  [ -n "$vendorclass" ] || return 0
405
406  xappend "--dhcp-vendorclass=set:$networkid,$vendorclass"
407
408  config_get_bool force "$cfg" force 0
409
410  dhcp_option_add "$cfg" "$networkid" "$force"
411}
412
413#######################################
414
415dhcp_tag_add() {
416  local cfg="$1"
417
418  tag="$cfg"
419
420  [ -n "$tag" ] || return 0
421
422  config_get_bool force "$cfg" force 0
423  [ "$force" = "0" ] && force=
424
425  config_get option "$cfg" dhcp_option
426  for o in $option; do
427    xappend "--dhcp-option${force:+-force}=tag:$tag,$o"
428  done
429}
430
431#######################################
432
433dhcp_mac_add() {
434  local cfg="$1"
435
436  config_get networkid "$cfg" networkid
437  [ -n "$networkid" ] || return 0
438
439  config_get mac "$cfg" mac
440  [ -n "$mac" ] || return 0
441
442  xappend "--dhcp-mac=set:$networkid,$mac"
443
444  dhcp_option_add "$cfg" "$networkid"
445}
446
447#######################################
448
449dhcp_boot_add() {
450  local cfg="$1"
451
452  config_get networkid "$cfg" networkid
453
454  config_get filename "$cfg" filename
455  [ -n "$filename" ] || return 0
456
457  config_get servername "$cfg" servername
458  [ -n "$servername" ] || return 0
459
460  config_get serveraddress "$cfg" serveraddress
461  [ -n "$serveraddress" ] || return 0
462
463  xappend "--dhcp-boot=${networkid:+net:$networkid,}$filename,$servername,$serveraddress"
464
465  config_get_bool force "$cfg" force 0
466
467  dhcp_option_add "$cfg" "$networkid" "$force"
468}
469
470#######################################
471
472dhcp_option_add() {
473  local cfg="$1"
474  local networkid="$2"
475  local force="$3"
476  local nettag4=""
477  local nettag6=""
478 
479  [ "$force" = "0" ] && force=
480
481  nettag4="${networkid:+tag:${networkid},}"
482  nettag6="${networkid:+tag:${networkid}6,}"
483
484  config_get dhcp_option "$cfg" dhcp_option
485 
486  for o in $dhcp_option; do
487    xappend "--dhcp-option${force:+-force}=$nettag4$o"
488  done
489 
490  if [ $DNSMASQ_DHCP_VER -eq 6 ]; then
491    config_get dhcp6_option "$cfg" dhcp6_option
492 
493    for o in $dhcp6_option; do
494      xappend "--dhcp-option${force:+-force}=$nettag6$o"
495    done
496  fi
497}
498
499#######################################
500
501dhcp_domain_add() {
502  local cfg="$1"
503  local ip name names record
504
505  config_get names "$cfg" name "$2"
506  [ -n "$names" ] || return 0
507
508  config_get ip "$cfg" ip "$3"
509  [ -n "$ip" ] || return 0
510
511  for name in $names; do
512    record="${record:+$record }$name"
513  done
514
515  echo "$ip $record" >> $HOSTFILE
516}
517
518#######################################
519
520dhcp_srv_add() {
521  local cfg="$1"
522
523  config_get srv "$cfg" srv
524  [ -n "$srv" ] || return 0
525
526  config_get target "$cfg" target
527  [ -n "$target" ] || return 0
528
529  config_get port "$cfg" port
530  [ -n "$port" ] || return 0
531
532  config_get class "$cfg" class
533  config_get weight "$cfg" weight
534
535  local service="$srv,$target,$port${class:+,$class${weight:+,$weight}}"
536
537  xappend "--srv-host=$service"
538}
539
540#######################################
541
542dhcp_mx_add() {
543  local cfg="$1"
544  local domain relay pref
545
546  config_get domain "$cfg" domain
547  [ -n "$domain" ] || return 0
548
549  config_get relay "$cfg" relay
550  [ -n "$relay" ] || return 0
551
552  config_get pref "$cfg" pref 0
553
554  local service="$domain,$relay,$pref"
555
556  xappend "--mx-host=$service"
557}
558
559#######################################
560
561dhcp_cname_add() {
562  local cfg="$1"
563  local cname target
564
565  config_get cname "$cfg" cname
566  [ -n "$cname" ] || return 0
567
568  config_get target "$cfg" target
569  [ -n "$target" ] || return 0
570
571  xappend "--cname=${cname},${target}"
572}
573
574#######################################
575
576dhcp_hostrecord_add() {
577  local cfg="$1"
578  local names addresses record val
579
580  config_get names "$cfg" name "$2"
581  if [ -z "$names" ]; then
582    return 0
583  fi
584
585  config_get addresses "$cfg" ip "$3"
586  if [ -z "$addresses" ]; then
587    return 0
588  fi
589
590  for val in $names $addresses; do
591    record="${record:+$record,}$val"
592  done
593
594  xappend "--host-record=$record"
595}
596
597#######################################
598
599dnsmasq() {
600  # Global Configuration for Entire Single Instance of dnsmasq
601  local cfg="$1"
602 
603  # Booleans
604  prettybar
605  append_bool "$cfg" authoritative "--dhcp-authoritative"
606  append_bool "$cfg" nodaemon "--no-daemon"
607  append_bool "$cfg" domainneeded "--domain-needed"
608  append_bool "$cfg" filterwin2k "--filterwin2k"
609  append_bool "$cfg" nohosts "--no-hosts"
610  append_bool "$cfg" nonegcache "--no-negcache"
611  append_bool "$cfg" strictorder "--strict-order"
612  append_bool "$cfg" logqueries "--log-queries"
613  append_bool "$cfg" noresolv "--no-resolv"
614  append_bool "$cfg" localise_queries "--localise-queries"
615  append_bool "$cfg" readethers "--read-ethers"
616  append_bool "$cfg" dbus "--enable-dbus"
617  append_bool "$cfg" boguspriv "--bogus-priv"
618  append_bool "$cfg" expandhosts "--expand-hosts"
619  append_bool "$cfg" enable_tftp "--enable-tftp"
620  append_bool "$cfg" nonwildcard "--bind-interfaces"
621  append_bool "$cfg" fqdn "--dhcp-fqdn"
622  append_bool "$cfg" proxydnssec "--proxy-dnssec"
623 
624  # No DHCP HOSTID option, lease file with MAC 00-00-00-00-00-00
625  xappend "--dhcp-generate-names"
626 
627  # Simple Settings
628  prettybar
629  append_parm "$cfg" cachesize "--cache-size"
630  append_parm "$cfg" dnsforwardmax "--dns-forward-max"
631  append_parm "$cfg" port "--port"
632  append_parm "$cfg" ednspacket_max "--edns-packet-max"
633  append_parm "$cfg" dhcpleasemax "--dhcp-lease-max"
634  append_parm "$cfg" "queryport" "--query-port"
635  append_parm "$cfg" "domain" "--domain"
636  append_parm "$cfg" "local" "--server"
637 
638  # Outbound DNS query will not start at 8080 for example
639  xappend "--min-port=16384"
640  xappend "--dhcp-broadcast=tag:needs-broadcast"
641  echo >> $CONFIGFILE
642 
643  # List Settings of some additional DNS options
644  config_list_foreach "$cfg" "server" append_server
645  config_list_foreach "$cfg" "address" append_address
646  config_list_foreach "$cfg" "interface" append_interface
647  config_list_foreach "$cfg" "notinterface" append_notinterface
648  config_list_foreach "$cfg" "addnhosts" append_addnhosts
649  config_list_foreach "$cfg" "bogusnxdomain" append_bogusnxdomain
650 
651  # Directories and Files
652  prettybar
653  append_parm "$cfg" dhcpscript "--dhcp-script"
654  append_parm "$cfg" "leasefile" "--dhcp-leasefile"
655  append_parm "$cfg" "resolvfile" "--resolv-file"
656  append_parm "$cfg" "tftp_root" "--tftp-root"
657  append_parm "$cfg" "dhcp_boot" "--dhcp-boot"
658  append_parm "$cfg" "local_ttl" "--local-ttl"
659 
660  # Ensure these directories are used
661  mkdir -p /tmp/hosts /tmp/dnsmasq.d
662  xappend "--addn-hosts=/tmp/hosts"
663  xappend "--conf-dir=/tmp/dnsmasq.d"
664
665  # The slightly uglier options, or ensure file touch
666  prettybar
667 
668  local rebind
669  local rebind_localhost
670  config_get DOMAIN "$cfg" domain
671  config_get leasefile "$cfg" leasefile
672  config_get hostsfile "$cfg" dhcphostsfile
673  config_get_bool ADD_LOCAL_DOMAIN "$cfg" add_local_domain 1
674  config_get_bool ADD_LOCAL_HOSTNAME "$cfg" add_local_hostname 1
675  config_get_bool readethers "$cfg" readethers
676  config_get_bool cachelocal "$cfg" cachelocal 1
677  config_get_bool rebind "$cfg" rebind_protection 1
678  config_get_bool rebind_localhost "$cfg" rebind_localhost 0
679  config_get_bool dnssec "$cfg" dnssec 0
680 
681  [ "$readethers" = "1" -a \! -e "/etc/ethers" ] && touch /etc/ethers
682 
683  [ -n "$leasefile" -a \! -e "$leasefile" ] && touch "$leasefile"
684 
685  [ -e "$hostsfile" ] && xappend "--dhcp-hostsfile=$hostsfile"
686 
687  [ $rebind -gt 0 ] && {
688    log_once \
689      "DNS rebinding protection is active," \
690      "will discard upstream RFC1918 responses!"
691    xappend "--stop-dns-rebind"
692
693    [ $rebind_localhost -gt 0 ] && {
694      log_once "Allowing 127.0.0.0/8 responses"
695      xappend "--rebind-localhost-ok"
696    }
697
698    config_list_foreach "$cfg" rebind_domain append_rebind_domain
699  }
700
701  [ "$dnssec" -gt 0 ] && {
702    xappend "--conf-file=$TRUSTANCHORSFILE"
703    xappend "--dnssec"
704    append_bool "$cfg" dnsseccheckunsigned "--dnssec-check-unsigned"
705  }
706
707  dhcp_option_add "$cfg" "" 0
708}
709
710#######################################
711
712start_service() {
713  include /lib/functions
714
715  config_load dhcp
716
717  procd_open_instance
718  procd_set_param command $PROG -C $CONFIGFILE -k
719  procd_set_param file $CONFIGFILE
720  procd_set_param respawn
721  procd_close_instance
722
723  # before we can call xappend
724  mkdir -p $(dirname $CONFIGFILE)
725  echo "# auto-generated config file from /etc/config/dhcp" > $CONFIGFILE
726  echo "# auto-generated config file from /etc/config/dhcp" > $HOSTFILE
727
728  # if we did this last, we could override auto-generated config
729  [ -f /etc/dnsmasq.conf ] && {
730    prettybar
731    xappend "--conf-file=/etc/dnsmasq.conf"
732  }
733 
734  # call the dnsmasq global configs for each instance
735  config_foreach dnsmasq dnsmasq
736 
737  config_get odhcpd_is_active odhcpd maindhcp
738 
739  if [ -f /usr/sbin/odhcpd ]; then
740    if [ "$odhcpd_is_active" != "1" ]; then
741      # You have ODHCPD but use DNSMASQ for DHCP4
742      DNSMASQ_DHCP_VER=4
743      prettybar
744      config_foreach dhcp_add dhcp
745    else
746      DNSMASQ_DHCP_VER=0
747    fi
748   
749  else
750    # DHCP4 and DHCP6 in DNSMASQ
751    prettybar
752    DNSMASQ_DHCP_VER=6
753    config_foreach dhcp_add dhcp
754    prettybar
755    # Enable RA Feature where constructed
756    # Suppress SYSLOG flood from RA logging
757    xappend "--enable-ra"
758    xappend "--quiet-ra"
759  fi
760 
761  # unique assignments like fixed host address
762  # DNSMASQ does DHCP6 and DHCP4 similarly
763  prettybar
764  config_foreach dhcp_host_add host
765  config_foreach dhcp_mac_add mac
766  config_foreach dhcp_boot_add boot
767  config_foreach dhcp_tag_add tag
768  echo >> $CONFIGFILE
769  config_foreach dhcp_vendorclass_add vendorclass
770  config_foreach dhcp_userclass_add userclass
771  config_foreach dhcp_circuitid_add circuitid
772  config_foreach dhcp_remoteid_add remoteid
773  config_foreach dhcp_subscrid_add subscrid
774  echo >> $CONFIGFILE
775  config_foreach dhcp_domain_add domain
776  config_foreach dhcp_hostrecord_add hostrecord
777  config_foreach dhcp_srv_add srvhost
778  config_foreach dhcp_mx_add mxhost
779  config_foreach dhcp_cname_add cname
780  echo >> $CONFIGFILE
781  prettybar
782  echo >> $CONFIGFILE
783 
784  # makesure RESOLV file specifies this running dnsmasq session
785  rm -f /tmp/resolv.conf
786  [ $ADD_LOCAL_DOMAIN -eq 1 ] && [ -n "$DOMAIN" ] && {
787    echo "search $DOMAIN" >> /tmp/resolv.conf
788  }
789  DNS_SERVERS="$DNS_SERVERS 127.0.0.1"
790  for DNS_SERVER in $DNS_SERVERS ; do
791    echo "nameserver $DNS_SERVER" >> /tmp/resolv.conf
792  done
793}
794
795#######################################
796
797reload_service() {
798  rc_procd start_service "$@"
799  return 0
800}
801
802#######################################
803
804stop_service() {
805  [ -f /tmp/resolv.conf ] && {
806    rm -f /tmp/resolv.conf
807    ln -s /tmp/resolv.conf.auto /tmp/resolv.conf
808  }
809  rm -f /var/run/dnsmasq.*.dhcp
810}
811
812#######################################
813
814service_triggers() {
815  procd_add_reload_trigger "dhcp"
816}
817
818#######################################
819
820boot() {
821  # Will be launched through hotplug
822  return 0
823}
824
825#######################################
826