acl.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package models
  2. import (
  3. "net"
  4. "time"
  5. )
  6. // AllowedTrafficDirection - allowed direction of traffic
  7. type AllowedTrafficDirection int
  8. const (
  9. // TrafficDirectionUni implies traffic is only allowed in one direction (src --> dst)
  10. TrafficDirectionUni AllowedTrafficDirection = iota
  11. // TrafficDirectionBi implies traffic is allowed both direction (src <--> dst )
  12. TrafficDirectionBi
  13. )
  14. // Protocol - allowed protocol
  15. type Protocol string
  16. const (
  17. ALL Protocol = "all"
  18. UDP Protocol = "udp"
  19. TCP Protocol = "tcp"
  20. ICMP Protocol = "icmp"
  21. )
  22. type ServiceType string
  23. const (
  24. Http = "HTTP"
  25. Https = "HTTPS"
  26. AllTCP = "All TCP"
  27. AllUDP = "All UDP"
  28. ICMPService = "ICMP"
  29. Custom = "Custom"
  30. Any = "Any"
  31. )
  32. func (p Protocol) String() string {
  33. return string(p)
  34. }
  35. type AclPolicyType string
  36. const (
  37. UserPolicy AclPolicyType = "user-policy"
  38. DevicePolicy AclPolicyType = "device-policy"
  39. )
  40. type AclPolicyTag struct {
  41. ID AclGroupType `json:"id"`
  42. Value string `json:"value"`
  43. }
  44. type AclGroupType string
  45. const (
  46. UserAclID AclGroupType = "user"
  47. UserGroupAclID AclGroupType = "user-group"
  48. DeviceAclID AclGroupType = "tag"
  49. NetmakerIPAclID AclGroupType = "ip"
  50. NetmakerSubNetRangeAClID AclGroupType = "ipset"
  51. )
  52. func (g AclGroupType) String() string {
  53. return string(g)
  54. }
  55. type UpdateAclRequest struct {
  56. Acl
  57. NewName string `json:"new_name"`
  58. }
  59. type AclPolicy struct {
  60. TypeID AclPolicyType
  61. PrefixTagUser AclGroupType
  62. }
  63. type Acl struct {
  64. ID string `json:"id"`
  65. Default bool `json:"default"`
  66. MetaData string `json:"meta_data"`
  67. Name string `json:"name"`
  68. NetworkID NetworkID `json:"network_id"`
  69. RuleType AclPolicyType `json:"policy_type"`
  70. Src []AclPolicyTag `json:"src_type"`
  71. Dst []AclPolicyTag `json:"dst_type"`
  72. Proto Protocol `json:"protocol"` // tcp, udp, etc.
  73. ServiceType string `json:"type"`
  74. Port []string `json:"ports"`
  75. AllowedDirection AllowedTrafficDirection `json:"allowed_traffic_direction"`
  76. Enabled bool `json:"enabled"`
  77. CreatedBy string `json:"created_by"`
  78. CreatedAt time.Time `json:"created_at"`
  79. }
  80. type AclPolicyTypes struct {
  81. ProtocolTypes []ProtocolType
  82. RuleTypes []AclPolicyType `json:"policy_types"`
  83. SrcGroupTypes []AclGroupType `json:"src_grp_types"`
  84. DstGroupTypes []AclGroupType `json:"dst_grp_types"`
  85. }
  86. type ProtocolType struct {
  87. Name string `json:"name"`
  88. AllowedProtocols []Protocol `json:"allowed_protocols"`
  89. PortRange string `json:"port_range"`
  90. AllowPortSetting bool `json:"allow_port_setting"`
  91. }
  92. type AclRule struct {
  93. ID string `json:"id"`
  94. IPList []net.IPNet `json:"ip_list"`
  95. IP6List []net.IPNet `json:"ip6_list"`
  96. AllowedProtocol Protocol `json:"allowed_protocols"` // tcp, udp, etc.
  97. AllowedPorts []string `json:"allowed_ports"`
  98. Direction AllowedTrafficDirection `json:"direction"` // single or two-way
  99. Allowed bool
  100. }