ipset-dns.init 1023 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2013 OpenWrt.org
  3. START=61
  4. USE_PROCD=1
  5. find_nameserver() {
  6. . /lib/functions/network.sh
  7. local tmp
  8. if network_find_wan tmp && network_get_dnsserver tmp "$tmp"; then
  9. echo "${tmp%% *}"
  10. return 0
  11. fi
  12. return 1
  13. }
  14. start_instance() {
  15. local cfg="$1"
  16. local ipset ipset6 port dns
  17. config_get ipset "$cfg" ipset
  18. config_get ipset6 "$cfg" ipset6
  19. [ -n "$ipset$ipset6" ] || {
  20. echo "No ipset specified for instance $cfg" >&2
  21. return 1
  22. }
  23. config_get dns "$cfg" dns "$DEFNS"
  24. [ -n "$dns" ] || {
  25. echo "No DNS server specified for instance $cfg" >&2
  26. return 1
  27. }
  28. config_get port "$cfg" port $((PORT++))
  29. procd_open_instance
  30. procd_set_param command /usr/sbin/ipset-dns "$ipset" "$ipset6" "$port" "$dns"
  31. procd_set_param env NO_DAEMONIZE=1
  32. procd_set_param respawn
  33. procd_close_instance
  34. }
  35. service_triggers()
  36. {
  37. procd_add_reload_trigger "ipset-dns"
  38. }
  39. start_service() {
  40. PORT=53001
  41. DEFNS="$(find_nameserver)"
  42. config_load ipset-dns
  43. config_foreach start_instance ipset-dns
  44. }