types.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package firewall
  2. // FilterRule represents a MikroTik-style /ip firewall filter rule
  3. type FilterRule struct {
  4. ID string `json:"id"`
  5. Order int `json:"order"`
  6. Chain string `json:"chain"` // input, forward, output, or custom
  7. Action string `json:"action"` // accept, drop, reject, return, jump, log, passthrough
  8. RejectWith string `json:"reject_with,omitempty"` // icmp-network-unreachable, icmp-host-unreachable, tcp-reset, etc.
  9. JumpTarget string `json:"jump_target,omitempty"`
  10. SrcAddress string `json:"src_address,omitempty"` // e.g. 192.168.1.0/24, !10.0.0.1
  11. DstAddress string `json:"dst_address,omitempty"`
  12. Protocol string `json:"protocol,omitempty"` // all, tcp, udp, icmp, etc.
  13. SrcPort string `json:"src_port,omitempty"` // e.g. 80, 80-443, 80,443
  14. DstPort string `json:"dst_port,omitempty"`
  15. InInterface string `json:"in_interface,omitempty"` // e.g. eth0, !eth0, wg0
  16. OutInterface string `json:"out_interface,omitempty"`
  17. ConnectionState []string `json:"connection_state,omitempty"` // new, established, related, invalid, untracked
  18. ConnectionMark string `json:"connection_mark,omitempty"`
  19. RoutingMark string `json:"routing_mark,omitempty"`
  20. SrcAddressList string `json:"src_address_list,omitempty"`
  21. DstAddressList string `json:"dst_address_list,omitempty"`
  22. Log bool `json:"log"`
  23. LogPrefix string `json:"log_prefix,omitempty"`
  24. Comment string `json:"comment,omitempty"`
  25. Disabled bool `json:"disabled"`
  26. Packets uint64 `json:"packets"`
  27. Bytes uint64 `json:"bytes"`
  28. }
  29. // NATRule represents a MikroTik-style /ip firewall nat rule
  30. type NATRule struct {
  31. ID string `json:"id"`
  32. Order int `json:"order"`
  33. Chain string `json:"chain"` // srcnat, dstnat
  34. Action string `json:"action"` // masquerade, src-nat, dst-nat, redirect, accept, return
  35. ToAddresses string `json:"to_addresses,omitempty"` // for src-nat or dst-nat
  36. ToPorts string `json:"to_ports,omitempty"` // for dst-nat, redirect, src-nat
  37. SrcAddress string `json:"src_address,omitempty"`
  38. DstAddress string `json:"dst_address,omitempty"`
  39. Protocol string `json:"protocol,omitempty"`
  40. SrcPort string `json:"src_port,omitempty"`
  41. DstPort string `json:"dst_port,omitempty"`
  42. InInterface string `json:"in_interface,omitempty"`
  43. OutInterface string `json:"out_interface,omitempty"`
  44. SrcAddressList string `json:"src_address_list,omitempty"`
  45. DstAddressList string `json:"dst_address_list,omitempty"`
  46. Comment string `json:"comment,omitempty"`
  47. Disabled bool `json:"disabled"`
  48. Packets uint64 `json:"packets"`
  49. Bytes uint64 `json:"bytes"`
  50. }
  51. // MangleRule represents a MikroTik-style /ip firewall mangle rule
  52. type MangleRule struct {
  53. ID string `json:"id"`
  54. Order int `json:"order"`
  55. Chain string `json:"chain"` // prerouting, postrouting, input, output, forward
  56. Action string `json:"action"` // mark-connection, mark-routing, mark-packet, change-mss, set-dscp, accept, return
  57. NewConnectionMark string `json:"new_connection_mark,omitempty"`
  58. NewRoutingMark string `json:"new_routing_mark,omitempty"`
  59. NewPacketMark string `json:"new_packet_mark,omitempty"`
  60. NewMSS string `json:"new_mss,omitempty"` // e.g. "1440" or "clamp-to-pmtu"
  61. NewDSCP int `json:"new_dscp,omitempty"`
  62. Passthrough bool `json:"passthrough"` // default true in MikroTik
  63. SrcAddress string `json:"src_address,omitempty"`
  64. DstAddress string `json:"dst_address,omitempty"`
  65. Protocol string `json:"protocol,omitempty"`
  66. SrcPort string `json:"src_port,omitempty"`
  67. DstPort string `json:"dst_port,omitempty"`
  68. InInterface string `json:"in_interface,omitempty"`
  69. OutInterface string `json:"out_interface,omitempty"`
  70. ConnectionState []string `json:"connection_state,omitempty"`
  71. ConnectionMark string `json:"connection_mark,omitempty"`
  72. RoutingMark string `json:"routing_mark,omitempty"`
  73. SrcAddressList string `json:"src_address_list,omitempty"`
  74. DstAddressList string `json:"dst_address_list,omitempty"`
  75. Comment string `json:"comment,omitempty"`
  76. Disabled bool `json:"disabled"`
  77. Packets uint64 `json:"packets"`
  78. Bytes uint64 `json:"bytes"`
  79. }
  80. // AddressListEntry represents a MikroTik /ip firewall address-list entry
  81. type AddressListEntry struct {
  82. ID string `json:"id"`
  83. Name string `json:"name"` // list name, e.g. "LAN_Subnets", "Blocked"
  84. Address string `json:"address"` // IP or CIDR, e.g. "192.168.1.0/24"
  85. Comment string `json:"comment,omitempty"`
  86. Disabled bool `json:"disabled"`
  87. }
  88. // ActiveConnection represents an active flow from /proc/net/nf_conntrack / conntrack table
  89. type ActiveConnection struct {
  90. ID string `json:"id"`
  91. Protocol string `json:"protocol"`
  92. SrcAddress string `json:"src_address"`
  93. SrcPort int `json:"src_port"`
  94. DstAddress string `json:"dst_address"`
  95. DstPort int `json:"dst_port"`
  96. ReplySrcAddress string `json:"reply_src_address"`
  97. ReplySrcPort int `json:"reply_src_port"`
  98. ReplyDstAddress string `json:"reply_dst_address"`
  99. ReplyDstPort int `json:"reply_dst_port"`
  100. TCPState string `json:"tcp_state"`
  101. Timeout int `json:"timeout"`
  102. ConnectionMark string `json:"connection_mark,omitempty"`
  103. Assured bool `json:"assured"`
  104. Bytes uint64 `json:"bytes,omitempty"`
  105. Packets uint64 `json:"packets,omitempty"`
  106. }
  107. // FirewallSummary contains total rule and connection counts
  108. type FirewallSummary struct {
  109. FilterRulesCount int `json:"filter_rules_count"`
  110. NATRulesCount int `json:"nat_rules_count"`
  111. MangleRulesCount int `json:"mangle_rules_count"`
  112. AddressListsCount int `json:"address_lists_count"`
  113. ActiveConnections int `json:"active_connections"`
  114. }