4cd5f673d8b5f1ce9d97241dd01d2e074b62a6f1
[openwrt/staging/lynxis/omap.git] / package / network / services / dnsmasq / files / dnsmasq.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2007-2012 OpenWrt.org
3
4 START=19
5
6 USE_PROCD=1
7 PROG=/usr/sbin/dnsmasq
8
9 DNS_SERVERS=""
10 DOMAIN=""
11
12 ADD_LOCAL_DOMAIN=1
13 ADD_LOCAL_HOSTNAME=1
14
15 CONFIGFILE="/var/etc/dnsmasq.conf"
16 CONFIGFILE_TMP="/var/etc/dnsmasq.conf.$$"
17 HOSTFILE="/tmp/hosts/dhcp"
18 TRUSTANCHORSFILE="/usr/share/dnsmasq/trust-anchors.conf"
19 TIMESTAMPFILE="/etc/dnsmasq.time"
20 TIMEVALIDFILE="/var/state/dnsmasqsec"
21
22 xappend() {
23 local value="$1"
24
25 echo "${value#--}" >> $CONFIGFILE_TMP
26 }
27
28 hex_to_hostid() {
29 local var="$1"
30 local hex="${2#0x}" # strip optional "0x" prefix
31
32 if [ -n "${hex//[0-9a-fA-F]/}" ]; then
33 # is invalid hex literal
34 return 1
35 fi
36
37 # convert into host id
38 export "$var=$(
39 printf "%0x:%0x" \
40 $(((0x$hex >> 16) % 65536)) \
41 $(( 0x$hex % 256))
42 )"
43
44 return 0
45 }
46
47 dhcp_calc() {
48 local ip="$1"
49 local res=0
50
51 while [ -n "$ip" ]; do
52 part="${ip%%.*}"
53 res="$(($res * 256))"
54 res="$(($res + $part))"
55 [ "${ip%.*}" != "$ip" ] && ip="${ip#*.}" || ip=
56 done
57 echo "$res"
58 }
59
60 dhcp_check() {
61 local ifname="$1"
62 local stamp="/var/run/dnsmasq.$ifname.dhcp"
63 local rv=0
64
65 [ -s "$stamp" ] && return $(cat "$stamp")
66
67 # If there's no carrier yet, skip this interface.
68 # The init script will be called again once the link is up
69 case "$(devstatus "$ifname" | jsonfilter -e @.carrier)" in
70 false) return 1;;
71 esac
72
73 udhcpc -n -q -s /bin/true -t 1 -i "$ifname" >&- && rv=1 || rv=0
74
75 [ $rv -eq 1 ] && \
76 logger -t dnsmasq \
77 "found already running DHCP-server on interface '$ifname'" \
78 "refusing to start, use 'option force 1' to override"
79
80 echo $rv > "$stamp"
81 return $rv
82 }
83
84 log_once() {
85 pidof dnsmasq >/dev/null || \
86 logger -t dnsmasq "$@"
87 }
88
89 append_bool() {
90 local section="$1"
91 local option="$2"
92 local value="$3"
93 local _loctmp
94 config_get_bool _loctmp "$section" "$option" 0
95 [ $_loctmp -gt 0 ] && xappend "$value"
96 }
97
98 append_parm() {
99 local section="$1"
100 local option="$2"
101 local switch="$3"
102 local default="$4"
103 local _loctmp
104 config_get _loctmp "$section" "$option" "$default"
105 [ -z "$_loctmp" ] && return 0
106 xappend "$switch=$_loctmp"
107 }
108
109 append_server() {
110 xappend "--server=$1"
111 }
112
113 append_address() {
114 xappend "--address=$1"
115 }
116
117 append_ipset() {
118 xappend "--ipset=$1"
119 }
120
121 append_interface() {
122 network_get_device ifname "$1" || return
123 xappend "--interface=$ifname"
124 }
125
126 append_notinterface() {
127 network_get_device ifname "$1" || return
128 xappend "--except-interface=$ifname"
129 }
130
131 append_addnhosts() {
132 xappend "--addn-hosts=$1"
133 }
134
135 append_bogusnxdomain() {
136 xappend "--bogus-nxdomain=$1"
137 }
138
139 append_pxe_service() {
140 xappend "--pxe-service=$1"
141 }
142
143 dnsmasq() {
144 local cfg="$1"
145 append_bool "$cfg" authoritative "--dhcp-authoritative"
146 append_bool "$cfg" nodaemon "--no-daemon"
147 append_bool "$cfg" domainneeded "--domain-needed"
148 append_bool "$cfg" filterwin2k "--filterwin2k"
149 append_bool "$cfg" nohosts "--no-hosts"
150 append_bool "$cfg" nonegcache "--no-negcache"
151 append_bool "$cfg" strictorder "--strict-order"
152 append_bool "$cfg" logqueries "--log-queries=extra"
153 append_bool "$cfg" noresolv "--no-resolv"
154 append_bool "$cfg" localise_queries "--localise-queries"
155 append_bool "$cfg" readethers "--read-ethers"
156 append_bool "$cfg" dbus "--enable-dbus"
157 append_bool "$cfg" boguspriv "--bogus-priv"
158 append_bool "$cfg" expandhosts "--expand-hosts"
159 config_get tftp_root "$cfg" "tftp_root"
160 [ -d "$tftp_root" ] && append_bool "$cfg" enable_tftp "--enable-tftp"
161 append_bool "$cfg" tftp_no_fail "--tftp-no-fail"
162 append_bool "$cfg" nonwildcard "--bind-dynamic"
163 append_bool "$cfg" fqdn "--dhcp-fqdn"
164 append_bool "$cfg" proxydnssec "--proxy-dnssec"
165 append_bool "$cfg" localservice "--local-service"
166 append_bool "$cfg" quietdhcp "--quiet-dhcp"
167 append_bool "$cfg" sequential_ip "--dhcp-sequential-ip"
168 append_bool "$cfg" allservers "--all-servers"
169 append_bool "$cfg" noping "--no-ping"
170
171 append_parm "$cfg" dhcpscript "--dhcp-script"
172 append_parm "$cfg" cachesize "--cache-size"
173 append_parm "$cfg" dnsforwardmax "--dns-forward-max"
174 append_parm "$cfg" port "--port"
175 append_parm "$cfg" ednspacket_max "--edns-packet-max"
176 append_parm "$cfg" dhcpleasemax "--dhcp-lease-max"
177 append_parm "$cfg" "queryport" "--query-port"
178 append_parm "$cfg" "minport" "--min-port"
179 append_parm "$cfg" "maxport" "--max-port"
180 append_parm "$cfg" "domain" "--domain"
181 append_parm "$cfg" "local" "--server"
182 config_list_foreach "$cfg" "server" append_server
183 config_list_foreach "$cfg" "address" append_address
184 config_list_foreach "$cfg" "ipset" append_ipset
185 config_list_foreach "$cfg" "interface" append_interface
186 config_list_foreach "$cfg" "notinterface" append_notinterface
187 config_list_foreach "$cfg" "addnhosts" append_addnhosts
188 config_list_foreach "$cfg" "bogusnxdomain" append_bogusnxdomain
189 append_parm "$cfg" "leasefile" "--dhcp-leasefile" "/tmp/dhcp.leases"
190 append_parm "$cfg" "resolvfile" "--resolv-file" "/tmp/resolv.conf.auto"
191 append_parm "$cfg" "serversfile" "--servers-file"
192 append_parm "$cfg" "tftp_root" "--tftp-root"
193 append_parm "$cfg" "dhcp_boot" "--dhcp-boot"
194 append_parm "$cfg" "local_ttl" "--local-ttl"
195 append_parm "$cfg" "pxe_prompt" "--pxe-prompt"
196 config_list_foreach "$cfg" "pxe_service" append_pxe_service
197 config_get DOMAIN "$cfg" domain
198
199 config_get_bool ADD_LOCAL_DOMAIN "$cfg" add_local_domain 1
200 config_get_bool ADD_LOCAL_HOSTNAME "$cfg" add_local_hostname 1
201
202 config_get_bool readethers "$cfg" readethers
203 [ "$readethers" = "1" -a \! -e "/etc/ethers" ] && touch /etc/ethers
204
205 config_get leasefile $cfg leasefile "/tmp/dhcp.leases"
206 [ -n "$leasefile" -a \! -e "$leasefile" ] && touch "$leasefile"
207 config_get_bool cachelocal "$cfg" cachelocal 1
208
209 config_get_bool noresolv "$cfg" noresolv 0
210 if [ "$noresolv" != "1" ]; then
211 config_get resolvfile "$cfg" resolvfile "/tmp/resolv.conf.auto"
212 # So jail doesn't complain if file missing
213 [ -n "$resolvfile" -a \! -e "$resolvfile" ] && touch "$resolvfile"
214 fi
215
216 config_get hostsfile "$cfg" dhcphostsfile
217 [ -e "$hostsfile" ] && xappend "--dhcp-hostsfile=$hostsfile"
218
219 local rebind
220 config_get_bool rebind "$cfg" rebind_protection 1
221 [ $rebind -gt 0 ] && {
222 log_once \
223 "DNS rebinding protection is active," \
224 "will discard upstream RFC1918 responses!"
225 xappend "--stop-dns-rebind"
226
227 local rebind_localhost
228 config_get_bool rebind_localhost "$cfg" rebind_localhost 0
229 [ $rebind_localhost -gt 0 ] && {
230 log_once "Allowing 127.0.0.0/8 responses"
231 xappend "--rebind-localhost-ok"
232 }
233
234 append_rebind_domain() {
235 log_once "Allowing RFC1918 responses for domain $1"
236 xappend "--rebind-domain-ok=$1"
237 }
238
239 config_list_foreach "$cfg" rebind_domain append_rebind_domain
240 }
241
242 config_get_bool dnssec "$cfg" dnssec 0
243 [ "$dnssec" -gt 0 ] && {
244 xappend "--conf-file=$TRUSTANCHORSFILE"
245 xappend "--dnssec"
246 [ -x /etc/init.d/sysntpd ] && {
247 /etc/init.d/sysntpd enabled
248 [ "$?" -ne 0 -o "$(uci_get system.ntp.enabled)" = "1" ] && {
249 [ -f "$TIMEVALIDFILE" ] || xappend "--dnssec-no-timecheck"
250 }
251 }
252 append_bool "$cfg" dnsseccheckunsigned "--dnssec-check-unsigned"
253 }
254
255 dhcp_option_add "$cfg" "" 0
256
257 xappend "--dhcp-broadcast=tag:needs-broadcast"
258
259 mkdir -p /tmp/hosts /tmp/dnsmasq.d
260 xappend "--addn-hosts=/tmp/hosts"
261 xappend "--conf-dir=/tmp/dnsmasq.d"
262 xappend "--user=dnsmasq"
263 xappend "--group=dnsmasq"
264
265 echo >> $CONFIGFILE_TMP
266
267 config_get_bool enable_tftp "$cfg" enable_tftp 0
268 [ "$enable_tftp" -gt 0 ] && {
269 config_get tftp_root "$cfg" tftp_root
270 append EXTRA_MOUNT $tftp_root
271 }
272 }
273
274 dhcp_subscrid_add() {
275 local cfg="$1"
276
277 config_get networkid "$cfg" networkid
278 [ -n "$networkid" ] || return 0
279
280 config_get subscriberid "$cfg" subscriberid
281 [ -n "$subscriberid" ] || return 0
282
283 xappend "--dhcp-subscrid=$networkid,$subscriberid"
284
285 config_get_bool force "$cfg" force 0
286
287 dhcp_option_add "$cfg" "$networkid" "$force"
288 }
289
290 dhcp_remoteid_add() {
291 local cfg="$1"
292
293 config_get networkid "$cfg" networkid
294 [ -n "$networkid" ] || return 0
295
296 config_get remoteid "$cfg" remoteid
297 [ -n "$remoteid" ] || return 0
298
299 xappend "--dhcp-remoteid=$networkid,$remoteid"
300
301 config_get_bool force "$cfg" force 0
302
303 dhcp_option_add "$cfg" "$networkid" "$force"
304 }
305
306 dhcp_circuitid_add() {
307 local cfg="$1"
308
309 config_get networkid "$cfg" networkid
310 [ -n "$networkid" ] || return 0
311
312 config_get circuitid "$cfg" circuitid
313 [ -n "$circuitid" ] || return 0
314
315 xappend "--dhcp-circuitid=$networkid,$circuitid"
316
317 config_get_bool force "$cfg" force 0
318
319 dhcp_option_add "$cfg" "$networkid" "$force"
320 }
321
322 dhcp_userclass_add() {
323 local cfg="$1"
324
325 config_get networkid "$cfg" networkid
326 [ -n "$networkid" ] || return 0
327
328 config_get userclass "$cfg" userclass
329 [ -n "$userclass" ] || return 0
330
331 xappend "--dhcp-userclass=$networkid,$userclass"
332
333 config_get_bool force "$cfg" force 0
334
335 dhcp_option_add "$cfg" "$networkid" "$force"
336 }
337
338 dhcp_vendorclass_add() {
339 local cfg="$1"
340
341 config_get networkid "$cfg" networkid
342 [ -n "$networkid" ] || return 0
343
344 config_get vendorclass "$cfg" vendorclass
345 [ -n "$vendorclass" ] || return 0
346
347 xappend "--dhcp-vendorclass=$networkid,$vendorclass"
348
349 config_get_bool force "$cfg" force 0
350
351 dhcp_option_add "$cfg" "$networkid" "$force"
352 }
353
354 dhcp_host_add() {
355 local cfg="$1"
356
357 config_get_bool force "$cfg" force 0
358
359 config_get networkid "$cfg" networkid
360 [ -n "$networkid" ] && dhcp_option_add "$cfg" "$networkid" "$force"
361
362 config_get_bool enable "$cfg" enable 1
363 [ "$enable" = "0" ] && return 0
364
365 config_get name "$cfg" name
366 config_get ip "$cfg" ip
367 [ -n "$ip" -o -n "$name" ] || return 0
368
369 config_get_bool dns "$cfg" dns 0
370 [ "$dns" = "1" -a -n "$ip" -a -n "$name" ] && {
371 echo "$ip $name${DOMAIN:+.$DOMAIN}" >> $HOSTFILE
372 }
373
374 config_get mac "$cfg" mac
375 if [ -n "$mac" ]; then
376 # --dhcp-host=00:20:e0:3b:13:af,192.168.0.199,lap
377 macs=""
378 for m in $mac; do append macs "$m" ","; done
379 else
380 # --dhcp-host=lap,192.168.0.199
381 [ -n "$name" ] || return 0
382 macs="$name"
383 name=""
384 fi
385
386 config_get tag "$cfg" tag
387
388 if [ "$DHCPv6CAPABLE" -eq 1 ]; then
389 config_get hostid "$cfg" hostid
390 if [ -n "$hostid" ]; then
391 hex_to_hostid hostid "$hostid"
392 fi
393 fi
394
395 config_get_bool broadcast "$cfg" broadcast 0
396 [ "$broadcast" = "0" ] && broadcast=
397
398 config_get leasetime "$cfg" leasetime
399
400 xappend "--dhcp-host=$macs${networkid:+,net:$networkid}${broadcast:+,set:needs-broadcast}${tag:+,set:$tag}${ip:+,$ip${hostid:+,[::$hostid]}}${name:+,$name}${leasetime:+,$leasetime}"
401 }
402
403 dhcp_tag_add() {
404 local cfg="$1"
405
406 tag="$cfg"
407
408 [ -n "$tag" ] || return 0
409
410 config_get_bool force "$cfg" force 0
411 [ "$force" = "0" ] && force=
412
413 config_get option "$cfg" dhcp_option
414 for o in $option; do
415 xappend "--dhcp-option${force:+-force}=tag:$tag,$o"
416 done
417 }
418
419 dhcp_mac_add() {
420 local cfg="$1"
421
422 config_get networkid "$cfg" networkid
423 [ -n "$networkid" ] || return 0
424
425 config_get mac "$cfg" mac
426 [ -n "$mac" ] || return 0
427
428 xappend "--dhcp-mac=$networkid,$mac"
429
430 dhcp_option_add "$cfg" "$networkid"
431 }
432
433 dhcp_boot_add() {
434 local cfg="$1"
435
436 config_get networkid "$cfg" networkid
437
438 config_get filename "$cfg" filename
439 [ -n "$filename" ] || return 0
440
441 config_get servername "$cfg" servername
442 config_get serveraddress "$cfg" serveraddress
443
444 [ -n "$serveraddress" -a ! -n "$servername" ] && return 0
445
446 xappend "--dhcp-boot=${networkid:+net:$networkid,}${filename}${servername:+,$servername}${serveraddress:+,$serveraddress}"
447
448 config_get_bool force "$cfg" force 0
449
450 dhcp_option_add "$cfg" "$networkid" "$force"
451 }
452
453
454 dhcp_add() {
455 local cfg="$1"
456 config_get net "$cfg" interface
457 [ -n "$net" ] || return 0
458
459 config_get dhcpv4 "$cfg" dhcpv4
460 [ "$dhcpv4" != "disabled" ] || return 0
461
462 config_get networkid "$cfg" networkid
463 [ -n "$networkid" ] || networkid="$net"
464
465 network_get_subnet subnet "$net" || return 0
466 network_get_device ifname "$net" || return 0
467 network_get_protocol proto "$net" || return 0
468
469 [ "$cachelocal" = "0" ] && network_get_dnsserver dnsserver "$net" && {
470 DNS_SERVERS="$DNS_SERVERS $dnsserver"
471 }
472
473 append_bool "$cfg" ignore "--no-dhcp-interface=$ifname" && return 0
474
475 # Do not support non-static interfaces for now
476 [ static = "$proto" ] || return 0
477
478 # Override interface netmask with dhcp config if applicable
479 config_get netmask "$cfg" netmask "${subnet##*/}"
480
481 #check for an already active dhcp server on the interface, unless 'force' is set
482 config_get_bool force "$cfg" force 0
483 [ $force -gt 0 ] || dhcp_check "$ifname" || return 0
484
485 config_get start "$cfg" start
486 config_get limit "$cfg" limit
487 config_get leasetime "$cfg" leasetime
488 config_get options "$cfg" options
489 config_get_bool dynamicdhcp "$cfg" dynamicdhcp 1
490
491 leasetime="${leasetime:-12h}"
492 start="$(dhcp_calc "${start:-100}")"
493 limit="${limit:-150}"
494 [ "$limit" -gt 0 ] && limit=$((limit-1))
495 eval "$(ipcalc.sh "${subnet%%/*}" $netmask $start $limit)"
496 if [ "$dynamicdhcp" = "0" ]; then END="static"; fi
497 xappend "--dhcp-range=$networkid,$START,$END,$NETMASK,$leasetime${options:+ $options}"
498
499 dhcp_option_add "$cfg" "$networkid"
500 }
501
502 dhcp_option_add() {
503 local cfg="$1"
504 local networkid="$2"
505 local force="$3"
506
507 [ "$force" = "0" ] && force=
508
509 config_get dhcp_option "$cfg" dhcp_option
510 for o in $dhcp_option; do
511 xappend "--dhcp-option${force:+-force}=${networkid:+$networkid,}$o"
512 done
513
514 }
515
516 dhcp_domain_add() {
517 local cfg="$1"
518 local ip name names record
519
520 config_get names "$cfg" name "$2"
521 [ -n "$names" ] || return 0
522
523 config_get ip "$cfg" ip "$3"
524 [ -n "$ip" ] || return 0
525
526 for name in $names; do
527 record="${record:+$record }$name"
528 done
529
530 echo "$ip $record" >> $HOSTFILE
531 }
532
533 dhcp_srv_add() {
534 local cfg="$1"
535
536 config_get srv "$cfg" srv
537 [ -n "$srv" ] || return 0
538
539 config_get target "$cfg" target
540 [ -n "$target" ] || return 0
541
542 config_get port "$cfg" port
543 [ -n "$port" ] || return 0
544
545 config_get class "$cfg" class
546 config_get weight "$cfg" weight
547
548 local service="$srv,$target,$port${class:+,$class${weight:+,$weight}}"
549
550 xappend "--srv-host=$service"
551 }
552
553 dhcp_mx_add() {
554 local cfg="$1"
555 local domain relay pref
556
557 config_get domain "$cfg" domain
558 [ -n "$domain" ] || return 0
559
560 config_get relay "$cfg" relay
561 [ -n "$relay" ] || return 0
562
563 config_get pref "$cfg" pref 0
564
565 local service="$domain,$relay,$pref"
566
567 xappend "--mx-host=$service"
568 }
569
570 dhcp_cname_add() {
571 local cfg="$1"
572 local cname target
573
574 config_get cname "$cfg" cname
575 [ -n "$cname" ] || return 0
576
577 config_get target "$cfg" target
578 [ -n "$target" ] || return 0
579
580 xappend "--cname=${cname},${target}"
581 }
582
583 dhcp_hostrecord_add() {
584 local cfg="$1"
585 local names addresses record val
586
587 config_get names "$cfg" name "$2"
588 if [ -z "$names" ]; then
589 return 0
590 fi
591
592 config_get addresses "$cfg" ip "$3"
593 if [ -z "$addresses" ]; then
594 return 0
595 fi
596
597 for val in $names $addresses; do
598 record="${record:+$record,}$val"
599 done
600
601 xappend "--host-record=$record"
602 }
603
604 dhcp_relay_add() {
605 local cfg="$1"
606 local local_addr server_addr interface
607
608 config_get local_addr "$cfg" local_addr
609 [ -n "$local_addr" ] || return 0
610
611 config_get server_addr "$cfg" server_addr
612 [ -n "$server_addr" ] || return 0
613
614 config_get interface "$cfg" interface
615 if [ -z "$interface" ]; then
616 xappend "--dhcp-relay=$local_addr,$server_addr"
617 else
618 xappend "--dhcp-relay=$local_addr,$server_addr,$interface"
619 fi
620 }
621
622 service_triggers()
623 {
624 procd_add_reload_trigger "dhcp"
625 procd_add_raw_trigger "interface.*" 2000 /etc/init.d/dnsmasq reload
626 }
627
628 boot()
629 {
630 BOOT=1
631 start "$@"
632 }
633
634 start_service() {
635 [ -n "$BOOT" ] && return
636
637 include /lib/functions
638
639 config_load dhcp
640
641 # before we can call xappend
642 mkdir -p /var/run/dnsmasq/
643 mkdir -p $(dirname $CONFIGFILE)
644 mkdir -p /var/lib/misc
645 touch /tmp/dhcp.leases
646 chown dnsmasq:dnsmasq /var/run/dnsmasq
647
648 [ -f "$TIMESTAMPFILE" ] && rm -f "$TIMESTAMPFILE"
649
650 echo "# auto-generated config file from /etc/config/dhcp" > $CONFIGFILE_TMP
651 echo "# auto-generated config file from /etc/config/dhcp" > $HOSTFILE
652
653 # if we did this last, we could override auto-generated config
654 [ -f /etc/dnsmasq.conf ] && {
655 xappend "--conf-file=/etc/dnsmasq.conf"
656 }
657
658 $PROG --version | grep -osqE "^Compile time options:.* DHCPv6( |$)" && DHCPv6CAPABLE=1 || DHCPv6CAPABLE=0
659
660 args=""
661 config_foreach dnsmasq dnsmasq
662 config_foreach dhcp_host_add host
663 echo >> $CONFIGFILE_TMP
664 config_foreach dhcp_boot_add boot
665 config_foreach dhcp_mac_add mac
666 config_foreach dhcp_tag_add tag
667 config_foreach dhcp_vendorclass_add vendorclass
668 config_foreach dhcp_userclass_add userclass
669 config_foreach dhcp_circuitid_add circuitid
670 config_foreach dhcp_remoteid_add remoteid
671 config_foreach dhcp_subscrid_add subscrid
672 config_foreach dhcp_domain_add domain
673 config_foreach dhcp_hostrecord_add hostrecord
674 config_foreach dhcp_relay_add relay
675
676 # add own hostname
677 [ $ADD_LOCAL_HOSTNAME -eq 1 ] && {
678 local lanaddr lanaddr6
679 local ulaprefix="$(uci_get network @globals[0] ula_prefix)"
680 local hostname="$(uci_get system @system[0] hostname Lede)"
681
682 network_get_ipaddr lanaddr "lan" && {
683 dhcp_domain_add "" "$hostname" "$lanaddr"
684 }
685
686 [ -n "$ulaprefix" ] && network_get_ipaddrs6 lanaddr6 "lan" && {
687 for lanaddr6 in $lanaddr6; do
688 case "$lanaddr6" in
689 "${ulaprefix%%:/*}"*)
690 dhcp_domain_add "" "$hostname" "$lanaddr6"
691 ;;
692 esac
693 done
694 }
695 }
696
697 echo >> $CONFIGFILE_TMP
698 config_foreach dhcp_srv_add srvhost
699 config_foreach dhcp_mx_add mxhost
700 echo >> $CONFIGFILE_TMP
701
702 config_get odhcpd_is_active odhcpd maindhcp
703 if [ "$odhcpd_is_active" != "1" ]; then
704 config_foreach dhcp_add dhcp
705 fi
706
707 echo >> $CONFIGFILE_TMP
708 config_foreach dhcp_cname_add cname
709 echo >> $CONFIGFILE_TMP
710 mv -f $CONFIGFILE_TMP $CONFIGFILE
711
712 rm -f /tmp/resolv.conf
713 [ $ADD_LOCAL_DOMAIN -eq 1 ] && [ -n "$DOMAIN" ] && {
714 echo "search $DOMAIN" >> /tmp/resolv.conf
715 }
716 DNS_SERVERS="$DNS_SERVERS 127.0.0.1"
717 for DNS_SERVER in $DNS_SERVERS ; do
718 echo "nameserver $DNS_SERVER" >> /tmp/resolv.conf
719 done
720
721 procd_open_instance
722 procd_set_param command $PROG -C $CONFIGFILE -k -x /var/run/dnsmasq/dnsmasq.pid
723 procd_set_param file $CONFIGFILE
724 procd_set_param respawn
725
726 procd_add_jail dnsmasq ubus log
727 procd_add_jail_mount $CONFIGFILE $TRUSTANCHORSFILE $HOSTFILE /etc/passwd /etc/group /etc/TZ /dev/null /dev/urandom /etc/dnsmasq.conf /tmp/dnsmasq.d /tmp/resolv.conf.auto /etc/hosts /etc/ethers $EXTRA_MOUNT
728 procd_add_jail_mount_rw /var/run/dnsmasq/ /tmp/dhcp.leases
729
730 procd_close_instance
731 }
732
733 reload_service() {
734 rc_procd start_service "$@"
735 return 0
736 }
737
738 stop_service() {
739 [ -f /tmp/resolv.conf ] && {
740 rm -f /tmp/resolv.conf
741 ln -s /tmp/resolv.conf.auto /tmp/resolv.conf
742 }
743 rm -f /var/run/dnsmasq.*.dhcp
744 }