2
0

01_direction 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. Testing that rule declarations are mapped to the proper chains depending
  2. on src and dest options.
  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 uci/firewall.json --
  19. {
  20. "rule": [
  21. {
  22. ".description": "Neither source, nor dest => should result in an output rule",
  23. "proto": "any"
  24. },
  25. {
  26. ".description": "Source any, no dest => should result in an input rule",
  27. "proto": "any",
  28. "src": "*"
  29. },
  30. {
  31. ".description": "Dest any, no source => should result in an output rule",
  32. "proto": "any",
  33. "dest": "*"
  34. },
  35. {
  36. ".description": "Source any, dest any => should result in a forward rule",
  37. "proto": "any",
  38. "src": "*",
  39. "dest": "*"
  40. }
  41. ]
  42. }
  43. -- End --
  44. -- Expect stdout --
  45. table inet fw4
  46. flush table inet fw4
  47. table inet fw4 {
  48. #
  49. # Defines
  50. #
  51. #
  52. # User includes
  53. #
  54. include "/etc/nftables.d/*.nft"
  55. #
  56. # Filter rules
  57. #
  58. chain input {
  59. type filter hook input priority filter; policy drop;
  60. iif "lo" accept comment "!fw4: Accept traffic from loopback"
  61. ct state vmap { established : accept, related : accept } comment "!fw4: Handle inbound flows"
  62. counter comment "!fw4: @rule[1]"
  63. }
  64. chain forward {
  65. type filter hook forward priority filter; policy drop;
  66. ct state vmap { established : accept, related : accept } comment "!fw4: Handle forwarded flows"
  67. counter comment "!fw4: @rule[3]"
  68. }
  69. chain output {
  70. type filter hook output priority filter; policy drop;
  71. oif "lo" accept comment "!fw4: Accept traffic towards loopback"
  72. ct state vmap { established : accept, related : accept } comment "!fw4: Handle outbound flows"
  73. counter comment "!fw4: @rule[0]"
  74. counter comment "!fw4: @rule[2]"
  75. }
  76. chain prerouting {
  77. type filter hook prerouting priority filter; policy accept;
  78. }
  79. chain handle_reject {
  80. meta l4proto tcp reject with tcp reset comment "!fw4: Reject TCP traffic"
  81. reject with icmpx type port-unreachable comment "!fw4: Reject any other traffic"
  82. }
  83. #
  84. # NAT rules
  85. #
  86. chain dstnat {
  87. type nat hook prerouting priority dstnat; policy accept;
  88. }
  89. chain srcnat {
  90. type nat hook postrouting priority srcnat; policy accept;
  91. }
  92. #
  93. # Raw rules (notrack)
  94. #
  95. chain raw_prerouting {
  96. type filter hook prerouting priority raw; policy accept;
  97. }
  98. chain raw_output {
  99. type filter hook output priority raw; policy accept;
  100. }
  101. #
  102. # Mangle rules
  103. #
  104. chain mangle_prerouting {
  105. type filter hook prerouting priority mangle; policy accept;
  106. }
  107. chain mangle_postrouting {
  108. type filter hook postrouting priority mangle; policy accept;
  109. }
  110. chain mangle_input {
  111. type filter hook input priority mangle; policy accept;
  112. }
  113. chain mangle_output {
  114. type route hook output priority mangle; policy accept;
  115. }
  116. chain mangle_forward {
  117. type filter hook forward priority mangle; policy accept;
  118. }
  119. }
  120. -- End --