From a5e6135dd93b79c5ceb0df15469d2455d761cbb2 Mon Sep 17 00:00:00 2001 From: fumiama Date: Fri, 31 Dec 2021 13:16:06 +0800 Subject: [PATCH] fix of --- lower/nic.go | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/lower/nic.go b/lower/nic.go index fd6fd76..15a9b9a 100644 --- a/lower/nic.go +++ b/lower/nic.go @@ -81,11 +81,12 @@ func (nc *NIC) Start(m *link.Me) { continue } packet = packet[:n] - n, rem := send(m, packet) + n, rem := nc.send(m, packet) for len(rem) > 20 && n > 0 { - n, rem = send(m, rem) + n, rem = nc.send(m, rem) } if len(rem) > 0 { + logrus.Infoln("[lower] remain", len(rem), "bytes to send") if off > 0 { off = copy(buf, rem) isrev = true @@ -120,12 +121,17 @@ func execute(c string, args ...string) { } } -func send(m *link.Me, packet []byte) (n int, rem []byte) { +func (nc *NIC) send(m *link.Me, packet []byte) (n int, rem []byte) { if !waterutil.IsIPv4(packet) { if waterutil.IsIPv6(packet) { n = int(binary.BigEndian.Uint16(packet[4:6])) + 40 - rem = packet[n:] - logrus.Warnln("[lower] skip to send", n, "bytes ipv6 packet") + if n > len(packet) { + rem = packet + logrus.Warnln("[lower] skip to send", len(packet), "bytes ipv6 packet head") + } else { + rem = packet[n:] + logrus.Warnln("[lower] skip to send", n, "bytes ipv6 packet") + } return } logrus.Warnln("[lower] skip to send", len(packet), "bytes non-ipv4/v6 packet") @@ -133,8 +139,10 @@ func send(m *link.Me, packet []byte) (n int, rem []byte) { } totl := waterutil.IPv4TotalLength(packet) if int(totl) > len(packet) { - rem = packet - return + buf := make([]byte, int(totl)) + copy(buf, packet) + nc.ifce.Read(buf[len(packet):]) + packet = buf } rem = packet[totl:] packet = packet[:totl]