1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
.\" Copyright, the authors of the Linux man-pages project
.\"
.\" SPDX-License-Identifier: Linux-man-pages-copyleft
.\"
.TH IP_RECVERR 2const (date) "Linux man-pages (unreleased)"
.SH NAME
IP_RECVERR
\-
extended reliable error message passing
.SH LIBRARY
Standard C library
.RI ( libc ,\~ \-lc )
.SH SYNOPSIS
.nf
.BR "#include <netinet/in.h>" " /* Definition of " IP* " constants */"
.B #include <sys/socket.h>
.P
.BI int\~setsockopt(int\~ sockfd ,\~IPPROTO_IP,\~IP_RECVERR,
.BI " const\~int\~*" enable ,\~sizeof(int));
.BI int\~getsockopt(int\~ sockfd ,\~IPPROTO_IP,\~IP_RECVERR,
.BI " int\~*" enabled ,\~sizeof(int));
.fi
.P
.EX
struct sock_extended_err {
uint32_t ee_errno; /* error number */
uint8_t ee_origin; /* where the error originated */
uint8_t ee_type; /* type */
uint8_t ee_code; /* code */
uint8_t ee_pad;
uint32_t ee_info; /* additional information */
uint32_t ee_data; /* other data */
/* More data may follow */
};
.EE
.P
.nf
#define SO_EE_ORIGIN_NONE 0
#define SO_EE_ORIGIN_LOCAL 1
#define SO_EE_ORIGIN_ICMP 2
#define SO_EE_ORIGIN_ICMP6 3
.P
.B struct\~sockaddr\~*SO_EE_OFFENDER(struct\~sock_extended_err\~*);
.SH DESCRIPTION
Enable extended reliable error message passing
(default: disabled).
.P
When enabled on a datagram socket,
all generated errors will be queued in a per-socket error queue.
When the user receives an error from a socket operation,
the errors can be received by calling
.BR recvmsg (2)
with the
.B MSG_ERRQUEUE
flag set.
The
.I sock_extended_err
structure describing the error
will be passed in an ancillary message
with the type
.B IP_RECVERR
and the level
.BR IPPROTO_IP .
.\" or SOL_IP on Linux
This is useful for reliable error handling on unconnected sockets.
The received data portion of the error queue contains the error packet.
.P
The
.B IP_RECVERR
control message contains a
.I sock_extended_err
structure.
.TP
.I .ee_errno
contains the
.I errno
number of the queued error.
.TP
.I .ee_origin
is the origin code of where the error originated.
.P
The other fields are protocol-specific.
.P
The macro
.BR SO_EE_OFFENDER ()
returns a pointer to the address of the network object
where the error originated from
given a pointer to the ancillary message.
If this address is not known,
the
.I .sa_family
member of the
.I sockaddr
contains
.B AF_UNSPEC
and the other fields of the
.I sockaddr
are undefined.
.P
IP uses the
.I sock_extended_err
structure as follows:
.IP \[bu] 3
.I .ee_origin
is set to
.B SO_EE_ORIGIN_ICMP
for errors received as an ICMP packet,
or
.B SO_EE_ORIGIN_LOCAL
for locally generated errors.
Unknown values should be ignored.
.IP \[bu]
.I .ee_type
and
.I .ee_code
are set from the type and code fields of the ICMP header.
.IP \[bu]
.I .ee_info
contains the discovered MTU for
.B EMSGSIZE
errors.
.IP \[bu]
The message also contains the
.I sockaddr_in
of the node caused that the error,
which can be accessed with the
.BR SO_EE_OFFENDER ()
macro.
.P
The
.I .sin_family
field of the
.BR SO_EE_OFFENDER ()
address is
.B AF_UNSPEC
when the source was unknown.
When the error originated from the network, all IP options
.RB ( IP_OPTIONS (2const),
.BR IP_TTL (2const),
etc.) enabled on the socket and contained in the
error packet are passed as control messages.
The payload of the packet causing the error is returned as normal payload.
.\" FIXME . Is it a good idea to document that? It is a dubious feature.
.\" On
.\" .B SOCK_STREAM
.\" sockets,
.\" .B IP_RECVERR
.\" has slightly different semantics. Instead of
.\" saving the errors for the next timeout, it passes all incoming
.\" errors immediately to the user.
.\" This might be useful for very short-lived TCP connections which
.\" need fast error handling. Use this option with care:
.\" it makes TCP unreliable
.\" by not allowing it to recover properly from routing
.\" shifts and other normal
.\" conditions and breaks the protocol specification.
.P
TCP has no error queue;
.B MSG_ERRQUEUE
is not permitted on
.B SOCK_STREAM
sockets.
.B IP_RECVERR
is valid for TCP,
but all errors are returned by socket function return or
.B SO_ERROR
only.
.P
For raw sockets,
.B IP_RECVERR
enables passing of all received ICMP errors to the
application, otherwise errors are reported only on connected sockets
.SH ERRORS
See
.BR IPPROTO_IP (2const).
See
.BR setsockopt (2).
See
.BR ip (7).
.SH STANDARDS
Linux.
.SH HISTORY
Linux 2.2.
.\" Precisely: since Linux 2.1.15
.SH SEE ALSO
.BR IPPROTO_IP (2const),
.BR setsockopt (2),
.BR ip (7)
|