gluon-ebtables 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 --concurrent -t " .. table .. " -A " .. command'
  45. export EBTABLES_CHAIN='"ebtables --concurrent -t " .. table .. " -N " .. name .. " -P " .. policy'
  46. # Contains /var/lib/ebtables/lock for '--concurrent'
  47. [ ! -d "/var/lib/ebtables" ] && \
  48. mkdir -p /var/lib/ebtables
  49. if [ -z "$1" ]; then
  50. exec_all ''
  51. else
  52. exec_file "$1"
  53. fi
  54. )
  55. }
  56. stop() {
  57. (
  58. export EBTABLES_RULE='"ebtables --concurrent -t " .. table .. " -D " .. command'
  59. export EBTABLES_CHAIN='"ebtables --concurrent -t " .. table .. " -X " .. name'
  60. if [ -z "$1" ]; then
  61. exec_all '-r'
  62. else
  63. exec_file "$1"
  64. fi
  65. )
  66. }