acl.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. const (
  23. Http = "HTTP"
  24. Https = "HTTPS"
  25. AllTCP = "All TCP"
  26. AllUDP = "All UDP"
  27. ICMPService = "ICMP"
  28. SSH = "SSH"
  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. NodeTagID AclGroupType = "tag"
  49. NodeID AclGroupType = "device"
  50. EgressRange AclGroupType = "egress-range"
  51. EgressID AclGroupType = "egress-id"
  52. NetmakerIPAclID AclGroupType = "ip"
  53. NetmakerSubNetRangeAClID AclGroupType = "ipset"
  54. )
  55. func (g AclGroupType) String() string {
  56. return string(g)
  57. }
  58. type UpdateAclRequest struct {
  59. Acl
  60. NewName string `json:"new_name"`
  61. }
  62. type AclPolicy struct {
  63. TypeID AclPolicyType
  64. PrefixTagUser AclGroupType
  65. }
  66. type Acl struct {
  67. ID string `json:"id"`
  68. Default bool `json:"default"`
  69. MetaData string `json:"meta_data"`
  70. Name string `json:"name"`
  71. NetworkID NetworkID `json:"network_id"`
  72. RuleType AclPolicyType `json:"policy_type"`
  73. Src []AclPolicyTag `json:"src_type"`
  74. Dst []AclPolicyTag `json:"dst_type"`
  75. Proto Protocol `json:"protocol"` // tcp, udp, etc.
  76. ServiceType string `json:"type"`
  77. Port []string `json:"ports"`
  78. AllowedDirection AllowedTrafficDirection `json:"allowed_traffic_direction"`
  79. Enabled bool `json:"enabled"`
  80. CreatedBy string `json:"created_by"`
  81. CreatedAt time.Time `json:"created_at"`
  82. }
  83. type AclPolicyTypes struct {
  84. ProtocolTypes []ProtocolType
  85. RuleTypes []AclPolicyType `json:"policy_types"`
  86. SrcGroupTypes []AclGroupType `json:"src_grp_types"`
  87. DstGroupTypes []AclGroupType `json:"dst_grp_types"`
  88. }
  89. type ProtocolType struct {
  90. Name string `json:"name"`
  91. AllowedProtocols []Protocol `json:"allowed_protocols"`
  92. PortRange string `json:"port_range"`
  93. AllowPortSetting bool `json:"allow_port_setting"`
  94. }
  95. type AclRule struct {
  96. ID string `json:"id"`
  97. IPList []net.IPNet `json:"ip_list"`
  98. IP6List []net.IPNet `json:"ip6_list"`
  99. AllowedProtocol Protocol `json:"allowed_protocols"` // tcp, udp, etc.
  100. AllowedPorts []string `json:"allowed_ports"`
  101. Direction AllowedTrafficDirection `json:"direction"` // single or two-way
  102. Dst []net.IPNet `json:"dst"`
  103. Dst6 []net.IPNet `json:"dst6"`
  104. Allowed bool
  105. }