03_constraints 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. Testing various option constraints.
  2. -- Testcase --
  3. {%
  4. include("./root/usr/share/firewall4/main.uc", {
  5. getenv: function(varname) {
  6. switch (varname) {
  7. case 'ACTION':
  8. return 'print';
  9. }
  10. }
  11. })
  12. %}
  13. -- End --
  14. -- File uci/helpers.json --
  15. {}
  16. -- End --
  17. -- File uci/firewall.json --
  18. {
  19. "zone": [
  20. {
  21. "name": "lan"
  22. }
  23. ],
  24. "rule": [
  25. {
  26. ".description": "Helper rules require an explicit source zone",
  27. "proto": "any",
  28. "name": "Helper rule #1",
  29. "target": "helper"
  30. },
  31. {
  32. ".description": "Helper rules require a set_helper option",
  33. "proto": "any",
  34. "name": "Helper rule #2",
  35. "src": "lan",
  36. "target": "helper"
  37. },
  38. {
  39. ".description": "Notrack rules require an explicit source zone",
  40. "proto": "any",
  41. "name": "Notrack rule",
  42. "target": "notrack"
  43. },
  44. {
  45. ".description": "DSCP target rules require a set_dscp option",
  46. "proto": "any",
  47. "name": "DSCP target rule #1",
  48. "target": "dscp"
  49. },
  50. {
  51. ".description": "DSCP matches enforce AF specific rules due to required ip/ip6 prefix",
  52. "proto": "any",
  53. "name": "DSCP match rule #1",
  54. "dscp": "0x0"
  55. },
  56. {
  57. ".description": "Mark rules require a set_xmark or set_mark option",
  58. "proto": "any",
  59. "name": "Mark rule #1",
  60. "target": "mark"
  61. },
  62. ]
  63. }
  64. -- End --
  65. -- Expect stderr --
  66. [!] Section @rule[0] (Helper rule #1) must specify a source zone for target 'helper'
  67. [!] Section @rule[1] (Helper rule #2) must specify option 'set_helper' for target 'helper'
  68. [!] Section @rule[2] (Notrack rule) must specify a source zone for target 'notrack'
  69. [!] Section @rule[3] (DSCP target rule #1) must specify option 'set_dscp' for target 'dscp'
  70. [!] Section @rule[5] (Mark rule #1) must specify option 'set_mark' or 'set_xmark' for target 'mark'
  71. -- End --
  72. -- Expect stdout --
  73. table inet fw4
  74. flush table inet fw4
  75. table inet fw4 {
  76. #
  77. # Defines
  78. #
  79. define lan_devices = { }
  80. define lan_subnets = { }
  81. #
  82. # User includes
  83. #
  84. include "/etc/nftables.d/*.nft"
  85. #
  86. # Filter rules
  87. #
  88. chain input {
  89. type filter hook input priority filter; policy drop;
  90. iif "lo" accept comment "!fw4: Accept traffic from loopback"
  91. ct state vmap { established : accept, related : accept } comment "!fw4: Handle inbound flows"
  92. }
  93. chain forward {
  94. type filter hook forward priority filter; policy drop;
  95. ct state vmap { established : accept, related : accept } comment "!fw4: Handle forwarded flows"
  96. }
  97. chain output {
  98. type filter hook output priority filter; policy drop;
  99. oif "lo" accept comment "!fw4: Accept traffic towards loopback"
  100. ct state vmap { established : accept, related : accept } comment "!fw4: Handle outbound flows"
  101. meta nfproto ipv4 ip dscp 0x0 counter comment "!fw4: DSCP match rule #1"
  102. meta nfproto ipv6 ip6 dscp 0x0 counter comment "!fw4: DSCP match rule #1"
  103. }
  104. chain prerouting {
  105. type filter hook prerouting priority filter; policy accept;
  106. }
  107. chain handle_reject {
  108. meta l4proto tcp reject with tcp reset comment "!fw4: Reject TCP traffic"
  109. reject with icmpx type port-unreachable comment "!fw4: Reject any other traffic"
  110. }
  111. chain input_lan {
  112. jump drop_from_lan
  113. }
  114. chain output_lan {
  115. jump drop_to_lan
  116. }
  117. chain forward_lan {
  118. jump drop_to_lan
  119. }
  120. chain helper_lan {
  121. }
  122. chain drop_from_lan {
  123. }
  124. chain drop_to_lan {
  125. }
  126. #
  127. # NAT rules
  128. #
  129. chain dstnat {
  130. type nat hook prerouting priority dstnat; policy accept;
  131. }
  132. chain srcnat {
  133. type nat hook postrouting priority srcnat; policy accept;
  134. }
  135. #
  136. # Raw rules (notrack)
  137. #
  138. chain raw_prerouting {
  139. type filter hook prerouting priority raw; policy accept;
  140. }
  141. chain raw_output {
  142. type filter hook output priority raw; policy accept;
  143. }
  144. #
  145. # Mangle rules
  146. #
  147. chain mangle_prerouting {
  148. type filter hook prerouting priority mangle; policy accept;
  149. }
  150. chain mangle_postrouting {
  151. type filter hook postrouting priority mangle; policy accept;
  152. }
  153. chain mangle_input {
  154. type filter hook input priority mangle; policy accept;
  155. }
  156. chain mangle_output {
  157. type route hook output priority mangle; policy accept;
  158. }
  159. chain mangle_forward {
  160. type filter hook forward priority mangle; policy accept;
  161. }
  162. }
  163. -- End --