insomniacslk / dhcp

DHCPv6 and DHCPv4 packet library, client and server written in Go
BSD 3-Clause "New" or "Revised" License
710 stars 169 forks source link

dhcpv6: proper DUID types #488

Closed hugelgupf closed 1 year ago

hugelgupf commented 1 year ago

Types now only allow valid combination of DUID data.

Before:

// Duid is a DHCP Unique Identifier.
type Duid struct {
    Type                 DuidType
    HwType               iana.HWType // for DUID-LLT and DUID-LL. Ignored otherwise. RFC 826
    Time                 uint32      // for DUID-LLT. Ignored otherwise
    LinkLayerAddr        net.HardwareAddr
    EnterpriseNumber     uint32 // for DUID-EN. Ignored otherwise
    EnterpriseIdentifier []byte // for DUID-EN. Ignored otherwise
    Uuid                 []byte // for DUID-UUID. Ignored otherwise
    Opaque               []byte // for unknown DUIDs
}

After:

// DUID is the interface that all DUIDs adhere to.
type DUID interface {
    fmt.Stringer

    ToBytes() []byte
    FromBytes(p []byte) error
    DUIDType() DUIDType
    Equal(d DUID) bool
}

// DUIDLLT is a DUID based on link-layer address plus time (RFC 8415 Section 11.2).
type DUIDLLT struct {
    HWType        iana.HWType
    Time          uint32
    LinkLayerAddr net.HardwareAddr
}

// DUIDLL is a DUID based on link-layer (RFC 8415 Section 11.4).
type DUIDLL struct {
    HWType        iana.HWType
    LinkLayerAddr net.HardwareAddr
}

// DUIDEN is a DUID based on enterprise number (RFC 8415 Section 11.3).
type DUIDEN struct {
    EnterpriseNumber     uint32
    EnterpriseIdentifier []byte
}

// DUIDUUID is a DUID based on UUID (RFC 8415 Section 11.5).
type DUIDUUID struct {
    // Defined by RFC 6355.
    UUID [16]byte
}

// DUIDOpaque is a DUID of unknown type.
type DUIDOpaque struct {
    Type DUIDType
    Data []byte
}
codecov[bot] commented 1 year ago

Codecov Report

Base: 69.18% // Head: 69.46% // Increases project coverage by +0.28% :tada:

Coverage data is based on head (60548e9) compared to base (f51b4d4). Patch coverage: 96.02% of modified lines in pull request are covered.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #488 +/- ## ========================================== + Coverage 69.18% 69.46% +0.28% ========================================== Files 90 90 Lines 5701 5737 +36 ========================================== + Hits 3944 3985 +41 + Misses 1572 1571 -1 + Partials 185 181 -4 ``` | [Impacted Files](https://codecov.io/gh/insomniacslk/dhcp/pull/488?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=insomniac) | Coverage Δ | | |---|---|---| | [dhcpv6/duid.go](https://codecov.io/gh/insomniacslk/dhcp/pull/488?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=insomniac#diff-ZGhjcHY2L2R1aWQuZ28=) | `94.53% <95.04%> (+6.65%)` | :arrow_up: | | [dhcpv6/dhcpv6message.go](https://codecov.io/gh/insomniacslk/dhcp/pull/488?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=insomniac#diff-ZGhjcHY2L2RoY3B2Nm1lc3NhZ2UuZ28=) | `56.59% <100.00%> (-0.11%)` | :arrow_down: | | [dhcpv6/iputils.go](https://codecov.io/gh/insomniacslk/dhcp/pull/488?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=insomniac#diff-ZGhjcHY2L2lwdXRpbHMuZ28=) | `73.91% <100.00%> (+2.48%)` | :arrow_up: | | [dhcpv6/modifiers.go](https://codecov.io/gh/insomniacslk/dhcp/pull/488?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=insomniac#diff-ZGhjcHY2L21vZGlmaWVycy5nbw==) | `87.03% <100.00%> (ø)` | | | [dhcpv6/option\_clientid.go](https://codecov.io/gh/insomniacslk/dhcp/pull/488?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=insomniac#diff-ZGhjcHY2L29wdGlvbl9jbGllbnRpZC5nbw==) | `100.00% <100.00%> (ø)` | | | [dhcpv6/option\_serverid.go](https://codecov.io/gh/insomniacslk/dhcp/pull/488?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=insomniac#diff-ZGhjcHY2L29wdGlvbl9zZXJ2ZXJpZC5nbw==) | `100.00% <100.00%> (ø)` | | | [dhcpv6/ztpv6/parse\_vendor\_options.go](https://codecov.io/gh/insomniacslk/dhcp/pull/488?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=insomniac#diff-ZGhjcHY2L3p0cHY2L3BhcnNlX3ZlbmRvcl9vcHRpb25zLmdv) | `88.67% <100.00%> (+0.44%)` | :arrow_up: | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=insomniac). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=insomniac)

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.