aiop-dnsmasq 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/sh
  2. source /jffs/scripts/aiop-func
  3. if [ `cat ${DNSMASQ_CONF} | grep -c "log-dhcp"` -eq 0 ]; then
  4. pc_append "log-dhcp" ${DNSMASQ_CONF}
  5. fi
  6. assign_ip () {
  7. if [ $# -ne 4 ]; then
  8. echo "Wrong number of parameters"
  9. return
  10. fi
  11. IFACE="${1}"
  12. IFACE_INET_ADDR="${2}"
  13. IFACE_NWRK_ADDR="${IFACE_INET_ADDR%.*}.0"
  14. IFACE_MASK_ADDR="255.255.255.0"
  15. DHCP_START="${IFACE_INET_ADDR%.*}.${3}"
  16. DHCP_END="${IFACE_INET_ADDR%.*}.${4}"
  17. if [ `ifconfig ${IFACE} 2&> /dev/null | grep -ice "UP"` -ne 1 ]; then
  18. logger "dnsmasq-dhcp: Unknown interface ${IFACE}."
  19. return
  20. fi
  21. if [ `ifconfig | grep -ice $(_quote ${IFACE_INET_ADDR%.*}.)` -ne 0 ]; then
  22. if [ `ifconfig ${IFACE} | grep -ice "$(_quote ${IFACE_INET_ADDR%.*}.)"` -ne 1 ]; then
  23. logger "dnsmasq-dhcp: Service already running on subnet ${IFACE_INET_ADDR%.*}"
  24. return
  25. fi
  26. fi
  27. logger "dnsmasq-dhcp: Configure ${IFACE} to have special DHCP on ${IFACE_INET_ADDR}"
  28. if [ `cat ${DNSMASQ_CONF} | grep -c ${IFACE}` -eq 0 ]; then
  29. cmd_run "pc_append" "pc_append interface=${IFACE} ${DNSMASQ_CONF}"
  30. cmd_run "pc_append" "pc_append dhcp-range=${IFACE},${DHCP_START},${DHCP_END},${IFACE_MASK_ADDR},24h ${DNSMASQ_CONF}"
  31. cmd_run "pc_append" "pc_append dhcp-option=${IFACE},3,${IFACE_INET_ADDR} ${DNSMASQ_CONF}"
  32. fi
  33. cmd_run "ifconfig" "ifconfig ${IFACE} ${IFACE_INET_ADDR} netmask ${IFACE_MASK_ADDR}"
  34. ebtable "${IFACE}" "I" "ipv4"
  35. ebtable "${IFACE}" "I" "ipv6"
  36. ebtable "${IFACE}" "I" "arp"
  37. iptable "${IFACE}" "I" "INPUT" "ACCEPT"
  38. }