summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/network/ipv6
diff options
context:
space:
mode:
authorNick Brown <nickbrow@google.com>2021-03-24 09:36:50 -0700
committergVisor bot <gvisor-bot@google.com>2021-03-24 09:38:27 -0700
commitec0aa657edfd98a1e8dfbbf017ee6cf8c7f1a40e (patch)
tree8506257a2992c91db2d2c3b1e7d29eb9ef5279bc /pkg/tcpip/network/ipv6
parent8ee4a3f6d0e75e51e088a431376d2976b0dac866 (diff)
Unexpose immutable fields in stack.Route
This change sets the inner `routeInfo` struct to be a named private member and replaces direct access with access through getters. Note that direct access to the fields of `routeInfo` is still possible through the `RouteInfo` struct. Fixes #4902 PiperOrigin-RevId: 364822872
Diffstat (limited to 'pkg/tcpip/network/ipv6')
-rw-r--r--pkg/tcpip/network/ipv6/icmp.go12
-rw-r--r--pkg/tcpip/network/ipv6/icmp_test.go4
-rw-r--r--pkg/tcpip/network/ipv6/ipv6.go20
3 files changed, 18 insertions, 18 deletions
diff --git a/pkg/tcpip/network/ipv6/icmp.go b/pkg/tcpip/network/ipv6/icmp.go
index 2afa856dc..a142b76c1 100644
--- a/pkg/tcpip/network/ipv6/icmp.go
+++ b/pkg/tcpip/network/ipv6/icmp.go
@@ -554,8 +554,8 @@ func (e *endpoint) handleICMP(pkt *stack.PacketBuffer, hasFragmentHeader bool, r
na.Options().Serialize(optsSerializer)
packet.SetChecksum(header.ICMPv6Checksum(header.ICMPv6ChecksumParams{
Header: packet,
- Src: r.LocalAddress,
- Dst: r.RemoteAddress,
+ Src: r.LocalAddress(),
+ Dst: r.RemoteAddress(),
}))
// RFC 4861 Neighbor Discovery for IP version 6 (IPv6)
@@ -699,8 +699,8 @@ func (e *endpoint) handleICMP(pkt *stack.PacketBuffer, hasFragmentHeader bool, r
dataRange := replyPkt.Data().AsRange()
icmp.SetChecksum(header.ICMPv6Checksum(header.ICMPv6ChecksumParams{
Header: icmp,
- Src: r.LocalAddress,
- Dst: r.RemoteAddress,
+ Src: r.LocalAddress(),
+ Dst: r.RemoteAddress(),
PayloadCsum: dataRange.Checksum(),
PayloadLen: dataRange.Size(),
}))
@@ -1161,8 +1161,8 @@ func (p *protocol) returnError(reason icmpReason, pkt *stack.PacketBuffer) tcpip
dataRange := newPkt.Data().AsRange()
icmpHdr.SetChecksum(header.ICMPv6Checksum(header.ICMPv6ChecksumParams{
Header: icmpHdr,
- Src: route.LocalAddress,
- Dst: route.RemoteAddress,
+ Src: route.LocalAddress(),
+ Dst: route.RemoteAddress(),
PayloadCsum: dataRange.Checksum(),
PayloadLen: dataRange.Size(),
}))
diff --git a/pkg/tcpip/network/ipv6/icmp_test.go b/pkg/tcpip/network/ipv6/icmp_test.go
index 47d713f88..6a7705ed1 100644
--- a/pkg/tcpip/network/ipv6/icmp_test.go
+++ b/pkg/tcpip/network/ipv6/icmp_test.go
@@ -510,8 +510,8 @@ func TestLinkResolution(t *testing.T) {
pkt.SetType(header.ICMPv6EchoRequest)
pkt.SetChecksum(header.ICMPv6Checksum(header.ICMPv6ChecksumParams{
Header: pkt,
- Src: r.LocalAddress,
- Dst: r.RemoteAddress,
+ Src: r.LocalAddress(),
+ Dst: r.RemoteAddress(),
}))
// We can't send our payload directly over the route because that
diff --git a/pkg/tcpip/network/ipv6/ipv6.go b/pkg/tcpip/network/ipv6/ipv6.go
index 83e98bab9..c6d9d8f0d 100644
--- a/pkg/tcpip/network/ipv6/ipv6.go
+++ b/pkg/tcpip/network/ipv6/ipv6.go
@@ -682,7 +682,7 @@ func (e *endpoint) handleFragments(r *stack.Route, gso *stack.GSO, networkMTU ui
// WritePacket writes a packet to the given destination address and protocol.
func (e *endpoint) WritePacket(r *stack.Route, gso *stack.GSO, params stack.NetworkHeaderParams, pkt *stack.PacketBuffer) tcpip.Error {
- if err := addIPHeader(r.LocalAddress, r.RemoteAddress, pkt, params, nil /* extensionHeaders */); err != nil {
+ if err := addIPHeader(r.LocalAddress(), r.RemoteAddress(), pkt, params, nil /* extensionHeaders */); err != nil {
return err
}
@@ -716,13 +716,13 @@ func (e *endpoint) WritePacket(r *stack.Route, gso *stack.GSO, params stack.Netw
}
func (e *endpoint) writePacket(r *stack.Route, gso *stack.GSO, pkt *stack.PacketBuffer, protocol tcpip.TransportProtocolNumber, headerIncluded bool) tcpip.Error {
- if r.Loop&stack.PacketLoop != 0 {
+ if r.Loop()&stack.PacketLoop != 0 {
// If the packet was generated by the stack (not a raw/packet endpoint
// where a packet may be written with the header included), then we can
// safely assume the checksum is valid.
e.handleLocalPacket(pkt, !headerIncluded /* canSkipRXChecksum */)
}
- if r.Loop&stack.PacketOut == 0 {
+ if r.Loop()&stack.PacketOut == 0 {
return nil
}
@@ -757,17 +757,17 @@ func (e *endpoint) writePacket(r *stack.Route, gso *stack.GSO, pkt *stack.Packet
// WritePackets implements stack.NetworkEndpoint.WritePackets.
func (e *endpoint) WritePackets(r *stack.Route, gso *stack.GSO, pkts stack.PacketBufferList, params stack.NetworkHeaderParams) (int, tcpip.Error) {
- if r.Loop&stack.PacketLoop != 0 {
+ if r.Loop()&stack.PacketLoop != 0 {
panic("not implemented")
}
- if r.Loop&stack.PacketOut == 0 {
+ if r.Loop()&stack.PacketOut == 0 {
return pkts.Len(), nil
}
stats := e.stats.ip
linkMTU := e.nic.MTU()
for pb := pkts.Front(); pb != nil; pb = pb.Next() {
- if err := addIPHeader(r.LocalAddress, r.RemoteAddress, pb, params, nil /* extensionHeaders */); err != nil {
+ if err := addIPHeader(r.LocalAddress(), r.RemoteAddress(), pb, params, nil /* extensionHeaders */); err != nil {
return 0, err
}
@@ -845,12 +845,12 @@ func (e *endpoint) WriteHeaderIncludedPacket(r *stack.Route, pkt *stack.PacketBu
// Set the source address when zero.
if ip.SourceAddress() == header.IPv6Any {
- ip.SetSourceAddress(r.LocalAddress)
+ ip.SetSourceAddress(r.LocalAddress())
}
// Set the destination. If the packet already included a destination, it will
// be part of the route anyways.
- ip.SetDestinationAddress(r.RemoteAddress)
+ ip.SetDestinationAddress(r.RemoteAddress())
// Populate the packet buffer's network header and don't allow an invalid
// packet to be sent.
@@ -2113,11 +2113,11 @@ func hashRoute(r *stack.Route, hashIV uint32) uint32 {
// The FNV-1a was chosen because it is a fast hashing algorithm, and
// cryptographic properties are not needed here.
h := fnv.New32a()
- if _, err := h.Write([]byte(r.LocalAddress)); err != nil {
+ if _, err := h.Write([]byte(r.LocalAddress())); err != nil {
panic(fmt.Sprintf("Hash.Write: %s, but Hash' implementation of Write is not expected to ever return an error", err))
}
- if _, err := h.Write([]byte(r.RemoteAddress)); err != nil {
+ if _, err := h.Write([]byte(r.RemoteAddress())); err != nil {
panic(fmt.Sprintf("Hash.Write: %s, but Hash' implementation of Write is not expected to ever return an error", err))
}