dhcpv6_options.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. // Copyright 2018 The GoPacket Authors. All rights reserved.
  2. //
  3. // Use of this source code is governed by a BSD-style license
  4. // that can be found in the LICENSE file in the root of the source
  5. // tree.
  6. package layers
  7. import (
  8. "bytes"
  9. "encoding/binary"
  10. "errors"
  11. "fmt"
  12. "github.com/google/gopacket"
  13. )
  14. // DHCPv6Opt represents a DHCP option or parameter from RFC-3315
  15. type DHCPv6Opt uint16
  16. // Constants for the DHCPv6Opt options.
  17. const (
  18. DHCPv6OptClientID DHCPv6Opt = 1
  19. DHCPv6OptServerID DHCPv6Opt = 2
  20. DHCPv6OptIANA DHCPv6Opt = 3
  21. DHCPv6OptIATA DHCPv6Opt = 4
  22. DHCPv6OptIAAddr DHCPv6Opt = 5
  23. DHCPv6OptOro DHCPv6Opt = 6
  24. DHCPv6OptPreference DHCPv6Opt = 7
  25. DHCPv6OptElapsedTime DHCPv6Opt = 8
  26. DHCPv6OptRelayMessage DHCPv6Opt = 9
  27. DHCPv6OptAuth DHCPv6Opt = 11
  28. DHCPv6OptUnicast DHCPv6Opt = 12
  29. DHCPv6OptStatusCode DHCPv6Opt = 13
  30. DHCPv6OptRapidCommit DHCPv6Opt = 14
  31. DHCPv6OptUserClass DHCPv6Opt = 15
  32. DHCPv6OptVendorClass DHCPv6Opt = 16
  33. DHCPv6OptVendorOpts DHCPv6Opt = 17
  34. DHCPv6OptInterfaceID DHCPv6Opt = 18
  35. DHCPv6OptReconfigureMessage DHCPv6Opt = 19
  36. DHCPv6OptReconfigureAccept DHCPv6Opt = 20
  37. // RFC 3319 Session Initiation Protocol (SIP)
  38. DHCPv6OptSIPServersDomainList DHCPv6Opt = 21
  39. DHCPv6OptSIPServersAddressList DHCPv6Opt = 22
  40. // RFC 3646 DNS Configuration
  41. DHCPv6OptDNSServers DHCPv6Opt = 23
  42. DHCPv6OptDomainList DHCPv6Opt = 24
  43. // RFC 3633 Prefix Delegation
  44. DHCPv6OptIAPD DHCPv6Opt = 25
  45. DHCPv6OptIAPrefix DHCPv6Opt = 26
  46. // RFC 3898 Network Information Service (NIS)
  47. DHCPv6OptNISServers DHCPv6Opt = 27
  48. DHCPv6OptNISPServers DHCPv6Opt = 28
  49. DHCPv6OptNISDomainName DHCPv6Opt = 29
  50. DHCPv6OptNISPDomainName DHCPv6Opt = 30
  51. // RFC 4075 Simple Network Time Protocol (SNTP)
  52. DHCPv6OptSNTPServers DHCPv6Opt = 31
  53. // RFC 4242 Information Refresh Time Option
  54. DHCPv6OptInformationRefreshTime DHCPv6Opt = 32
  55. // RFC 4280 Broadcast and Multicast Control Servers
  56. DHCPv6OptBCMCSServerDomainNameList DHCPv6Opt = 33
  57. DHCPv6OptBCMCSServerAddressList DHCPv6Opt = 34
  58. // RFC 4776 Civic Address ConfigurationOption
  59. DHCPv6OptGeoconfCivic DHCPv6Opt = 36
  60. // RFC 4649 Relay Agent Remote-ID
  61. DHCPv6OptRemoteID DHCPv6Opt = 37
  62. // RFC 4580 Relay Agent Subscriber-ID
  63. DHCPv6OptSubscriberID DHCPv6Opt = 38
  64. // RFC 4704 Client Full Qualified Domain Name (FQDN)
  65. DHCPv6OptClientFQDN DHCPv6Opt = 39
  66. // RFC 5192 Protocol for Carrying Authentication for Network Access (PANA)
  67. DHCPv6OptPanaAgent DHCPv6Opt = 40
  68. // RFC 4833 Timezone Options
  69. DHCPv6OptNewPOSIXTimezone DHCPv6Opt = 41
  70. DHCPv6OptNewTZDBTimezone DHCPv6Opt = 42
  71. // RFC 4994 Relay Agent Echo Request
  72. DHCPv6OptEchoRequestOption DHCPv6Opt = 43
  73. // RFC 5007 Leasequery
  74. DHCPv6OptLQQuery DHCPv6Opt = 44
  75. DHCPv6OptCLTTime DHCPv6Opt = 45
  76. DHCPv6OptClientData DHCPv6Opt = 46
  77. DHCPv6OptLQRelayData DHCPv6Opt = 47
  78. DHCPv6OptLQClientLink DHCPv6Opt = 48
  79. // RFC 6610 Home Information Discovery in Mobile IPv6 (MIPv6)
  80. DHCPv6OptMIP6HNIDF DHCPv6Opt = 49
  81. DHCPv6OptMIP6VDINF DHCPv6Opt = 50
  82. DHCPv6OptMIP6IDINF DHCPv6Opt = 69
  83. DHCPv6OptMIP6UDINF DHCPv6Opt = 70
  84. DHCPv6OptMIP6HNP DHCPv6Opt = 71
  85. DHCPv6OptMIP6HAA DHCPv6Opt = 72
  86. DHCPv6OptMIP6HAF DHCPv6Opt = 73
  87. // RFC 5223 Discovering Location-to-Service Translation (LoST) Servers
  88. DHCPv6OptV6LOST DHCPv6Opt = 51
  89. // RFC 5417 Control And Provisioning of Wireless Access Points (CAPWAP)
  90. DHCPv6OptCAPWAPACV6 DHCPv6Opt = 52
  91. // RFC 5460 Bulk Leasequery
  92. DHCPv6OptRelayID DHCPv6Opt = 53
  93. // RFC 5678 IEEE 802.21 Mobility Services (MoS) Discovery
  94. DHCPv6OptIPv6AddressMoS DHCPv6Opt = 54
  95. DHCPv6OptIPv6FQDNMoS DHCPv6Opt = 55
  96. // RFC 5908 NTP Server Option
  97. DHCPv6OptNTPServer DHCPv6Opt = 56
  98. // RFC 5986 Discovering the Local Location Information Server (LIS)
  99. DHCPv6OptV6AccessDomain DHCPv6Opt = 57
  100. // RFC 5986 SIP User Agent
  101. DHCPv6OptSIPUACSList DHCPv6Opt = 58
  102. // RFC 5970 Options for Network Boot
  103. DHCPv6OptBootFileURL DHCPv6Opt = 59
  104. DHCPv6OptBootFileParam DHCPv6Opt = 60
  105. DHCPv6OptClientArchType DHCPv6Opt = 61
  106. DHCPv6OptNII DHCPv6Opt = 62
  107. // RFC 6225 Coordinate-Based Location Configuration Information
  108. DHCPv6OptGeolocation DHCPv6Opt = 63
  109. // RFC 6334 Dual-Stack Lite
  110. DHCPv6OptAFTRName DHCPv6Opt = 64
  111. // RFC 6440 EAP Re-authentication Protocol (ERP)
  112. DHCPv6OptERPLocalDomainName DHCPv6Opt = 65
  113. // RFC 6422 Relay-Supplied DHCP Options
  114. DHCPv6OptRSOO DHCPv6Opt = 66
  115. // RFC 6603 Prefix Exclude Option for DHCPv6-based Prefix Delegation
  116. DHCPv6OptPDExclude DHCPv6Opt = 67
  117. // RFC 6607 Virtual Subnet Selection
  118. DHCPv6OptVSS DHCPv6Opt = 68
  119. // RFC 6731 Improved Recursive DNS Server Selection for Multi-Interfaced Nodes
  120. DHCPv6OptRDNSSSelection DHCPv6Opt = 74
  121. // RFC 6784 Kerberos Options for DHCPv6
  122. DHCPv6OptKRBPrincipalName DHCPv6Opt = 75
  123. DHCPv6OptKRBRealmName DHCPv6Opt = 76
  124. DHCPv6OptKRBKDC DHCPv6Opt = 77
  125. // RFC 6939 Client Link-Layer Address Option
  126. DHCPv6OptClientLinkLayerAddress DHCPv6Opt = 79
  127. // RFC 6977 Triggering DHCPv6 Reconfiguration from Relay Agents
  128. DHCPv6OptLinkAddress DHCPv6Opt = 80
  129. // RFC 7037 RADIUS Option for the DHCPv6 Relay Agent
  130. DHCPv6OptRADIUS DHCPv6Opt = 81
  131. // RFC 7083 Modification to Default Values of SOL_MAX_RT and INF_MAX_RT
  132. DHCPv6OptSolMaxRt DHCPv6Opt = 82
  133. DHCPv6OptInfMaxRt DHCPv6Opt = 83
  134. // RFC 7078 Distributing Address Selection Policy
  135. DHCPv6OptAddrSel DHCPv6Opt = 84
  136. DHCPv6OptAddrSelTable DHCPv6Opt = 85
  137. // RFC 7291 DHCP Options for the Port Control Protocol (PCP)
  138. DHCPv6OptV6PCPServer DHCPv6Opt = 86
  139. // RFC 7341 DHCPv4-over-DHCPv6 (DHCP 4o6) Transport
  140. DHCPv6OptDHCPv4Message DHCPv6Opt = 87
  141. DHCPv6OptDHCPv4OverDHCPv6Server DHCPv6Opt = 88
  142. // RFC 7598 Configuration of Softwire Address and Port-Mapped Clients
  143. DHCPv6OptS46Rule DHCPv6Opt = 89
  144. DHCPv6OptS46BR DHCPv6Opt = 90
  145. DHCPv6OptS46DMR DHCPv6Opt = 91
  146. DHCPv6OptS46V4V4Bind DHCPv6Opt = 92
  147. DHCPv6OptS46PortParameters DHCPv6Opt = 93
  148. DHCPv6OptS46ContMAPE DHCPv6Opt = 94
  149. DHCPv6OptS46ContMAPT DHCPv6Opt = 95
  150. DHCPv6OptS46ContLW DHCPv6Opt = 96
  151. // RFC 7600 IPv4 Residual Deployment via IPv6
  152. DHCPv6Opt4RD DHCPv6Opt = 97
  153. DHCPv6Opt4RDMapRule DHCPv6Opt = 98
  154. DHCPv6Opt4RDNonMapRule DHCPv6Opt = 99
  155. // RFC 7653 Active Leasequery
  156. DHCPv6OptLQBaseTime DHCPv6Opt = 100
  157. DHCPv6OptLQStartTime DHCPv6Opt = 101
  158. DHCPv6OptLQEndTime DHCPv6Opt = 102
  159. // RFC 7710 Captive-Portal Identification
  160. DHCPv6OptCaptivePortal DHCPv6Opt = 103
  161. // RFC 7774 Multicast Protocol for Low-Power and Lossy Networks (MPL) Parameter Configuration
  162. DHCPv6OptMPLParameters DHCPv6Opt = 104
  163. // RFC 7839 Access-Network-Identifier (ANI)
  164. DHCPv6OptANIATT DHCPv6Opt = 105
  165. DHCPv6OptANINetworkName DHCPv6Opt = 106
  166. DHCPv6OptANIAPName DHCPv6Opt = 107
  167. DHCPv6OptANIAPBSSID DHCPv6Opt = 108
  168. DHCPv6OptANIOperatorID DHCPv6Opt = 109
  169. DHCPv6OptANIOperatorRealm DHCPv6Opt = 110
  170. // RFC 8026 Unified IPv4-in-IPv6 Softwire Customer Premises Equipment (CPE)
  171. DHCPv6OptS46Priority DHCPv6Opt = 111
  172. // draft-ietf-opsawg-mud-25 Manufacturer Usage Description (MUD)
  173. DHCPv6OptMUDURLV6 DHCPv6Opt = 112
  174. // RFC 8115 IPv4-Embedded Multicast and Unicast IPv6 Prefixes
  175. DHCPv6OptV6Prefix64 DHCPv6Opt = 113
  176. // RFC 8156 DHCPv6 Failover Protocol
  177. DHCPv6OptFBindingStatus DHCPv6Opt = 114
  178. DHCPv6OptFConnectFlags DHCPv6Opt = 115
  179. DHCPv6OptFDNSRemovalInfo DHCPv6Opt = 116
  180. DHCPv6OptFDNSHostName DHCPv6Opt = 117
  181. DHCPv6OptFDNSZoneName DHCPv6Opt = 118
  182. DHCPv6OptFDNSFlags DHCPv6Opt = 119
  183. DHCPv6OptFExpirationTime DHCPv6Opt = 120
  184. DHCPv6OptFMaxUnacknowledgedBNDUPD DHCPv6Opt = 121
  185. DHCPv6OptFMCLT DHCPv6Opt = 122
  186. DHCPv6OptFPartnerLifetime DHCPv6Opt = 123
  187. DHCPv6OptFPartnerLifetimeSent DHCPv6Opt = 124
  188. DHCPv6OptFPartnerDownTime DHCPv6Opt = 125
  189. DHCPv6OptFPartnerRawCltTime DHCPv6Opt = 126
  190. DHCPv6OptFProtocolVersion DHCPv6Opt = 127
  191. DHCPv6OptFKeepaliveTime DHCPv6Opt = 128
  192. DHCPv6OptFReconfigureData DHCPv6Opt = 129
  193. DHCPv6OptFRelationshipName DHCPv6Opt = 130
  194. DHCPv6OptFServerFlags DHCPv6Opt = 131
  195. DHCPv6OptFServerState DHCPv6Opt = 132
  196. DHCPv6OptFStartTimeOfState DHCPv6Opt = 133
  197. DHCPv6OptFStateExpirationTime DHCPv6Opt = 134
  198. // RFC 8357 Generalized UDP Source Port for DHCP Relay
  199. DHCPv6OptRelayPort DHCPv6Opt = 135
  200. // draft-ietf-netconf-zerotouch-25 Zero Touch Provisioning for Networking Devices
  201. DHCPv6OptV6ZeroTouchRedirect DHCPv6Opt = 136
  202. // RFC 6153 Access Network Discovery and Selection Function (ANDSF) Discovery
  203. DHCPv6OptIPV6AddressANDSF DHCPv6Opt = 143
  204. )
  205. // String returns a string version of a DHCPv6Opt.
  206. func (o DHCPv6Opt) String() string {
  207. switch o {
  208. case DHCPv6OptClientID:
  209. return "ClientID"
  210. case DHCPv6OptServerID:
  211. return "ServerID"
  212. case DHCPv6OptIANA:
  213. return "IA_NA"
  214. case DHCPv6OptIATA:
  215. return "IA_TA"
  216. case DHCPv6OptIAAddr:
  217. return "IAAddr"
  218. case DHCPv6OptOro:
  219. return "Oro"
  220. case DHCPv6OptPreference:
  221. return "Preference"
  222. case DHCPv6OptElapsedTime:
  223. return "ElapsedTime"
  224. case DHCPv6OptRelayMessage:
  225. return "RelayMessage"
  226. case DHCPv6OptAuth:
  227. return "Auth"
  228. case DHCPv6OptUnicast:
  229. return "Unicast"
  230. case DHCPv6OptStatusCode:
  231. return "StatusCode"
  232. case DHCPv6OptRapidCommit:
  233. return "RapidCommit"
  234. case DHCPv6OptUserClass:
  235. return "UserClass"
  236. case DHCPv6OptVendorClass:
  237. return "VendorClass"
  238. case DHCPv6OptVendorOpts:
  239. return "VendorOpts"
  240. case DHCPv6OptInterfaceID:
  241. return "InterfaceID"
  242. case DHCPv6OptReconfigureMessage:
  243. return "ReconfigureMessage"
  244. case DHCPv6OptReconfigureAccept:
  245. return "ReconfigureAccept"
  246. case DHCPv6OptSIPServersDomainList:
  247. return "SIPServersDomainList"
  248. case DHCPv6OptSIPServersAddressList:
  249. return "SIPServersAddressList"
  250. case DHCPv6OptDNSServers:
  251. return "DNSRecursiveNameServer"
  252. case DHCPv6OptDomainList:
  253. return "DomainSearchList"
  254. case DHCPv6OptIAPD:
  255. return "IdentityAssociationPrefixDelegation"
  256. case DHCPv6OptIAPrefix:
  257. return "IAPDPrefix"
  258. case DHCPv6OptNISServers:
  259. return "NISServers"
  260. case DHCPv6OptNISPServers:
  261. return "NISv2Servers"
  262. case DHCPv6OptNISDomainName:
  263. return "NISDomainName"
  264. case DHCPv6OptNISPDomainName:
  265. return "NISv2DomainName"
  266. case DHCPv6OptSNTPServers:
  267. return "SNTPServers"
  268. case DHCPv6OptInformationRefreshTime:
  269. return "InformationRefreshTime"
  270. case DHCPv6OptBCMCSServerDomainNameList:
  271. return "BCMCSControlServersDomainNameList"
  272. case DHCPv6OptBCMCSServerAddressList:
  273. return "BCMCSControlServersAddressList"
  274. case DHCPv6OptGeoconfCivic:
  275. return "CivicAddress"
  276. case DHCPv6OptRemoteID:
  277. return "RelayAgentRemoteID"
  278. case DHCPv6OptSubscriberID:
  279. return "RelayAgentSubscriberID"
  280. case DHCPv6OptClientFQDN:
  281. return "ClientFQDN"
  282. case DHCPv6OptPanaAgent:
  283. return "PANAAuthenticationAgent"
  284. case DHCPv6OptNewPOSIXTimezone:
  285. return "NewPOSIXTimezone"
  286. case DHCPv6OptNewTZDBTimezone:
  287. return "NewTZDBTimezone"
  288. case DHCPv6OptEchoRequestOption:
  289. return "EchoRequest"
  290. case DHCPv6OptLQQuery:
  291. return "LeasequeryQuery"
  292. case DHCPv6OptClientData:
  293. return "LeasequeryClientData"
  294. case DHCPv6OptCLTTime:
  295. return "LeasequeryClientLastTransactionTime"
  296. case DHCPv6OptLQRelayData:
  297. return "LeasequeryRelayData"
  298. case DHCPv6OptLQClientLink:
  299. return "LeasequeryClientLink"
  300. case DHCPv6OptMIP6HNIDF:
  301. return "MIPv6HomeNetworkIDFQDN"
  302. case DHCPv6OptMIP6VDINF:
  303. return "MIPv6VisitedHomeNetworkInformation"
  304. case DHCPv6OptMIP6IDINF:
  305. return "MIPv6IdentifiedHomeNetworkInformation"
  306. case DHCPv6OptMIP6UDINF:
  307. return "MIPv6UnrestrictedHomeNetworkInformation"
  308. case DHCPv6OptMIP6HNP:
  309. return "MIPv6HomeNetworkPrefix"
  310. case DHCPv6OptMIP6HAA:
  311. return "MIPv6HomeAgentAddress"
  312. case DHCPv6OptMIP6HAF:
  313. return "MIPv6HomeAgentFQDN"
  314. case DHCPv6OptV6LOST:
  315. return "LoST Server"
  316. case DHCPv6OptCAPWAPACV6:
  317. return "CAPWAPAccessControllerV6"
  318. case DHCPv6OptRelayID:
  319. return "LeasequeryRelayID"
  320. case DHCPv6OptIPv6AddressMoS:
  321. return "MoSIPv6Address"
  322. case DHCPv6OptIPv6FQDNMoS:
  323. return "MoSDomainNameList"
  324. case DHCPv6OptNTPServer:
  325. return "NTPServer"
  326. case DHCPv6OptV6AccessDomain:
  327. return "AccessNetworkDomainName"
  328. case DHCPv6OptSIPUACSList:
  329. return "SIPUserAgentConfigurationServiceDomains"
  330. case DHCPv6OptBootFileURL:
  331. return "BootFileURL"
  332. case DHCPv6OptBootFileParam:
  333. return "BootFileParameters"
  334. case DHCPv6OptClientArchType:
  335. return "ClientSystemArchitectureType"
  336. case DHCPv6OptNII:
  337. return "ClientNetworkInterfaceIdentifier"
  338. case DHCPv6OptGeolocation:
  339. return "Geolocation"
  340. case DHCPv6OptAFTRName:
  341. return "AFTRName"
  342. case DHCPv6OptERPLocalDomainName:
  343. return "AFTRName"
  344. case DHCPv6OptRSOO:
  345. return "RSOOption"
  346. case DHCPv6OptPDExclude:
  347. return "PrefixExclude"
  348. case DHCPv6OptVSS:
  349. return "VirtualSubnetSelection"
  350. case DHCPv6OptRDNSSSelection:
  351. return "RDNSSSelection"
  352. case DHCPv6OptKRBPrincipalName:
  353. return "KerberosPrincipalName"
  354. case DHCPv6OptKRBRealmName:
  355. return "KerberosRealmName"
  356. case DHCPv6OptKRBKDC:
  357. return "KerberosKDC"
  358. case DHCPv6OptClientLinkLayerAddress:
  359. return "ClientLinkLayerAddress"
  360. case DHCPv6OptLinkAddress:
  361. return "LinkAddress"
  362. case DHCPv6OptRADIUS:
  363. return "RADIUS"
  364. case DHCPv6OptSolMaxRt:
  365. return "SolMaxRt"
  366. case DHCPv6OptInfMaxRt:
  367. return "InfMaxRt"
  368. case DHCPv6OptAddrSel:
  369. return "AddressSelection"
  370. case DHCPv6OptAddrSelTable:
  371. return "AddressSelectionTable"
  372. case DHCPv6OptV6PCPServer:
  373. return "PCPServer"
  374. case DHCPv6OptDHCPv4Message:
  375. return "DHCPv4Message"
  376. case DHCPv6OptDHCPv4OverDHCPv6Server:
  377. return "DHCP4o6ServerAddress"
  378. case DHCPv6OptS46Rule:
  379. return "S46Rule"
  380. case DHCPv6OptS46BR:
  381. return "S46BR"
  382. case DHCPv6OptS46DMR:
  383. return "S46DMR"
  384. case DHCPv6OptS46V4V4Bind:
  385. return "S46IPv4IPv6AddressBinding"
  386. case DHCPv6OptS46PortParameters:
  387. return "S46PortParameters"
  388. case DHCPv6OptS46ContMAPE:
  389. return "S46MAPEContainer"
  390. case DHCPv6OptS46ContMAPT:
  391. return "S46MAPTContainer"
  392. case DHCPv6OptS46ContLW:
  393. return "S46Lightweight4Over6Container"
  394. case DHCPv6Opt4RD:
  395. return "4RD"
  396. case DHCPv6Opt4RDMapRule:
  397. return "4RDMapRule"
  398. case DHCPv6Opt4RDNonMapRule:
  399. return "4RDNonMapRule"
  400. case DHCPv6OptLQBaseTime:
  401. return "LQBaseTime"
  402. case DHCPv6OptLQStartTime:
  403. return "LQStartTime"
  404. case DHCPv6OptLQEndTime:
  405. return "LQEndTime"
  406. case DHCPv6OptCaptivePortal:
  407. return "CaptivePortal"
  408. case DHCPv6OptMPLParameters:
  409. return "MPLParameterConfiguration"
  410. case DHCPv6OptANIATT:
  411. return "ANIAccessTechnologyType"
  412. case DHCPv6OptANINetworkName:
  413. return "ANINetworkName"
  414. case DHCPv6OptANIAPName:
  415. return "ANIAccessPointName"
  416. case DHCPv6OptANIAPBSSID:
  417. return "ANIAccessPointBSSID"
  418. case DHCPv6OptANIOperatorID:
  419. return "ANIOperatorIdentifier"
  420. case DHCPv6OptANIOperatorRealm:
  421. return "ANIOperatorRealm"
  422. case DHCPv6OptS46Priority:
  423. return "S64Priority"
  424. case DHCPv6OptMUDURLV6:
  425. return "ManufacturerUsageDescriptionURL"
  426. case DHCPv6OptV6Prefix64:
  427. return "V6Prefix64"
  428. case DHCPv6OptFBindingStatus:
  429. return "FailoverBindingStatus"
  430. case DHCPv6OptFConnectFlags:
  431. return "FailoverConnectFlags"
  432. case DHCPv6OptFDNSRemovalInfo:
  433. return "FailoverDNSRemovalInfo"
  434. case DHCPv6OptFDNSHostName:
  435. return "FailoverDNSHostName"
  436. case DHCPv6OptFDNSZoneName:
  437. return "FailoverDNSZoneName"
  438. case DHCPv6OptFDNSFlags:
  439. return "FailoverDNSFlags"
  440. case DHCPv6OptFExpirationTime:
  441. return "FailoverExpirationTime"
  442. case DHCPv6OptFMaxUnacknowledgedBNDUPD:
  443. return "FailoverMaxUnacknowledgedBNDUPDMessages"
  444. case DHCPv6OptFMCLT:
  445. return "FailoverMaximumClientLeadTime"
  446. case DHCPv6OptFPartnerLifetime:
  447. return "FailoverPartnerLifetime"
  448. case DHCPv6OptFPartnerLifetimeSent:
  449. return "FailoverPartnerLifetimeSent"
  450. case DHCPv6OptFPartnerDownTime:
  451. return "FailoverPartnerDownTime"
  452. case DHCPv6OptFPartnerRawCltTime:
  453. return "FailoverPartnerRawClientLeadTime"
  454. case DHCPv6OptFProtocolVersion:
  455. return "FailoverProtocolVersion"
  456. case DHCPv6OptFKeepaliveTime:
  457. return "FailoverKeepaliveTime"
  458. case DHCPv6OptFReconfigureData:
  459. return "FailoverReconfigureData"
  460. case DHCPv6OptFRelationshipName:
  461. return "FailoverRelationshipName"
  462. case DHCPv6OptFServerFlags:
  463. return "FailoverServerFlags"
  464. case DHCPv6OptFServerState:
  465. return "FailoverServerState"
  466. case DHCPv6OptFStartTimeOfState:
  467. return "FailoverStartTimeOfState"
  468. case DHCPv6OptFStateExpirationTime:
  469. return "FailoverStateExpirationTime"
  470. case DHCPv6OptRelayPort:
  471. return "RelayPort"
  472. case DHCPv6OptV6ZeroTouchRedirect:
  473. return "ZeroTouch"
  474. case DHCPv6OptIPV6AddressANDSF:
  475. return "ANDSFIPv6Address"
  476. default:
  477. return fmt.Sprintf("Unknown(%d)", uint16(o))
  478. }
  479. }
  480. // DHCPv6Options is used to get nicely printed option lists which would normally
  481. // be cut off after 5 options.
  482. type DHCPv6Options []DHCPv6Option
  483. // String returns a string version of the options list.
  484. func (o DHCPv6Options) String() string {
  485. buf := &bytes.Buffer{}
  486. buf.WriteByte('[')
  487. for i, opt := range o {
  488. buf.WriteString(opt.String())
  489. if i+1 != len(o) {
  490. buf.WriteString(", ")
  491. }
  492. }
  493. buf.WriteByte(']')
  494. return buf.String()
  495. }
  496. // DHCPv6Option rerpresents a DHCP option.
  497. type DHCPv6Option struct {
  498. Code DHCPv6Opt
  499. Length uint16
  500. Data []byte
  501. }
  502. // String returns a string version of a DHCP Option.
  503. func (o DHCPv6Option) String() string {
  504. switch o.Code {
  505. case DHCPv6OptClientID, DHCPv6OptServerID:
  506. duid, err := decodeDHCPv6DUID(o.Data)
  507. if err != nil {
  508. return fmt.Sprintf("Option(%s:INVALID)", o.Code)
  509. }
  510. return fmt.Sprintf("Option(%s:[%s])", o.Code, duid.String())
  511. case DHCPv6OptOro:
  512. options := ""
  513. for i := 0; i < int(o.Length); i += 2 {
  514. if options != "" {
  515. options += ","
  516. }
  517. option := DHCPv6Opt(binary.BigEndian.Uint16(o.Data[i : i+2]))
  518. options += option.String()
  519. }
  520. return fmt.Sprintf("Option(%s:[%s])", o.Code, options)
  521. default:
  522. return fmt.Sprintf("Option(%s:%v)", o.Code, o.Data)
  523. }
  524. }
  525. // NewDHCPv6Option constructs a new DHCPv6Option with a given type and data.
  526. func NewDHCPv6Option(code DHCPv6Opt, data []byte) DHCPv6Option {
  527. o := DHCPv6Option{Code: code}
  528. if data != nil {
  529. o.Data = data
  530. o.Length = uint16(len(data))
  531. }
  532. return o
  533. }
  534. func (o *DHCPv6Option) encode(b []byte, opts gopacket.SerializeOptions) error {
  535. binary.BigEndian.PutUint16(b[0:2], uint16(o.Code))
  536. if opts.FixLengths {
  537. binary.BigEndian.PutUint16(b[2:4], uint16(len(o.Data)))
  538. } else {
  539. binary.BigEndian.PutUint16(b[2:4], o.Length)
  540. }
  541. copy(b[4:], o.Data)
  542. return nil
  543. }
  544. func (o *DHCPv6Option) decode(data []byte) error {
  545. if len(data) < 2 {
  546. return errors.New("not enough data to decode")
  547. }
  548. o.Code = DHCPv6Opt(binary.BigEndian.Uint16(data[0:2]))
  549. if len(data) < 3 {
  550. return errors.New("not enough data to decode")
  551. }
  552. o.Length = binary.BigEndian.Uint16(data[2:4])
  553. o.Data = data[4 : 4+o.Length]
  554. return nil
  555. }