2
0

02_firewall.user_include 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. Testing that /etc/firewall.user is treated specially and requires an extra
  2. option to be marked compatible.
  3. -- Testcase --
  4. {%
  5. include("./root/usr/share/firewall4/main.uc", {
  6. getenv: function(varname) {
  7. switch (varname) {
  8. case 'ACTION':
  9. return 'print';
  10. }
  11. }
  12. })
  13. %}
  14. -- End --
  15. -- File uci/helpers.json --
  16. {}
  17. -- End --
  18. -- File fs/open~_sys_class_net_eth0_flags.txt --
  19. 0x1103
  20. -- End --
  21. -- File fs/open~_etc_firewall_user.txt --
  22. # dummy
  23. -- End --
  24. -- File fs/open~_usr_share_miniupnpd_firewall_include.txt --
  25. # dummy
  26. -- End --
  27. -- File uci/firewall.json --
  28. {
  29. "zone": [
  30. {
  31. "name": "test",
  32. "device": [ "eth0" ],
  33. "auto_helper": 0
  34. }
  35. ],
  36. "include": [
  37. {
  38. ".description": "By default, this /etc/firewall.user include should be skipped with a warning",
  39. "path": "/etc/firewall.user"
  40. },
  41. {
  42. ".description": "This /etc/firewall.user include should be added due to the compatible flag",
  43. "path": "/etc/firewall.user",
  44. "fw4_compatible": 1
  45. },
  46. {
  47. ".description": "An include of another path should not require a compatible flag",
  48. "path": "/usr/share/miniupnpd/firewall.include"
  49. }
  50. ]
  51. }
  52. -- End --
  53. -- Expect stderr --
  54. [!] Section @include[0] is not marked as compatible with fw4, ignoring section
  55. [!] Section @include[0] requires 'option fw4_compatible 1' to be considered compatible
  56. -- End --
  57. -- Expect stdout --
  58. table inet fw4
  59. flush table inet fw4
  60. table inet fw4 {
  61. #
  62. # Defines
  63. #
  64. define test_devices = { "eth0" }
  65. define test_subnets = { }
  66. #
  67. # User includes
  68. #
  69. include "/etc/nftables.d/*.nft"
  70. #
  71. # Filter rules
  72. #
  73. chain input {
  74. type filter hook input priority filter; policy drop;
  75. iif "lo" accept comment "!fw4: Accept traffic from loopback"
  76. ct state vmap { established : accept, related : accept } comment "!fw4: Handle inbound flows"
  77. iifname "eth0" jump input_test comment "!fw4: Handle test IPv4/IPv6 input traffic"
  78. }
  79. chain forward {
  80. type filter hook forward priority filter; policy drop;
  81. ct state vmap { established : accept, related : accept } comment "!fw4: Handle forwarded flows"
  82. iifname "eth0" jump forward_test comment "!fw4: Handle test IPv4/IPv6 forward traffic"
  83. }
  84. chain output {
  85. type filter hook output priority filter; policy drop;
  86. oif "lo" accept comment "!fw4: Accept traffic towards loopback"
  87. ct state vmap { established : accept, related : accept } comment "!fw4: Handle outbound flows"
  88. oifname "eth0" jump output_test comment "!fw4: Handle test IPv4/IPv6 output traffic"
  89. }
  90. chain prerouting {
  91. type filter hook prerouting priority filter; policy accept;
  92. }
  93. chain handle_reject {
  94. meta l4proto tcp reject with tcp reset comment "!fw4: Reject TCP traffic"
  95. reject with icmpx type port-unreachable comment "!fw4: Reject any other traffic"
  96. }
  97. chain input_test {
  98. jump drop_from_test
  99. }
  100. chain output_test {
  101. jump drop_to_test
  102. }
  103. chain forward_test {
  104. jump drop_to_test
  105. }
  106. chain drop_from_test {
  107. iifname "eth0" counter drop comment "!fw4: drop test IPv4/IPv6 traffic"
  108. }
  109. chain drop_to_test {
  110. oifname "eth0" counter drop comment "!fw4: drop test IPv4/IPv6 traffic"
  111. }
  112. #
  113. # NAT rules
  114. #
  115. chain dstnat {
  116. type nat hook prerouting priority dstnat; policy accept;
  117. }
  118. chain srcnat {
  119. type nat hook postrouting priority srcnat; policy accept;
  120. }
  121. #
  122. # Raw rules (notrack)
  123. #
  124. chain raw_prerouting {
  125. type filter hook prerouting priority raw; policy accept;
  126. }
  127. chain raw_output {
  128. type filter hook output priority raw; policy accept;
  129. }
  130. #
  131. # Mangle rules
  132. #
  133. chain mangle_prerouting {
  134. type filter hook prerouting priority mangle; policy accept;
  135. }
  136. chain mangle_postrouting {
  137. type filter hook postrouting priority mangle; policy accept;
  138. }
  139. chain mangle_input {
  140. type filter hook input priority mangle; policy accept;
  141. }
  142. chain mangle_output {
  143. type route hook output priority mangle; policy accept;
  144. }
  145. chain mangle_forward {
  146. type filter hook forward priority mangle; policy accept;
  147. }
  148. }
  149. -- End --