140-firewall-rules 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/usr/bin/lua
  2. local uci = require('simple-uci').cursor()
  3. local defaults = uci:get_first('firewall', 'defaults')
  4. uci:set('firewall', defaults, 'input', 'REJECT')
  5. local function reject_input_on_wan(zone)
  6. if zone.name == 'wan' then
  7. uci:set('firewall', zone['.name'], 'input', 'REJECT')
  8. uci:set('firewall', zone['.name'], 'conntrack', true)
  9. end
  10. return true
  11. end
  12. uci:foreach('firewall', 'zone', reject_input_on_wan)
  13. for _, zone in ipairs({'mesh', 'local_client', 'wired_mesh'}) do
  14. -- Other packages assign interfaces to these zones
  15. uci:section('firewall', 'zone', zone, {
  16. name = zone,
  17. network = {},
  18. input = 'REJECT',
  19. output = 'ACCEPT',
  20. forward = 'REJECT',
  21. })
  22. uci:section('firewall', 'rule', zone .. '_ICMPv6_in', {
  23. src = zone,
  24. proto = 'icmp',
  25. icmp_type = {
  26. 'echo-request',
  27. 'echo-reply',
  28. 'destination-unreachable',
  29. 'packet-too-big',
  30. 'time-exceeded',
  31. 'bad-header',
  32. 'unknown-header-type',
  33. 'router-solicitation',
  34. 'neighbour-solicitation',
  35. 'router-advertisement',
  36. 'neighbour-advertisement',
  37. '130/0', -- Multicast Listener Query
  38. '131/0', -- Multicast Listener Report
  39. '132/0', -- Multicast Listener Done
  40. '143/0', -- MLDv2
  41. },
  42. limit = '1000/sec',
  43. family = 'ipv6',
  44. target = 'ACCEPT',
  45. })
  46. -- Can be removed soon: was never in a release
  47. uci:delete('firewall', zone .. '_ICMPv6_out')
  48. end
  49. uci:section('firewall', 'rule', 'local_client_ICMPv4_in', {
  50. src = 'local_client',
  51. proto = 'icmp',
  52. icmp_type = {
  53. 'echo-request',
  54. },
  55. family = 'ipv4',
  56. target = 'ACCEPT',
  57. })
  58. -- allow inbound SSH from anywhere
  59. for _, zone in ipairs({ 'wan', 'local_client', 'mesh' }) do
  60. uci:section('firewall', 'rule', zone .. '_ssh', {
  61. name = zone .. '_ssh',
  62. src = zone,
  63. dest_port = '22',
  64. proto = 'tcp',
  65. target = 'ACCEPT',
  66. })
  67. end
  68. -- We can't put mesh_wan into this zone, as mesh_wan is the same
  69. -- interface as wan, which has its own zone
  70. uci:set('firewall', 'wired_mesh', 'network', {'mesh_lan'})
  71. -- VXLAN for wired meshing
  72. for _, zone in ipairs({'wired_mesh', 'wan'}) do
  73. uci:section('firewall', 'rule', zone .. '_vxlan', {
  74. name = zone .. '_vxlan',
  75. src = zone,
  76. family = 'ipv6',
  77. src_ip = 'fe80::/64',
  78. proto = 'udp',
  79. dest_port = '4789',
  80. target = 'ACCEPT',
  81. })
  82. uci:reorder('firewall', zone .. '_vxlan', 0)
  83. end
  84. uci:save('firewall')