Unverified Commit f0d29a18 authored by Kroese's avatar Kroese Committed by GitHub
Browse files

fix: Avoid duplicating dnsmasq arguments (#983)

parent 26c9e711
Loading
Loading
Loading
Loading
+15 −14
Original line number Diff line number Diff line
@@ -123,6 +123,7 @@ configureDNS() {
  local host="$4"
  local mask="$5"
  local gateway="$6"
  local arguments="$DNSMASQ_OPTS"

  [[ "${DNSMASQ_DISABLE:-}" == [Yy1]* ]] && return 0
  [[ "$DEBUG" == [Yy1]* ]] && echo "Starting dnsmasq daemon..."
@@ -138,38 +139,38 @@ configureDNS() {
      chmod 644 /var/lib/misc/dnsmasq.leases

      # dnsmasq configuration:
      DNSMASQ_OPTS+=" --dhcp-authoritative"
      arguments+=" --dhcp-authoritative"

      # Set DHCP range and host
      DNSMASQ_OPTS+=" --dhcp-range=$ip,$ip"
      DNSMASQ_OPTS+=" --dhcp-host=$mac,,$ip,$host,infinite"
      arguments+=" --dhcp-range=$ip,$ip"
      arguments+=" --dhcp-host=$mac,,$ip,$host,infinite"

      # Set DNS server and gateway
      DNSMASQ_OPTS+=" --dhcp-option=option:netmask,$mask"
      DNSMASQ_OPTS+=" --dhcp-option=option:router,$gateway"
      DNSMASQ_OPTS+=" --dhcp-option=option:dns-server,$gateway"
      arguments+=" --dhcp-option=option:netmask,$mask"
      arguments+=" --dhcp-option=option:router,$gateway"
      arguments+=" --dhcp-option=option:dns-server,$gateway"

  esac

  # Set interfaces
  DNSMASQ_OPTS+=" --interface=$if"
  DNSMASQ_OPTS+=" --bind-interfaces"
  arguments+=" --interface=$if"
  arguments+=" --bind-interfaces"

  # Add DNS entry for container
  DNSMASQ_OPTS+=" --address=/host.lan/$gateway"
  arguments+=" --address=/host.lan/$gateway"

  # Set local dns resolver to dnsmasq when needed
  [ -f /etc/resolv.dnsmasq ] && DNSMASQ_OPTS+=" --resolv-file=/etc/resolv.dnsmasq"
  [ -f /etc/resolv.dnsmasq ] && arguments+=" --resolv-file=/etc/resolv.dnsmasq"

  # Enable logging to file
  local log="/var/log/dnsmasq.log"
  rm -f "$log"
  DNSMASQ_OPTS+=" --log-facility=$log"
  arguments+=" --log-facility=$log"

  DNSMASQ_OPTS=$(echo "$DNSMASQ_OPTS" | sed 's/\t/ /g' | tr -s ' ' | sed 's/^ *//')
  [[ "$DEBUG" == [Yy1]* ]] && printf "Dnsmasq arguments:\n\n%s\n\n" "${DNSMASQ_OPTS// -/$'\n-'}"
  arguments=$(echo "$arguments" | sed 's/\t/ /g' | tr -s ' ' | sed 's/^ *//')
  [[ "$DEBUG" == [Yy1]* ]] && printf "Dnsmasq arguments:\n\n%s\n\n" "${arguments// -/$'\n-'}"

  if ! $DNSMASQ ${DNSMASQ_OPTS:+ $DNSMASQ_OPTS}; then
  if ! $DNSMASQ ${arguments:+ $arguments}; then

    local msg="Failed to start Dnsmasq, reason: $?"
    [ -f "$log" ] && cat "$log"