12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- #!/bin/sh
- CONFIG=1
- source /usr/sbin/helper.sh
- DNSMASQ_CONF=/tmp/etc/dnsmasq.conf
- if [ `cat ${DNSMASQ_CONF} | grep -c "log-dhcp"` -eq 0 ]; then
- pc_append "log-dhcp" ${DNSMASQ_CONF}
- fi
- cmd_log () {
- logger "${2}[${1}] - ${3}"
- }
- cmd_run () {
- ERR=`${2}`
- ERRCODE=$?
- cmd_log ${ERRCODE} "${1}" "${ERR}: ${2}"
- return ${ERRCODE}
- }
- iptable () {
- if [ `iptables -L ${2} -v | grep -c ""${3}.*${1}""` -eq 0 ]; then
- cmd_run "iptables" "iptables -I ${2} -i ${1} -j ${3}"
- else
- cmd_run "iptables" "iptables -D ${2} -i ${1} -j ${3}"
- iptable ${1} ${2} ${3}
- fi
- }
- ebtable () {
- CMD="-p ${2} -i ${1} -j ${3}"
- if [ `ebtables -t broute -L | grep -ice "${CMD}"` -eq 0 ]; then
- cmd_run "ebtables" "ebtables -t broute -I BROUTING ${CMD}"
- else
- cmd_run "ebtables" "ebtables -t broute -D BROUTING ${CMD}"
- ebtable ${1} ${2} ${3}
- fi
- }
- assign_ip () {
- IFACE=${1}
- IFACE_NWRK_ADDR=${2}
- IFACE_INET_ADDR=${3}
- IFACE_NETMASK=${4}
-
- DHCP_START=${5}
- DHCP_END=${6}
- if [ `cat ${DNSMASQ_CONF} | grep -c ${IFACE}` -eq 0 ]; then
- logger "dnsmasq-dhcp: Configure ${IFACE} to have special DHCP"
- pc_append "interface=${IFACE}" ${DNSMASQ_CONF}
- pc_append "dhcp-range=${IFACE},${DHCP_START},${DHCP_END},${IFACE_NETMASK},24h" ${DNSMASQ_CONF}
- pc_append "dhcp-option=${IFACE},3,${IFACE_INET_ADDR}" ${DNSMASQ_CONF}
- pc_append "dhcp-option=${IFACE},6,8.8.8.8,8.8.4.4" ${DNSMASQ_CONF}
- pc_append "dhcp-option=${IFACE},252,\"\n\"" ${DNSMASQ_CONF}
- fi
- cmd_run "ifconfig" "ifconfig ${IFACE} ${IFACE_INET_ADDR} netmask ${IFACE_NETMASK} up"
- ebtable "${IFACE}" "ipv4" "DROP"
- ebtable "${IFACE}" "ipv6" "DROP"
- ebtable "${IFACE}" "arp" "DROP"
- iptable "${IFACE}" "FORWARD" "ACCEPT"
- iptable "${IFACE}" "INPUT" "ACCEPT"
- #cmd_run "ip-route" "ip route flush cache"
- }
- killall dnsmasq
- #assign_ip "vlan1" "192.168.1.0" "192.168.1.1" "255.255.255.0" "192.168.1.1" "192.168.1.127" #/25
- 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
- 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
- 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
- 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
- cat ${DNSMASQ_CONF}
- dnsmasq --log-async
|