summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/transport/ping/protocol.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/tcpip/transport/ping/protocol.go')
-rw-r--r--pkg/tcpip/transport/ping/protocol.go16
1 files changed, 12 insertions, 4 deletions
diff --git a/pkg/tcpip/transport/ping/protocol.go b/pkg/tcpip/transport/ping/protocol.go
index 8a8192064..b885f3627 100644
--- a/pkg/tcpip/transport/ping/protocol.go
+++ b/pkg/tcpip/transport/ping/protocol.go
@@ -71,7 +71,7 @@ func (p *protocol) NewEndpoint(stack *stack.Stack, netProto tcpip.NetworkProtoco
if netProto != p.netProto() {
return nil, tcpip.ErrUnknownProtocol
}
- return newEndpoint(stack, netProto, waiterQueue), nil
+ return newEndpoint(stack, netProto, p.number, waiterQueue), nil
}
// MinimumPacketSize returns the minimum valid ping packet size.
@@ -87,8 +87,14 @@ func (p *protocol) MinimumPacketSize() int {
// ParsePorts returns the source and destination ports stored in the given ping
// packet.
-func (*protocol) ParsePorts(v buffer.View) (src, dst uint16, err *tcpip.Error) {
- return 0, binary.BigEndian.Uint16(v[header.ICMPv4MinimumSize:]), nil
+func (p *protocol) ParsePorts(v buffer.View) (src, dst uint16, err *tcpip.Error) {
+ switch p.number {
+ case ProtocolNumber4:
+ return 0, binary.BigEndian.Uint16(v[header.ICMPv4MinimumSize:]), nil
+ case ProtocolNumber6:
+ return 0, binary.BigEndian.Uint16(v[header.ICMPv6MinimumSize:]), nil
+ }
+ panic(fmt.Sprint("unknown protocol number: ", p.number))
}
// HandleUnknownDestinationPacket handles packets targeted at this protocol but
@@ -112,5 +118,7 @@ func init() {
return &protocol{ProtocolNumber4}
})
- // TODO: Support IPv6.
+ stack.RegisterTransportProtocolFactory(ProtocolName6, func() stack.TransportProtocol {
+ return &protocol{ProtocolNumber6}
+ })
}