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

Function convertAddr

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

convertAddr converts an InterfaceAddr to a ProtocolAddress.

(addr inet.InterfaceAddr)

Source from the content-addressed store, hash-verified

611
612// convertAddr converts an InterfaceAddr to a ProtocolAddress.
613func 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.
653func (s *Stack) AddInterfaceAddr(idx int32, addr inet.InterfaceAddr) error {

Callers 2

AddInterfaceAddrMethod · 0.85
RemoveInterfaceAddrMethod · 0.85

Calls 2

AddrFrom4SliceFunction · 0.92
AddrFrom16SliceFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…