MCPcopy Index your code
hub / github.com/google/gvisor / AddInterfaceAddr

Method AddInterfaceAddr

pkg/sentry/socket/netstack/stack.go:653–682  ·  view source on GitHub ↗

AddInterfaceAddr implements inet.Stack.AddInterfaceAddr.

(idx int32, addr inet.InterfaceAddr)

Source from the content-addressed store, hash-verified

651
652// AddInterfaceAddr implements inet.Stack.AddInterfaceAddr.
653func (s *Stack) AddInterfaceAddr(idx int32, addr inet.InterfaceAddr) error {
654 protocolAddress, err := convertAddr(addr)
655 if err != nil {
656 return err
657 }
658
659 // Attach address to interface.
660 nicID := tcpip.NICID(idx)
661 if err := s.Stack.AddProtocolAddress(nicID, protocolAddress, stack.AddressProperties{}); err != nil {
662 return syserr.TranslateNetstackError(err).ToError()
663 }
664
665 // Add route for local network if it doesn't exist already.
666 localRoute := tcpip.Route{
667 Destination: protocolAddress.AddressWithPrefix.Subnet(),
668 Gateway: tcpip.Address{}, // No gateway for local network.
669 NIC: nicID,
670 }
671
672 for _, rt := range s.Stack.GetRouteTable() {
673 if rt.Equal(localRoute) {
674 return nil
675 }
676 }
677
678 // Local route does not exist yet. Add it.
679 s.Stack.AddRoute(localRoute)
680
681 return nil
682}
683
684// RemoveInterfaceAddr implements inet.Stack.RemoveInterfaceAddr.
685func (s *Stack) RemoveInterfaceAddr(idx int32, addr inet.InterfaceAddr) error {

Callers

nothing calls this directly

Calls 9

NICIDTypeAlias · 0.92
TranslateNetstackErrorFunction · 0.92
convertAddrFunction · 0.85
AddProtocolAddressMethod · 0.80
ToErrorMethod · 0.80
GetRouteTableMethod · 0.80
AddRouteMethod · 0.80
SubnetMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected