SetNICStack moves the network device to the specified network namespace.
(id tcpip.NICID, peer *Stack)
| 2522 | |
| 2523 | // SetNICStack moves the network device to the specified network namespace. |
| 2524 | func (s *Stack) SetNICStack(id tcpip.NICID, peer *Stack) (tcpip.NICID, tcpip.Error) { |
| 2525 | s.mu.Lock() |
| 2526 | nic, ok := s.nics[id] |
| 2527 | if !ok { |
| 2528 | s.mu.Unlock() |
| 2529 | return 0, &tcpip.ErrUnknownNICID{} |
| 2530 | } |
| 2531 | if s == peer { |
| 2532 | s.mu.Unlock() |
| 2533 | return id, nil |
| 2534 | } |
| 2535 | |
| 2536 | linkEp := nic.NetworkLinkEndpoint.(LinkEndpoint) |
| 2537 | name := nic.Name() |
| 2538 | |
| 2539 | deferAct, err := s.removeNICLocked(id, false /* closeLinkEndpoint */) |
| 2540 | s.mu.Unlock() |
| 2541 | if deferAct != nil { |
| 2542 | deferAct() |
| 2543 | } |
| 2544 | if err != nil { |
| 2545 | return 0, err |
| 2546 | } |
| 2547 | |
| 2548 | id = tcpip.NICID(peer.NextNICID()) |
| 2549 | return id, peer.CreateNICWithOptions(id, linkEp, NICOptions{Name: name}) |
| 2550 | } |
| 2551 | |
| 2552 | // SetRemoveConf sets the removeConf in stack to the given value. |
| 2553 | func (s *Stack) SetRemoveConf(removeConf bool) { |