acl.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. )
  31. func (p Protocol) String() string {
  32. return string(p)
  33. }
  34. type AclPolicyType string
  35. const (
  36. UserPolicy AclPolicyType = "user-policy"
  37. DevicePolicy AclPolicyType = "device-policy"
  38. )
  39. type AclPolicyTag struct {
  40. ID AclGroupType `json:"id"`
  41. Value string `json:"value"`
  42. }
  43. type AclGroupType string
  44. const (
  45. UserAclID AclGroupType = "user"
  46. UserGroupAclID AclGroupType = "user-group"
  47. DeviceAclID AclGroupType = "tag"
  48. NetmakerIPAclID AclGroupType = "ip"
  49. NetmakerSubNetRangeAClID AclGroupType = "ipset"
  50. )
  51. func (g AclGroupType) String() string {
  52. return string(g)
  53. }
  54. type UpdateAclRequest struct {
  55. Acl
  56. NewName string `json:"new_name"`
  57. }
  58. type AclPolicy struct {
  59. TypeID AclPolicyType
  60. PrefixTagUser AclGroupType
  61. }
  62. type Acl struct {
  63. ID string `json:"id"`
  64. Default bool `json:"default"`
  65. MetaData string `json:"meta_data"`
  66. Name string `json:"name"`
  67. NetworkID NetworkID `json:"network_id"`
  68. RuleType AclPolicyType `json:"policy_type"`
  69. Src []AclPolicyTag `json:"src_type"`
  70. Dst []AclPolicyTag `json:"dst_type"`
  71. Proto Protocol `json:"protocol"` // tcp, udp, etc.
  72. ServiceType string `json:"type"`
  73. Port []string `json:"ports"`
  74. AllowedDirection AllowedTrafficDirection `json:"allowed_traffic_direction"`
  75. Enabled bool `json:"enabled"`
  76. CreatedBy string `json:"created_by"`
  77. CreatedAt time.Time `json:"created_at"`
  78. }
  79. type AclPolicyTypes struct {
  80. ProtocolTypes []ProtocolType
  81. RuleTypes []AclPolicyType `json:"policy_types"`
  82. SrcGroupTypes []AclGroupType `json:"src_grp_types"`
  83. DstGroupTypes []AclGroupType `json:"dst_grp_types"`
  84. }
  85. type ProtocolType struct {
  86. Name string `json:"name"`
  87. AllowedProtocols []Protocol `json:"allowed_protocols"`
  88. PortRange string `json:"port_range"`
  89. AllowPortSetting bool `json:"allow_port_setting"`
  90. }
  91. type AclRule struct {
  92. ID string `json:"id"`
  93. IPList []net.IPNet `json:"ip_list"`
  94. IP6List []net.IPNet `json:"ip6_list"`
  95. AllowedProtocol Protocol `json:"allowed_protocols"` // tcp, udp, etc.
  96. AllowedPorts []string `json:"allowed_ports"`
  97. Direction AllowedTrafficDirection `json:"direction"` // single or two-way
  98. Allowed bool
  99. }