04_icmp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. Testing handling of ICMP related options.
  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. "rule": [
  20. {
  21. ".description": "Proto 'icmp' maps to a single IPv4 and IPv6 rule",
  22. "proto": "icmp",
  23. "name": "ICMP rule #1"
  24. },
  25. {
  26. ".description": "Proto 'icmpv6' maps to IPv6 rule only",
  27. "proto": "icmpv6",
  28. "name": "ICMP rule #2",
  29. },
  30. {
  31. ".description": "Proto 'ipv6-icmp' is an alias for 'icmpv6'",
  32. "proto": "ipv6-icmp",
  33. "name": "ICMP rule #3",
  34. },
  35. {
  36. ".description": "Proto 'icmp' with IPv4 specific types inhibits IPv6 rule",
  37. "proto": "icmp",
  38. "name": "ICMP rule #4",
  39. "icmp_type": [ "ip-header-bad" ]
  40. },
  41. {
  42. ".description": "Proto 'icmp' with IPv6 specific types inhibits IPv4 rule",
  43. "proto": "icmp",
  44. "name": "ICMP rule #5",
  45. "icmp_type": [ "neighbour-advertisement" ]
  46. }
  47. ]
  48. }
  49. -- End --
  50. -- Expect stdout --
  51. table inet fw4
  52. flush table inet fw4
  53. table inet fw4 {
  54. #
  55. # Defines
  56. #
  57. #
  58. # User includes
  59. #
  60. include "/etc/nftables.d/*.nft"
  61. #
  62. # Filter rules
  63. #
  64. chain input {
  65. type filter hook input priority filter; policy drop;
  66. iif "lo" accept comment "!fw4: Accept traffic from loopback"
  67. ct state vmap { established : accept, related : accept } comment "!fw4: Handle inbound flows"
  68. }
  69. chain forward {
  70. type filter hook forward priority filter; policy drop;
  71. ct state vmap { established : accept, related : accept } comment "!fw4: Handle forwarded flows"
  72. }
  73. chain output {
  74. type filter hook output priority filter; policy drop;
  75. oif "lo" accept comment "!fw4: Accept traffic towards loopback"
  76. ct state vmap { established : accept, related : accept } comment "!fw4: Handle outbound flows"
  77. meta l4proto { "icmp", "ipv6-icmp" } counter comment "!fw4: ICMP rule #1"
  78. meta nfproto ipv6 meta l4proto ipv6-icmp counter comment "!fw4: ICMP rule #2"
  79. meta nfproto ipv6 meta l4proto ipv6-icmp counter comment "!fw4: ICMP rule #3"
  80. meta nfproto ipv4 icmp type . icmp code { 12 . 0 } counter comment "!fw4: ICMP rule #4"
  81. meta nfproto ipv6 icmpv6 type . icmpv6 code { 136 . 0 } counter comment "!fw4: ICMP rule #5"
  82. }
  83. chain prerouting {
  84. type filter hook prerouting priority filter; policy accept;
  85. }
  86. chain handle_reject {
  87. meta l4proto tcp reject with tcp reset comment "!fw4: Reject TCP traffic"
  88. reject with icmpx type port-unreachable comment "!fw4: Reject any other traffic"
  89. }
  90. #
  91. # NAT rules
  92. #
  93. chain dstnat {
  94. type nat hook prerouting priority dstnat; policy accept;
  95. }
  96. chain srcnat {
  97. type nat hook postrouting priority srcnat; policy accept;
  98. }
  99. #
  100. # Raw rules (notrack)
  101. #
  102. chain raw_prerouting {
  103. type filter hook prerouting priority raw; policy accept;
  104. }
  105. chain raw_output {
  106. type filter hook output priority raw; policy accept;
  107. }
  108. #
  109. # Mangle rules
  110. #
  111. chain mangle_prerouting {
  112. type filter hook prerouting priority mangle; policy accept;
  113. }
  114. chain mangle_postrouting {
  115. type filter hook postrouting priority mangle; policy accept;
  116. }
  117. chain mangle_input {
  118. type filter hook input priority mangle; policy accept;
  119. }
  120. chain mangle_output {
  121. type route hook output priority mangle; policy accept;
  122. }
  123. chain mangle_forward {
  124. type filter hook forward priority mangle; policy accept;
  125. }
  126. }
  127. -- End --