140-firewall-rules 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/usr/bin/lua
  2. local uci = require('simple-uci').cursor()
  3. local function reject_input_on_wan(zone)
  4. if zone.name == 'wan' then
  5. uci:set('firewall', zone['.name'], 'input', 'REJECT')
  6. uci:set('firewall', zone['.name'], 'conntrack', true)
  7. end
  8. return true
  9. end
  10. uci:foreach('firewall', 'zone', reject_input_on_wan)
  11. -- the client zone is set up by gluon-client-bridge
  12. --
  13. uci:section('firewall', 'zone', 'mesh', {
  14. name = 'mesh',
  15. network = {},
  16. input = 'REJECT',
  17. output = 'ACCEPT',
  18. forward = 'REJECT',
  19. })
  20. -- allow inbound ssh from anywhere
  21. for _, zone in ipairs({ 'wan', 'local_client', 'mesh' }) do
  22. uci:section('firewall', 'rule', zone .. '_ssh', {
  23. name = zone .. '_ssh',
  24. src = zone,
  25. dest_port = '22',
  26. proto = 'tcp',
  27. target = 'ACCEPT',
  28. })
  29. end
  30. -- allow icmp in/out on all relevant zones
  31. uci:section('firewall', 'rule', 'local_client_ICMPv4_in', {
  32. src = 'local_client',
  33. proto = 'icmp',
  34. icmp_type = {
  35. 'echo-request',
  36. },
  37. family = 'ipv4',
  38. target = 'ACCEPT',
  39. })
  40. for _, zone in ipairs ({ 'mesh', 'local_client' } ) do
  41. uci:section('firewall', 'rule', zone .. '_ICMPv6_in', {
  42. src = zone,
  43. proto = 'icmp',
  44. icmp_type = {
  45. 'echo-request',
  46. 'echo-reply',
  47. 'destination-unreachable',
  48. 'packet-too-big',
  49. 'time-exceeded',
  50. 'bad-header',
  51. 'unknown-header-type',
  52. 'router-solicitation',
  53. 'neighbour-solicitation',
  54. 'router-advertisement',
  55. 'neighbour-advertisement',
  56. '130/0', -- Multicast Listener Query
  57. '131/0', -- Multicast Listener Report
  58. '132/0', -- Multicast Listener Done
  59. '143/0', -- MLDv2
  60. },
  61. limit = '1000/sec',
  62. family = 'ipv6',
  63. target = 'ACCEPT',
  64. })
  65. -- Can be removed soon: was never in a release
  66. uci:delete('firewall', zone .. '_ICMPv6_out')
  67. end
  68. uci:save('firewall')