gluon-ebtables 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2013 Project Gluon
  3. #
  4. # Firewall script for inserting and removing ebtables rules.
  5. #
  6. # Example format, for filtering any IPv4 multicast packets to the SSDP UDP port:
  7. # rule FORWARD --logical-out br-client -d Multicast -p IPv4 --ip-protocol udp --ip-destination-port 5355 -j DROP
  8. #
  9. # Removing all rules:
  10. # $ ./firewall-ebtables stop
  11. # Inserting all rules:
  12. # $ ./firewall-ebtables start
  13. # Inserting a specific rule file:
  14. # $ ./firewall-ebtables start /lib/gluon/ebtables/100-mcast-chain
  15. # Removing a specific rule file:
  16. # $ ./firewall-ebtables stop /lib/gluon/ebtables/100-mcast-chain
  17. START=19
  18. STOP=91
  19. exec_file() {
  20. local file="$1"
  21. /usr/bin/lua -e "
  22. function rule(command, table)
  23. table = table or 'filter'
  24. os.execute($EBTABLES_RULE)
  25. end
  26. function chain(name, policy, table)
  27. table = table or 'filter'
  28. os.execute($EBTABLES_CHAIN)
  29. end
  30. " "$file"
  31. }
  32. exec_all() {
  33. local sort_arg="$1"
  34. local old_ifs="$IFS"
  35. IFS='
  36. '
  37. for file in `find /lib/gluon/ebtables -type f | sort $sort_arg`; do
  38. exec_file "$file"
  39. done
  40. IFS="$old_ifs"
  41. }
  42. start() {
  43. (
  44. export EBTABLES_RULE='"ebtables -t " .. table .. " -A " .. command'
  45. export EBTABLES_CHAIN='"ebtables -t " .. table .. " -N " .. name .. " -P " .. policy'
  46. if [ -z "$1" ]; then
  47. exec_all ''
  48. else
  49. exec_file "$1"
  50. fi
  51. )
  52. }
  53. stop() {
  54. (
  55. export EBTABLES_RULE='"ebtables -t " .. table .. " -D " .. command'
  56. export EBTABLES_CHAIN='"ebtables -t " .. table .. " -X " .. name'
  57. if [ -z "$1" ]; then
  58. exec_all '-r'
  59. else
  60. exec_file "$1"
  61. fi
  62. )
  63. }