mirror of
https://github.com/slackhq/nebula.git
synced 2026-05-16 04:47:38 +02:00
robot fixes
This commit is contained in:
@@ -6,14 +6,17 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// fakeTunWriter records plain Writes and WriteGSO calls without touching a
|
// fakeTunWriter records plain Writes and WriteGSO calls without touching a
|
||||||
// real TUN fd. WriteGSO preserves the split between hdr and borrowed pays
|
// real TUN fd. WriteGSO records the IP header, transport header, and
|
||||||
// so tests can inspect each independently.
|
// borrowed payload fragments separately so tests can inspect each.
|
||||||
type fakeTunWriter struct {
|
type fakeTunWriter struct {
|
||||||
gsoEnabled bool
|
gsoEnabled bool
|
||||||
writes [][]byte
|
writes [][]byte
|
||||||
gsoWrites []fakeGSOWrite
|
gsoWrites []fakeGSOWrite
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fakeGSOWrite captures one WriteGSO call. hdr is the concatenation of the
|
||||||
|
// IP and transport headers (in that order), gsoSize / isV6 / csumStart are
|
||||||
|
// derived from the call so existing assertions keep working unchanged.
|
||||||
type fakeGSOWrite struct {
|
type fakeGSOWrite struct {
|
||||||
hdr []byte
|
hdr []byte
|
||||||
pays [][]byte
|
pays [][]byte
|
||||||
@@ -47,21 +50,27 @@ func (w *fakeTunWriter) Write(p []byte) (int, error) {
|
|||||||
return len(p), nil
|
return len(p), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *fakeTunWriter) WriteGSO(hdr []byte, pays [][]byte, gsoSize uint16, isV6 bool, csumStart uint16) error {
|
func (w *fakeTunWriter) WriteGSO(hdr []byte, transportHdr []byte, pays [][]byte) error {
|
||||||
hcopy := make([]byte, len(hdr))
|
hcopy := make([]byte, len(hdr)+len(transportHdr))
|
||||||
copy(hcopy, hdr)
|
copy(hcopy, hdr)
|
||||||
|
copy(hcopy[len(hdr):], transportHdr)
|
||||||
paysCopy := make([][]byte, len(pays))
|
paysCopy := make([][]byte, len(pays))
|
||||||
for i, p := range pays {
|
for i, p := range pays {
|
||||||
pc := make([]byte, len(p))
|
pc := make([]byte, len(p))
|
||||||
copy(pc, p)
|
copy(pc, p)
|
||||||
paysCopy[i] = pc
|
paysCopy[i] = pc
|
||||||
}
|
}
|
||||||
|
var gsoSize uint16
|
||||||
|
if len(pays) > 1 {
|
||||||
|
gsoSize = uint16(len(pays[0]))
|
||||||
|
}
|
||||||
|
isV6 := len(hdr) > 0 && hdr[0]>>4 == 6
|
||||||
w.gsoWrites = append(w.gsoWrites, fakeGSOWrite{
|
w.gsoWrites = append(w.gsoWrites, fakeGSOWrite{
|
||||||
hdr: hcopy,
|
hdr: hcopy,
|
||||||
pays: paysCopy,
|
pays: paysCopy,
|
||||||
gsoSize: gsoSize,
|
gsoSize: gsoSize,
|
||||||
isV6: isV6,
|
isV6: isV6,
|
||||||
csumStart: csumStart,
|
csumStart: uint16(len(hdr)),
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -502,7 +511,7 @@ func (w *orderedFakeWriter) Write(p []byte) (int, error) {
|
|||||||
return len(p), nil
|
return len(p), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *orderedFakeWriter) WriteGSO(hdr []byte, pays [][]byte, gsoSize uint16, isV6 bool, csumStart uint16) error {
|
func (w *orderedFakeWriter) WriteGSO(hdr []byte, transportHdr []byte, pays [][]byte) error {
|
||||||
w.events = append(w.events, "gso")
|
w.events = append(w.events, "gso")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ const gsoInitialPayIovs = 66
|
|||||||
|
|
||||||
// validVnetHdr is the 10-byte virtio_net_hdr we prepend to every non-GSO TUN
|
// validVnetHdr is the 10-byte virtio_net_hdr we prepend to every non-GSO TUN
|
||||||
// write. Only flag set is VIRTIO_NET_HDR_F_DATA_VALID, which marks the skb
|
// write. Only flag set is VIRTIO_NET_HDR_F_DATA_VALID, which marks the skb
|
||||||
// CHECKSUM_UNNECESSARY so the receiving network stack skips L4 checksum
|
// CHECKSUM_UNNECESSARY so the receiving network stack skips L4 checks
|
||||||
// verification. All packets that reach the plain Write / WriteFromSelf paths
|
// verification. All packets that reach the plain Write / WriteFromSelf paths
|
||||||
// already carry a valid L4 checksum (either supplied by a remote peer whose
|
// already carry a valid L4 checksum (either supplied by a remote peer whose
|
||||||
// ciphertext we AEAD-authenticated, or produced by finishChecksum during TSO
|
// ciphertext we AEAD-authenticated, or produced by finishChecksum during TSO
|
||||||
|
|||||||
@@ -310,8 +310,6 @@ func TestTunFileWriteVnetHdrNoAlloc(t *testing.T) {
|
|||||||
t.Cleanup(func() { _ = unix.Close(fd) })
|
t.Cleanup(func() { _ = unix.Close(fd) })
|
||||||
|
|
||||||
tf := &Offload{fd: fd}
|
tf := &Offload{fd: fd}
|
||||||
tf.writeIovs[0].Base = &validVnetHdr[0]
|
|
||||||
tf.writeIovs[0].SetLen(virtioNetHdrLen)
|
|
||||||
|
|
||||||
payload := make([]byte, 1400)
|
payload := make([]byte, 1400)
|
||||||
// Warm up (first call may trigger one-time internal allocations elsewhere).
|
// Warm up (first call may trigger one-time internal allocations elsewhere).
|
||||||
|
|||||||
Reference in New Issue
Block a user