diff options
author | Pablo Mazzini <pmazzini@gmail.com> | 2020-09-22 22:00:17 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-22 22:00:17 +0100 |
commit | 67c425063dcad32c5d14ce9a520c8865240dc945 (patch) | |
tree | e07ea9d127393d14d78b3842560903ac127e3818 | |
parent | 1a1c38473709f69a75e1d90fb3b4ff63f7b8c2cd (diff) | |
parent | 293d999bca6dd08bc2b7f1830625d22c7ea19695 (diff) |
Merge pull request #393 from hujun-open/master
fix some debug output issues
-rw-r--r-- | dhcpv4/option_relay_agent_information.go | 14 | ||||
-rw-r--r-- | dhcpv4/option_relay_agent_information_test.go | 2 | ||||
-rw-r--r-- | dhcpv4/options_test.go | 4 |
3 files changed, 14 insertions, 6 deletions
diff --git a/dhcpv4/option_relay_agent_information.go b/dhcpv4/option_relay_agent_information.go index 63162a4..a338902 100644 --- a/dhcpv4/option_relay_agent_information.go +++ b/dhcpv4/option_relay_agent_information.go @@ -12,16 +12,16 @@ type RelayOptions struct { var relayHumanizer = OptionHumanizer{ ValueHumanizer: func(code OptionCode, data []byte) fmt.Stringer { - return OptionGeneric{data} + return raiSubOptionValue{data} }, CodeHumanizer: func(c uint8) OptionCode { - return GenericOptionCode(c) + return raiSubOptionCode(c) }, } // String prints the contained options using Relay Agent-specific option code parsing. func (r RelayOptions) String() string { - return r.Options.ToString(relayHumanizer) + return "\n" + r.Options.ToString(relayHumanizer) } // FromBytes parses relay agent options from data. @@ -37,6 +37,14 @@ func OptRelayAgentInfo(o ...Option) Option { return Option{Code: OptionRelayAgentInformation, Value: RelayOptions{OptionsFromList(o...)}} } +type raiSubOptionValue struct { + val []byte +} + +func (rv raiSubOptionValue) String() string { + return fmt.Sprintf("%s (%v)", string(rv.val), rv.val) +} + type raiSubOptionCode uint8 func (o raiSubOptionCode) Code() uint8 { diff --git a/dhcpv4/option_relay_agent_information_test.go b/dhcpv4/option_relay_agent_information_test.go index d16aedd..a875d14 100644 --- a/dhcpv4/option_relay_agent_information_test.go +++ b/dhcpv4/option_relay_agent_information_test.go @@ -41,7 +41,7 @@ func TestOptRelayAgentInfo(t *testing.T) { 1, 5, 'l', 'i', 'n', 'u', 'x', 2, 4, 'b', 'o', 'o', 't', } - wantString := "Relay Agent Information:\n unknown (1): [108 105 110 117 120]\n unknown (2): [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" require.Equal(t, wantBytes, opt.Value.ToBytes()) require.Equal(t, OptionRelayAgentInformation, opt.Code) require.Equal(t, wantString, opt.String()) diff --git a/dhcpv4/options_test.go b/dhcpv4/options_test.go index 3850d2d..fed2312 100644 --- a/dhcpv4/options_test.go +++ b/dhcpv4/options_test.go @@ -113,8 +113,8 @@ func TestParseOption(t *testing.T) { }, { code: OptionRelayAgentInformation, - value: []byte{1, 4, 129, 168, 0, 1}, - want: " unknown (1): [129 168 0 1]\n", + value: []byte{1, 12, 99, 105, 114, 99, 117, 105, 116, 45, 105, 100, 45, 49}, + want: "\n Agent Circuit ID Sub-option: circuit-id-1 ([99 105 114 99 117 105 116 45 105 100 45 49])\n", }, { code: OptionClientSystemArchitectureType, |