mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Rename IsV6LinkLocalAddress to IsV6LinkLocalUnicastAddress
To match the V4 variant. PiperOrigin-RevId: 367691981
This commit is contained in:
committed by
gVisor bot
parent
070b76fe7f
commit
973ace6bd9
@@ -391,23 +391,23 @@ func LinkLocalAddr(linkAddr tcpip.LinkAddress) tcpip.Address {
|
||||
return tcpip.Address(lladdrb[:])
|
||||
}
|
||||
|
||||
// IsV6LinkLocalAddress determines if the provided address is an IPv6
|
||||
// link-local address (fe80::/10).
|
||||
func IsV6LinkLocalAddress(addr tcpip.Address) bool {
|
||||
// IsV6LinkLocalUnicastAddress returns true iff the provided address is an IPv6
|
||||
// link-local unicast address, as defined by RFC 4291 section 2.5.6.
|
||||
func IsV6LinkLocalUnicastAddress(addr tcpip.Address) bool {
|
||||
if len(addr) != IPv6AddressSize {
|
||||
return false
|
||||
}
|
||||
return addr[0] == 0xfe && (addr[1]&0xc0) == 0x80
|
||||
}
|
||||
|
||||
// IsV6LoopbackAddress determines if the provided address is an IPv6 loopback
|
||||
// address.
|
||||
// IsV6LoopbackAddress returns true iff the provided address is an IPv6 loopback
|
||||
// address, as defined by RFC 4291 section 2.5.3.
|
||||
func IsV6LoopbackAddress(addr tcpip.Address) bool {
|
||||
return addr == IPv6Loopback
|
||||
}
|
||||
|
||||
// IsV6LinkLocalMulticastAddress determines if the provided address is an IPv6
|
||||
// link-local multicast address.
|
||||
// IsV6LinkLocalMulticastAddress returns true iff the provided address is an
|
||||
// IPv6 link-local multicast address, as defined by RFC 4291 section 2.7.
|
||||
func IsV6LinkLocalMulticastAddress(addr tcpip.Address) bool {
|
||||
return IsV6MulticastAddress(addr) && V6MulticastScope(addr) == IPv6LinkLocalMulticastScope
|
||||
}
|
||||
@@ -472,7 +472,7 @@ func ScopeForIPv6Address(addr tcpip.Address) (IPv6AddressScope, tcpip.Error) {
|
||||
case IsV6LinkLocalMulticastAddress(addr):
|
||||
return LinkLocalScope, nil
|
||||
|
||||
case IsV6LinkLocalAddress(addr):
|
||||
case IsV6LinkLocalUnicastAddress(addr):
|
||||
return LinkLocalScope, nil
|
||||
|
||||
default:
|
||||
@@ -531,7 +531,8 @@ func GenerateTempIPv6SLAACAddr(tempIIDHistory []byte, stableAddr tcpip.Address)
|
||||
}
|
||||
}
|
||||
|
||||
// IPv6MulticastScope is the scope of a multicast IPv6 address.
|
||||
// IPv6MulticastScope is the scope of a multicast IPv6 address, as defined by
|
||||
// RFC 7346 section 2.
|
||||
type IPv6MulticastScope uint8
|
||||
|
||||
// The various values for IPv6 multicast scopes, as per RFC 7346 section 2:
|
||||
|
||||
@@ -252,7 +252,7 @@ func TestIsV6LinkLocalMulticastAddress(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsV6LinkLocalAddress(t *testing.T) {
|
||||
func TestIsV6LinkLocalUnicastAddress(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
addr tcpip.Address
|
||||
@@ -287,8 +287,8 @@ func TestIsV6LinkLocalAddress(t *testing.T) {
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
if got := header.IsV6LinkLocalAddress(test.addr); got != test.expected {
|
||||
t.Errorf("got header.IsV6LinkLocalAddress(%s) = %t, want = %t", test.addr, got, test.expected)
|
||||
if got := header.IsV6LinkLocalUnicastAddress(test.addr); got != test.expected {
|
||||
t.Errorf("got header.IsV6LinkLocalUnicastAddress(%s) = %t, want = %t", test.addr, got, test.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -273,7 +273,7 @@ func isMLDValid(pkt *stack.PacketBuffer, iph header.IPv6, routerAlert *header.IP
|
||||
if iph.HopLimit() != header.MLDHopLimit {
|
||||
return false
|
||||
}
|
||||
if !header.IsV6LinkLocalAddress(iph.SourceAddress()) {
|
||||
if !header.IsV6LinkLocalUnicastAddress(iph.SourceAddress()) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
@@ -804,7 +804,7 @@ func (e *endpoint) handleICMP(pkt *stack.PacketBuffer, hasFragmentHeader bool, r
|
||||
routerAddr := srcAddr
|
||||
|
||||
// Is the IP Source Address a link-local address?
|
||||
if !header.IsV6LinkLocalAddress(routerAddr) {
|
||||
if !header.IsV6LinkLocalUnicastAddress(routerAddr) {
|
||||
// ...No, silently drop the packet.
|
||||
received.invalid.Increment()
|
||||
return
|
||||
|
||||
@@ -314,7 +314,7 @@ func (e *endpoint) onAddressAssignedLocked(addr tcpip.Address) {
|
||||
// Snooping switches MUST manage multicast forwarding state based on MLD
|
||||
// Report and Done messages sent with the unspecified address as the
|
||||
// IPv6 source address.
|
||||
if header.IsV6LinkLocalAddress(addr) {
|
||||
if header.IsV6LinkLocalUnicastAddress(addr) {
|
||||
e.mu.mld.sendQueuedReports()
|
||||
}
|
||||
}
|
||||
@@ -914,7 +914,7 @@ func (e *endpoint) forwardPacket(pkt *stack.PacketBuffer) tcpip.Error {
|
||||
h := header.IPv6(pkt.NetworkHeader().View())
|
||||
|
||||
dstAddr := h.DestinationAddress()
|
||||
if header.IsV6LinkLocalAddress(h.SourceAddress()) || header.IsV6LinkLocalAddress(dstAddr) || header.IsV6LinkLocalMulticastAddress(dstAddr) {
|
||||
if header.IsV6LinkLocalUnicastAddress(h.SourceAddress()) || header.IsV6LinkLocalUnicastAddress(dstAddr) || header.IsV6LinkLocalMulticastAddress(dstAddr) {
|
||||
// As per RFC 4291 section 2.5.6,
|
||||
//
|
||||
// Routers must not forward any packets with Link-Local source or
|
||||
@@ -1622,7 +1622,7 @@ func (e *endpoint) getLinkLocalAddressRLocked() tcpip.Address {
|
||||
var linkLocalAddr tcpip.Address
|
||||
e.mu.addressableEndpointState.ForEachPrimaryEndpoint(func(addressEndpoint stack.AddressEndpoint) bool {
|
||||
if addressEndpoint.IsAssigned(false /* allowExpired */) {
|
||||
if addr := addressEndpoint.AddressWithPrefix().Address; header.IsV6LinkLocalAddress(addr) {
|
||||
if addr := addressEndpoint.AddressWithPrefix().Address; header.IsV6LinkLocalUnicastAddress(addr) {
|
||||
linkLocalAddr = addr
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -737,7 +737,7 @@ func (ndp *ndpState) handleRA(ip tcpip.Address, ra header.NDPRouterAdvert) {
|
||||
prefix := opt.Subnet()
|
||||
|
||||
// Is the prefix a link-local?
|
||||
if header.IsV6LinkLocalAddress(prefix.ID()) {
|
||||
if header.IsV6LinkLocalUnicastAddress(prefix.ID()) {
|
||||
// ...Yes, skip as per RFC 4861 section 6.3.4,
|
||||
// and RFC 4862 section 5.5.3.b (for SLAAC).
|
||||
continue
|
||||
|
||||
@@ -132,7 +132,7 @@ func constructAndValidateRoute(netProto tcpip.NetworkProtocolNumber, addressEndp
|
||||
localAddr = addressEndpoint.AddressWithPrefix().Address
|
||||
}
|
||||
|
||||
if localAddressNIC != outgoingNIC && header.IsV6LinkLocalAddress(localAddr) {
|
||||
if localAddressNIC != outgoingNIC && header.IsV6LinkLocalUnicastAddress(localAddr) {
|
||||
addressEndpoint.DecRef()
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1344,7 +1344,7 @@ func (s *Stack) FindRoute(id tcpip.NICID, localAddr, remoteAddr tcpip.Address, n
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
|
||||
isLinkLocal := header.IsV6LinkLocalAddress(remoteAddr) || header.IsV6LinkLocalMulticastAddress(remoteAddr)
|
||||
isLinkLocal := header.IsV6LinkLocalUnicastAddress(remoteAddr) || header.IsV6LinkLocalMulticastAddress(remoteAddr)
|
||||
isLocalBroadcast := remoteAddr == header.IPv4Broadcast
|
||||
isMulticast := header.IsV4MulticastAddress(remoteAddr) || header.IsV6MulticastAddress(remoteAddr)
|
||||
isLoopback := header.IsV4LoopbackAddress(remoteAddr) || header.IsV6LoopbackAddress(remoteAddr)
|
||||
@@ -1381,7 +1381,7 @@ func (s *Stack) FindRoute(id tcpip.NICID, localAddr, remoteAddr tcpip.Address, n
|
||||
return nil, &tcpip.ErrNetworkUnreachable{}
|
||||
}
|
||||
|
||||
canForward := s.Forwarding(netProto) && !header.IsV6LinkLocalAddress(localAddr) && !isLinkLocal
|
||||
canForward := s.Forwarding(netProto) && !header.IsV6LinkLocalUnicastAddress(localAddr) && !isLinkLocal
|
||||
|
||||
// Find a route to the remote with the route table.
|
||||
var chosenRoute tcpip.Route
|
||||
|
||||
Reference in New Issue
Block a user