types.go 6.7 KB

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