2
0

acl.go 3.4 KB

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