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