|
|
|
@ -39,7 +39,7 @@ type neighborTable interface {
|
|
|
|
|
setNUDConfig(NUDConfigurations) tcpip.Error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var _ NetworkInterface = (*NIC)(nil)
|
|
|
|
|
var _ NetworkInterface = (*nic)(nil)
|
|
|
|
|
|
|
|
|
|
type linkResolver struct {
|
|
|
|
|
resolver LinkAddressResolver
|
|
|
|
@ -55,9 +55,9 @@ func (l *linkResolver) confirmReachable(addr tcpip.Address) {
|
|
|
|
|
l.neighborTable.handleUpperLevelConfirmation(addr)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NIC represents a "network interface card" to which the networking stack is
|
|
|
|
|
// nic represents a "network interface card" to which the networking stack is
|
|
|
|
|
// attached.
|
|
|
|
|
type NIC struct {
|
|
|
|
|
type nic struct {
|
|
|
|
|
LinkEndpoint
|
|
|
|
|
|
|
|
|
|
stack *Stack
|
|
|
|
@ -147,7 +147,7 @@ func (p *packetEndpointList) forEach(fn func(PacketEndpoint)) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// newNIC returns a new NIC using the default NDP configurations from stack.
|
|
|
|
|
func newNIC(stack *Stack, id tcpip.NICID, name string, ep LinkEndpoint, ctx NICContext) *NIC {
|
|
|
|
|
func newNIC(stack *Stack, id tcpip.NICID, name string, ep LinkEndpoint, ctx NICContext) *nic {
|
|
|
|
|
// TODO(b/141011931): Validate a LinkEndpoint (ep) is valid. For
|
|
|
|
|
// example, make sure that the link address it provides is a valid
|
|
|
|
|
// unicast ethernet address.
|
|
|
|
@ -156,7 +156,7 @@ func newNIC(stack *Stack, id tcpip.NICID, name string, ep LinkEndpoint, ctx NICC
|
|
|
|
|
// observe an MTU of at least 1280 bytes. Ensure that this requirement
|
|
|
|
|
// of IPv6 is supported on this endpoint's LinkEndpoint.
|
|
|
|
|
|
|
|
|
|
nic := &NIC{
|
|
|
|
|
nic := &nic{
|
|
|
|
|
LinkEndpoint: ep,
|
|
|
|
|
|
|
|
|
|
stack: stack,
|
|
|
|
@ -212,19 +212,19 @@ func newNIC(stack *Stack, id tcpip.NICID, name string, ep LinkEndpoint, ctx NICC
|
|
|
|
|
return nic
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (n *NIC) getNetworkEndpoint(proto tcpip.NetworkProtocolNumber) NetworkEndpoint {
|
|
|
|
|
func (n *nic) getNetworkEndpoint(proto tcpip.NetworkProtocolNumber) NetworkEndpoint {
|
|
|
|
|
return n.networkEndpoints[proto]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Enabled implements NetworkInterface.
|
|
|
|
|
func (n *NIC) Enabled() bool {
|
|
|
|
|
func (n *nic) Enabled() bool {
|
|
|
|
|
return atomic.LoadUint32(&n.enabled) == 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// setEnabled sets the enabled status for the NIC.
|
|
|
|
|
//
|
|
|
|
|
// Returns true if the enabled status was updated.
|
|
|
|
|
func (n *NIC) setEnabled(v bool) bool {
|
|
|
|
|
func (n *nic) setEnabled(v bool) bool {
|
|
|
|
|
if v {
|
|
|
|
|
return atomic.SwapUint32(&n.enabled, 1) == 0
|
|
|
|
|
}
|
|
|
|
@ -234,7 +234,7 @@ func (n *NIC) setEnabled(v bool) bool {
|
|
|
|
|
// disable disables n.
|
|
|
|
|
//
|
|
|
|
|
// It undoes the work done by enable.
|
|
|
|
|
func (n *NIC) disable() {
|
|
|
|
|
func (n *nic) disable() {
|
|
|
|
|
n.mu.Lock()
|
|
|
|
|
n.disableLocked()
|
|
|
|
|
n.mu.Unlock()
|
|
|
|
@ -245,7 +245,7 @@ func (n *NIC) disable() {
|
|
|
|
|
// It undoes the work done by enable.
|
|
|
|
|
//
|
|
|
|
|
// n MUST be locked.
|
|
|
|
|
func (n *NIC) disableLocked() {
|
|
|
|
|
func (n *nic) disableLocked() {
|
|
|
|
|
if !n.Enabled() {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
@ -283,7 +283,7 @@ func (n *NIC) disableLocked() {
|
|
|
|
|
// address (ff02::1), start DAD for permanent addresses, and start soliciting
|
|
|
|
|
// routers if the stack is not operating as a router. If the stack is also
|
|
|
|
|
// configured to auto-generate a link-local address, one will be generated.
|
|
|
|
|
func (n *NIC) enable() tcpip.Error {
|
|
|
|
|
func (n *nic) enable() tcpip.Error {
|
|
|
|
|
n.mu.Lock()
|
|
|
|
|
defer n.mu.Unlock()
|
|
|
|
|
|
|
|
|
@ -303,7 +303,7 @@ func (n *NIC) enable() tcpip.Error {
|
|
|
|
|
// remove detaches NIC from the link endpoint and releases network endpoint
|
|
|
|
|
// resources. This guarantees no packets between this NIC and the network
|
|
|
|
|
// stack.
|
|
|
|
|
func (n *NIC) remove() tcpip.Error {
|
|
|
|
|
func (n *nic) remove() tcpip.Error {
|
|
|
|
|
n.mu.Lock()
|
|
|
|
|
defer n.mu.Unlock()
|
|
|
|
|
|
|
|
|
@ -319,14 +319,14 @@ func (n *NIC) remove() tcpip.Error {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// setPromiscuousMode enables or disables promiscuous mode.
|
|
|
|
|
func (n *NIC) setPromiscuousMode(enable bool) {
|
|
|
|
|
func (n *nic) setPromiscuousMode(enable bool) {
|
|
|
|
|
n.mu.Lock()
|
|
|
|
|
n.mu.promiscuous = enable
|
|
|
|
|
n.mu.Unlock()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Promiscuous implements NetworkInterface.
|
|
|
|
|
func (n *NIC) Promiscuous() bool {
|
|
|
|
|
func (n *nic) Promiscuous() bool {
|
|
|
|
|
n.mu.RLock()
|
|
|
|
|
rv := n.mu.promiscuous
|
|
|
|
|
n.mu.RUnlock()
|
|
|
|
@ -334,17 +334,17 @@ func (n *NIC) Promiscuous() bool {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IsLoopback implements NetworkInterface.
|
|
|
|
|
func (n *NIC) IsLoopback() bool {
|
|
|
|
|
func (n *nic) IsLoopback() bool {
|
|
|
|
|
return n.LinkEndpoint.Capabilities()&CapabilityLoopback != 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// WritePacket implements NetworkLinkEndpoint.
|
|
|
|
|
func (n *NIC) WritePacket(r *Route, gso *GSO, protocol tcpip.NetworkProtocolNumber, pkt *PacketBuffer) tcpip.Error {
|
|
|
|
|
func (n *nic) WritePacket(r *Route, gso *GSO, protocol tcpip.NetworkProtocolNumber, pkt *PacketBuffer) tcpip.Error {
|
|
|
|
|
_, err := n.enqueuePacketBuffer(r, gso, protocol, pkt)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (n *NIC) writePacketBuffer(r RouteInfo, gso *GSO, protocol tcpip.NetworkProtocolNumber, pkt pendingPacketBuffer) (int, tcpip.Error) {
|
|
|
|
|
func (n *nic) writePacketBuffer(r RouteInfo, gso *GSO, protocol tcpip.NetworkProtocolNumber, pkt pendingPacketBuffer) (int, tcpip.Error) {
|
|
|
|
|
switch pkt := pkt.(type) {
|
|
|
|
|
case *PacketBuffer:
|
|
|
|
|
if err := n.writePacket(r, gso, protocol, pkt); err != nil {
|
|
|
|
@ -358,7 +358,7 @@ func (n *NIC) writePacketBuffer(r RouteInfo, gso *GSO, protocol tcpip.NetworkPro
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (n *NIC) enqueuePacketBuffer(r *Route, gso *GSO, protocol tcpip.NetworkProtocolNumber, pkt pendingPacketBuffer) (int, tcpip.Error) {
|
|
|
|
|
func (n *nic) enqueuePacketBuffer(r *Route, gso *GSO, protocol tcpip.NetworkProtocolNumber, pkt pendingPacketBuffer) (int, tcpip.Error) {
|
|
|
|
|
routeInfo, _, err := r.resolvedFields(nil)
|
|
|
|
|
switch err.(type) {
|
|
|
|
|
case nil:
|
|
|
|
@ -388,14 +388,14 @@ func (n *NIC) enqueuePacketBuffer(r *Route, gso *GSO, protocol tcpip.NetworkProt
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// WritePacketToRemote implements NetworkInterface.
|
|
|
|
|
func (n *NIC) WritePacketToRemote(remoteLinkAddr tcpip.LinkAddress, gso *GSO, protocol tcpip.NetworkProtocolNumber, pkt *PacketBuffer) tcpip.Error {
|
|
|
|
|
func (n *nic) WritePacketToRemote(remoteLinkAddr tcpip.LinkAddress, gso *GSO, protocol tcpip.NetworkProtocolNumber, pkt *PacketBuffer) tcpip.Error {
|
|
|
|
|
var r RouteInfo
|
|
|
|
|
r.NetProto = protocol
|
|
|
|
|
r.RemoteLinkAddress = remoteLinkAddr
|
|
|
|
|
return n.writePacket(r, gso, protocol, pkt)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (n *NIC) writePacket(r RouteInfo, gso *GSO, protocol tcpip.NetworkProtocolNumber, pkt *PacketBuffer) tcpip.Error {
|
|
|
|
|
func (n *nic) writePacket(r RouteInfo, gso *GSO, protocol tcpip.NetworkProtocolNumber, pkt *PacketBuffer) tcpip.Error {
|
|
|
|
|
// WritePacket takes ownership of pkt, calculate numBytes first.
|
|
|
|
|
numBytes := pkt.Size()
|
|
|
|
|
|
|
|
|
@ -412,11 +412,11 @@ func (n *NIC) writePacket(r RouteInfo, gso *GSO, protocol tcpip.NetworkProtocolN
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// WritePackets implements NetworkLinkEndpoint.
|
|
|
|
|
func (n *NIC) WritePackets(r *Route, gso *GSO, pkts PacketBufferList, protocol tcpip.NetworkProtocolNumber) (int, tcpip.Error) {
|
|
|
|
|
func (n *nic) WritePackets(r *Route, gso *GSO, pkts PacketBufferList, protocol tcpip.NetworkProtocolNumber) (int, tcpip.Error) {
|
|
|
|
|
return n.enqueuePacketBuffer(r, gso, protocol, &pkts)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (n *NIC) writePackets(r RouteInfo, gso *GSO, protocol tcpip.NetworkProtocolNumber, pkts PacketBufferList) (int, tcpip.Error) {
|
|
|
|
|
func (n *nic) writePackets(r RouteInfo, gso *GSO, protocol tcpip.NetworkProtocolNumber, pkts PacketBufferList) (int, tcpip.Error) {
|
|
|
|
|
for pkt := pkts.Front(); pkt != nil; pkt = pkt.Next() {
|
|
|
|
|
pkt.EgressRoute = r
|
|
|
|
|
pkt.GSOOptions = gso
|
|
|
|
@ -435,14 +435,14 @@ func (n *NIC) writePackets(r RouteInfo, gso *GSO, protocol tcpip.NetworkProtocol
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// setSpoofing enables or disables address spoofing.
|
|
|
|
|
func (n *NIC) setSpoofing(enable bool) {
|
|
|
|
|
func (n *nic) setSpoofing(enable bool) {
|
|
|
|
|
n.mu.Lock()
|
|
|
|
|
n.mu.spoofing = enable
|
|
|
|
|
n.mu.Unlock()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Spoofing implements NetworkInterface.
|
|
|
|
|
func (n *NIC) Spoofing() bool {
|
|
|
|
|
func (n *nic) Spoofing() bool {
|
|
|
|
|
n.mu.RLock()
|
|
|
|
|
defer n.mu.RUnlock()
|
|
|
|
|
return n.mu.spoofing
|
|
|
|
@ -450,7 +450,7 @@ func (n *NIC) Spoofing() bool {
|
|
|
|
|
|
|
|
|
|
// primaryAddress returns an address that can be used to communicate with
|
|
|
|
|
// remoteAddr.
|
|
|
|
|
func (n *NIC) primaryEndpoint(protocol tcpip.NetworkProtocolNumber, remoteAddr tcpip.Address) AssignableAddressEndpoint {
|
|
|
|
|
func (n *nic) primaryEndpoint(protocol tcpip.NetworkProtocolNumber, remoteAddr tcpip.Address) AssignableAddressEndpoint {
|
|
|
|
|
ep, ok := n.networkEndpoints[protocol]
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil
|
|
|
|
@ -480,11 +480,11 @@ const (
|
|
|
|
|
promiscuous
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func (n *NIC) getAddress(protocol tcpip.NetworkProtocolNumber, dst tcpip.Address) AssignableAddressEndpoint {
|
|
|
|
|
func (n *nic) getAddress(protocol tcpip.NetworkProtocolNumber, dst tcpip.Address) AssignableAddressEndpoint {
|
|
|
|
|
return n.getAddressOrCreateTemp(protocol, dst, CanBePrimaryEndpoint, promiscuous)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (n *NIC) hasAddress(protocol tcpip.NetworkProtocolNumber, addr tcpip.Address) bool {
|
|
|
|
|
func (n *nic) hasAddress(protocol tcpip.NetworkProtocolNumber, addr tcpip.Address) bool {
|
|
|
|
|
ep := n.getAddressOrCreateTempInner(protocol, addr, false, NeverPrimaryEndpoint)
|
|
|
|
|
if ep != nil {
|
|
|
|
|
ep.DecRef()
|
|
|
|
@ -495,7 +495,7 @@ func (n *NIC) hasAddress(protocol tcpip.NetworkProtocolNumber, addr tcpip.Addres
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// findEndpoint finds the endpoint, if any, with the given address.
|
|
|
|
|
func (n *NIC) findEndpoint(protocol tcpip.NetworkProtocolNumber, address tcpip.Address, peb PrimaryEndpointBehavior) AssignableAddressEndpoint {
|
|
|
|
|
func (n *nic) findEndpoint(protocol tcpip.NetworkProtocolNumber, address tcpip.Address, peb PrimaryEndpointBehavior) AssignableAddressEndpoint {
|
|
|
|
|
return n.getAddressOrCreateTemp(protocol, address, peb, spoofing)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -508,7 +508,7 @@ func (n *NIC) findEndpoint(protocol tcpip.NetworkProtocolNumber, address tcpip.A
|
|
|
|
|
//
|
|
|
|
|
// If the address is the IPv4 broadcast address for an endpoint's network, that
|
|
|
|
|
// endpoint will be returned.
|
|
|
|
|
func (n *NIC) getAddressOrCreateTemp(protocol tcpip.NetworkProtocolNumber, address tcpip.Address, peb PrimaryEndpointBehavior, tempRef getAddressBehaviour) AssignableAddressEndpoint {
|
|
|
|
|
func (n *nic) getAddressOrCreateTemp(protocol tcpip.NetworkProtocolNumber, address tcpip.Address, peb PrimaryEndpointBehavior, tempRef getAddressBehaviour) AssignableAddressEndpoint {
|
|
|
|
|
n.mu.RLock()
|
|
|
|
|
var spoofingOrPromiscuous bool
|
|
|
|
|
switch tempRef {
|
|
|
|
@ -523,7 +523,7 @@ func (n *NIC) getAddressOrCreateTemp(protocol tcpip.NetworkProtocolNumber, addre
|
|
|
|
|
|
|
|
|
|
// getAddressOrCreateTempInner is like getAddressEpOrCreateTemp except a boolean
|
|
|
|
|
// is passed to indicate whether or not we should generate temporary endpoints.
|
|
|
|
|
func (n *NIC) getAddressOrCreateTempInner(protocol tcpip.NetworkProtocolNumber, address tcpip.Address, createTemp bool, peb PrimaryEndpointBehavior) AssignableAddressEndpoint {
|
|
|
|
|
func (n *nic) getAddressOrCreateTempInner(protocol tcpip.NetworkProtocolNumber, address tcpip.Address, createTemp bool, peb PrimaryEndpointBehavior) AssignableAddressEndpoint {
|
|
|
|
|
ep, ok := n.networkEndpoints[protocol]
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil
|
|
|
|
@ -539,7 +539,7 @@ func (n *NIC) getAddressOrCreateTempInner(protocol tcpip.NetworkProtocolNumber,
|
|
|
|
|
|
|
|
|
|
// addAddress adds a new address to n, so that it starts accepting packets
|
|
|
|
|
// targeted at the given address (and network protocol).
|
|
|
|
|
func (n *NIC) addAddress(protocolAddress tcpip.ProtocolAddress, peb PrimaryEndpointBehavior) tcpip.Error {
|
|
|
|
|
func (n *nic) addAddress(protocolAddress tcpip.ProtocolAddress, peb PrimaryEndpointBehavior) tcpip.Error {
|
|
|
|
|
ep, ok := n.networkEndpoints[protocolAddress.Protocol]
|
|
|
|
|
if !ok {
|
|
|
|
|
return &tcpip.ErrUnknownProtocol{}
|
|
|
|
@ -560,7 +560,7 @@ func (n *NIC) addAddress(protocolAddress tcpip.ProtocolAddress, peb PrimaryEndpo
|
|
|
|
|
|
|
|
|
|
// allPermanentAddresses returns all permanent addresses associated with
|
|
|
|
|
// this NIC.
|
|
|
|
|
func (n *NIC) allPermanentAddresses() []tcpip.ProtocolAddress {
|
|
|
|
|
func (n *nic) allPermanentAddresses() []tcpip.ProtocolAddress {
|
|
|
|
|
var addrs []tcpip.ProtocolAddress
|
|
|
|
|
for p, ep := range n.networkEndpoints {
|
|
|
|
|
addressableEndpoint, ok := ep.(AddressableEndpoint)
|
|
|
|
@ -576,7 +576,7 @@ func (n *NIC) allPermanentAddresses() []tcpip.ProtocolAddress {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// primaryAddresses returns the primary addresses associated with this NIC.
|
|
|
|
|
func (n *NIC) primaryAddresses() []tcpip.ProtocolAddress {
|
|
|
|
|
func (n *nic) primaryAddresses() []tcpip.ProtocolAddress {
|
|
|
|
|
var addrs []tcpip.ProtocolAddress
|
|
|
|
|
for p, ep := range n.networkEndpoints {
|
|
|
|
|
addressableEndpoint, ok := ep.(AddressableEndpoint)
|
|
|
|
@ -596,7 +596,7 @@ func (n *NIC) primaryAddresses() []tcpip.ProtocolAddress {
|
|
|
|
|
// primaryAddress will return the first non-deprecated address if such an
|
|
|
|
|
// address exists. If no non-deprecated address exists, the first deprecated
|
|
|
|
|
// address will be returned.
|
|
|
|
|
func (n *NIC) primaryAddress(proto tcpip.NetworkProtocolNumber) tcpip.AddressWithPrefix {
|
|
|
|
|
func (n *nic) primaryAddress(proto tcpip.NetworkProtocolNumber) tcpip.AddressWithPrefix {
|
|
|
|
|
ep, ok := n.networkEndpoints[proto]
|
|
|
|
|
if !ok {
|
|
|
|
|
return tcpip.AddressWithPrefix{}
|
|
|
|
@ -611,7 +611,7 @@ func (n *NIC) primaryAddress(proto tcpip.NetworkProtocolNumber) tcpip.AddressWit
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// removeAddress removes an address from n.
|
|
|
|
|
func (n *NIC) removeAddress(addr tcpip.Address) tcpip.Error {
|
|
|
|
|
func (n *nic) removeAddress(addr tcpip.Address) tcpip.Error {
|
|
|
|
|
for _, ep := range n.networkEndpoints {
|
|
|
|
|
addressableEndpoint, ok := ep.(AddressableEndpoint)
|
|
|
|
|
if !ok {
|
|
|
|
@ -629,7 +629,7 @@ func (n *NIC) removeAddress(addr tcpip.Address) tcpip.Error {
|
|
|
|
|
return &tcpip.ErrBadLocalAddress{}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (n *NIC) getLinkAddress(addr, localAddr tcpip.Address, protocol tcpip.NetworkProtocolNumber, onResolve func(LinkResolutionResult)) tcpip.Error {
|
|
|
|
|
func (n *nic) getLinkAddress(addr, localAddr tcpip.Address, protocol tcpip.NetworkProtocolNumber, onResolve func(LinkResolutionResult)) tcpip.Error {
|
|
|
|
|
linkRes, ok := n.linkAddrResolvers[protocol]
|
|
|
|
|
if !ok {
|
|
|
|
|
return &tcpip.ErrNotSupported{}
|
|
|
|
@ -644,7 +644,7 @@ func (n *NIC) getLinkAddress(addr, localAddr tcpip.Address, protocol tcpip.Netwo
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (n *NIC) neighbors(protocol tcpip.NetworkProtocolNumber) ([]NeighborEntry, tcpip.Error) {
|
|
|
|
|
func (n *nic) neighbors(protocol tcpip.NetworkProtocolNumber) ([]NeighborEntry, tcpip.Error) {
|
|
|
|
|
if linkRes, ok := n.linkAddrResolvers[protocol]; ok {
|
|
|
|
|
return linkRes.neighborTable.neighbors()
|
|
|
|
|
}
|
|
|
|
@ -652,7 +652,7 @@ func (n *NIC) neighbors(protocol tcpip.NetworkProtocolNumber) ([]NeighborEntry,
|
|
|
|
|
return nil, &tcpip.ErrNotSupported{}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (n *NIC) addStaticNeighbor(addr tcpip.Address, protocol tcpip.NetworkProtocolNumber, linkAddress tcpip.LinkAddress) tcpip.Error {
|
|
|
|
|
func (n *nic) addStaticNeighbor(addr tcpip.Address, protocol tcpip.NetworkProtocolNumber, linkAddress tcpip.LinkAddress) tcpip.Error {
|
|
|
|
|
if linkRes, ok := n.linkAddrResolvers[protocol]; ok {
|
|
|
|
|
linkRes.neighborTable.addStaticEntry(addr, linkAddress)
|
|
|
|
|
return nil
|
|
|
|
@ -661,7 +661,7 @@ func (n *NIC) addStaticNeighbor(addr tcpip.Address, protocol tcpip.NetworkProtoc
|
|
|
|
|
return &tcpip.ErrNotSupported{}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (n *NIC) removeNeighbor(protocol tcpip.NetworkProtocolNumber, addr tcpip.Address) tcpip.Error {
|
|
|
|
|
func (n *nic) removeNeighbor(protocol tcpip.NetworkProtocolNumber, addr tcpip.Address) tcpip.Error {
|
|
|
|
|
if linkRes, ok := n.linkAddrResolvers[protocol]; ok {
|
|
|
|
|
return linkRes.neighborTable.remove(addr)
|
|
|
|
|
}
|
|
|
|
@ -669,7 +669,7 @@ func (n *NIC) removeNeighbor(protocol tcpip.NetworkProtocolNumber, addr tcpip.Ad
|
|
|
|
|
return &tcpip.ErrNotSupported{}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (n *NIC) clearNeighbors(protocol tcpip.NetworkProtocolNumber) tcpip.Error {
|
|
|
|
|
func (n *nic) clearNeighbors(protocol tcpip.NetworkProtocolNumber) tcpip.Error {
|
|
|
|
|
if linkRes, ok := n.linkAddrResolvers[protocol]; ok {
|
|
|
|
|
return linkRes.neighborTable.removeAll()
|
|
|
|
|
}
|
|
|
|
@ -679,7 +679,7 @@ func (n *NIC) clearNeighbors(protocol tcpip.NetworkProtocolNumber) tcpip.Error {
|
|
|
|
|
|
|
|
|
|
// joinGroup adds a new endpoint for the given multicast address, if none
|
|
|
|
|
// exists yet. Otherwise it just increments its count.
|
|
|
|
|
func (n *NIC) joinGroup(protocol tcpip.NetworkProtocolNumber, addr tcpip.Address) tcpip.Error {
|
|
|
|
|
func (n *nic) joinGroup(protocol tcpip.NetworkProtocolNumber, addr tcpip.Address) tcpip.Error {
|
|
|
|
|
// TODO(b/143102137): When implementing MLD, make sure MLD packets are
|
|
|
|
|
// not sent unless a valid link-local address is available for use on n
|
|
|
|
|
// as an MLD packet's source address must be a link-local address as
|
|
|
|
@ -700,7 +700,7 @@ func (n *NIC) joinGroup(protocol tcpip.NetworkProtocolNumber, addr tcpip.Address
|
|
|
|
|
|
|
|
|
|
// leaveGroup decrements the count for the given multicast address, and when it
|
|
|
|
|
// reaches zero removes the endpoint for this address.
|
|
|
|
|
func (n *NIC) leaveGroup(protocol tcpip.NetworkProtocolNumber, addr tcpip.Address) tcpip.Error {
|
|
|
|
|
func (n *nic) leaveGroup(protocol tcpip.NetworkProtocolNumber, addr tcpip.Address) tcpip.Error {
|
|
|
|
|
ep, ok := n.networkEndpoints[protocol]
|
|
|
|
|
if !ok {
|
|
|
|
|
return &tcpip.ErrNotSupported{}
|
|
|
|
@ -715,7 +715,7 @@ func (n *NIC) leaveGroup(protocol tcpip.NetworkProtocolNumber, addr tcpip.Addres
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// isInGroup returns true if n has joined the multicast group addr.
|
|
|
|
|
func (n *NIC) isInGroup(addr tcpip.Address) bool {
|
|
|
|
|
func (n *nic) isInGroup(addr tcpip.Address) bool {
|
|
|
|
|
for _, ep := range n.networkEndpoints {
|
|
|
|
|
gep, ok := ep.(GroupAddressableEndpoint)
|
|
|
|
|
if !ok {
|
|
|
|
@ -736,7 +736,7 @@ func (n *NIC) isInGroup(addr tcpip.Address) bool {
|
|
|
|
|
// Note that the ownership of the slice backing vv is retained by the caller.
|
|
|
|
|
// This rule applies only to the slice itself, not to the items of the slice;
|
|
|
|
|
// the ownership of the items is not retained by the caller.
|
|
|
|
|
func (n *NIC) DeliverNetworkPacket(remote, local tcpip.LinkAddress, protocol tcpip.NetworkProtocolNumber, pkt *PacketBuffer) {
|
|
|
|
|
func (n *nic) DeliverNetworkPacket(remote, local tcpip.LinkAddress, protocol tcpip.NetworkProtocolNumber, pkt *PacketBuffer) {
|
|
|
|
|
n.mu.RLock()
|
|
|
|
|
enabled := n.Enabled()
|
|
|
|
|
// If the NIC is not yet enabled, don't receive any packets.
|
|
|
|
@ -788,7 +788,7 @@ func (n *NIC) DeliverNetworkPacket(remote, local tcpip.LinkAddress, protocol tcp
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeliverOutboundPacket implements NetworkDispatcher.DeliverOutboundPacket.
|
|
|
|
|
func (n *NIC) DeliverOutboundPacket(remote, local tcpip.LinkAddress, protocol tcpip.NetworkProtocolNumber, pkt *PacketBuffer) {
|
|
|
|
|
func (n *nic) DeliverOutboundPacket(remote, local tcpip.LinkAddress, protocol tcpip.NetworkProtocolNumber, pkt *PacketBuffer) {
|
|
|
|
|
n.mu.RLock()
|
|
|
|
|
// We do not deliver to protocol specific packet endpoints as on Linux
|
|
|
|
|
// only ETH_P_ALL endpoints get outbound packets.
|
|
|
|
@ -808,7 +808,7 @@ func (n *NIC) DeliverOutboundPacket(remote, local tcpip.LinkAddress, protocol tc
|
|
|
|
|
|
|
|
|
|
// DeliverTransportPacket delivers the packets to the appropriate transport
|
|
|
|
|
// protocol endpoint.
|
|
|
|
|
func (n *NIC) DeliverTransportPacket(protocol tcpip.TransportProtocolNumber, pkt *PacketBuffer) TransportPacketDisposition {
|
|
|
|
|
func (n *nic) DeliverTransportPacket(protocol tcpip.TransportProtocolNumber, pkt *PacketBuffer) TransportPacketDisposition {
|
|
|
|
|
state, ok := n.stack.transportProtocols[protocol]
|
|
|
|
|
if !ok {
|
|
|
|
|
n.stack.stats.UnknownProtocolRcvdPackets.Increment()
|
|
|
|
@ -889,7 +889,7 @@ func (n *NIC) DeliverTransportPacket(protocol tcpip.TransportProtocolNumber, pkt
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeliverTransportError implements TransportDispatcher.
|
|
|
|
|
func (n *NIC) DeliverTransportError(local, remote tcpip.Address, net tcpip.NetworkProtocolNumber, trans tcpip.TransportProtocolNumber, transErr TransportError, pkt *PacketBuffer) {
|
|
|
|
|
func (n *nic) DeliverTransportError(local, remote tcpip.Address, net tcpip.NetworkProtocolNumber, trans tcpip.TransportProtocolNumber, transErr TransportError, pkt *PacketBuffer) {
|
|
|
|
|
state, ok := n.stack.transportProtocols[trans]
|
|
|
|
|
if !ok {
|
|
|
|
|
return
|
|
|
|
@ -917,17 +917,17 @@ func (n *NIC) DeliverTransportError(local, remote tcpip.Address, net tcpip.Netwo
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ID implements NetworkInterface.
|
|
|
|
|
func (n *NIC) ID() tcpip.NICID {
|
|
|
|
|
func (n *nic) ID() tcpip.NICID {
|
|
|
|
|
return n.id
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Name implements NetworkInterface.
|
|
|
|
|
func (n *NIC) Name() string {
|
|
|
|
|
func (n *nic) Name() string {
|
|
|
|
|
return n.name
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// nudConfigs gets the NUD configurations for n.
|
|
|
|
|
func (n *NIC) nudConfigs(protocol tcpip.NetworkProtocolNumber) (NUDConfigurations, tcpip.Error) {
|
|
|
|
|
func (n *nic) nudConfigs(protocol tcpip.NetworkProtocolNumber) (NUDConfigurations, tcpip.Error) {
|
|
|
|
|
if linkRes, ok := n.linkAddrResolvers[protocol]; ok {
|
|
|
|
|
return linkRes.neighborTable.nudConfig()
|
|
|
|
|
}
|
|
|
|
@ -939,7 +939,7 @@ func (n *NIC) nudConfigs(protocol tcpip.NetworkProtocolNumber) (NUDConfiguration
|
|
|
|
|
//
|
|
|
|
|
// Note, if c contains invalid NUD configuration values, it will be fixed to
|
|
|
|
|
// use default values for the erroneous values.
|
|
|
|
|
func (n *NIC) setNUDConfigs(protocol tcpip.NetworkProtocolNumber, c NUDConfigurations) tcpip.Error {
|
|
|
|
|
func (n *nic) setNUDConfigs(protocol tcpip.NetworkProtocolNumber, c NUDConfigurations) tcpip.Error {
|
|
|
|
|
if linkRes, ok := n.linkAddrResolvers[protocol]; ok {
|
|
|
|
|
c.resetInvalidFields()
|
|
|
|
|
return linkRes.neighborTable.setNUDConfig(c)
|
|
|
|
@ -948,7 +948,7 @@ func (n *NIC) setNUDConfigs(protocol tcpip.NetworkProtocolNumber, c NUDConfigura
|
|
|
|
|
return &tcpip.ErrNotSupported{}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (n *NIC) registerPacketEndpoint(netProto tcpip.NetworkProtocolNumber, ep PacketEndpoint) tcpip.Error {
|
|
|
|
|
func (n *nic) registerPacketEndpoint(netProto tcpip.NetworkProtocolNumber, ep PacketEndpoint) tcpip.Error {
|
|
|
|
|
n.mu.Lock()
|
|
|
|
|
defer n.mu.Unlock()
|
|
|
|
|
|
|
|
|
@ -961,7 +961,7 @@ func (n *NIC) registerPacketEndpoint(netProto tcpip.NetworkProtocolNumber, ep Pa
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (n *NIC) unregisterPacketEndpoint(netProto tcpip.NetworkProtocolNumber, ep PacketEndpoint) {
|
|
|
|
|
func (n *nic) unregisterPacketEndpoint(netProto tcpip.NetworkProtocolNumber, ep PacketEndpoint) {
|
|
|
|
|
n.mu.Lock()
|
|
|
|
|
defer n.mu.Unlock()
|
|
|
|
|
|
|
|
|
@ -975,7 +975,7 @@ func (n *NIC) unregisterPacketEndpoint(netProto tcpip.NetworkProtocolNumber, ep
|
|
|
|
|
// isValidForOutgoing returns true if the endpoint can be used to send out a
|
|
|
|
|
// packet. It requires the endpoint to not be marked expired (i.e., its address
|
|
|
|
|
// has been removed) unless the NIC is in spoofing mode, or temporary.
|
|
|
|
|
func (n *NIC) isValidForOutgoing(ep AssignableAddressEndpoint) bool {
|
|
|
|
|
func (n *nic) isValidForOutgoing(ep AssignableAddressEndpoint) bool {
|
|
|
|
|
n.mu.RLock()
|
|
|
|
|
spoofing := n.mu.spoofing
|
|
|
|
|
n.mu.RUnlock()
|
|
|
|
@ -983,7 +983,7 @@ func (n *NIC) isValidForOutgoing(ep AssignableAddressEndpoint) bool {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// HandleNeighborProbe implements NetworkInterface.
|
|
|
|
|
func (n *NIC) HandleNeighborProbe(protocol tcpip.NetworkProtocolNumber, addr tcpip.Address, linkAddr tcpip.LinkAddress) tcpip.Error {
|
|
|
|
|
func (n *nic) HandleNeighborProbe(protocol tcpip.NetworkProtocolNumber, addr tcpip.Address, linkAddr tcpip.LinkAddress) tcpip.Error {
|
|
|
|
|
if l, ok := n.linkAddrResolvers[protocol]; ok {
|
|
|
|
|
l.neighborTable.handleProbe(addr, linkAddr)
|
|
|
|
|
return nil
|
|
|
|
@ -993,7 +993,7 @@ func (n *NIC) HandleNeighborProbe(protocol tcpip.NetworkProtocolNumber, addr tcp
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// HandleNeighborConfirmation implements NetworkInterface.
|
|
|
|
|
func (n *NIC) HandleNeighborConfirmation(protocol tcpip.NetworkProtocolNumber, addr tcpip.Address, linkAddr tcpip.LinkAddress, flags ReachabilityConfirmationFlags) tcpip.Error {
|
|
|
|
|
func (n *nic) HandleNeighborConfirmation(protocol tcpip.NetworkProtocolNumber, addr tcpip.Address, linkAddr tcpip.LinkAddress, flags ReachabilityConfirmationFlags) tcpip.Error {
|
|
|
|
|
if l, ok := n.linkAddrResolvers[protocol]; ok {
|
|
|
|
|
l.neighborTable.handleConfirmation(addr, linkAddr, flags)
|
|
|
|
|
return nil
|
|
|
|
@ -1003,7 +1003,7 @@ func (n *NIC) HandleNeighborConfirmation(protocol tcpip.NetworkProtocolNumber, a
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CheckLocalAddress implements NetworkInterface.
|
|
|
|
|
func (n *NIC) CheckLocalAddress(protocol tcpip.NetworkProtocolNumber, addr tcpip.Address) bool {
|
|
|
|
|
func (n *nic) CheckLocalAddress(protocol tcpip.NetworkProtocolNumber, addr tcpip.Address) bool {
|
|
|
|
|
if n.Spoofing() {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|