constants.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. from django.db.models import Q
  2. from .choices import FHRPGroupProtocolChoices, IPAddressRoleChoices, PrefixClassificationChoices
  3. #
  4. # VRFs
  5. #
  6. # Per RFC 4364 section 4.2, a route distinguisher may be encoded as one of the following:
  7. # * Type 0 (16-bit AS number : 32-bit integer)
  8. # * Type 1 (32-bit IPv4 address : 16-bit integer)
  9. # * Type 2 (32-bit AS number : 16-bit integer)
  10. # 21 characters are sufficient to convey the longest possible string value (255.255.255.255:65535)
  11. # Also used for RouteTargets
  12. VRF_RD_MAX_LENGTH = 21
  13. #
  14. # Prefixes
  15. #
  16. PREFIX_LENGTH_MIN = 1
  17. PREFIX_LENGTH_MAX = 127 # IPv6
  18. # Address space by classification per the IANA registries, matched tier by tier in get_prefix_classification(). A change
  19. # needs a migration which replaces ipam_prefix_classification() and reclassifies prefixes overlapping changed blocks.
  20. PREFIX_CLASSIFICATION_NETWORKS = {
  21. PrefixClassificationChoices.CLASSIFICATION_PRIVATE: (
  22. '10.0.0.0/8', # RFC 1918
  23. '172.16.0.0/12', # RFC 1918
  24. '192.168.0.0/16', # RFC 1918
  25. 'fc00::/7', # RFC 4193
  26. ),
  27. PrefixClassificationChoices.CLASSIFICATION_SHARED: (
  28. '100.64.0.0/10', # RFC 6598
  29. ),
  30. PrefixClassificationChoices.CLASSIFICATION_LOOPBACK: (
  31. '127.0.0.0/8', # RFC 1122
  32. '::1/128', # RFC 4291
  33. ),
  34. PrefixClassificationChoices.CLASSIFICATION_LINK_LOCAL: (
  35. '169.254.0.0/16', # RFC 3927
  36. 'fe80::/10', # RFC 4291
  37. ),
  38. PrefixClassificationChoices.CLASSIFICATION_DOCUMENTATION: (
  39. '192.0.2.0/24', # RFC 5737
  40. '198.51.100.0/24', # RFC 5737
  41. '203.0.113.0/24', # RFC 5737
  42. '2001:db8::/32', # RFC 3849
  43. '3fff::/20', # RFC 9637
  44. ),
  45. PrefixClassificationChoices.CLASSIFICATION_MULTICAST: (
  46. '224.0.0.0/4', # RFC 5771
  47. 'ff00::/8', # RFC 4291
  48. ),
  49. PrefixClassificationChoices.CLASSIFICATION_BENCHMARKING: (
  50. '198.18.0.0/15', # RFC 2544
  51. '2001:2::/48', # RFC 5180
  52. ),
  53. PrefixClassificationChoices.CLASSIFICATION_SPECIAL: (
  54. '0.0.0.0/8', # RFC 791
  55. '192.0.0.0/24', # RFC 6890
  56. '192.88.99.0/24', # RFC 7526
  57. '240.0.0.0/4', # RFC 1112
  58. '::/8', '100::/8', '200::/7', '400::/6', '800::/5', '1000::/4', # Reserved by IETF
  59. '2001::/23', # RFC 2928
  60. '2002::/16', # RFC 3056
  61. '4000::/3', '6000::/3', '8000::/3', 'a000::/3', 'c000::/3', # Reserved by IETF
  62. 'e000::/4', 'f000::/5', 'f800::/6', 'fe00::/9', # Reserved by IETF
  63. 'fec0::/10', # RFC 3879
  64. ),
  65. }
  66. # Globally reachable blocks within special-purpose space
  67. PREFIX_CLASSIFICATION_PUBLIC_EXCEPTIONS = (
  68. '192.0.0.9/32', # RFC 7723
  69. '192.0.0.10/32', # RFC 8155
  70. '64:ff9b::/96', # RFC 6052
  71. '2001:1::1/128', # RFC 7723
  72. '2001:1::2/128', # RFC 8155
  73. '2001:1::3/128', # RFC 9665
  74. '2001:3::/32', # RFC 7450
  75. '2001:4:112::/48', # RFC 7535
  76. '2001:20::/28', # RFC 7343
  77. '2001:30::/28', # RFC 9374
  78. )
  79. #
  80. # IPAddresses
  81. #
  82. IPADDRESS_ASSIGNMENT_MODELS = Q(
  83. Q(app_label='dcim', model='interface') |
  84. Q(app_label='ipam', model='fhrpgroup') |
  85. Q(app_label='virtualization', model='vminterface')
  86. )
  87. IPADDRESS_MASK_LENGTH_MIN = 1
  88. IPADDRESS_MASK_LENGTH_MAX = 128 # IPv6
  89. IPADDRESS_ROLES_NONUNIQUE = (
  90. # IPAddress roles which are exempt from unique address enforcement
  91. IPAddressRoleChoices.ROLE_ANYCAST,
  92. IPAddressRoleChoices.ROLE_VIP,
  93. IPAddressRoleChoices.ROLE_VRRP,
  94. IPAddressRoleChoices.ROLE_HSRP,
  95. IPAddressRoleChoices.ROLE_GLBP,
  96. IPAddressRoleChoices.ROLE_CARP,
  97. )
  98. #
  99. # FHRP groups
  100. #
  101. FHRPGROUPASSIGNMENT_PRIORITY_MIN = 0
  102. FHRPGROUPASSIGNMENT_PRIORITY_MAX = 255
  103. FHRP_PROTOCOL_ROLE_MAPPINGS = {
  104. FHRPGroupProtocolChoices.PROTOCOL_VRRP2: IPAddressRoleChoices.ROLE_VRRP,
  105. FHRPGroupProtocolChoices.PROTOCOL_VRRP3: IPAddressRoleChoices.ROLE_VRRP,
  106. FHRPGroupProtocolChoices.PROTOCOL_HSRP: IPAddressRoleChoices.ROLE_HSRP,
  107. FHRPGroupProtocolChoices.PROTOCOL_GLBP: IPAddressRoleChoices.ROLE_GLBP,
  108. FHRPGroupProtocolChoices.PROTOCOL_CARP: IPAddressRoleChoices.ROLE_CARP,
  109. FHRPGroupProtocolChoices.PROTOCOL_OTHER: IPAddressRoleChoices.ROLE_VIP,
  110. }
  111. #
  112. # VLANs
  113. #
  114. # 12-bit VLAN ID (values 0 and 4095 are reserved)
  115. VLAN_VID_MIN = 1
  116. VLAN_VID_MAX = 4094
  117. # models values for ContentTypes which may be VLANGroup scope types
  118. VLANGROUP_SCOPE_TYPES = (
  119. 'region', 'sitegroup', 'site', 'location', 'rackgroup', 'rack', 'clustergroup', 'cluster',
  120. )
  121. #
  122. # Services
  123. #
  124. SERVICE_ASSIGNMENT_MODELS = Q(
  125. Q(app_label='dcim', model='device') |
  126. Q(app_label='ipam', model='fhrpgroup') |
  127. Q(app_label='virtualization', model='virtualmachine')
  128. )
  129. # 16-bit port number
  130. SERVICE_PORT_MIN = 1
  131. SERVICE_PORT_MAX = 65535