acl.go 3.0 KB

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