1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- #!/bin/sh
- CONFIG=1
- source /usr/sbin/helper.sh
- DNSMASQ_CONF=/tmp/etc/dnsmasq.conf
- cmd_log () {
- if [ ${1} -ne 0 ]; then
- logger "${2}[${1}] - ${3}"
- fi
- }
- cmd_run () {
- CMD=`${2} 2> /dev/null`
- ERRCODE=$?
- if [ $# -eq 3 ] && [ "${3}" = "-nolog" ]; then
- return ${ERRCODE}
- fi
- cmd_log ${ERRCODE} "${1}" "${ERR}: ${2}, ${CMD}"
- return ${ERRCODE}
- }
- iptable () {
- IFACE=`echo "${1}"`
- local OPT=`echo "${2}"`
- shift 2
- if [ "${OPT}" = "I" ]; then
- iptable "${IFACE}" "D" ${@}
- fi
- if [ $# -eq 1 ]; then
- if [ "${OPT}" = "D" ]; then
- cmd_run "iptable" "iptables -t nat -${OPT} POSTROUTING -s ${1} -o ${IFACE} -j MASQUERADE" "-nolog"
- else
- cmd_run "iptable" "iptables -t nat -${OPT} POSTROUTING -s ${1} -o ${IFACE} -j MASQUERADE"
- fi
- elif [ $# -eq 2 ]; then
- if [ "${OPT}" = "D" ]; then
- cmd_run "iptable" "iptables -${OPT} ${1} -i ${IFACE} -m state --state NEW -j ${2}" "-nolog"
- else
- cmd_run "iptable" "iptables -${OPT} ${1} -i ${IFACE} -m state --state NEW -j ${2}"
- fi
- elif [ $# -eq 3 ]; then
- if [ "${OPT}" = "D" ]; then
- cmd_run "iptable" "iptables -${OPT} ${1} -i ${IFACE} -o ${3} -j ${2}" "-nolog"
- else
- cmd_run "iptable" "iptables -${OPT} ${1} -i ${IFACE} -o ${3} -j ${2}"
- fi
- else
- cmd_log 0 "iptable" "Unknown argument length ${#} (${@})."
- fi
- }
- ebtable () {
- if [ "${2}" = "I" ]; then
- ebtable "${1}" "D" "${3}"
- fi
- if [ "${2}" = "D" ]; then
- cmd_run "ebtable" "ebtables -t broute -${2} BROUTING -p ${3} -i ${1} -j DROP" "-nolog"
- else
- cmd_run "ebtable" "ebtables -t broute -${2} BROUTING -p ${3} -i ${1} -j DROP"
- fi
- }
|