mirror of
https://github.com/tailscale/tailscale.git
synced 2025-11-13 00:41:28 +00:00
ip.WithPort
This commit is contained in:
@@ -237,10 +237,8 @@ func (n *SNAT44) allocateMappedPort() (net.PacketConn, netaddr.IPPort) {
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("ran out of NAT ports: %v", err))
|
||||
}
|
||||
addr := netaddr.IPPort{
|
||||
IP: ip,
|
||||
Port: uint16(pc.LocalAddr().(*net.UDPAddr).Port),
|
||||
}
|
||||
port := uint16(pc.LocalAddr().(*net.UDPAddr).Port)
|
||||
addr := ip.WithPort(port)
|
||||
return pc, addr
|
||||
}
|
||||
|
||||
|
||||
@@ -396,8 +396,8 @@ func (m *Machine) deliverLocalPacket(p *Packet, iface *Interface) {
|
||||
}
|
||||
possibleDsts := []netaddr.IPPort{
|
||||
p.Dst,
|
||||
netaddr.IPPort{IP: v6unspec, Port: p.Dst.Port},
|
||||
netaddr.IPPort{IP: v4unspec, Port: p.Dst.Port},
|
||||
v6unspec.WithPort(p.Dst.Port),
|
||||
v4unspec.WithPort(p.Dst.Port),
|
||||
}
|
||||
for _, dest := range possibleDsts {
|
||||
c, ok := conns[dest]
|
||||
@@ -707,7 +707,7 @@ func (m *Machine) ListenPacket(ctx context.Context, network, address string) (ne
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
ipp := netaddr.IPPort{IP: ip, Port: port}
|
||||
ipp := ip.WithPort(port)
|
||||
|
||||
c := &conn{
|
||||
m: m,
|
||||
|
||||
@@ -49,8 +49,8 @@ func TestSendPacket(t *testing.T) {
|
||||
ifFoo := foo.Attach("eth0", internet)
|
||||
ifBar := bar.Attach("enp0s1", internet)
|
||||
|
||||
fooAddr := netaddr.IPPort{IP: ifFoo.V4(), Port: 123}
|
||||
barAddr := netaddr.IPPort{IP: ifBar.V4(), Port: 456}
|
||||
fooAddr := ifFoo.V4().WithPort(123)
|
||||
barAddr := ifBar.V4().WithPort(456)
|
||||
|
||||
ctx := context.Background()
|
||||
fooPC, err := foo.ListenPacket(ctx, "udp4", fooAddr.String())
|
||||
@@ -111,10 +111,10 @@ func TestMultiNetwork(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
clientAddr := netaddr.IPPort{IP: ifClient.V4(), Port: 123}
|
||||
natLANAddr := netaddr.IPPort{IP: ifNATLAN.V4(), Port: 456}
|
||||
natWANAddr := netaddr.IPPort{IP: ifNATWAN.V4(), Port: 456}
|
||||
serverAddr := netaddr.IPPort{IP: ifServer.V4(), Port: 789}
|
||||
clientAddr := ifClient.V4().WithPort(123)
|
||||
natLANAddr := ifNATLAN.V4().WithPort(456)
|
||||
natWANAddr := ifNATWAN.V4().WithPort(456)
|
||||
serverAddr := ifServer.V4().WithPort(789)
|
||||
|
||||
const msg1, msg2 = "hello", "world"
|
||||
if _, err := natPC.WriteTo([]byte(msg1), clientAddr.UDPAddr()); err != nil {
|
||||
@@ -216,7 +216,7 @@ func TestPacketHandler(t *testing.T) {
|
||||
}
|
||||
|
||||
const msg = "some message"
|
||||
serverAddr := netaddr.IPPort{IP: ifServer.V4(), Port: 456}
|
||||
serverAddr := ifServer.V4().WithPort(456)
|
||||
if _, err := clientPC.WriteTo([]byte(msg), serverAddr.UDPAddr()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -230,7 +230,7 @@ func TestPacketHandler(t *testing.T) {
|
||||
if string(buf) != msg {
|
||||
t.Errorf("read %q; want %q", buf, msg)
|
||||
}
|
||||
mappedAddr := netaddr.IPPort{IP: ifNATWAN.V4(), Port: 123}
|
||||
mappedAddr := ifNATWAN.V4().WithPort(123)
|
||||
if addr.String() != mappedAddr.String() {
|
||||
t.Errorf("addr = %q; want %q", addr, mappedAddr)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user