aiop-func 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/sh
  2. CONFIG=1
  3. source /usr/sbin/helper.sh
  4. DNSMASQ_CONF=/tmp/etc/dnsmasq.conf
  5. cmd_log () {
  6. if [ ${1} -ne 0 ]; then
  7. logger "${2}[${1}] - ${3}"
  8. fi
  9. }
  10. cmd_run () {
  11. CMD=`${2} 2> /dev/null`
  12. ERRCODE=$?
  13. if [ $# -eq 3 ] && [ "${3}" = "-nolog" ]; then
  14. return ${ERRCODE}
  15. fi
  16. cmd_log ${ERRCODE} "${1}" "${ERR}: ${2}, ${CMD}"
  17. return ${ERRCODE}
  18. }
  19. iptable () {
  20. IFACE=`echo "${1}"`
  21. local OPT=`echo "${2}"`
  22. shift 2
  23. if [ "${OPT}" = "I" ]; then
  24. iptable "${IFACE}" "D" ${@}
  25. fi
  26. if [ $# -eq 1 ]; then
  27. if [ "${OPT}" = "D" ]; then
  28. cmd_run "iptable" "iptables -t nat -${OPT} POSTROUTING -s ${1} -o ${IFACE} -j MASQUERADE" "-nolog"
  29. else
  30. cmd_run "iptable" "iptables -t nat -${OPT} POSTROUTING -s ${1} -o ${IFACE} -j MASQUERADE"
  31. fi
  32. elif [ $# -eq 2 ]; then
  33. if [ "${OPT}" = "D" ]; then
  34. cmd_run "iptable" "iptables -${OPT} ${1} -i ${IFACE} -m state --state NEW -j ${2}" "-nolog"
  35. else
  36. cmd_run "iptable" "iptables -${OPT} ${1} -i ${IFACE} -m state --state NEW -j ${2}"
  37. fi
  38. elif [ $# -eq 3 ]; then
  39. if [ "${OPT}" = "D" ]; then
  40. cmd_run "iptable" "iptables -${OPT} ${1} -i ${IFACE} -o ${3} -j ${2}" "-nolog"
  41. else
  42. cmd_run "iptable" "iptables -${OPT} ${1} -i ${IFACE} -o ${3} -j ${2}"
  43. fi
  44. else
  45. cmd_log 0 "iptable" "Unknown argument length ${#} (${@})."
  46. fi
  47. }
  48. ebtable () {
  49. if [ "${2}" = "I" ]; then
  50. ebtable "${1}" "D" "${3}"
  51. fi
  52. if [ "${2}" = "D" ]; then
  53. cmd_run "ebtable" "ebtables -t broute -${2} BROUTING -p ${3} -i ${1} -j DROP" "-nolog"
  54. else
  55. cmd_run "ebtable" "ebtables -t broute -${2} BROUTING -p ${3} -i ${1} -j DROP"
  56. fi
  57. }