dnsmasq.init 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2007-2012 OpenWrt.org
  3. START=60
  4. USE_PROCD=1
  5. PROG=/usr/sbin/dnsmasq
  6. DNS_SERVERS=""
  7. DOMAIN=""
  8. ADD_LOCAL_DOMAIN=1
  9. ADD_LOCAL_HOSTNAME=1
  10. CONFIGFILE="/var/etc/dnsmasq.conf"
  11. HOSTFILE="/tmp/hosts/dhcp"
  12. TRUSTANCHORSFILE="/usr/share/dnsmasq/trust-anchors.conf"
  13. TIMESTAMPFILE="/etc/dnsmasq.time"
  14. xappend() {
  15. local value="$1"
  16. echo "${value#--}" >> $CONFIGFILE
  17. }
  18. dhcp_calc() {
  19. local ip="$1"
  20. local res=0
  21. while [ -n "$ip" ]; do
  22. part="${ip%%.*}"
  23. res="$(($res * 256))"
  24. res="$(($res + $part))"
  25. [ "${ip%.*}" != "$ip" ] && ip="${ip#*.}" || ip=
  26. done
  27. echo "$res"
  28. }
  29. dhcp_check() {
  30. local ifname="$1"
  31. local stamp="/var/run/dnsmasq.$ifname.dhcp"
  32. local rv=0
  33. [ -s "$stamp" ] && return $(cat "$stamp")
  34. udhcpc -n -q -s /bin/true -t 1 -i "$ifname" >&- && rv=1 || rv=0
  35. [ $rv -eq 1 ] && \
  36. logger -t dnsmasq \
  37. "found already running DHCP-server on interface '$ifname'" \
  38. "refusing to start, use 'option force 1' to override"
  39. echo $rv > "$stamp"
  40. return $rv
  41. }
  42. log_once() {
  43. pidof dnsmasq >/dev/null || \
  44. logger -t dnsmasq "$@"
  45. }
  46. append_bool() {
  47. local section="$1"
  48. local option="$2"
  49. local value="$3"
  50. local _loctmp
  51. config_get_bool _loctmp "$section" "$option" 0
  52. [ $_loctmp -gt 0 ] && xappend "$value"
  53. }
  54. append_parm() {
  55. local section="$1"
  56. local option="$2"
  57. local switch="$3"
  58. local _loctmp
  59. config_get _loctmp "$section" "$option"
  60. [ -z "$_loctmp" ] && return 0
  61. xappend "$switch=$_loctmp"
  62. }
  63. append_server() {
  64. xappend "--server=$1"
  65. }
  66. append_address() {
  67. xappend "--address=$1"
  68. }
  69. append_ipset() {
  70. xappend "--ipset=$1"
  71. }
  72. append_interface() {
  73. local ifname=$(uci_get_state network "$1" ifname "$1")
  74. xappend "--interface=$ifname"
  75. }
  76. append_notinterface() {
  77. local ifname=$(uci_get_state network "$1" ifname "$1")
  78. xappend "--except-interface=$ifname"
  79. }
  80. append_addnhosts() {
  81. xappend "--addn-hosts=$1"
  82. }
  83. append_bogusnxdomain() {
  84. xappend "--bogus-nxdomain=$1"
  85. }
  86. append_pxe_service() {
  87. xappend "--pxe-service=$1"
  88. }
  89. dnsmasq() {
  90. local cfg="$1"
  91. append_bool "$cfg" authoritative "--dhcp-authoritative"
  92. append_bool "$cfg" nodaemon "--no-daemon"
  93. append_bool "$cfg" domainneeded "--domain-needed"
  94. append_bool "$cfg" filterwin2k "--filterwin2k"
  95. append_bool "$cfg" nohosts "--no-hosts"
  96. append_bool "$cfg" nonegcache "--no-negcache"
  97. append_bool "$cfg" strictorder "--strict-order"
  98. append_bool "$cfg" logqueries "--log-queries=extra"
  99. append_bool "$cfg" noresolv "--no-resolv"
  100. append_bool "$cfg" localise_queries "--localise-queries"
  101. append_bool "$cfg" readethers "--read-ethers"
  102. append_bool "$cfg" dbus "--enable-dbus"
  103. append_bool "$cfg" boguspriv "--bogus-priv"
  104. append_bool "$cfg" expandhosts "--expand-hosts"
  105. config_get tftp_root "$cfg" "tftp_root"
  106. [ -d "$tftp_root" ] && append_bool "$cfg" enable_tftp "--enable-tftp"
  107. append_bool "$cfg" tftp_no_fail "--tftp-no-fail"
  108. append_bool "$cfg" nonwildcard "--bind-dynamic"
  109. append_bool "$cfg" fqdn "--dhcp-fqdn"
  110. append_bool "$cfg" proxydnssec "--proxy-dnssec"
  111. append_bool "$cfg" localservice "--local-service"
  112. append_bool "$cfg" quietdhcp "--quiet-dhcp"
  113. append_bool "$cfg" sequential_ip "--dhcp-sequential-ip"
  114. append_bool "$cfg" allservers "--all-servers"
  115. append_bool "$cfg" noping "--no-ping"
  116. append_parm "$cfg" dhcpscript "--dhcp-script"
  117. append_parm "$cfg" cachesize "--cache-size"
  118. append_parm "$cfg" dnsforwardmax "--dns-forward-max"
  119. append_parm "$cfg" port "--port"
  120. append_parm "$cfg" ednspacket_max "--edns-packet-max"
  121. append_parm "$cfg" dhcpleasemax "--dhcp-lease-max"
  122. append_parm "$cfg" "queryport" "--query-port"
  123. append_parm "$cfg" "minport" "--min-port"
  124. append_parm "$cfg" "domain" "--domain"
  125. append_parm "$cfg" "local" "--server"
  126. config_list_foreach "$cfg" "server" append_server
  127. config_list_foreach "$cfg" "address" append_address
  128. config_list_foreach "$cfg" "ipset" append_ipset
  129. config_list_foreach "$cfg" "interface" append_interface
  130. config_list_foreach "$cfg" "notinterface" append_notinterface
  131. config_list_foreach "$cfg" "addnhosts" append_addnhosts
  132. config_list_foreach "$cfg" "bogusnxdomain" append_bogusnxdomain
  133. append_parm "$cfg" "leasefile" "--dhcp-leasefile"
  134. append_parm "$cfg" "resolvfile" "--resolv-file"
  135. append_parm "$cfg" "serversfile" "--servers-file"
  136. append_parm "$cfg" "tftp_root" "--tftp-root"
  137. append_parm "$cfg" "dhcp_boot" "--dhcp-boot"
  138. append_parm "$cfg" "local_ttl" "--local-ttl"
  139. append_parm "$cfg" "pxe_prompt" "--pxe-prompt"
  140. config_list_foreach "$cfg" "pxe_service" append_pxe_service
  141. config_get DOMAIN "$cfg" domain
  142. config_get_bool ADD_LOCAL_DOMAIN "$cfg" add_local_domain 1
  143. config_get_bool ADD_LOCAL_HOSTNAME "$cfg" add_local_hostname 1
  144. config_get_bool readethers "$cfg" readethers
  145. [ "$readethers" = "1" -a \! -e "/etc/ethers" ] && touch /etc/ethers
  146. config_get leasefile $cfg leasefile
  147. [ -n "$leasefile" -a \! -e "$leasefile" ] && touch "$leasefile"
  148. config_get_bool cachelocal "$cfg" cachelocal 1
  149. config_get hostsfile "$cfg" dhcphostsfile
  150. [ -e "$hostsfile" ] && xappend "--dhcp-hostsfile=$hostsfile"
  151. local rebind
  152. config_get_bool rebind "$cfg" rebind_protection 1
  153. [ $rebind -gt 0 ] && {
  154. log_once \
  155. "DNS rebinding protection is active," \
  156. "will discard upstream RFC1918 responses!"
  157. xappend "--stop-dns-rebind"
  158. local rebind_localhost
  159. config_get_bool rebind_localhost "$cfg" rebind_localhost 0
  160. [ $rebind_localhost -gt 0 ] && {
  161. log_once "Allowing 127.0.0.0/8 responses"
  162. xappend "--rebind-localhost-ok"
  163. }
  164. append_rebind_domain() {
  165. log_once "Allowing RFC1918 responses for domain $1"
  166. xappend "--rebind-domain-ok=$1"
  167. }
  168. config_list_foreach "$cfg" rebind_domain append_rebind_domain
  169. }
  170. config_get_bool dnssec "$cfg" dnssec 0
  171. [ "$dnssec" -gt 0 ] && {
  172. xappend "--conf-file=$TRUSTANCHORSFILE"
  173. xappend "--dnssec"
  174. xappend "--dnssec-timestamp=$TIMESTAMPFILE"
  175. append_bool "$cfg" dnsseccheckunsigned "--dnssec-check-unsigned"
  176. }
  177. dhcp_option_add "$cfg" "" 0
  178. xappend "--dhcp-broadcast=tag:needs-broadcast"
  179. mkdir -p /tmp/hosts /tmp/dnsmasq.d
  180. xappend "--addn-hosts=/tmp/hosts"
  181. xappend "--conf-dir=/tmp/dnsmasq.d"
  182. xappend "--user=dnsmasq"
  183. xappend "--group=dnsmasq"
  184. echo >> $CONFIGFILE
  185. config_get_bool enable_tftp "$cfg" enable_tftp 0
  186. [ "$enable_tftp" -gt 0 ] && {
  187. config_get tftp_root "$cfg" tftp_root
  188. append EXTRA_MOUNT $tftp_root
  189. }
  190. }
  191. dhcp_subscrid_add() {
  192. local cfg="$1"
  193. config_get networkid "$cfg" networkid
  194. [ -n "$networkid" ] || return 0
  195. config_get subscriberid "$cfg" subscriberid
  196. [ -n "$subscriberid" ] || return 0
  197. xappend "--dhcp-subscrid=$networkid,$subscriberid"
  198. config_get_bool force "$cfg" force 0
  199. dhcp_option_add "$cfg" "$networkid" "$force"
  200. }
  201. dhcp_remoteid_add() {
  202. local cfg="$1"
  203. config_get networkid "$cfg" networkid
  204. [ -n "$networkid" ] || return 0
  205. config_get remoteid "$cfg" remoteid
  206. [ -n "$remoteid" ] || return 0
  207. xappend "--dhcp-remoteid=$networkid,$remoteid"
  208. config_get_bool force "$cfg" force 0
  209. dhcp_option_add "$cfg" "$networkid" "$force"
  210. }
  211. dhcp_circuitid_add() {
  212. local cfg="$1"
  213. config_get networkid "$cfg" networkid
  214. [ -n "$networkid" ] || return 0
  215. config_get circuitid "$cfg" circuitid
  216. [ -n "$circuitid" ] || return 0
  217. xappend "--dhcp-circuitid=$networkid,$circuitid"
  218. config_get_bool force "$cfg" force 0
  219. dhcp_option_add "$cfg" "$networkid" "$force"
  220. }
  221. dhcp_userclass_add() {
  222. local cfg="$1"
  223. config_get networkid "$cfg" networkid
  224. [ -n "$networkid" ] || return 0
  225. config_get userclass "$cfg" userclass
  226. [ -n "$userclass" ] || return 0
  227. xappend "--dhcp-userclass=$networkid,$userclass"
  228. config_get_bool force "$cfg" force 0
  229. dhcp_option_add "$cfg" "$networkid" "$force"
  230. }
  231. dhcp_vendorclass_add() {
  232. local cfg="$1"
  233. config_get networkid "$cfg" networkid
  234. [ -n "$networkid" ] || return 0
  235. config_get vendorclass "$cfg" vendorclass
  236. [ -n "$vendorclass" ] || return 0
  237. xappend "--dhcp-vendorclass=$networkid,$vendorclass"
  238. config_get_bool force "$cfg" force 0
  239. dhcp_option_add "$cfg" "$networkid" "$force"
  240. }
  241. dhcp_host_add() {
  242. local cfg="$1"
  243. config_get_bool force "$cfg" force 0
  244. config_get networkid "$cfg" networkid
  245. [ -n "$networkid" ] && dhcp_option_add "$cfg" "$networkid" "$force"
  246. config_get_bool enable "$cfg" enable 1
  247. [ "$enable" = "0" ] && return 0
  248. config_get name "$cfg" name
  249. config_get ip "$cfg" ip
  250. [ -n "$ip" -o -n "$name" ] || return 0
  251. config_get_bool dns "$cfg" dns 0
  252. [ "$dns" = "1" -a -n "$ip" -a -n "$name" ] && {
  253. echo "$ip $name${DOMAIN:+.$DOMAIN}" >> $HOSTFILE
  254. }
  255. config_get mac "$cfg" mac
  256. if [ -n "$mac" ]; then
  257. # --dhcp-host=00:20:e0:3b:13:af,192.168.0.199,lap
  258. macs=""
  259. for m in $mac; do append macs "$m" ","; done
  260. else
  261. # --dhcp-host=lap,192.168.0.199
  262. [ -n "$name" ] || return 0
  263. macs="$name"
  264. name=""
  265. fi
  266. config_get tag "$cfg" tag
  267. config_get_bool broadcast "$cfg" broadcast 0
  268. [ "$broadcast" = "0" ] && broadcast=
  269. config_get leasetime "$cfg" leasetime
  270. xappend "--dhcp-host=$macs${networkid:+,net:$networkid}${broadcast:+,set:needs-broadcast}${tag:+,set:$tag}${ip:+,$ip}${name:+,$name}${leasetime:+,$leasetime}"
  271. }
  272. dhcp_tag_add() {
  273. local cfg="$1"
  274. tag="$cfg"
  275. [ -n "$tag" ] || return 0
  276. config_get_bool force "$cfg" force 0
  277. [ "$force" = "0" ] && force=
  278. config_get option "$cfg" dhcp_option
  279. for o in $option; do
  280. xappend "--dhcp-option${force:+-force}=tag:$tag,$o"
  281. done
  282. }
  283. dhcp_mac_add() {
  284. local cfg="$1"
  285. config_get networkid "$cfg" networkid
  286. [ -n "$networkid" ] || return 0
  287. config_get mac "$cfg" mac
  288. [ -n "$mac" ] || return 0
  289. xappend "--dhcp-mac=$networkid,$mac"
  290. dhcp_option_add "$cfg" "$networkid"
  291. }
  292. dhcp_boot_add() {
  293. local cfg="$1"
  294. config_get networkid "$cfg" networkid
  295. config_get filename "$cfg" filename
  296. [ -n "$filename" ] || return 0
  297. config_get servername "$cfg" servername
  298. config_get serveraddress "$cfg" serveraddress
  299. [ -n "$serveraddress" -a ! -n "$servername" ] && return 0
  300. xappend "--dhcp-boot=${networkid:+net:$networkid,}${filename}${servername:+,$servername}${serveraddress:+,$serveraddress}"
  301. config_get_bool force "$cfg" force 0
  302. dhcp_option_add "$cfg" "$networkid" "$force"
  303. }
  304. dhcp_add() {
  305. local cfg="$1"
  306. config_get net "$cfg" interface
  307. [ -n "$net" ] || return 0
  308. config_get dhcpv4 "$cfg" dhcpv4
  309. [ "$dhcpv4" != "disabled" ] || return 0
  310. config_get networkid "$cfg" networkid
  311. [ -n "$networkid" ] || networkid="$net"
  312. network_get_subnet subnet "$net" || return 0
  313. network_get_device ifname "$net" || return 0
  314. network_get_protocol proto "$net" || return 0
  315. [ "$cachelocal" = "0" ] && network_get_dnsserver dnsserver "$net" && {
  316. DNS_SERVERS="$DNS_SERVERS $dnsserver"
  317. }
  318. append_bool "$cfg" ignore "--no-dhcp-interface=$ifname" && return 0
  319. # Do not support non-static interfaces for now
  320. [ static = "$proto" ] || return 0
  321. # Override interface netmask with dhcp config if applicable
  322. config_get netmask "$cfg" netmask "${subnet##*/}"
  323. #check for an already active dhcp server on the interface, unless 'force' is set
  324. config_get_bool force "$cfg" force 0
  325. [ $force -gt 0 ] || dhcp_check "$ifname" || return 0
  326. config_get start "$cfg" start
  327. config_get limit "$cfg" limit
  328. config_get leasetime "$cfg" leasetime
  329. config_get options "$cfg" options
  330. config_get_bool dynamicdhcp "$cfg" dynamicdhcp 1
  331. leasetime="${leasetime:-12h}"
  332. start="$(dhcp_calc "${start:-100}")"
  333. limit="${limit:-150}"
  334. [ "$limit" -gt 0 ] && limit=$((limit-1))
  335. eval "$(ipcalc.sh "${subnet%%/*}" $netmask $start $limit)"
  336. if [ "$dynamicdhcp" = "0" ]; then END="static"; fi
  337. xappend "--dhcp-range=$networkid,$START,$END,$NETMASK,$leasetime${options:+ $options}"
  338. dhcp_option_add "$cfg" "$networkid"
  339. }
  340. dhcp_option_add() {
  341. local cfg="$1"
  342. local networkid="$2"
  343. local force="$3"
  344. [ "$force" = "0" ] && force=
  345. config_get dhcp_option "$cfg" dhcp_option
  346. for o in $dhcp_option; do
  347. xappend "--dhcp-option${force:+-force}=${networkid:+$networkid,}$o"
  348. done
  349. }
  350. dhcp_domain_add() {
  351. local cfg="$1"
  352. local ip name names record
  353. config_get names "$cfg" name "$2"
  354. [ -n "$names" ] || return 0
  355. config_get ip "$cfg" ip "$3"
  356. [ -n "$ip" ] || return 0
  357. for name in $names; do
  358. record="${record:+$record }$name"
  359. done
  360. echo "$ip $record" >> $HOSTFILE
  361. }
  362. dhcp_srv_add() {
  363. local cfg="$1"
  364. config_get srv "$cfg" srv
  365. [ -n "$srv" ] || return 0
  366. config_get target "$cfg" target
  367. [ -n "$target" ] || return 0
  368. config_get port "$cfg" port
  369. [ -n "$port" ] || return 0
  370. config_get class "$cfg" class
  371. config_get weight "$cfg" weight
  372. local service="$srv,$target,$port${class:+,$class${weight:+,$weight}}"
  373. xappend "--srv-host=$service"
  374. }
  375. dhcp_mx_add() {
  376. local cfg="$1"
  377. local domain relay pref
  378. config_get domain "$cfg" domain
  379. [ -n "$domain" ] || return 0
  380. config_get relay "$cfg" relay
  381. [ -n "$relay" ] || return 0
  382. config_get pref "$cfg" pref 0
  383. local service="$domain,$relay,$pref"
  384. xappend "--mx-host=$service"
  385. }
  386. dhcp_cname_add() {
  387. local cfg="$1"
  388. local cname target
  389. config_get cname "$cfg" cname
  390. [ -n "$cname" ] || return 0
  391. config_get target "$cfg" target
  392. [ -n "$target" ] || return 0
  393. xappend "--cname=${cname},${target}"
  394. }
  395. dhcp_hostrecord_add() {
  396. local cfg="$1"
  397. local names addresses record val
  398. config_get names "$cfg" name "$2"
  399. if [ -z "$names" ]; then
  400. return 0
  401. fi
  402. config_get addresses "$cfg" ip "$3"
  403. if [ -z "$addresses" ]; then
  404. return 0
  405. fi
  406. for val in $names $addresses; do
  407. record="${record:+$record,}$val"
  408. done
  409. xappend "--host-record=$record"
  410. }
  411. dhcp_relay_add() {
  412. local cfg="$1"
  413. local local_addr server_addr interface
  414. config_get local_addr "$cfg" local_addr
  415. [ -n "$local_addr" ] || return 0
  416. config_get server_addr "$cfg" server_addr
  417. [ -n "$server_addr" ] || return 0
  418. config_get interface "$cfg" interface
  419. if [ -z "$interface" ]; then
  420. xappend "--dhcp-relay=$local_addr,$server_addr"
  421. else
  422. xappend "--dhcp-relay=$local_addr,$server_addr,$interface"
  423. fi
  424. }
  425. service_triggers()
  426. {
  427. procd_add_reload_trigger "dhcp"
  428. }
  429. boot() {
  430. # Will be launched through hotplug
  431. return 0
  432. }
  433. start_service() {
  434. include /lib/functions
  435. config_load dhcp
  436. # before we can call xappend
  437. mkdir -p /var/run/dnsmasq/
  438. mkdir -p $(dirname $CONFIGFILE)
  439. mkdir -p /var/lib/misc
  440. touch /tmp/dhcp.leases
  441. if [ ! -f "$TIMESTAMPFILE" ]; then
  442. touch "$TIMESTAMPFILE"
  443. chown dnsmasq.dnsmasq "$TIMESTAMPFILE"
  444. fi
  445. echo "# auto-generated config file from /etc/config/dhcp" > $CONFIGFILE
  446. echo "# auto-generated config file from /etc/config/dhcp" > $HOSTFILE
  447. # if we did this last, we could override auto-generated config
  448. [ -f /etc/dnsmasq.conf ] && {
  449. xappend "--conf-file=/etc/dnsmasq.conf"
  450. }
  451. args=""
  452. config_foreach dnsmasq dnsmasq
  453. config_foreach dhcp_host_add host
  454. echo >> $CONFIGFILE
  455. config_foreach dhcp_boot_add boot
  456. config_foreach dhcp_mac_add mac
  457. config_foreach dhcp_tag_add tag
  458. config_foreach dhcp_vendorclass_add vendorclass
  459. config_foreach dhcp_userclass_add userclass
  460. config_foreach dhcp_circuitid_add circuitid
  461. config_foreach dhcp_remoteid_add remoteid
  462. config_foreach dhcp_subscrid_add subscrid
  463. config_foreach dhcp_domain_add domain
  464. config_foreach dhcp_hostrecord_add hostrecord
  465. config_foreach dhcp_relay_add relay
  466. # add own hostname
  467. [ $ADD_LOCAL_HOSTNAME -eq 1 ] && {
  468. local lanaddr lanaddr6
  469. local ulaprefix="$(uci_get network @globals[0] ula_prefix)"
  470. local hostname="$(uci_get system @system[0] hostname OpenWrt)"
  471. network_get_ipaddr lanaddr "lan" && {
  472. dhcp_domain_add "" "$hostname" "$lanaddr"
  473. }
  474. [ -n "$ulaprefix" ] && network_get_ipaddrs6 lanaddr6 "lan" && {
  475. for lanaddr6 in $lanaddr6; do
  476. case "$lanaddr6" in
  477. "${ulaprefix%%:/*}"*)
  478. dhcp_domain_add "" "$hostname" "$lanaddr6"
  479. ;;
  480. esac
  481. done
  482. }
  483. }
  484. echo >> $CONFIGFILE
  485. config_foreach dhcp_srv_add srvhost
  486. config_foreach dhcp_mx_add mxhost
  487. echo >> $CONFIGFILE
  488. config_get odhcpd_is_active odhcpd maindhcp
  489. if [ "$odhcpd_is_active" != "1" ]; then
  490. config_foreach dhcp_add dhcp
  491. fi
  492. echo >> $CONFIGFILE
  493. config_foreach dhcp_cname_add cname
  494. echo >> $CONFIGFILE
  495. rm -f /tmp/resolv.conf
  496. [ $ADD_LOCAL_DOMAIN -eq 1 ] && [ -n "$DOMAIN" ] && {
  497. echo "search $DOMAIN" >> /tmp/resolv.conf
  498. }
  499. DNS_SERVERS="$DNS_SERVERS 127.0.0.1"
  500. for DNS_SERVER in $DNS_SERVERS ; do
  501. echo "nameserver $DNS_SERVER" >> /tmp/resolv.conf
  502. done
  503. procd_open_instance
  504. procd_set_param command $PROG -C $CONFIGFILE -k -x /var/run/dnsmasq/dnsmasq.pid
  505. procd_set_param file $CONFIGFILE
  506. procd_set_param respawn
  507. procd_add_jail dnsmasq ubus log
  508. 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
  509. procd_add_jail_mount_rw /var/run/dnsmasq/ /tmp/dhcp.leases $TIMESTAMPFILE
  510. procd_close_instance
  511. }
  512. reload_service() {
  513. rc_procd start_service "$@"
  514. return 0
  515. }
  516. stop_service() {
  517. [ -f /tmp/resolv.conf ] && {
  518. rm -f /tmp/resolv.conf
  519. ln -s /tmp/resolv.conf.auto /tmp/resolv.conf
  520. }
  521. rm -f /var/run/dnsmasq.*.dhcp
  522. }