convertAddr converts an InterfaceAddr to a ProtocolAddress.
(addr inet.InterfaceAddr)
| 611 | |
| 612 | // convertAddr converts an InterfaceAddr to a ProtocolAddress. |
| 613 | func convertAddr(addr inet.InterfaceAddr) (tcpip.ProtocolAddress, error) { |
| 614 | var ( |
| 615 | protocol tcpip.NetworkProtocolNumber |
| 616 | address tcpip.Address |
| 617 | protocolAddress tcpip.ProtocolAddress |
| 618 | ) |
| 619 | switch addr.Family { |
| 620 | case linux.AF_INET: |
| 621 | if len(addr.Addr) != header.IPv4AddressSize { |
| 622 | return protocolAddress, linuxerr.EINVAL |
| 623 | } |
| 624 | if addr.PrefixLen > header.IPv4AddressSize*8 { |
| 625 | return protocolAddress, linuxerr.EINVAL |
| 626 | } |
| 627 | protocol = ipv4.ProtocolNumber |
| 628 | address = tcpip.AddrFrom4Slice(addr.Addr) |
| 629 | case linux.AF_INET6: |
| 630 | if len(addr.Addr) != header.IPv6AddressSize { |
| 631 | return protocolAddress, linuxerr.EINVAL |
| 632 | } |
| 633 | if addr.PrefixLen > header.IPv6AddressSize*8 { |
| 634 | return protocolAddress, linuxerr.EINVAL |
| 635 | } |
| 636 | protocol = ipv6.ProtocolNumber |
| 637 | address = tcpip.AddrFrom16Slice(addr.Addr) |
| 638 | default: |
| 639 | return protocolAddress, linuxerr.ENOTSUP |
| 640 | } |
| 641 | |
| 642 | protocolAddress = tcpip.ProtocolAddress{ |
| 643 | Protocol: protocol, |
| 644 | AddressWithPrefix: tcpip.AddressWithPrefix{ |
| 645 | Address: address, |
| 646 | PrefixLen: int(addr.PrefixLen), |
| 647 | }, |
| 648 | } |
| 649 | return protocolAddress, nil |
| 650 | } |
| 651 | |
| 652 | // AddInterfaceAddr implements inet.Stack.AddInterfaceAddr. |
| 653 | func (s *Stack) AddInterfaceAddr(idx int32, addr inet.InterfaceAddr) error { |
no test coverage detected
searching dependent graphs…