AddInterfaceAddr implements inet.Stack.AddInterfaceAddr.
(idx int32, addr inet.InterfaceAddr)
| 651 | |
| 652 | // AddInterfaceAddr implements inet.Stack.AddInterfaceAddr. |
| 653 | func (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. |
| 685 | func (s *Stack) RemoveInterfaceAddr(idx int32, addr inet.InterfaceAddr) error { |
nothing calls this directly
no test coverage detected