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

Method CreateNICWithOptions

pkg/tcpip/stack/stack.go:937–976  ·  view source on GitHub ↗

CreateNICWithOptions creates a NIC with the provided id, LinkEndpoint, and NICOptions. See the documentation on type NICOptions for details on how NICs can be configured. LinkEndpoint.Attach will be called to bind ep with a NetworkDispatcher.

(id tcpip.NICID, ep LinkEndpoint, opts NICOptions)

Source from the content-addressed store, hash-verified

935//
936// LinkEndpoint.Attach will be called to bind ep with a NetworkDispatcher.
937func (s *Stack) CreateNICWithOptions(id tcpip.NICID, ep LinkEndpoint, opts NICOptions) tcpip.Error {
938 s.mu.Lock()
939 defer s.mu.Unlock()
940
941 if id == 0 {
942 return &tcpip.ErrInvalidNICID{}
943 }
944 // Make sure id is unique.
945 if _, ok := s.nics[id]; ok {
946 return &tcpip.ErrDuplicateNICID{}
947 }
948
949 // Make sure name is unique, unless unnamed.
950 if opts.Name != "" {
951 for _, n := range s.nics {
952 if n.Name() == opts.Name {
953 return &tcpip.ErrDuplicateNICID{}
954 }
955 }
956 }
957
958 n := newNIC(s, id, ep, opts)
959 for proto := range s.defaultForwardingEnabled {
960 if _, err := n.setForwarding(proto, true); err != nil {
961 panic(fmt.Sprintf("newNIC(%d, ...).setForwarding(%d, true): %s", id, proto, err))
962 }
963 }
964 s.nics[id] = n
965 if n.IsLoopback() {
966 s.loopbackNIC = n
967 }
968 ep.SetOnCloseAction(func() {
969 s.RemoveNIC(id)
970 })
971 if !opts.Disabled {
972 return n.enable()
973 }
974
975 return nil
976}
977
978// CreateNIC creates a NIC with the provided id and LinkEndpoint and calls
979// LinkEndpoint.Attach to bind ep with a NetworkDispatcher.

Callers 15

CreateNICMethod · 0.95
newVethMethod · 0.80
newBridgeMethod · 0.80
newStackWithOptionsFunction · 0.80
attachOrCreateNICFunction · 0.80
TestBindToDeviceOptionFunction · 0.80
addNICWithDefaultRouteFunction · 0.80
NewWithOptionsFunction · 0.80
NewWithOptsFunction · 0.80

Calls 9

RemoveNICMethod · 0.95
newNICFunction · 0.85
LockMethod · 0.65
UnlockMethod · 0.65
NameMethod · 0.65
IsLoopbackMethod · 0.65
SetOnCloseActionMethod · 0.65
enableMethod · 0.65
setForwardingMethod · 0.45