Skip to content

Commit

Permalink
Merge pull request #544 from michaelharo/format
Browse files Browse the repository at this point in the history
Humanize some more options
  • Loading branch information
pmazzini authored Aug 12, 2024
2 parents ddd8a41 + 4322ec4 commit b105c29
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
8 changes: 8 additions & 0 deletions dhcpv4/option_relay_agent_information.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ type RelayOptions struct {

var relayHumanizer = OptionHumanizer{
ValueHumanizer: func(code OptionCode, data []byte) fmt.Stringer {
var d OptionDecoder
switch code {
case LinkSelectionSubOption, ServerIdentifierOverrideSubOption:
d = &IPs{}
}
if d != nil && d.FromBytes(data) == nil {
return d
}
return raiSubOptionValue{data}
},
CodeHumanizer: func(c uint8) OptionCode {
Expand Down
4 changes: 3 additions & 1 deletion dhcpv4/option_relay_agent_information_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ func TestOptRelayAgentInfo(t *testing.T) {
opt := OptRelayAgentInfo(
OptGeneric(GenericOptionCode(1), []byte("linux")),
OptGeneric(GenericOptionCode(2), []byte("boot")),
OptGeneric(GenericOptionCode(LinkSelectionSubOption), []byte{192, 0, 2, 1}),
)
wantBytes := []byte{
1, 5, 'l', 'i', 'n', 'u', 'x',
2, 4, 'b', 'o', 'o', 't',
5, 4, 192, 0, 2, 1,
}
wantString := "Relay Agent Information:\n\n Agent Circuit ID Sub-option: linux ([108 105 110 117 120])\n Agent Remote ID Sub-option: boot ([98 111 111 116])\n"
wantString := "Relay Agent Information:\n\n Agent Circuit ID Sub-option: linux ([108 105 110 117 120])\n Agent Remote ID Sub-option: boot ([98 111 111 116])\n Link Selection Sub-option: 192.0.2.1\n"
require.Equal(t, wantBytes, opt.Value.ToBytes())
require.Equal(t, OptionRelayAgentInformation, opt.Code)
require.Equal(t, wantString, opt.String())
Expand Down
7 changes: 5 additions & 2 deletions dhcpv4/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,8 @@ func getOption(code OptionCode, data []byte, vendorDecoder OptionDecoder) fmt.St
d = &OptionCodeList{}

case OptionHostName, OptionDomainName, OptionRootPath,
OptionClassIdentifier, OptionTFTPServerName, OptionBootfileName:
OptionClassIdentifier, OptionTFTPServerName, OptionBootfileName,
OptionMessage, OptionReferenceToTZDatabase:
var s String
d = &s

Expand All @@ -354,7 +355,9 @@ func getOption(code OptionCode, data []byte, vendorDecoder OptionDecoder) fmt.St
case OptionDNSDomainSearchList:
d = &rfc1035label.Labels{}

case OptionIPAddressLeaseTime, OptionRenewTimeValue, OptionRebindingTimeValue, OptionIPv6OnlyPreferred:
case OptionIPAddressLeaseTime, OptionRenewTimeValue,
OptionRebindingTimeValue, OptionIPv6OnlyPreferred, OptionArpCacheTimeout,
OptionTimeOffset:
var dur Duration
d = &dur

Expand Down

0 comments on commit b105c29

Please sign in to comment.