01_family_selections 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. Test that the zone family is honoured when setting up inter-zone forwarding rules.
  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": "wanA",
  22. "device": [ "eth0" ],
  23. "auto_helper": 0
  24. },
  25. {
  26. "name": "wanB",
  27. "device": [ "eth1" ],
  28. "auto_helper": 0
  29. },
  30. {
  31. "name": "lan",
  32. "device": [ "eth2" ],
  33. "auto_helper": 0
  34. }
  35. ],
  36. "forwarding": [
  37. {
  38. ".description": "This should only allow IPv6 forwarding from lan to wanA",
  39. "src": "lan",
  40. "dest": "wanA",
  41. "family": "IPv6"
  42. },
  43. {
  44. ".description": "This should only allow IPv4 forwarding from lan to wanB",
  45. "src": "lan",
  46. "dest": "wanB",
  47. "family": "IPv4"
  48. }
  49. ]
  50. }
  51. -- End --
  52. -- Expect stdout --
  53. table inet fw4
  54. flush table inet fw4
  55. table inet fw4 {
  56. #
  57. # Defines
  58. #
  59. define wanA_devices = { "eth0" }
  60. define wanA_subnets = { }
  61. define wanB_devices = { "eth1" }
  62. define wanB_subnets = { }
  63. define lan_devices = { "eth2" }
  64. define lan_subnets = { }
  65. #
  66. # User includes
  67. #
  68. include "/etc/nftables.d/*.nft"
  69. #
  70. # Filter rules
  71. #
  72. chain input {
  73. type filter hook input priority filter; policy drop;
  74. iif "lo" accept comment "!fw4: Accept traffic from loopback"
  75. ct state vmap { established : accept, related : accept } comment "!fw4: Handle inbound flows"
  76. iifname "eth0" jump input_wanA comment "!fw4: Handle wanA IPv4/IPv6 input traffic"
  77. iifname "eth1" jump input_wanB comment "!fw4: Handle wanB IPv4/IPv6 input traffic"
  78. iifname "eth2" jump input_lan comment "!fw4: Handle lan IPv4/IPv6 input traffic"
  79. }
  80. chain forward {
  81. type filter hook forward priority filter; policy drop;
  82. ct state vmap { established : accept, related : accept } comment "!fw4: Handle forwarded flows"
  83. iifname "eth0" jump forward_wanA comment "!fw4: Handle wanA IPv4/IPv6 forward traffic"
  84. iifname "eth1" jump forward_wanB comment "!fw4: Handle wanB IPv4/IPv6 forward traffic"
  85. iifname "eth2" jump forward_lan comment "!fw4: Handle lan IPv4/IPv6 forward traffic"
  86. }
  87. chain output {
  88. type filter hook output priority filter; policy drop;
  89. oif "lo" accept comment "!fw4: Accept traffic towards loopback"
  90. ct state vmap { established : accept, related : accept } comment "!fw4: Handle outbound flows"
  91. oifname "eth0" jump output_wanA comment "!fw4: Handle wanA IPv4/IPv6 output traffic"
  92. oifname "eth1" jump output_wanB comment "!fw4: Handle wanB IPv4/IPv6 output traffic"
  93. oifname "eth2" jump output_lan comment "!fw4: Handle lan IPv4/IPv6 output traffic"
  94. }
  95. chain prerouting {
  96. type filter hook prerouting priority filter; policy accept;
  97. }
  98. chain handle_reject {
  99. meta l4proto tcp reject with tcp reset comment "!fw4: Reject TCP traffic"
  100. reject with icmpx type port-unreachable comment "!fw4: Reject any other traffic"
  101. }
  102. chain input_wanA {
  103. jump drop_from_wanA
  104. }
  105. chain output_wanA {
  106. jump drop_to_wanA
  107. }
  108. chain forward_wanA {
  109. jump drop_to_wanA
  110. }
  111. chain accept_to_wanA {
  112. oifname "eth0" counter accept comment "!fw4: accept wanA IPv4/IPv6 traffic"
  113. }
  114. chain drop_from_wanA {
  115. iifname "eth0" counter drop comment "!fw4: drop wanA IPv4/IPv6 traffic"
  116. }
  117. chain drop_to_wanA {
  118. oifname "eth0" counter drop comment "!fw4: drop wanA IPv4/IPv6 traffic"
  119. }
  120. chain input_wanB {
  121. jump drop_from_wanB
  122. }
  123. chain output_wanB {
  124. jump drop_to_wanB
  125. }
  126. chain forward_wanB {
  127. jump drop_to_wanB
  128. }
  129. chain accept_to_wanB {
  130. oifname "eth1" counter accept comment "!fw4: accept wanB IPv4/IPv6 traffic"
  131. }
  132. chain drop_from_wanB {
  133. iifname "eth1" counter drop comment "!fw4: drop wanB IPv4/IPv6 traffic"
  134. }
  135. chain drop_to_wanB {
  136. oifname "eth1" counter drop comment "!fw4: drop wanB IPv4/IPv6 traffic"
  137. }
  138. chain input_lan {
  139. jump drop_from_lan
  140. }
  141. chain output_lan {
  142. jump drop_to_lan
  143. }
  144. chain forward_lan {
  145. meta nfproto ipv6 jump accept_to_wanA comment "!fw4: Accept lan to wanA IPv6 forwarding"
  146. meta nfproto ipv4 jump accept_to_wanB comment "!fw4: Accept lan to wanB IPv4 forwarding"
  147. jump drop_to_lan
  148. }
  149. chain drop_from_lan {
  150. iifname "eth2" counter drop comment "!fw4: drop lan IPv4/IPv6 traffic"
  151. }
  152. chain drop_to_lan {
  153. oifname "eth2" counter drop comment "!fw4: drop lan IPv4/IPv6 traffic"
  154. }
  155. #
  156. # NAT rules
  157. #
  158. chain dstnat {
  159. type nat hook prerouting priority dstnat; policy accept;
  160. }
  161. chain srcnat {
  162. type nat hook postrouting priority srcnat; policy accept;
  163. }
  164. #
  165. # Raw rules (notrack)
  166. #
  167. chain raw_prerouting {
  168. type filter hook prerouting priority raw; policy accept;
  169. }
  170. chain raw_output {
  171. type filter hook output priority raw; policy accept;
  172. }
  173. #
  174. # Mangle rules
  175. #
  176. chain mangle_prerouting {
  177. type filter hook prerouting priority mangle; policy accept;
  178. }
  179. chain mangle_postrouting {
  180. type filter hook postrouting priority mangle; policy accept;
  181. }
  182. chain mangle_input {
  183. type filter hook input priority mangle; policy accept;
  184. }
  185. chain mangle_output {
  186. type route hook output priority mangle; policy accept;
  187. }
  188. chain mangle_forward {
  189. type filter hook forward priority mangle; policy accept;
  190. }
  191. }
  192. -- End --