nftables.ut 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/utpl -S
  2. {% if (acl_http_addr): -%}
  3. set acl_neteasemusic_http {
  4. type ipv4_addr;
  5. flags interval;
  6. auto-merge;
  7. elements = {
  8. {% for (let addr in split(trim(acl_http_addr), '\n')): %}
  9. {{ addr }},
  10. {% endfor %}
  11. };
  12. }
  13. {% endif -%}
  14. {% if (acl_https_addr): %}
  15. set acl_neteasemusic_https {
  16. type ipv4_addr;
  17. flags interval;
  18. auto-merge;
  19. elements = {
  20. {% for (let addr in split(trim(acl_https_addr), '\n')): %}
  21. {{ addr }},
  22. {% endfor %}
  23. };
  24. }
  25. {% endif -%}
  26. {% if (hijack_ways === 'use_ipset'): %}
  27. set neteasemusic {
  28. type ipv4_addr;
  29. flags interval;
  30. auto-merge;
  31. elements = {
  32. {% for (let addr in split(trim(neteasemusic_addr), '\n')): %}
  33. {{ addr }},
  34. {% endfor %}
  35. }
  36. }
  37. chain netease_cloud_music {
  38. type nat hook prerouting priority -1; policy accept;
  39. meta l4proto tcp ip daddr @neteasemusic jump netease_cloud_music_redir;
  40. }
  41. chain netease_cloud_music_redir {
  42. ip daddr { 0.0.0.0/8, 10.0.0.0/8, 100.64.0.0/10, 127.0.0.0/8,
  43. 169.254.0.0/16, 172.16.0.0/12, 192.0.0.0/24,
  44. 192.0.2.0/24, 192.31.196.0/24, 192.52.193.0/24,
  45. 192.88.99.0/24, 192.168.0.0/16, 192.175.48.0/24,
  46. 198.18.0.0/15, 198.51.100.0/24, 203.0.113.0/24,
  47. 224.0.0.0/4, 240.0.0.0/4 } counter return;
  48. {% if (acl_http_addr): %}
  49. ip saddr @acl_neteasemusic_http tcp dport 80 counter return;
  50. {% endif %}
  51. {% if (acl_https_addr): %}
  52. ip saddr @acl_neteasemusic_https tcp dport 443 counter return;
  53. {% endif %}
  54. tcp dport 80 counter redirect to :{{ http_port }};
  55. tcp dport 443 counter redirect to :{{ https_port }};
  56. }
  57. {% endif %}