summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--pkg/tcpip/network/ipv4/ipv4.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/pkg/tcpip/network/ipv4/ipv4.go b/pkg/tcpip/network/ipv4/ipv4.go
index 9953f83cd..c0af9a2d8 100644
--- a/pkg/tcpip/network/ipv4/ipv4.go
+++ b/pkg/tcpip/network/ipv4/ipv4.go
@@ -408,6 +408,42 @@ func (e *endpoint) HandlePacket(r *stack.Route, pkt tcpip.PacketBuffer) {
e.dispatcher.DeliverTransportPacket(r, p, pkt)
}
+func (e *endpoint) SendIcmp(pkt tcpip.PacketBuffer, icmpv4type header.ICMPv4Type, icmpv4code byte, nextHopMtu uint16) *tcpip.Error {
+ headerView := pkt.Header.View()
+ h := header.IPv4(headerView)
+ vv := headerView.ToVectorisedView()
+ vv.Append(pkt.Data.Clone(nil))
+ fmt.Println("SendIcmp ", vv.Size())
+ hdr := buffer.NewPrependable(int(e.MaxHeaderLength()) + header.ICMPv4MinimumSize)
+ icmp := header.ICMPv4(hdr.Prepend(header.ICMPv4MinimumSize))
+ copy(icmp, h)
+ icmp.SetType(icmpv4type)
+ icmp.SetCode(icmpv4code)
+ if nextHopMtu != 0 {
+ icmp.SetMTU(nextHopMtu)
+ }
+ icmp.SetChecksum(0)
+ icmp.SetChecksum(^header.Checksum(icmp, header.ChecksumVV(vv, 0)))
+ //sent := stats.ICMP.V4PacketsSent
+ r, err := e.stack.FindRoute(0, "", h.SourceAddress(), ProtocolNumber, false /* multicastLoop */)
+ if err != nil {
+ fmt.Println("FindRoute error ", err)
+ return tcpip.ErrInvalidOptionValue
+ }
+ ttl := r.DefaultTTL()
+ if err := r.WritePacket(nil /* gso */, stack.NetworkHeaderParams{Protocol: header.ICMPv4ProtocolNumber, TTL: ttl, TOS: stack.DefaultTOS}, tcpip.PacketBuffer{
+ Header: hdr,
+ Data: vv,
+// TransportHeader: buffer.View(icmp),
+ }); err != nil {
+ //sent.Dropped.Increment()
+ fmt.Println("WritePacket error ", err)
+ return tcpip.ErrInvalidOptionValue
+ }
+
+ return nil
+}
+
func (*endpoint) UpdateTTL(pkt tcpip.PacketBuffer, n uint8) *tcpip.Error {
headerView := pkt.Header.View()
h := header.IPv4(headerView)