From 2cff07381a911ad52cf9df70d702f39217e9539e Mon Sep 17 00:00:00 2001 From: Bhasker Hariharan Date: Tue, 4 Sep 2018 14:30:15 -0700 Subject: Automated rollback of changelist 211156845 PiperOrigin-RevId: 211525182 Change-Id: I462c20328955c77ecc7bfd8ee803ac91f15858e6 --- pkg/tcpip/transport/ping/protocol.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'pkg/tcpip/transport/ping/protocol.go') 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} + }) } -- cgit v1.2.3