04_masq_allow_invalid 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. Testing that dropping of invalid conntrack state traffic can be inhibited.
  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 fs/open~_sys_class_net_zone1_flags.txt --
  18. 0x1103
  19. -- End --
  20. -- File fs/open~_sys_class_net_zone2_flags.txt --
  21. 0x1103
  22. -- End --
  23. -- File uci/firewall.json --
  24. {
  25. "zone": [
  26. {
  27. ".description": "No ct state invalid drop rule should be generated",
  28. "name": "test1",
  29. "input": "ACCEPT",
  30. "output": "ACCEPT",
  31. "forward": "ACCEPT",
  32. "device": "zone1",
  33. "masq": "1",
  34. "masq_allow_invalid": 1
  35. }
  36. ]
  37. }
  38. -- End --
  39. -- Expect stdout --
  40. table inet fw4
  41. flush table inet fw4
  42. table inet fw4 {
  43. #
  44. # Defines
  45. #
  46. define test1_devices = { "zone1" }
  47. define test1_subnets = { }
  48. #
  49. # User includes
  50. #
  51. include "/etc/nftables.d/*.nft"
  52. #
  53. # Filter rules
  54. #
  55. chain input {
  56. type filter hook input priority filter; policy drop;
  57. iif "lo" accept comment "!fw4: Accept traffic from loopback"
  58. ct state vmap { established : accept, related : accept } comment "!fw4: Handle inbound flows"
  59. iifname "zone1" jump input_test1 comment "!fw4: Handle test1 IPv4/IPv6 input traffic"
  60. }
  61. chain forward {
  62. type filter hook forward priority filter; policy drop;
  63. ct state vmap { established : accept, related : accept } comment "!fw4: Handle forwarded flows"
  64. iifname "zone1" jump forward_test1 comment "!fw4: Handle test1 IPv4/IPv6 forward traffic"
  65. }
  66. chain output {
  67. type filter hook output priority filter; policy drop;
  68. oif "lo" accept comment "!fw4: Accept traffic towards loopback"
  69. ct state vmap { established : accept, related : accept } comment "!fw4: Handle outbound flows"
  70. oifname "zone1" jump output_test1 comment "!fw4: Handle test1 IPv4/IPv6 output traffic"
  71. }
  72. chain prerouting {
  73. type filter hook prerouting priority filter; policy accept;
  74. }
  75. chain handle_reject {
  76. meta l4proto tcp reject with tcp reset comment "!fw4: Reject TCP traffic"
  77. reject with icmpx type port-unreachable comment "!fw4: Reject any other traffic"
  78. }
  79. chain input_test1 {
  80. jump accept_from_test1
  81. }
  82. chain output_test1 {
  83. jump accept_to_test1
  84. }
  85. chain forward_test1 {
  86. jump accept_to_test1
  87. }
  88. chain accept_from_test1 {
  89. iifname "zone1" counter accept comment "!fw4: accept test1 IPv4/IPv6 traffic"
  90. }
  91. chain accept_to_test1 {
  92. oifname "zone1" counter accept comment "!fw4: accept test1 IPv4/IPv6 traffic"
  93. }
  94. #
  95. # NAT rules
  96. #
  97. chain dstnat {
  98. type nat hook prerouting priority dstnat; policy accept;
  99. }
  100. chain srcnat {
  101. type nat hook postrouting priority srcnat; policy accept;
  102. oifname "zone1" jump srcnat_test1 comment "!fw4: Handle test1 IPv4/IPv6 srcnat traffic"
  103. }
  104. chain srcnat_test1 {
  105. meta nfproto ipv4 masquerade comment "!fw4: Masquerade IPv4 test1 traffic"
  106. }
  107. #
  108. # Raw rules (notrack)
  109. #
  110. chain raw_prerouting {
  111. type filter hook prerouting priority raw; policy accept;
  112. }
  113. chain raw_output {
  114. type filter hook output priority raw; policy accept;
  115. }
  116. #
  117. # Mangle rules
  118. #
  119. chain mangle_prerouting {
  120. type filter hook prerouting priority mangle; policy accept;
  121. }
  122. chain mangle_postrouting {
  123. type filter hook postrouting priority mangle; policy accept;
  124. }
  125. chain mangle_input {
  126. type filter hook input priority mangle; policy accept;
  127. }
  128. chain mangle_output {
  129. type route hook output priority mangle; policy accept;
  130. }
  131. chain mangle_forward {
  132. type filter hook forward priority mangle; policy accept;
  133. }
  134. }
  135. -- End --