Skip to content

Commit b105c29

Browse files
authored
Merge pull request #544 from michaelharo/format
Humanize some more options
2 parents ddd8a41 + 4322ec4 commit b105c29

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

dhcpv4/option_relay_agent_information.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ type RelayOptions struct {
1212

1313
var relayHumanizer = OptionHumanizer{
1414
ValueHumanizer: func(code OptionCode, data []byte) fmt.Stringer {
15+
var d OptionDecoder
16+
switch code {
17+
case LinkSelectionSubOption, ServerIdentifierOverrideSubOption:
18+
d = &IPs{}
19+
}
20+
if d != nil && d.FromBytes(data) == nil {
21+
return d
22+
}
1523
return raiSubOptionValue{data}
1624
},
1725
CodeHumanizer: func(c uint8) OptionCode {

dhcpv4/option_relay_agent_information_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ func TestOptRelayAgentInfo(t *testing.T) {
3636
opt := OptRelayAgentInfo(
3737
OptGeneric(GenericOptionCode(1), []byte("linux")),
3838
OptGeneric(GenericOptionCode(2), []byte("boot")),
39+
OptGeneric(GenericOptionCode(LinkSelectionSubOption), []byte{192, 0, 2, 1}),
3940
)
4041
wantBytes := []byte{
4142
1, 5, 'l', 'i', 'n', 'u', 'x',
4243
2, 4, 'b', 'o', 'o', 't',
44+
5, 4, 192, 0, 2, 1,
4345
}
44-
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"
46+
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"
4547
require.Equal(t, wantBytes, opt.Value.ToBytes())
4648
require.Equal(t, OptionRelayAgentInformation, opt.Code)
4749
require.Equal(t, wantString, opt.String())

dhcpv4/options.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@ func getOption(code OptionCode, data []byte, vendorDecoder OptionDecoder) fmt.St
344344
d = &OptionCodeList{}
345345

346346
case OptionHostName, OptionDomainName, OptionRootPath,
347-
OptionClassIdentifier, OptionTFTPServerName, OptionBootfileName:
347+
OptionClassIdentifier, OptionTFTPServerName, OptionBootfileName,
348+
OptionMessage, OptionReferenceToTZDatabase:
348349
var s String
349350
d = &s
350351

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

357-
case OptionIPAddressLeaseTime, OptionRenewTimeValue, OptionRebindingTimeValue, OptionIPv6OnlyPreferred:
358+
case OptionIPAddressLeaseTime, OptionRenewTimeValue,
359+
OptionRebindingTimeValue, OptionIPv6OnlyPreferred, OptionArpCacheTimeout,
360+
OptionTimeOffset:
358361
var dur Duration
359362
d = &dur
360363

0 commit comments

Comments
 (0)