diff --git a/pkg/tcpip/link/channel/BUILD b/pkg/tcpip/link/channel/BUILD index 63e30e0ef3..f7746092f6 100644 --- a/pkg/tcpip/link/channel/BUILD +++ b/pkg/tcpip/link/channel/BUILD @@ -1,4 +1,4 @@ -load("//tools:defs.bzl", "go_library") +load("//tools:defs.bzl", "go_library", "go_test") package( default_applicable_licenses = ["//:license"], @@ -16,3 +16,10 @@ go_library( "//pkg/tcpip/stack", ], ) + +go_test( + name = "channel_test", + srcs = ["channel_test.go"], + library = ":channel", + deps = ["//pkg/tcpip"], +) diff --git a/pkg/tcpip/link/channel/channel.go b/pkg/tcpip/link/channel/channel.go index d1d87b6df1..1bfb8537da 100644 --- a/pkg/tcpip/link/channel/channel.go +++ b/pkg/tcpip/link/channel/channel.go @@ -252,6 +252,13 @@ func (e *Endpoint) LinkAddress() tcpip.LinkAddress { return e.linkAddr } +// SetLinkAddress implements stack.LinkEndpoint.SetLinkAddress. +func (e *Endpoint) SetLinkAddress(addr tcpip.LinkAddress) { + e.mu.Lock() + defer e.mu.Unlock() + e.linkAddr = addr +} + // WritePackets stores outbound packets into the channel. // Multiple concurrent calls are permitted. func (e *Endpoint) WritePackets(pkts stack.PacketBufferList) (int, tcpip.Error) { diff --git a/pkg/tcpip/link/channel/channel_test.go b/pkg/tcpip/link/channel/channel_test.go new file mode 100644 index 0000000000..5d5139157b --- /dev/null +++ b/pkg/tcpip/link/channel/channel_test.go @@ -0,0 +1,34 @@ +// Copyright 2024 The gVisor Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package channel + +import ( + "testing" + + "gvisor.dev/gvisor/pkg/tcpip" +) + +func TestSetLinkAddress(t *testing.T) { + addrs := []tcpip.LinkAddress{"abc", "def"} + size, mtu, linkAddr := 10, uint32(2000), tcpip.LinkAddress("xyz") + e := New(size, mtu, linkAddr) + defer e.Close() + for _, addr := range addrs { + e.SetLinkAddress(addr) + + if want, v := addr, e.LinkAddress(); want != v { + t.Errorf("LinkAddress() = %v, want %v", v, want) + } + } +} diff --git a/pkg/tcpip/link/fdbased/endpoint.go b/pkg/tcpip/link/fdbased/endpoint.go index 91ac25d526..e284a931f1 100644 --- a/pkg/tcpip/link/fdbased/endpoint.go +++ b/pkg/tcpip/link/fdbased/endpoint.go @@ -473,6 +473,13 @@ func (e *endpoint) LinkAddress() tcpip.LinkAddress { return e.addr } +// SetLinkAddress implements stack.LinkEndpoint.SetLinkAddress. +func (e *endpoint) SetLinkAddress(addr tcpip.LinkAddress) { + e.mu.Lock() + defer e.mu.Unlock() + e.addr = addr +} + // Wait implements stack.LinkEndpoint.Wait. It waits for the endpoint to stop // reading from its FD. func (e *endpoint) Wait() { diff --git a/pkg/tcpip/link/fdbased/endpoint_test.go b/pkg/tcpip/link/fdbased/endpoint_test.go index c9474eec47..975b5571e0 100644 --- a/pkg/tcpip/link/fdbased/endpoint_test.go +++ b/pkg/tcpip/link/fdbased/endpoint_test.go @@ -181,6 +181,19 @@ func TestAddress(t *testing.T) { } } +func TestSetAddress(t *testing.T) { + addrs := []tcpip.LinkAddress{"abc", "def"} + c := newContext(t, &Options{Address: laddr, MTU: mtu}) + defer c.cleanup() + for _, addr := range addrs { + c.ep.SetLinkAddress(addr) + + if want, v := addr, c.ep.LinkAddress(); want != v { + t.Errorf("LinkAddress() = %v, want %v", v, want) + } + } +} + func testWritePacket(t *testing.T, plen int, eth bool, gsoMaxSize uint32, hash uint32) { c := newContext(t, &Options{Address: laddr, MTU: mtu, EthernetHeader: eth, GSOMaxSize: gsoMaxSize}) defer c.cleanup() diff --git a/pkg/tcpip/link/loopback/loopback.go b/pkg/tcpip/link/loopback/loopback.go index 8a263067a4..de4a29799c 100644 --- a/pkg/tcpip/link/loopback/loopback.go +++ b/pkg/tcpip/link/loopback/loopback.go @@ -79,6 +79,9 @@ func (*endpoint) LinkAddress() tcpip.LinkAddress { return "" } +// SetLinkAddress implements stack.LinkEndpoint.SetLinkAddress. +func (*endpoint) SetLinkAddress(tcpip.LinkAddress) {} + // Wait implements stack.LinkEndpoint.Wait. func (*endpoint) Wait() {} diff --git a/pkg/tcpip/link/muxed/injectable.go b/pkg/tcpip/link/muxed/injectable.go index 9055e85da1..b297c0fcb8 100644 --- a/pkg/tcpip/link/muxed/injectable.go +++ b/pkg/tcpip/link/muxed/injectable.go @@ -74,6 +74,9 @@ func (m *InjectableEndpoint) LinkAddress() tcpip.LinkAddress { return "" } +// SetLinkAddress implements stack.LinkEndpoint.SetLinkAddress. +func (m *InjectableEndpoint) SetLinkAddress(tcpip.LinkAddress) {} + // Attach implements stack.LinkEndpoint. func (m *InjectableEndpoint) Attach(dispatcher stack.NetworkDispatcher) { for _, endpoint := range m.routes { diff --git a/pkg/tcpip/link/nested/nested.go b/pkg/tcpip/link/nested/nested.go index 22c3fa8f9e..72af021803 100644 --- a/pkg/tcpip/link/nested/nested.go +++ b/pkg/tcpip/link/nested/nested.go @@ -114,6 +114,13 @@ func (e *Endpoint) LinkAddress() tcpip.LinkAddress { return e.child.LinkAddress() } +// SetLinkAddress implements stack.LinkEndpoint.SetLinkAddress. +func (e *Endpoint) SetLinkAddress(addr tcpip.LinkAddress) { + e.mu.Lock() + defer e.mu.Unlock() + e.child.SetLinkAddress(addr) +} + // WritePackets implements stack.LinkEndpoint. func (e *Endpoint) WritePackets(pkts stack.PacketBufferList) (int, tcpip.Error) { return e.child.WritePackets(pkts) diff --git a/pkg/tcpip/link/nested/nested_test.go b/pkg/tcpip/link/nested/nested_test.go index f4b80da32a..77e1bb74b3 100644 --- a/pkg/tcpip/link/nested/nested_test.go +++ b/pkg/tcpip/link/nested/nested_test.go @@ -33,6 +33,7 @@ var _ stack.LinkEndpoint = (*parentEndpoint)(nil) var _ stack.NetworkDispatcher = (*parentEndpoint)(nil) type childEndpoint struct { + addr tcpip.LinkAddress stack.LinkEndpoint dispatcher stack.NetworkDispatcher } @@ -47,6 +48,14 @@ func (c *childEndpoint) IsAttached() bool { return c.dispatcher != nil } +func (c *childEndpoint) LinkAddress() tcpip.LinkAddress { + return c.addr +} + +func (c *childEndpoint) SetLinkAddress(addr tcpip.LinkAddress) { + c.addr = addr +} + type counterDispatcher struct { count int } @@ -115,6 +124,23 @@ func TestNestedLinkEndpoint(t *testing.T) { } } +func TestSetLinkAddress(t *testing.T) { + var ( + childEP childEndpoint + ep parentEndpoint + disp counterDispatcher + ) + addrs := []tcpip.LinkAddress{"abc", "def"} + ep.Endpoint.Init(&childEP, &disp) + for _, addr := range addrs { + ep.SetLinkAddress(addr) + + if want, v := addr, ep.LinkAddress(); want != v { + t.Errorf("LinkAddress() = %v, want %v", v, want) + } + } +} + func TestMain(m *testing.M) { refs.SetLeakMode(refs.LeaksPanic) code := m.Run() diff --git a/pkg/tcpip/link/packetsocket/packetsocket_test.go b/pkg/tcpip/link/packetsocket/packetsocket_test.go index b715c19f54..64c2a3bf5d 100644 --- a/pkg/tcpip/link/packetsocket/packetsocket_test.go +++ b/pkg/tcpip/link/packetsocket/packetsocket_test.go @@ -42,8 +42,9 @@ func (*nullEndpoint) MaxHeaderLength() uint16 { return 0 } func (*nullEndpoint) LinkAddress() tcpip.LinkAddress { - var l tcpip.LinkAddress - return l + return "" +} +func (*nullEndpoint) SetLinkAddress(tcpip.LinkAddress) { } func (*nullEndpoint) WritePackets(pkts stack.PacketBufferList) (int, tcpip.Error) { return pkts.Len(), nil diff --git a/pkg/tcpip/link/pipe/BUILD b/pkg/tcpip/link/pipe/BUILD index ce1de68ada..4bfa14795d 100644 --- a/pkg/tcpip/link/pipe/BUILD +++ b/pkg/tcpip/link/pipe/BUILD @@ -1,4 +1,4 @@ -load("//tools:defs.bzl", "go_library") +load("//tools:defs.bzl", "go_library", "go_test") package( default_applicable_licenses = ["//:license"], @@ -15,3 +15,10 @@ go_library( "//pkg/tcpip/stack", ], ) + +go_test( + name = "pipe_test", + srcs = ["pipe_test.go"], + library = ":pipe", + deps = ["//pkg/tcpip"], +) diff --git a/pkg/tcpip/link/pipe/pipe.go b/pkg/tcpip/link/pipe/pipe.go index dddbd3eabb..3e4522077d 100644 --- a/pkg/tcpip/link/pipe/pipe.go +++ b/pkg/tcpip/link/pipe/pipe.go @@ -118,6 +118,13 @@ func (e *Endpoint) LinkAddress() tcpip.LinkAddress { return e.linkAddr } +// SetLinkAddress implements stack.LinkEndpoint. +func (e *Endpoint) SetLinkAddress(addr tcpip.LinkAddress) { + e.mu.Lock() + defer e.mu.Unlock() + e.linkAddr = addr +} + // ARPHardwareType implements stack.LinkEndpoint. func (*Endpoint) ARPHardwareType() header.ARPHardwareType { return header.ARPHardwareNone diff --git a/pkg/tcpip/link/pipe/pipe_test.go b/pkg/tcpip/link/pipe/pipe_test.go new file mode 100644 index 0000000000..cd19d1c897 --- /dev/null +++ b/pkg/tcpip/link/pipe/pipe_test.go @@ -0,0 +1,35 @@ +// Copyright 2024 The gVisor Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package pipe + +import ( + "testing" + + "gvisor.dev/gvisor/pkg/tcpip" +) + +func TestSetAddress(t *testing.T) { + addrs := []tcpip.LinkAddress{"abc", "def"} + e := &Endpoint{ + linkAddr: "xyz", + mtu: 1234, + } + for _, addr := range addrs { + e.SetLinkAddress(addr) + + if want, v := addr, e.LinkAddress(); want != v { + t.Errorf("LinkAddress() = %v, want %v", v, want) + } + } +} diff --git a/pkg/tcpip/link/sharedmem/sharedmem.go b/pkg/tcpip/link/sharedmem/sharedmem.go index 6f5c44b079..9e8a8552ac 100644 --- a/pkg/tcpip/link/sharedmem/sharedmem.go +++ b/pkg/tcpip/link/sharedmem/sharedmem.go @@ -345,6 +345,13 @@ func (e *endpoint) LinkAddress() tcpip.LinkAddress { return e.addr } +// SetLinkAddress implements stack.LinkEndpoint.SetLinkAddress. +func (e *endpoint) SetLinkAddress(addr tcpip.LinkAddress) { + e.mu.Lock() + defer e.mu.Unlock() + e.addr = addr +} + // AddHeader implements stack.LinkEndpoint.AddHeader. func (e *endpoint) AddHeader(pkt *stack.PacketBuffer) { // Add ethernet header if needed. diff --git a/pkg/tcpip/link/sharedmem/sharedmem_server.go b/pkg/tcpip/link/sharedmem/sharedmem_server.go index 36b2b9710c..08900cfb6e 100644 --- a/pkg/tcpip/link/sharedmem/sharedmem_server.go +++ b/pkg/tcpip/link/sharedmem/sharedmem_server.go @@ -202,6 +202,13 @@ func (e *serverEndpoint) LinkAddress() tcpip.LinkAddress { return e.addr } +// SetLinkAddress implements stack.LinkEndpoint.SetLinkAddress. +func (e *serverEndpoint) SetLinkAddress(addr tcpip.LinkAddress) { + e.mu.Lock() + defer e.mu.Unlock() + e.addr = addr +} + // AddHeader implements stack.LinkEndpoint.AddHeader. func (e *serverEndpoint) AddHeader(pkt *stack.PacketBuffer) { // Add ethernet header if needed. diff --git a/pkg/tcpip/link/sharedmem/sharedmem_server_test.go b/pkg/tcpip/link/sharedmem/sharedmem_server_test.go index 7deeaee03d..29e623bb43 100644 --- a/pkg/tcpip/link/sharedmem/sharedmem_server_test.go +++ b/pkg/tcpip/link/sharedmem/sharedmem_server_test.go @@ -403,6 +403,34 @@ func TestClientBulkTransfer(t *testing.T) { } } +func TestSetLinkAddress(t *testing.T) { + q, err := sharedmem.NewQueuePair(sharedmem.QueueOptions{}) + if err != nil { + q.Close() + t.Fatalf("failed to create sharedmem queue: %s", err) + } + defer q.Close() + ep, err := sharedmem.NewServerEndpoint(sharedmem.Options{ + MTU: defaultMTU, + BufferSize: defaultBufferSize, + LinkAddress: remoteLinkAddr, + TX: q.TXQueueConfig(), + RX: q.RXQueueConfig(), + PeerFD: 123, + }) + if err != nil { + t.Fatalf("failed to create sharedmem endpoint: %s", err) + } + addrs := []tcpip.LinkAddress{"abc", "def"} + for _, addr := range addrs { + ep.SetLinkAddress(addr) + + if want, v := addr, ep.LinkAddress(); want != v { + t.Errorf("LinkAddress() = %v, want %v", v, want) + } + } +} + func TestMain(m *testing.M) { refs.SetLeakMode(refs.LeaksPanic) code := m.Run() diff --git a/pkg/tcpip/link/sharedmem/sharedmem_test.go b/pkg/tcpip/link/sharedmem/sharedmem_test.go index f3713a8c65..1fc12bdcc4 100644 --- a/pkg/tcpip/link/sharedmem/sharedmem_test.go +++ b/pkg/tcpip/link/sharedmem/sharedmem_test.go @@ -821,6 +821,20 @@ func TestCloseWhileWaitingToPost(t *testing.T) { c.ep.Wait() } +func TestSetLinkAddress(t *testing.T) { + c := newTestContext(t, 20000, 1500, tcpip.LinkAddress("xyz")) + defer c.cleanup() + + addrs := []tcpip.LinkAddress{"abc", "def"} + for _, addr := range addrs { + c.ep.SetLinkAddress(addr) + + if want, v := addr, c.ep.LinkAddress(); want != v { + t.Errorf("LinkAddress() = %v, want %v", v, want) + } + } +} + func TestMain(m *testing.M) { refs.SetLeakMode(refs.LeaksPanic) code := m.Run() diff --git a/pkg/tcpip/link/veth/BUILD b/pkg/tcpip/link/veth/BUILD index 3fd5b1c3b9..8911686a6e 100644 --- a/pkg/tcpip/link/veth/BUILD +++ b/pkg/tcpip/link/veth/BUILD @@ -1,4 +1,4 @@ -load("//tools:defs.bzl", "go_library") +load("//tools:defs.bzl", "go_library", "go_test") package( default_applicable_licenses = ["//:license"], @@ -16,3 +16,10 @@ go_library( "//pkg/tcpip/stack", ], ) + +go_test( + name = "veth_test", + srcs = ["veth_test.go"], + library = ":veth", + deps = ["//pkg/tcpip"], +) diff --git a/pkg/tcpip/link/veth/veth.go b/pkg/tcpip/link/veth/veth.go index 885ca1d908..3a3eb19f1f 100644 --- a/pkg/tcpip/link/veth/veth.go +++ b/pkg/tcpip/link/veth/veth.go @@ -170,6 +170,13 @@ func (e *Endpoint) LinkAddress() tcpip.LinkAddress { return e.linkAddr } +// SetLinkAddress implements stack.LinkEndpoint.SetLinkAddress. +func (e *Endpoint) SetLinkAddress(addr tcpip.LinkAddress) { + e.mu.Lock() + defer e.mu.Unlock() + e.linkAddr = addr +} + // WritePackets stores outbound packets into the channel. // Multiple concurrent calls are permitted. func (e *Endpoint) WritePackets(pkts stack.PacketBufferList) (int, tcpip.Error) { diff --git a/pkg/tcpip/link/veth/veth_test.go b/pkg/tcpip/link/veth/veth_test.go new file mode 100644 index 0000000000..76433e977f --- /dev/null +++ b/pkg/tcpip/link/veth/veth_test.go @@ -0,0 +1,35 @@ +// Copyright 2024 The gVisor Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package veth + +import ( + "testing" + + "gvisor.dev/gvisor/pkg/tcpip" +) + +func TestSetLinkAddress(t *testing.T) { + addrs := []tcpip.LinkAddress{"abc", "def"} + e := &Endpoint{ + linkAddr: tcpip.LinkAddress("xyz"), + } + defer e.Close() + for _, addr := range addrs { + e.SetLinkAddress(addr) + + if want, v := addr, e.LinkAddress(); want != v { + t.Errorf("LinkAddress() = %v, want %v", v, want) + } + } +} diff --git a/pkg/tcpip/link/waitable/waitable.go b/pkg/tcpip/link/waitable/waitable.go index dee19708a6..2a8a9c6599 100644 --- a/pkg/tcpip/link/waitable/waitable.go +++ b/pkg/tcpip/link/waitable/waitable.go @@ -126,6 +126,14 @@ func (e *Endpoint) LinkAddress() tcpip.LinkAddress { return e.lower.LinkAddress() } +// SetLinkAddress implements stack.LinkEndpoint.SetLinkAddress. It forwards the +// request to the lower endpoint. +func (e *Endpoint) SetLinkAddress(addr tcpip.LinkAddress) { + e.mu.Lock() + defer e.mu.Unlock() + e.lower.SetLinkAddress(addr) +} + // WritePackets implements stack.LinkEndpoint.WritePackets. It is called by // higher-level protocols to write packets. It only forwards packets to the // lower endpoint if Wait or WaitWrite haven't been called. diff --git a/pkg/tcpip/link/waitable/waitable_test.go b/pkg/tcpip/link/waitable/waitable_test.go index 9f93bad058..9f8c8c1695 100644 --- a/pkg/tcpip/link/waitable/waitable_test.go +++ b/pkg/tcpip/link/waitable/waitable_test.go @@ -73,6 +73,10 @@ func (e *countedEndpoint) LinkAddress() tcpip.LinkAddress { return e.linkAddr } +func (e *countedEndpoint) SetLinkAddress(addr tcpip.LinkAddress) { + e.linkAddr = addr +} + // WritePackets implements stack.LinkEndpoint.WritePackets. func (e *countedEndpoint) WritePackets(pkts stack.PacketBufferList) (int, tcpip.Error) { e.writeCount += pkts.Len() diff --git a/pkg/tcpip/link/xdp/BUILD b/pkg/tcpip/link/xdp/BUILD index 4f1be49b41..cc3cf69f11 100644 --- a/pkg/tcpip/link/xdp/BUILD +++ b/pkg/tcpip/link/xdp/BUILD @@ -1,4 +1,4 @@ -load("//tools:defs.bzl", "go_library") +load("//tools:defs.bzl", "go_library", "go_test") package( default_applicable_licenses = ["//:license"], @@ -24,3 +24,10 @@ go_library( "@org_golang_x_sys//unix:go_default_library", ], ) + +go_test( + name = "xdp_test", + srcs = ["endpoint_test.go"], + library = ":xdp", + deps = ["//pkg/tcpip"], +) diff --git a/pkg/tcpip/link/xdp/endpoint.go b/pkg/tcpip/link/xdp/endpoint.go index 8345431882..c47ba81b67 100644 --- a/pkg/tcpip/link/xdp/endpoint.go +++ b/pkg/tcpip/link/xdp/endpoint.go @@ -239,6 +239,13 @@ func (ep *endpoint) LinkAddress() tcpip.LinkAddress { return ep.addr } +// SetLinkAddress implemens stack.LinkEndpoint.SetLinkAddress +func (ep *endpoint) SetLinkAddress(addr tcpip.LinkAddress) { + ep.mu.Lock() + defer ep.mu.Unlock() + ep.addr = addr +} + // Wait implements stack.LinkEndpoint.Wait. It waits for the endpoint to stop // reading from its FD. func (ep *endpoint) Wait() { diff --git a/pkg/tcpip/link/xdp/endpoint_test.go b/pkg/tcpip/link/xdp/endpoint_test.go new file mode 100644 index 0000000000..eff3665e65 --- /dev/null +++ b/pkg/tcpip/link/xdp/endpoint_test.go @@ -0,0 +1,34 @@ +// Copyright 2024 The gVisor Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package xdp + +import ( + "testing" + + "gvisor.dev/gvisor/pkg/tcpip" +) + +func TestSetAddress(t *testing.T) { + ep := &endpoint{ + addr: "xyz", + } + addrs := []tcpip.LinkAddress{"abc", "def"} + for _, addr := range addrs { + ep.SetLinkAddress(addr) + + if want, v := addr, ep.LinkAddress(); want != v { + t.Errorf("LinkAddress() = %v, want %v", v, want) + } + } +} diff --git a/pkg/tcpip/network/internal/testutil/testutil.go b/pkg/tcpip/network/internal/testutil/testutil.go index 638adeadd6..8647db95a8 100644 --- a/pkg/tcpip/network/internal/testutil/testutil.go +++ b/pkg/tcpip/network/internal/testutil/testutil.go @@ -65,6 +65,9 @@ func (*MockLinkEndpoint) MaxHeaderLength() uint16 { return 0 } // LinkAddress implements LinkEndpoint.LinkAddress. func (*MockLinkEndpoint) LinkAddress() tcpip.LinkAddress { return "" } +// SetLinkAddress implements LinkEndpoint.LinkAddress. +func (*MockLinkEndpoint) SetLinkAddress(tcpip.LinkAddress) {} + // WritePackets implements LinkEndpoint.WritePackets. func (ep *MockLinkEndpoint) WritePackets(pkts stack.PacketBufferList) (int, tcpip.Error) { var n int diff --git a/pkg/tcpip/network/ip_test.go b/pkg/tcpip/network/ip_test.go index 9ba4c2d1f4..307ac23a26 100644 --- a/pkg/tcpip/network/ip_test.go +++ b/pkg/tcpip/network/ip_test.go @@ -192,6 +192,9 @@ func (*testObject) LinkAddress() tcpip.LinkAddress { return "" } +// SetLinkAddress sets the link address of this endpoint. +func (*testObject) SetLinkAddress(tcpip.LinkAddress) {} + // Wait implements stack.LinkEndpoint.Wait. func (*testObject) Wait() {} diff --git a/pkg/tcpip/stack/forwarding_test.go b/pkg/tcpip/stack/forwarding_test.go index f60e972339..8e695fbffc 100644 --- a/pkg/tcpip/stack/forwarding_test.go +++ b/pkg/tcpip/stack/forwarding_test.go @@ -304,6 +304,11 @@ func (e *fwdTestLinkEndpoint) LinkAddress() tcpip.LinkAddress { return e.linkAddr } +// SetLinkAddress sets the link address of this endpoint. +func (e *fwdTestLinkEndpoint) SetLinkAddress(addr tcpip.LinkAddress) { + e.linkAddr = addr +} + // WritePackets stores outbound packets into the channel. func (e *fwdTestLinkEndpoint) WritePackets(pkts PacketBufferList) (int, tcpip.Error) { n := 0 diff --git a/pkg/tcpip/stack/registration.go b/pkg/tcpip/stack/registration.go index ed208e6755..53e70a2ae0 100644 --- a/pkg/tcpip/stack/registration.go +++ b/pkg/tcpip/stack/registration.go @@ -1100,6 +1100,9 @@ type NetworkLinkEndpoint interface { // endpoint. LinkAddress() tcpip.LinkAddress + // SetLinkAddress updated the endpoint's link address (typically a MAC). + SetLinkAddress(addr tcpip.LinkAddress) + // Capabilities returns the set of capabilities supported by the // endpoint. Capabilities() LinkEndpointCapabilities diff --git a/pkg/tcpip/transport/datagram_test.go b/pkg/tcpip/transport/datagram_test.go index 7d7787ffe7..dd878bfba5 100644 --- a/pkg/tcpip/transport/datagram_test.go +++ b/pkg/tcpip/transport/datagram_test.go @@ -149,9 +149,9 @@ func (*mockEndpoint) MaxHeaderLength() uint16 { return 0 } func (*mockEndpoint) LinkAddress() tcpip.LinkAddress { - var l tcpip.LinkAddress - return l + return "" } +func (*mockEndpoint) SetLinkAddress(tcpip.LinkAddress) {} func (e *mockEndpoint) WritePackets(pkts stack.PacketBufferList) (int, tcpip.Error) { if e.writeErr != nil { return 0, e.writeErr