mirror of
https://github.com/fumiama/WireGold.git
synced 2026-06-12 04:43:22 +08:00
fix of
This commit is contained in:
22
lower/nic.go
22
lower/nic.go
@@ -81,11 +81,12 @@ func (nc *NIC) Start(m *link.Me) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
packet = packet[:n]
|
packet = packet[:n]
|
||||||
n, rem := send(m, packet)
|
n, rem := nc.send(m, packet)
|
||||||
for len(rem) > 20 && n > 0 {
|
for len(rem) > 20 && n > 0 {
|
||||||
n, rem = send(m, rem)
|
n, rem = nc.send(m, rem)
|
||||||
}
|
}
|
||||||
if len(rem) > 0 {
|
if len(rem) > 0 {
|
||||||
|
logrus.Infoln("[lower] remain", len(rem), "bytes to send")
|
||||||
if off > 0 {
|
if off > 0 {
|
||||||
off = copy(buf, rem)
|
off = copy(buf, rem)
|
||||||
isrev = true
|
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.IsIPv4(packet) {
|
||||||
if waterutil.IsIPv6(packet) {
|
if waterutil.IsIPv6(packet) {
|
||||||
n = int(binary.BigEndian.Uint16(packet[4:6])) + 40
|
n = int(binary.BigEndian.Uint16(packet[4:6])) + 40
|
||||||
rem = packet[n:]
|
if n > len(packet) {
|
||||||
logrus.Warnln("[lower] skip to send", n, "bytes ipv6 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
|
return
|
||||||
}
|
}
|
||||||
logrus.Warnln("[lower] skip to send", len(packet), "bytes non-ipv4/v6 packet")
|
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)
|
totl := waterutil.IPv4TotalLength(packet)
|
||||||
if int(totl) > len(packet) {
|
if int(totl) > len(packet) {
|
||||||
rem = packet
|
buf := make([]byte, int(totl))
|
||||||
return
|
copy(buf, packet)
|
||||||
|
nc.ifce.Read(buf[len(packet):])
|
||||||
|
packet = buf
|
||||||
}
|
}
|
||||||
rem = packet[totl:]
|
rem = packet[totl:]
|
||||||
packet = packet[:totl]
|
packet = packet[:totl]
|
||||||
|
|||||||
Reference in New Issue
Block a user