netstack: fix test bug using wrong address family

TestPreflightBindsEndpoint was using an IPv6 destination address with an IPv4
endpoint. This starts causing a panic once we properly check the length of
addresses (see child CL).

PiperOrigin-RevId: 558267882
This commit is contained in:
Kevin Krakauer
2023-08-18 15:51:17 -07:00
committed by gVisor bot
parent eb6b3ac00b
commit a20ae31ca0
+20 -9
View File
@@ -725,20 +725,31 @@ func TestDualWriteConnectedToV4Mapped(t *testing.T) {
}
func TestPreflightBindsEndpoint(t *testing.T) {
protocols := map[string]tcpip.NetworkProtocolNumber{
"ipv4": ipv4.ProtocolNumber,
"ipv6": ipv6.ProtocolNumber,
tcs := []struct {
name string
proto tcpip.NetworkProtocolNumber
flow context.TestFlow
}{
{
name: "ipv4",
proto: ipv4.ProtocolNumber,
flow: context.UnicastV4,
},
{
name: "ipv6",
proto: ipv6.ProtocolNumber,
flow: context.UnicastV6,
},
}
for name, ipProtocolNumber := range protocols {
t.Run(name, func(t *testing.T) {
for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
c := context.New(t, []stack.TransportProtocolFactory{udp.NewProtocol})
defer c.Cleanup()
c.CreateEndpoint(ipProtocolNumber, udp.ProtocolNumber)
c.CreateEndpoint(tc.proto, udp.ProtocolNumber)
flow := context.UnicastV6
h := flow.MakeHeader4Tuple(context.Outgoing)
writeDstAddr := flow.MapAddrIfApplicable(h.Dst.Addr)
h := tc.flow.MakeHeader4Tuple(context.Outgoing)
writeDstAddr := tc.flow.MapAddrIfApplicable(h.Dst.Addr)
writeOpts := tcpip.WriteOptions{
To: &tcpip.FullAddress{Addr: writeDstAddr, Port: h.Dst.Port},
}