assign-ip-ssid 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/bin/sh
  2. CONFIG=1
  3. source /usr/sbin/helper.sh
  4. DNSMASQ_CONF=/tmp/etc/dnsmasq.conf
  5. if [ `cat ${DNSMASQ_CONF} | grep -c "log-dhcp"` -eq 0 ]; then
  6. pc_append "log-dhcp" ${DNSMASQ_CONF}
  7. fi
  8. cmd_log () {
  9. logger "${2}[${1}] - ${3}"
  10. }
  11. cmd_run () {
  12. ERR=`${2}`
  13. ERRCODE=$?
  14. cmd_log ${ERRCODE} "${1}" "${ERR}: ${2}"
  15. return ${ERRCODE}
  16. }
  17. iptable () {
  18. if [ `iptables -L ${2} -v | grep -c ""${3}.*${1}""` -eq 0 ]; then
  19. cmd_run "iptables" "iptables -I ${2} -i ${1} -j ${3}"
  20. else
  21. cmd_run "iptables" "iptables -D ${2} -i ${1} -j ${3}"
  22. iptable ${1} ${2} ${3}
  23. fi
  24. }
  25. ebtable () {
  26. CMD="-p ${2} -i ${1} -j ${3}"
  27. if [ `ebtables -t broute -L | grep -ice "${CMD}"` -eq 0 ]; then
  28. cmd_run "ebtables" "ebtables -t broute -I BROUTING ${CMD}"
  29. else
  30. cmd_run "ebtables" "ebtables -t broute -D BROUTING ${CMD}"
  31. ebtable ${1} ${2} ${3}
  32. fi
  33. }
  34. assign_ip () {
  35. IFACE=${1}
  36. IFACE_NWRK_ADDR=${2}
  37. IFACE_INET_ADDR=${3}
  38. IFACE_NETMASK=${4}
  39. DHCP_START=${5}
  40. DHCP_END=${6}
  41. if [ `cat ${DNSMASQ_CONF} | grep -c ${IFACE}` -eq 0 ]; then
  42. logger "dnsmasq-dhcp: Configure ${IFACE} to have special DHCP"
  43. pc_append "interface=${IFACE}" ${DNSMASQ_CONF}
  44. pc_append "dhcp-range=${IFACE},${DHCP_START},${DHCP_END},${IFACE_NETMASK},24h" ${DNSMASQ_CONF}
  45. pc_append "dhcp-option=${IFACE},3,${IFACE_INET_ADDR}" ${DNSMASQ_CONF}
  46. pc_append "dhcp-option=${IFACE},6,8.8.8.8,8.8.4.4" ${DNSMASQ_CONF}
  47. pc_append "dhcp-option=${IFACE},252,\"\n\"" ${DNSMASQ_CONF}
  48. fi
  49. cmd_run "ifconfig" "ifconfig ${IFACE} ${IFACE_INET_ADDR} netmask ${IFACE_NETMASK} up"
  50. ebtable "${IFACE}" "ipv4" "DROP"
  51. ebtable "${IFACE}" "ipv6" "DROP"
  52. ebtable "${IFACE}" "arp" "DROP"
  53. iptable "${IFACE}" "FORWARD" "ACCEPT"
  54. iptable "${IFACE}" "INPUT" "ACCEPT"
  55. #cmd_run "ip-route" "ip route flush cache"
  56. }
  57. killall dnsmasq
  58. #assign_ip "vlan1" "192.168.1.0" "192.168.1.1" "255.255.255.0" "192.168.1.1" "192.168.1.127" #/25
  59. assign_ip "wl0.1" "192.168.2.0" "192.168.2.1" "255.255.255.0" "192.168.2.1" "192.168.2.128" #/25
  60. assign_ip "wl1.1" "192.168.2.0" "192.168.2.1" "255.255.255.0" "192.168.2.1" "192.168.2.128" #/25
  61. assign_ip "wl2.1" "192.168.2.0" "192.168.2.1" "255.255.255.0" "192.168.2.1" "192.168.2.128" #/25
  62. assign_ip "wl0.2" "192.168.2.0" "192.168.2.1" "255.255.255.0" "192.168.2.129" "192.168.2.255" #/25
  63. cat ${DNSMASQ_CONF}
  64. dnsmasq --log-async