summaryrefslogtreecommitdiffhomepage
path: root/pkg
diff options
context:
space:
mode:
authorMikael Magnusson <mikma@users.sourceforge.net>2020-03-17 20:03:03 +0100
committerMikael Magnusson <mikma@users.sourceforge.net>2020-03-17 20:06:04 +0100
commit7d8e321a65ee1dc2659b41ad13370f5a530c498e (patch)
tree869b1880fff7164f6fbb08304210657a181ff3e6 /pkg
parentf10dc5ab203ecf9e56f6e69be284855ef0793fad (diff)
WIP SendIcmp
Diffstat (limited to 'pkg')
-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)