types.go 7.0 KB

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