-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option IPv6OnlyPreferred (RFC 8925)
Signed-off-by: Brian Candler <[email protected]>
- Loading branch information
Showing
6 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package dhcpv4 | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
// The IPv6-Only Preferred option is described by RFC 8925, Section 3.1 | ||
func OptIPv6OnlyPreferred(d time.Duration) Option { | ||
return Option{Code: OptionIPv6OnlyPreferred, Value: Duration(d)} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package dhcpv4 | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestOptIPv6OnlyPreferred(t *testing.T) { | ||
o := OptIPv6OnlyPreferred(43200 * time.Second) | ||
require.Equal(t, OptionIPv6OnlyPreferred, o.Code, "Code") | ||
require.Equal(t, []byte{0, 0, 168, 192}, o.Value.ToBytes(), "ToBytes") | ||
require.Equal(t, "IPv6-Only Preferred: 12h0m0s", o.String(), "String") | ||
} | ||
|
||
func TestOptIPv6OnlyPreferredZero(t *testing.T) { | ||
o := OptIPv6OnlyPreferred(0) | ||
require.Equal(t, OptionIPv6OnlyPreferred, o.Code, "Code") | ||
require.Equal(t, []byte{0, 0, 0, 0}, o.Value.ToBytes(), "ToBytes") | ||
require.Equal(t, "IPv6-Only Preferred: 0s", o.String(), "String") | ||
} | ||
|
||
func TestGetIPv6OnlyPreferred(t *testing.T) { | ||
m, _ := New(WithGeneric(OptionIPv6OnlyPreferred, []byte{0, 0, 168, 192})) | ||
found, v6onlyWait := m.IPv6OnlyPreferred() | ||
require.True(t, found) | ||
require.Equal(t, 43200*time.Second, v6onlyWait) | ||
|
||
// Too short. | ||
m, _ = New(WithGeneric(OptionIPv6OnlyPreferred, []byte{168, 192})) | ||
found, v6onlyWait = m.IPv6OnlyPreferred() | ||
require.False(t, found) | ||
|
||
// Too long. | ||
m, _ = New(WithGeneric(OptionIPv6OnlyPreferred, []byte{1, 1, 1, 1, 1})) | ||
found, v6onlyWait = m.IPv6OnlyPreferred() | ||
require.False(t, found) | ||
|
||
// Empty. | ||
m, _ = New() | ||
require.False(t, found) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters