summaryrefslogtreecommitdiffhomepage
path: root/test/packetimpact/testbench/layers.go
diff options
context:
space:
mode:
authorJulian Elischer <jrelis@google.com>2020-08-14 02:05:23 -0700
committergVisor bot <gvisor-bot@google.com>2020-08-14 02:07:36 -0700
commit190634e0fcf4cf25a449e1bd39533ca2ddad66e6 (patch)
tree9fcd438bcdf162d3e3c1bf7954b8a50baf1e7b2c /test/packetimpact/testbench/layers.go
parentd6520e1d0592f99161faedef3eba49439b140917 (diff)
Give the ICMP Code its own type
This is a preparatory commit for a larger commit working on ICMP generation in error cases. This is removal of technical debt and cleanup in the gvisor code as part of gvisor issue 2211. Updates #2211. PiperOrigin-RevId: 326615389
Diffstat (limited to 'test/packetimpact/testbench/layers.go')
-rw-r--r--test/packetimpact/testbench/layers.go22
1 files changed, 17 insertions, 5 deletions
diff --git a/test/packetimpact/testbench/layers.go b/test/packetimpact/testbench/layers.go
index 24aa46cce..a35562ca8 100644
--- a/test/packetimpact/testbench/layers.go
+++ b/test/packetimpact/testbench/layers.go
@@ -775,7 +775,7 @@ func (l *IPv6FragmentExtHdr) String() string {
type ICMPv6 struct {
LayerBase
Type *header.ICMPv6Type
- Code *byte
+ Code *header.ICMPv6Code
Checksum *uint16
Payload []byte
}
@@ -823,6 +823,12 @@ func ICMPv6Type(v header.ICMPv6Type) *header.ICMPv6Type {
return &v
}
+// ICMPv6Code is a helper routine that allocates a new ICMPv6Type value to store
+// v and returns a pointer to it.
+func ICMPv6Code(v header.ICMPv6Code) *header.ICMPv6Code {
+ return &v
+}
+
// Byte is a helper routine that allocates a new byte value to store
// v and returns a pointer to it.
func Byte(v byte) *byte {
@@ -834,7 +840,7 @@ func parseICMPv6(b []byte) (Layer, layerParser) {
h := header.ICMPv6(b)
icmpv6 := ICMPv6{
Type: ICMPv6Type(h.Type()),
- Code: Byte(h.Code()),
+ Code: ICMPv6Code(h.Code()),
Checksum: Uint16(h.Checksum()),
Payload: h.NDPPayload(),
}
@@ -861,11 +867,17 @@ func ICMPv4Type(t header.ICMPv4Type) *header.ICMPv4Type {
return &t
}
+// ICMPv4Code is a helper routine that allocates a new header.ICMPv4Code value
+// to store t and returns a pointer to it.
+func ICMPv4Code(t header.ICMPv4Code) *header.ICMPv4Code {
+ return &t
+}
+
// ICMPv4 can construct and match an ICMPv4 encapsulation.
type ICMPv4 struct {
LayerBase
Type *header.ICMPv4Type
- Code *uint8
+ Code *header.ICMPv4Code
Checksum *uint16
}
@@ -881,7 +893,7 @@ func (l *ICMPv4) ToBytes() ([]byte, error) {
h.SetType(*l.Type)
}
if l.Code != nil {
- h.SetCode(byte(*l.Code))
+ h.SetCode(*l.Code)
}
if l.Checksum != nil {
h.SetChecksum(*l.Checksum)
@@ -901,7 +913,7 @@ func parseICMPv4(b []byte) (Layer, layerParser) {
h := header.ICMPv4(b)
icmpv4 := ICMPv4{
Type: ICMPv4Type(h.Type()),
- Code: Uint8(h.Code()),
+ Code: ICMPv4Code(h.Code()),
Checksum: Uint16(h.Checksum()),
}
return &icmpv4, parsePayload