Skip to content
This repository has been archived by the owner on May 20, 2020. It is now read-only.

Commit

Permalink
Rename nicid to nicID to follow go-readability initialisms
Browse files Browse the repository at this point in the history
https://github.com/golang/go/wiki/CodeReviewComments#initialisms

This change does not introduce any new functionality. It just renames variables
from `nicid` to `nicID`.

PiperOrigin-RevId: 278992966
  • Loading branch information
ghananigans authored and gvisor-bot committed Nov 7, 2019
1 parent 8ef4b51 commit cd2b4b3
Show file tree
Hide file tree
Showing 15 changed files with 166 additions and 166 deletions.
12 changes: 6 additions & 6 deletions tcpip/network/arp/arp.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const (

// endpoint implements stack.NetworkEndpoint.
type endpoint struct {
nicid tcpip.NICID
nicID tcpip.NICID
linkEP stack.LinkEndpoint
linkAddrCache stack.LinkAddressCache
}
Expand All @@ -58,7 +58,7 @@ func (e *endpoint) MTU() uint32 {
}

func (e *endpoint) NICID() tcpip.NICID {
return e.nicid
return e.nicID
}

func (e *endpoint) Capabilities() stack.LinkEndpointCapabilities {
Expand Down Expand Up @@ -102,7 +102,7 @@ func (e *endpoint) HandlePacket(r *stack.Route, pkt tcpip.PacketBuffer) {
switch h.Op() {
case header.ARPRequest:
localAddr := tcpip.Address(h.ProtocolAddressTarget())
if e.linkAddrCache.CheckLocalAddress(e.nicid, header.IPv4ProtocolNumber, localAddr) == 0 {
if e.linkAddrCache.CheckLocalAddress(e.nicID, header.IPv4ProtocolNumber, localAddr) == 0 {
return // we have no useful answer, ignore the request
}
hdr := buffer.NewPrependable(int(e.linkEP.MaxHeaderLength()) + header.ARPSize)
Expand All @@ -118,7 +118,7 @@ func (e *endpoint) HandlePacket(r *stack.Route, pkt tcpip.PacketBuffer) {
case header.ARPReply:
addr := tcpip.Address(h.ProtocolAddressSender())
linkAddr := tcpip.LinkAddress(h.HardwareAddressSender())
e.linkAddrCache.AddLinkAddress(e.nicid, addr, linkAddr)
e.linkAddrCache.AddLinkAddress(e.nicID, addr, linkAddr)
}
}

Expand All @@ -135,12 +135,12 @@ func (*protocol) ParseAddresses(v buffer.View) (src, dst tcpip.Address) {
return tcpip.Address(h.ProtocolAddressSender()), ProtocolAddress
}

func (p *protocol) NewEndpoint(nicid tcpip.NICID, addrWithPrefix tcpip.AddressWithPrefix, linkAddrCache stack.LinkAddressCache, dispatcher stack.TransportDispatcher, sender stack.LinkEndpoint) (stack.NetworkEndpoint, *tcpip.Error) {
func (p *protocol) NewEndpoint(nicID tcpip.NICID, addrWithPrefix tcpip.AddressWithPrefix, linkAddrCache stack.LinkAddressCache, dispatcher stack.TransportDispatcher, sender stack.LinkEndpoint) (stack.NetworkEndpoint, *tcpip.Error) {
if addrWithPrefix.Address != ProtocolAddress {
return nil, tcpip.ErrBadLocalAddress
}
return &endpoint{
nicid: nicid,
nicID: nicID,
linkEP: sender,
linkAddrCache: linkAddrCache,
}, nil
Expand Down
8 changes: 4 additions & 4 deletions tcpip/network/ipv4/ipv4.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const (
)

type endpoint struct {
nicid tcpip.NICID
nicID tcpip.NICID
id stack.NetworkEndpointID
prefixLen int
linkEP stack.LinkEndpoint
Expand All @@ -57,9 +57,9 @@ type endpoint struct {
}

// NewEndpoint creates a new ipv4 endpoint.
func (p *protocol) NewEndpoint(nicid tcpip.NICID, addrWithPrefix tcpip.AddressWithPrefix, linkAddrCache stack.LinkAddressCache, dispatcher stack.TransportDispatcher, linkEP stack.LinkEndpoint) (stack.NetworkEndpoint, *tcpip.Error) {
func (p *protocol) NewEndpoint(nicID tcpip.NICID, addrWithPrefix tcpip.AddressWithPrefix, linkAddrCache stack.LinkAddressCache, dispatcher stack.TransportDispatcher, linkEP stack.LinkEndpoint) (stack.NetworkEndpoint, *tcpip.Error) {
e := &endpoint{
nicid: nicid,
nicID: nicID,
id: stack.NetworkEndpointID{LocalAddress: addrWithPrefix.Address},
prefixLen: addrWithPrefix.PrefixLen,
linkEP: linkEP,
Expand Down Expand Up @@ -89,7 +89,7 @@ func (e *endpoint) Capabilities() stack.LinkEndpointCapabilities {

// NICID returns the ID of the NIC this endpoint belongs to.
func (e *endpoint) NICID() tcpip.NICID {
return e.nicid
return e.nicID
}

// ID returns the ipv4 endpoint ID.
Expand Down
4 changes: 2 additions & 2 deletions tcpip/network/ipv4/ipv4_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ func TestInvalidFragments(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
const nicid tcpip.NICID = 42
const nicID tcpip.NICID = 42
s := stack.New(stack.Options{
NetworkProtocols: []stack.NetworkProtocol{
ipv4.NewProtocol(),
Expand All @@ -461,7 +461,7 @@ func TestInvalidFragments(t *testing.T) {
var linkAddr = tcpip.LinkAddress([]byte{0x30, 0x30, 0x30, 0x30, 0x30, 0x30})
var remoteLinkAddr = tcpip.LinkAddress([]byte{0x30, 0x30, 0x30, 0x30, 0x30, 0x31})
ep := channel.New(10, 1500, linkAddr)
s.CreateNIC(nicid, sniffer.New(ep))
s.CreateNIC(nicID, sniffer.New(ep))

for _, pkt := range tc.packets {
ep.InjectLinkAddr(header.IPv4ProtocolNumber, remoteLinkAddr, tcpip.PacketBuffer{
Expand Down
8 changes: 4 additions & 4 deletions tcpip/network/ipv6/icmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (e *endpoint) handleICMP(r *stack.Route, netHeader buffer.View, pkt tcpip.P
// rxNICID so the packet is processed as defined in RFC 4861,
// as per RFC 4862 section 5.4.3.

if e.linkAddrCache.CheckLocalAddress(e.nicid, ProtocolNumber, targetAddr) == 0 {
if e.linkAddrCache.CheckLocalAddress(e.nicID, ProtocolNumber, targetAddr) == 0 {
// We don't have a useful answer; the best we can do is ignore the request.
return
}
Expand Down Expand Up @@ -218,7 +218,7 @@ func (e *endpoint) handleICMP(r *stack.Route, netHeader buffer.View, pkt tcpip.P
//
// Furthermore, the entirety of NDP handling here seems to be
// contradicted by RFC 4861.
e.linkAddrCache.AddLinkAddress(e.nicid, r.RemoteAddress, r.RemoteLinkAddress)
e.linkAddrCache.AddLinkAddress(e.nicID, r.RemoteAddress, r.RemoteLinkAddress)

// RFC 4861 Neighbor Discovery for IP version 6 (IPv6)
//
Expand Down Expand Up @@ -274,9 +274,9 @@ func (e *endpoint) handleICMP(r *stack.Route, netHeader buffer.View, pkt tcpip.P
// inform the netstack integration that a duplicate address was
// detected outside of DAD.

e.linkAddrCache.AddLinkAddress(e.nicid, targetAddr, r.RemoteLinkAddress)
e.linkAddrCache.AddLinkAddress(e.nicID, targetAddr, r.RemoteLinkAddress)
if targetAddr != r.RemoteAddress {
e.linkAddrCache.AddLinkAddress(e.nicid, r.RemoteAddress, r.RemoteLinkAddress)
e.linkAddrCache.AddLinkAddress(e.nicID, r.RemoteAddress, r.RemoteLinkAddress)
}

case header.ICMPv6EchoRequest:
Expand Down
8 changes: 4 additions & 4 deletions tcpip/network/ipv6/ipv6.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const (
)

type endpoint struct {
nicid tcpip.NICID
nicID tcpip.NICID
id stack.NetworkEndpointID
prefixLen int
linkEP stack.LinkEndpoint
Expand All @@ -65,7 +65,7 @@ func (e *endpoint) MTU() uint32 {

// NICID returns the ID of the NIC this endpoint belongs to.
func (e *endpoint) NICID() tcpip.NICID {
return e.nicid
return e.nicID
}

// ID returns the ipv6 endpoint ID.
Expand Down Expand Up @@ -218,9 +218,9 @@ func (*protocol) ParseAddresses(v buffer.View) (src, dst tcpip.Address) {
}

// NewEndpoint creates a new ipv6 endpoint.
func (p *protocol) NewEndpoint(nicid tcpip.NICID, addrWithPrefix tcpip.AddressWithPrefix, linkAddrCache stack.LinkAddressCache, dispatcher stack.TransportDispatcher, linkEP stack.LinkEndpoint) (stack.NetworkEndpoint, *tcpip.Error) {
func (p *protocol) NewEndpoint(nicID tcpip.NICID, addrWithPrefix tcpip.AddressWithPrefix, linkAddrCache stack.LinkAddressCache, dispatcher stack.TransportDispatcher, linkEP stack.LinkEndpoint) (stack.NetworkEndpoint, *tcpip.Error) {
return &endpoint{
nicid: nicid,
nicID: nicID,
id: stack.NetworkEndpointID{LocalAddress: addrWithPrefix.Address},
prefixLen: addrWithPrefix.PrefixLen,
linkEP: linkEP,
Expand Down
8 changes: 4 additions & 4 deletions tcpip/stack/ndp.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const (
// receive and handle NDP related events.
type NDPDispatcher interface {
// OnDuplicateAddressDetectionStatus will be called when the DAD process
// for an address (addr) on a NIC (with ID nicid) completes. resolved
// for an address (addr) on a NIC (with ID nicID) completes. resolved
// will be set to true if DAD completed successfully (no duplicate addr
// detected); false otherwise (addr was detected to be a duplicate on
// the link the NIC is a part of, or it was stopped for some other
Expand All @@ -87,7 +87,7 @@ type NDPDispatcher interface {
//
// This function is permitted to block indefinitely without interfering
// with the stack's operation.
OnDuplicateAddressDetectionStatus(nicid tcpip.NICID, addr tcpip.Address, resolved bool, err *tcpip.Error)
OnDuplicateAddressDetectionStatus(nicID tcpip.NICID, addr tcpip.Address, resolved bool, err *tcpip.Error)

// OnDefaultRouterDiscovered will be called when a new default router is
// discovered. Implementations must return true along with a new valid
Expand All @@ -97,15 +97,15 @@ type NDPDispatcher interface {
//
// This function is not permitted to block indefinitely. This function
// is also not permitted to call into the stack.
OnDefaultRouterDiscovered(nicid tcpip.NICID, addr tcpip.Address) (bool, []tcpip.Route)
OnDefaultRouterDiscovered(nicID tcpip.NICID, addr tcpip.Address) (bool, []tcpip.Route)

// OnDefaultRouterInvalidated will be called when a discovered default
// router is invalidated. Implementers must return a new valid route
// table.
//
// This function is not permitted to block indefinitely. This function
// is also not permitted to call into the stack.
OnDefaultRouterInvalidated(nicid tcpip.NICID, addr tcpip.Address) []tcpip.Route
OnDefaultRouterInvalidated(nicID tcpip.NICID, addr tcpip.Address) []tcpip.Route
}

// NDPConfigurations is the NDP configurations for the netstack.
Expand Down
48 changes: 24 additions & 24 deletions tcpip/stack/ndp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ func TestDADDisabled(t *testing.T) {
// ndpDADEvent is a set of parameters that was passed to
// ndpDispatcher.OnDuplicateAddressDetectionStatus.
type ndpDADEvent struct {
nicid tcpip.NICID
nicID tcpip.NICID
addr tcpip.Address
resolved bool
err *tcpip.Error
}

type ndpRouterEvent struct {
nicid tcpip.NICID
nicID tcpip.NICID
addr tcpip.Address
// true if router was discovered, false if invalidated.
discovered bool
Expand All @@ -108,10 +108,10 @@ type ndpDispatcher struct {
}

// Implements stack.NDPDispatcher.OnDuplicateAddressDetectionStatus.
func (n *ndpDispatcher) OnDuplicateAddressDetectionStatus(nicid tcpip.NICID, addr tcpip.Address, resolved bool, err *tcpip.Error) {
func (n *ndpDispatcher) OnDuplicateAddressDetectionStatus(nicID tcpip.NICID, addr tcpip.Address, resolved bool, err *tcpip.Error) {
if n.dadC != nil {
n.dadC <- ndpDADEvent{
nicid,
nicID,
addr,
resolved,
err,
Expand All @@ -120,10 +120,10 @@ func (n *ndpDispatcher) OnDuplicateAddressDetectionStatus(nicid tcpip.NICID, add
}

// Implements stack.NDPDispatcher.OnDefaultRouterDiscovered.
func (n *ndpDispatcher) OnDefaultRouterDiscovered(nicid tcpip.NICID, addr tcpip.Address) (bool, []tcpip.Route) {
func (n *ndpDispatcher) OnDefaultRouterDiscovered(nicID tcpip.NICID, addr tcpip.Address) (bool, []tcpip.Route) {
if n.routerC != nil {
n.routerC <- ndpRouterEvent{
nicid,
nicID,
addr,
true,
}
Expand All @@ -137,17 +137,17 @@ func (n *ndpDispatcher) OnDefaultRouterDiscovered(nicid tcpip.NICID, addr tcpip.
rt = append(rt, tcpip.Route{
Destination: header.IPv6EmptySubnet,
Gateway: addr,
NIC: nicid,
NIC: nicID,
})
n.routeTable = rt
return true, rt
}

// Implements stack.NDPDispatcher.OnDefaultRouterInvalidated.
func (n *ndpDispatcher) OnDefaultRouterInvalidated(nicid tcpip.NICID, addr tcpip.Address) []tcpip.Route {
func (n *ndpDispatcher) OnDefaultRouterInvalidated(nicID tcpip.NICID, addr tcpip.Address) []tcpip.Route {
if n.routerC != nil {
n.routerC <- ndpRouterEvent{
nicid,
nicID,
addr,
false,
}
Expand All @@ -157,7 +157,7 @@ func (n *ndpDispatcher) OnDefaultRouterInvalidated(nicid tcpip.NICID, addr tcpip
exclude := tcpip.Route{
Destination: header.IPv6EmptySubnet,
Gateway: addr,
NIC: nicid,
NIC: nicID,
}

for _, r := range n.routeTable {
Expand Down Expand Up @@ -254,8 +254,8 @@ func TestDADResolve(t *testing.T) {
if e.err != nil {
t.Fatal("got DAD error: ", e.err)
}
if e.nicid != 1 {
t.Fatalf("got DAD event w/ nicid = %d, want = 1", e.nicid)
if e.nicID != 1 {
t.Fatalf("got DAD event w/ nicID = %d, want = 1", e.nicID)
}
if e.addr != addr1 {
t.Fatalf("got DAD event w/ addr = %s, want = %s", addr, addr1)
Expand Down Expand Up @@ -421,8 +421,8 @@ func TestDADFail(t *testing.T) {
if e.err != nil {
t.Fatal("got DAD error: ", e.err)
}
if e.nicid != 1 {
t.Fatalf("got DAD event w/ nicid = %d, want = 1", e.nicid)
if e.nicID != 1 {
t.Fatalf("got DAD event w/ nicID = %d, want = 1", e.nicID)
}
if e.addr != addr1 {
t.Fatalf("got DAD event w/ addr = %s, want = %s", addr, addr1)
Expand Down Expand Up @@ -492,8 +492,8 @@ func TestDADStop(t *testing.T) {
if e.err != nil {
t.Fatal("got DAD error: ", e.err)
}
if e.nicid != 1 {
t.Fatalf("got DAD event w/ nicid = %d, want = 1", e.nicid)
if e.nicID != 1 {
t.Fatalf("got DAD event w/ nicID = %d, want = 1", e.nicID)
}
if e.addr != addr1 {
t.Fatalf("got DAD event w/ addr = %s, want = %s", addr, addr1)
Expand Down Expand Up @@ -661,8 +661,8 @@ func TestSetNDPConfigurations(t *testing.T) {
if e.err != nil {
t.Fatal("got DAD error: ", e.err)
}
if e.nicid != 1 {
t.Fatalf("got DAD event w/ nicid = %d, want = 1", e.nicid)
if e.nicID != 1 {
t.Fatalf("got DAD event w/ nicID = %d, want = 1", e.nicID)
}
if e.addr != addr1 {
t.Fatalf("got DAD event w/ addr = %s, want = %s", addr, addr1)
Expand Down Expand Up @@ -786,8 +786,8 @@ func TestRouterDiscoveryDispatcherNoRemember(t *testing.T) {
e.InjectInbound(header.IPv6ProtocolNumber, raBuf(llAddr2, uint16(lifetime)))
select {
case r := <-ndpDisp.routerC:
if r.nicid != 1 {
t.Fatalf("got r.nicid = %d, want = 1", r.nicid)
if r.nicID != 1 {
t.Fatalf("got r.nicID = %d, want = 1", r.nicID)
}
if r.addr != llAddr2 {
t.Fatalf("got r.addr = %s, want = %s", r.addr, llAddr2)
Expand Down Expand Up @@ -839,8 +839,8 @@ func TestRouterDiscovery(t *testing.T) {

select {
case r := <-ndpDisp.routerC:
if r.nicid != 1 {
t.Fatalf("got r.nicid = %d, want = 1", r.nicid)
if r.nicID != 1 {
t.Fatalf("got r.nicID = %d, want = 1", r.nicID)
}
if r.addr != addr {
t.Fatalf("got r.addr = %s, want = %s", r.addr, addr)
Expand Down Expand Up @@ -983,8 +983,8 @@ func TestRouterDiscoveryMaxRouters(t *testing.T) {
expectedRt[i-1] = tcpip.Route{header.IPv6EmptySubnet, llAddr, 1}
select {
case r := <-ndpDisp.routerC:
if r.nicid != 1 {
t.Fatalf("got r.nicid = %d, want = 1", r.nicid)
if r.nicID != 1 {
t.Fatalf("got r.nicID = %d, want = 1", r.nicID)
}
if r.addr != llAddr {
t.Fatalf("got r.addr = %s, want = %s", r.addr, llAddr)
Expand Down
12 changes: 6 additions & 6 deletions tcpip/stack/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ type PacketEndpoint interface {
// should construct its own ethernet header for applications.
//
// HandlePacket takes ownership of pkt.
HandlePacket(nicid tcpip.NICID, addr tcpip.LinkAddress, netProto tcpip.NetworkProtocolNumber, pkt tcpip.PacketBuffer)
HandlePacket(nicID tcpip.NICID, addr tcpip.LinkAddress, netProto tcpip.NetworkProtocolNumber, pkt tcpip.PacketBuffer)
}

// TransportProtocol is the interface that needs to be implemented by transport
Expand Down Expand Up @@ -281,7 +281,7 @@ type NetworkProtocol interface {
ParseAddresses(v buffer.View) (src, dst tcpip.Address)

// NewEndpoint creates a new endpoint of this protocol.
NewEndpoint(nicid tcpip.NICID, addrWithPrefix tcpip.AddressWithPrefix, linkAddrCache LinkAddressCache, dispatcher TransportDispatcher, sender LinkEndpoint) (NetworkEndpoint, *tcpip.Error)
NewEndpoint(nicID tcpip.NICID, addrWithPrefix tcpip.AddressWithPrefix, linkAddrCache LinkAddressCache, dispatcher TransportDispatcher, sender LinkEndpoint) (NetworkEndpoint, *tcpip.Error)

// SetOption allows enabling/disabling protocol specific features.
// SetOption returns an error if the option is not supported or the
Expand Down Expand Up @@ -440,10 +440,10 @@ type LinkAddressResolver interface {
type LinkAddressCache interface {
// CheckLocalAddress determines if the given local address exists, and if it
// does not exist.
CheckLocalAddress(nicid tcpip.NICID, protocol tcpip.NetworkProtocolNumber, addr tcpip.Address) tcpip.NICID
CheckLocalAddress(nicID tcpip.NICID, protocol tcpip.NetworkProtocolNumber, addr tcpip.Address) tcpip.NICID

// AddLinkAddress adds a link address to the cache.
AddLinkAddress(nicid tcpip.NICID, addr tcpip.Address, linkAddr tcpip.LinkAddress)
AddLinkAddress(nicID tcpip.NICID, addr tcpip.Address, linkAddr tcpip.LinkAddress)

// GetLinkAddress looks up the cache to translate address to link address (e.g. IP -> MAC).
// If the LinkEndpoint requests address resolution and there is a LinkAddressResolver
Expand All @@ -454,10 +454,10 @@ type LinkAddressCache interface {
// If address resolution is required, ErrNoLinkAddress and a notification channel is
// returned for the top level caller to block. Channel is closed once address resolution
// is complete (success or not).
GetLinkAddress(nicid tcpip.NICID, addr, localAddr tcpip.Address, protocol tcpip.NetworkProtocolNumber, w *sleep.Waker) (tcpip.LinkAddress, <-chan struct{}, *tcpip.Error)
GetLinkAddress(nicID tcpip.NICID, addr, localAddr tcpip.Address, protocol tcpip.NetworkProtocolNumber, w *sleep.Waker) (tcpip.LinkAddress, <-chan struct{}, *tcpip.Error)

// RemoveWaker removes a waker that has been added in GetLinkAddress().
RemoveWaker(nicid tcpip.NICID, addr tcpip.Address, waker *sleep.Waker)
RemoveWaker(nicID tcpip.NICID, addr tcpip.Address, waker *sleep.Waker)
}

// RawFactory produces endpoints for writing various types of raw packets.
Expand Down
Loading

0 comments on commit cd2b4b3

Please sign in to comment.