sockErrCmsgToLinux converts SockError control message from tcpip format to Linux format.
(sockErr *tcpip.SockError)
| 84 | // sockErrCmsgToLinux converts SockError control message from tcpip format to |
| 85 | // Linux format. |
| 86 | func sockErrCmsgToLinux(sockErr *tcpip.SockError) linux.SockErrCMsg { |
| 87 | if sockErr == nil { |
| 88 | return nil |
| 89 | } |
| 90 | |
| 91 | ee := linux.SockExtendedErr{ |
| 92 | Errno: uint32(syserr.TranslateNetstackError(sockErr.Err).ToLinux()), |
| 93 | Origin: errOriginToLinux(sockErr.Cause.Origin()), |
| 94 | Type: sockErr.Cause.Type(), |
| 95 | Code: sockErr.Cause.Code(), |
| 96 | Info: sockErr.Cause.Info(), |
| 97 | } |
| 98 | |
| 99 | switch sockErr.NetProto { |
| 100 | case header.IPv4ProtocolNumber: |
| 101 | errMsg := &linux.SockErrCMsgIPv4{SockExtendedErr: ee} |
| 102 | if len(sockErr.Offender.Addr.AsSlice()) > 0 { |
| 103 | addr, _ := ConvertAddress(linux.AF_INET, sockErr.Offender) |
| 104 | errMsg.Offender = *addr.(*linux.SockAddrInet) |
| 105 | } |
| 106 | return errMsg |
| 107 | case header.IPv6ProtocolNumber: |
| 108 | errMsg := &linux.SockErrCMsgIPv6{SockExtendedErr: ee} |
| 109 | if len(sockErr.Offender.Addr.AsSlice()) > 0 { |
| 110 | addr, _ := ConvertAddress(linux.AF_INET6, sockErr.Offender) |
| 111 | errMsg.Offender = *addr.(*linux.SockAddrInet6) |
| 112 | } |
| 113 | return errMsg |
| 114 | default: |
| 115 | panic(fmt.Sprintf("invalid net proto for creating SockErrCMsg: %d", sockErr.NetProto)) |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | // NewIPControlMessages converts the tcpip.ReceivableControlMessages (which does |
| 120 | // not have Linux specific format) to Linux format. |
no test coverage detected
searching dependent graphs…