OSDN Git Service

a980d221d130ece697510d58670be291c6901c19
[linuxjm/LDP_man-pages.git] / original / man7 / ip.7
1 '\" t
2 .\" This man page is Copyright (C) 1999 Andi Kleen <ak@muc.de>.
3 .\"
4 .\" %%%LICENSE_START(VERBATIM_ONE_PARA)
5 .\" Permission is granted to distribute possibly modified copies
6 .\" of this page provided the header is included verbatim,
7 .\" and in case of nontrivial modification author and date
8 .\" of the modification is added to the header.
9 .\" %%%LICENSE_END
10 .\"
11 .\" $Id: ip.7,v 1.19 2000/12/20 18:10:31 ak Exp $
12 .\"
13 .\" FIXME: The following socket options are yet to be documented
14 .\"     IP_XFRM_POLICY (2.5.48)
15 .\"         Needs CAP_NET_ADMIN
16 .\"     IP_IPSEC_POLICY (2.5.47)
17 .\"         Needs CAP_NET_ADMIN
18 .\"     IP_PASSSEC (2.6.17)
19 .\"         Boolean
20 .\"         commit 2c7946a7bf45ae86736ab3b43d0085e43947945c
21 .\"         Author: Catherine Zhang <cxzhang@watson.ibm.com>
22 .\"     IP_MINTTL (2.6.34)
23 .\"         commit d218d11133d888f9745802146a50255a4781d37a
24 .\"         Author: Stephen Hemminger <shemminger@vyatta.com>
25 .\"     MCAST_JOIN_GROUP (2.4.22 / 2.6)
26 .\"     MCAST_BLOCK_SOURCE (2.4.22 / 2.6)
27 .\"     MCAST_UNBLOCK_SOURCE (2.4.22 / 2.6)
28 .\"     MCAST_LEAVE_GROUP (2.4.22 / 2.6)
29 .\"     MCAST_JOIN_SOURCE_GROUP (2.4.22 / 2.6)
30 .\"     MCAST_LEAVE_SOURCE_GROUP (2.4.22 / 2.6)
31 .\"     MCAST_MSFILTER (2.4.22 / 2.6)
32 .\"     IP_UNICAST_IF (3.4)
33 .\"         commit 76e21053b5bf33a07c76f99d27a74238310e3c71
34 .\"         Author: Erich E. Hoover <ehoover@mines.edu>
35 .\"
36 .TH IP  7 2014-05-10 "Linux" "Linux Programmer's Manual"
37 .SH NAME
38 ip \- Linux IPv4 protocol implementation
39 .SH SYNOPSIS
40 .B #include <sys/socket.h>
41 .br
42 .\" .B #include <net/netinet.h> -- does not exist anymore
43 .\" .B #include <linux/errqueue.h> -- never include <linux/foo.h>
44 .B #include <netinet/in.h>
45 .br
46 .B #include <netinet/ip.h>        \fR/* superset of previous */
47 .sp
48 .IB tcp_socket " = socket(AF_INET, SOCK_STREAM, 0);"
49 .br
50 .IB udp_socket " = socket(AF_INET, SOCK_DGRAM, 0);"
51 .br
52 .IB raw_socket " = socket(AF_INET, SOCK_RAW, " protocol ");"
53 .SH DESCRIPTION
54 Linux implements the Internet Protocol, version 4,
55 described in RFC\ 791 and RFC\ 1122.
56 .B ip
57 contains a level 2 multicasting implementation conforming to RFC\ 1112.
58 It also contains an IP router including a packet filter.
59 .\" FIXME has someone verified that 2.1 is really 1812 compliant?
60 .PP
61 The programming interface is BSD-sockets compatible.
62 For more information on sockets, see
63 .BR socket (7).
64 .PP
65 An IP socket is created by calling the
66 .BR socket (2)
67 function as
68 .BI "socket(AF_INET, " socket_type ", " protocol ) \fR.
69 Valid socket types are
70 .B SOCK_STREAM
71 to open a
72 .BR tcp (7)
73 socket,
74 .B SOCK_DGRAM
75 to open a
76 .BR udp (7)
77 socket, or
78 .B SOCK_RAW
79 to open a
80 .BR raw (7)
81 socket to access the IP protocol directly.
82 .I protocol
83 is the IP protocol in the IP header to be received or sent.
84 The only valid values for
85 .I protocol
86 are 0 and
87 .B IPPROTO_TCP
88 for TCP sockets, and 0 and
89 .B IPPROTO_UDP
90 for UDP sockets.
91 For
92 .B SOCK_RAW
93 you may specify a valid IANA IP protocol defined in
94 RFC\ 1700 assigned numbers.
95 .PP
96 When a process wants to receive new incoming packets or connections, it
97 should bind a socket to a local interface address using
98 .BR bind (2).
99 In this case, only one IP socket may be bound to any given local
100 (address, port) pair.
101 When
102 .B INADDR_ANY
103 is specified in the bind call, the socket will be bound to
104 .I all
105 local interfaces.
106 When
107 .BR listen (2)
108 is called on an unbound socket, the socket is automatically bound
109 to a random free port with the local address set to
110 .BR INADDR_ANY .
111 When
112 .BR connect (2)
113 is called on an unbound socket, the socket is automatically bound
114 to a random free port or to a usable shared port with the local address
115 set to
116 .BR INADDR_ANY .
117
118 A TCP local socket address that has been bound is unavailable for
119 some time after closing, unless the
120 .B SO_REUSEADDR
121 flag has been set.
122 Care should be taken when using this flag as it makes TCP less reliable.
123 .SS Address format
124 An IP socket address is defined as a combination of an IP interface
125 address and a 16-bit port number.
126 The basic IP protocol does not supply port numbers, they
127 are implemented by higher level protocols like
128 .BR udp (7)
129 and
130 .BR tcp (7).
131 On raw sockets
132 .I sin_port
133 is set to the IP protocol.
134 .PP
135 .in +4n
136 .nf
137 struct sockaddr_in {
138     sa_family_t    sin_family; /* address family: AF_INET */
139     in_port_t      sin_port;   /* port in network byte order */
140     struct in_addr sin_addr;   /* internet address */
141 };
142
143 /* Internet address. */
144 struct in_addr {
145     uint32_t       s_addr;     /* address in network byte order */
146 };
147 .fi
148 .in
149 .PP
150 .I sin_family
151 is always set to
152 .BR AF_INET .
153 This is required; in Linux 2.2 most networking functions return
154 .B EINVAL
155 when this setting is missing.
156 .I sin_port
157 contains the port in network byte order.
158 The port numbers below 1024 are called
159 .IR "privileged ports"
160 (or sometimes:
161 .IR "reserved ports" ).
162 Only privileged processes (i.e., those having the
163 .B CAP_NET_BIND_SERVICE
164 capability) may
165 .BR bind (2)
166 to these sockets.
167 Note that the raw IPv4 protocol as such has no concept of a
168 port, they are implemented only by higher protocols like
169 .BR tcp (7)
170 and
171 .BR udp (7).
172 .PP
173 .I sin_addr
174 is the IP host address.
175 The
176 .I s_addr
177 member of
178 .I struct in_addr
179 contains the host interface address in network byte order.
180 .I in_addr
181 should be assigned one of the
182 .BR INADDR_*
183 values (e.g.,
184 .BR INADDR_ANY )
185 or set using the
186 .BR inet_aton (3),
187 .BR inet_addr (3),
188 .BR inet_makeaddr (3)
189 library functions or directly with the name resolver (see
190 .BR gethostbyname (3)).
191
192 IPv4 addresses are divided into unicast, broadcast
193 and multicast addresses.
194 Unicast addresses specify a single interface of a host,
195 broadcast addresses specify all hosts on a network and multicast
196 addresses address all hosts in a multicast group.
197 Datagrams to broadcast addresses can be sent or received only when the
198 .B SO_BROADCAST
199 socket flag is set.
200 In the current implementation, connection-oriented sockets are allowed
201 to use only unicast addresses.
202 .\" Leave a loophole for XTP @)
203
204 Note that the address and the port are always stored in
205 network byte order.
206 In particular, this means that you need to call
207 .BR htons (3)
208 on the number that is assigned to a port.
209 All address/port manipulation
210 functions in the standard library work in network byte order.
211
212 There are several special addresses:
213 .B INADDR_LOOPBACK
214 (127.0.0.1)
215 always refers to the local host via the loopback device;
216 .B INADDR_ANY
217 (0.0.0.0)
218 means any address for binding;
219 .B INADDR_BROADCAST
220 (255.255.255.255)
221 means any host and has the same effect on bind as
222 .B INADDR_ANY
223 for historical reasons.
224 .SS Socket options
225 IP supports some protocol-specific socket options that can be set with
226 .BR setsockopt (2)
227 and read with
228 .BR getsockopt (2).
229 The socket option level for IP is
230 .BR IPPROTO_IP .
231 .\" or SOL_IP on Linux
232 A boolean integer flag is zero when it is false, otherwise true.
233 .TP
234 .BR IP_ADD_MEMBERSHIP " (since Linux 1.2)"
235 Join a multicast group.
236 Argument is an
237 .I ip_mreqn
238 structure.
239 .sp
240 .in +4n
241 .nf
242 struct ip_mreqn {
243     struct in_addr imr_multiaddr; /* IP multicast group
244                                      address */
245     struct in_addr imr_address;   /* IP address of local
246                                      interface */
247     int            imr_ifindex;   /* interface index */
248 };
249 .fi
250 .in
251 .sp
252 .I imr_multiaddr
253 contains the address of the multicast group the application
254 wants to join or leave.
255 It must be a valid multicast address
256 .\" (i.e., within the 224.0.0.0-239.255.255.255 range)
257 (or
258 .BR setsockopt (2)
259 fails with the error
260 .BR EINVAL ).
261 .I imr_address
262 is the address of the local interface with which the system
263 should join the multicast group; if it is equal to
264 .BR INADDR_ANY ,
265 an appropriate interface is chosen by the system.
266 .I imr_ifindex
267 is the interface index of the interface that should join/leave the
268 .I imr_multiaddr
269 group, or 0 to indicate any interface.
270 .IP
271 The
272 .I ip_mreqn
273 structure is available only since Linux 2.2.
274 For compatibility, the old
275 .I ip_mreq
276 structure (present since Linux 1.2) is still supported;
277 it differs from
278 .I ip_mreqn
279 only by not including the
280 .I imr_ifindex
281 field.
282 Only valid as a
283 .BR setsockopt (2).
284 .\"
285 .TP
286 .BR IP_ADD_SOURCE_MEMBERSHIP " (since Linux 2.4.22 / 2.5.68)"
287 Join a multicast group and allow receiving data only
288 from a specified source.
289 Argument is an
290 .I ip_mreq_source
291 structure.
292 .sp
293 .in +4n
294 .nf
295 struct ip_mreq_source {
296     struct in_addr imr_multiaddr;  /* IP multicast group
297                                       address */
298     struct in_addr imr_interface;  /* IP address of local
299                                       interface */
300     struct in_addr imr_sourceaddr; /* IP address of
301                                       multicast source */
302 };
303 .fi
304 .in
305 .sp
306 The
307 .I ip_mreq_source
308 structure is similar to
309 .I ip_mreqn
310 described under
311 .BR IP_ADD_MEMBERSIP .
312 The
313 .I imr_multiaddr
314 field contains the address of the multicast group the application
315 wants to join or leave.
316 The
317 .I imr_interface
318 field is the address of the local interface with which
319 the system should join the multicast group.
320 Finally, the
321 .I imr_sourceaddr
322 field contains the address of the source the
323 application wants to receive data from.
324 .IP
325 This option can be used multiple times to allow
326 receiving data from more than one source.
327 .TP
328 .BR IP_BLOCK_SOURCE " (since Linux 2.4.22 / 2.5.68)"
329 Stop receiving multicast data from a specific source in a given group.
330 This is valid only after the application has subscribed
331 to the multicast group using either
332 .BR IP_ADD_MEMBERSHIP
333 or
334 .BR IP_ADD_SOURCE_MEMBERSHIP .
335 .IP
336 Argument is an
337 .I ip_mreq_source
338 structure as described under
339 .BR IP_ADD_SOURCE_MEMBERSHIP .
340 .TP
341 .BR IP_DROP_MEMBERSHIP " (since Linux 1.2)"
342 Leave a multicast group.
343 Argument is an
344 .I ip_mreqn
345 or
346 .I ip_mreq
347 structure similar to
348 .BR IP_ADD_MEMBERSHIP .
349 .TP
350 .BR IP_DROP_SOURCE_MEMBERSHIP " (since Linux 2.4.22 / 2.5.68)"
351 Leave a source-specific group\(emthat is, stop receiving data from
352 a given multicast group that come from a given source.
353 If the application has subscribed to multiple sources within
354 the same group, data from the remaining sources will still be delivered.
355 To stop receiving data from all sources at once, use
356 .BR IP_LEAVE_GROUP .
357 .IP
358 Argument is an
359 .I ip_mreq_source
360 structure as described under
361 .BR IP_ADD_SOURCE_MEMBERSHIP .
362 .TP
363 .BR IP_FREEBIND " (since Linux 2.4)"
364 .\" Precisely: 2.4.0-test10
365 If enabled, this boolean option allows binding to an IP address
366 that is nonlocal or does not (yet) exist.
367 This permits listening on a socket,
368 without requiring the underlying network interface or the
369 specified dynamic IP address to be up at the time that
370 the application is trying to bind to it.
371 This option is the per-socket equivalent of the
372 .IR ip_nonlocal_bind
373 .I /proc
374 interface described below.
375 .TP
376 .BR IP_HDRINCL " (since Linux 2.0)"
377 If enabled,
378 the user supplies an IP header in front of the user data.
379 Only valid for
380 .B SOCK_RAW
381 sockets.
382 See
383 .BR raw (7)
384 for more information.
385 When this flag is enabled the values set by
386 .BR IP_OPTIONS ,
387 .B IP_TTL
388 and
389 .B IP_TOS
390 are ignored.
391 .TP
392 .BR IP_MSFILTER " (since Linux 2.4.22 / 2.5.68)"
393 This option provides access to the advanced full-state filtering API.
394 Argument is an
395 .I ip_msfilter
396 structure.
397 .sp
398 .in +4n
399 .nf
400 struct ip_msfilter {
401     struct in_addr imsf_multiaddr; /* IP multicast group
402                                       address */
403     struct in_addr imsf_interface; /* IP address of local
404                                       interface */
405     uint32_t       imsf_fmode;     /* Filter-mode */
406
407     uint32_t       imsf_numsrc;    /* Number of sources in
408                                       the following array */
409     struct in_addr imsf_slist[1];  /* Array of source
410                                       addresses */
411 };
412 .fi
413 .in
414 .sp
415 There are two macros,
416 .BR MCAST_INCLUDE
417 and
418 .BR MCAST_EXCLUDE ,
419 which can be used to specify the filtering mode.
420 Additionally, the
421 .BR IP_MSFILTER_SIZE (n)
422 macro exists to determine how much memory is needed to store
423 .I ip_msfilter
424 structure with
425 .I n
426 sources in the source list.
427 .IP
428 For the full description of multicast source filtering
429 refer to RFC 3376.
430 .TP
431 .BR IP_MTU " (since Linux 2.2)"
432 .\" Precisely: 2.1.124
433 Retrieve the current known path MTU of the current socket.
434 Valid only when the socket has been connected.
435 Returns an integer.
436 Only valid as a
437 .BR getsockopt (2).
438 .TP
439 .BR IP_MTU_DISCOVER " (since Linux 2.2)"
440 .\" Precisely: 2.1.124
441 Set or receive the Path MTU Discovery setting for a socket.
442 When enabled, Linux will perform Path MTU Discovery
443 as defined in RFC\ 1191 on
444 .B SOCK_STREAM
445 sockets.
446 For
447 .RB non- SOCK_STREAM
448 sockets,
449 .B IP_PMTUDISC_DO
450 forces the don't-fragment flag to be set on all outgoing packets.
451 It is the user's responsibility to packetize the data
452 in MTU-sized chunks and to do the retransmits if necessary.
453 The kernel will reject (with
454 .BR EMSGSIZE )
455 datagrams that are bigger than the known path MTU.
456 .B IP_PMTUDISC_WANT
457 will fragment a datagram if needed according to the path MTU,
458 or will set the don't-fragment flag otherwise.
459
460 The system-wide default can be toggled between
461 .B IP_PMTUDISC_WANT
462 and
463 .B IP_PMTUDISC_DONT
464 by writing (respectively, zero and nonzero values) to the
465 .I /proc/sys/net/ipv4/ip_no_pmtu_disc
466 file.
467 .TS
468 tab(:);
469 c l
470 l l.
471 Path MTU discovery value:Meaning
472 IP_PMTUDISC_WANT:Use per-route settings.
473 IP_PMTUDISC_DONT:Never do Path MTU Discovery.
474 IP_PMTUDISC_DO:Always do Path MTU Discovery.
475 IP_PMTUDISC_PROBE:Set DF but ignore Path MTU.
476 .TE
477
478 When PMTU discovery is enabled, the kernel automatically keeps track of
479 the path MTU per destination host.
480 When it is connected to a specific peer with
481 .BR connect (2),
482 the currently known path MTU can be retrieved conveniently using the
483 .B IP_MTU
484 socket option (e.g., after an
485 .B EMSGSIZE
486 error occurred).
487 The path MTU may change over time.
488 For connectionless sockets with many destinations,
489 the new MTU for a given destination can also be accessed using the
490 error queue (see
491 .BR IP_RECVERR ).
492 A new error will be queued for every incoming MTU update.
493
494 While MTU discovery is in progress, initial packets from datagram sockets
495 may be dropped.
496 Applications using UDP should be aware of this and not
497 take it into account for their packet retransmit strategy.
498
499 To bootstrap the path MTU discovery process on unconnected sockets, it
500 is possible to start with a big datagram size
501 (up to 64K-headers bytes long) and let it shrink by updates of the path MTU.
502 .\" FIXME this is an ugly hack
503
504 To get an initial estimate of the
505 path MTU, connect a datagram socket to the destination address using
506 .BR connect (2)
507 and retrieve the MTU by calling
508 .BR getsockopt (2)
509 with the
510 .B IP_MTU
511 option.
512
513 It is possible to implement RFC 4821 MTU probing with
514 .B SOCK_DGRAM
515 or
516 .B SOCK_RAW
517 sockets by setting a value of
518 .BR IP_PMTUDISC_PROBE
519 (available since Linux 2.6.22).
520 This is also particularly useful for diagnostic tools such as
521 .BR tracepath (8)
522 that wish to deliberately send probe packets larger than
523 the observed Path MTU.
524 .TP
525 .BR IP_MULTICAST_ALL " (since Linux 2.6.31)"
526 This option can be used to modify the delivery policy of multicast messages
527 to sockets bound to the wildcard
528 .B INADDR_ANY
529 address.
530 The argument is a boolean integer (defaults to 1).
531 If set to 1,
532 the socket will receive messages from all the groups that have been joined
533 globally on the whole system.
534 Otherwise, it will deliver messages only from
535 the groups that have been explicitly joined (for example via the
536 .B IP_ADD_MEMBERSHIP
537 option) on this particular socket.
538 .TP
539 .BR IP_MULTICAST_IF " (since Linux 1.2)"
540 Set the local device for a multicast socket.
541 Argument is an
542 .I ip_mreqn
543 or
544 .I ip_mreq
545 .\" net: IP_MULTICAST_IF setsockopt now recognizes struct mreq
546 .\" Commit: 3a084ddb4bf299a6e898a9a07c89f3917f0713f7
547 (since Linux 3.5)
548 structure similar to
549 .BR IP_ADD_MEMBERSHIP .
550 .IP
551 When an invalid socket option is passed,
552 .B ENOPROTOOPT
553 is returned.
554 .TP
555 .BR IP_MULTICAST_LOOP " (since Linux 1.2)"
556 Set or read a boolean integer argument that determines whether
557 sent multicast packets should be looped back to the local sockets.
558 .TP
559 .BR IP_MULTICAST_TTL " (since Linux 1.2)"
560 Set or read the time-to-live value of outgoing multicast packets for this
561 socket.
562 It is very important for multicast packets to set the smallest TTL possible.
563 The default is 1 which means that multicast packets don't leave the local
564 network unless the user program explicitly requests it.
565 Argument is an integer.
566 .TP
567 .BR IP_NODEFRAG " (since Linux 2.6.36)"
568 If enabled (argument is nonzero),
569 the reassembly of outgoing packets is disabled in the netfilter layer.
570 This option is valid only for
571 .B SOCK_RAW
572 sockets.
573 The argument is an integer.
574 .TP
575 .BR IP_OPTIONS " (since Linux 2.0)"
576 .\" Precisely: 1.3.30
577 Set or get the IP options to be sent with every packet from this socket.
578 The arguments are a pointer to a memory buffer containing the options
579 and the option length.
580 The
581 .BR setsockopt (2)
582 call sets the IP options associated with a socket.
583 The maximum option size for IPv4 is 40 bytes.
584 See RFC\ 791 for the allowed options.
585 When the initial connection request packet for a
586 .B SOCK_STREAM
587 socket contains IP options, the IP options will be set automatically
588 to the options from the initial packet with routing headers reversed.
589 Incoming packets are not allowed to change options after the connection
590 is established.
591 The processing of all incoming source routing options
592 is disabled by default and can be enabled by using the
593 .I accept_source_route
594 .I /proc
595 interface.
596 Other options like timestamps are still handled.
597 For datagram sockets, IP options can be only set by the local user.
598 Calling
599 .BR getsockopt (2)
600 with
601 .B IP_OPTIONS
602 puts the current IP options used for sending into the supplied buffer.
603 .TP
604 .BR IP_PKTINFO " (since Linux 2.2)"
605 .\" Precisely: 2.1.68
606 Pass an
607 .B IP_PKTINFO
608 ancillary message that contains a
609 .I pktinfo
610 structure that supplies some information about the incoming packet.
611 This only works for datagram oriented sockets.
612 The argument is a flag that tells the socket whether the
613 .B IP_PKTINFO
614 message should be passed or not.
615 The message itself can only be sent/retrieved
616 as control message with a packet using
617 .BR recvmsg (2)
618 or
619 .BR sendmsg (2).
620 .IP
621 .in +4n
622 .nf
623 struct in_pktinfo {
624     unsigned int   ipi_ifindex;  /* Interface index */
625     struct in_addr ipi_spec_dst; /* Local address */
626     struct in_addr ipi_addr;     /* Header Destination
627                                     address */
628 };
629 .fi
630 .in
631 .IP
632 .\" FIXME elaborate on that.
633 .I ipi_ifindex
634 is the unique index of the interface the packet was received on.
635 .I ipi_spec_dst
636 is the local address of the packet and
637 .I ipi_addr
638 is the destination address in the packet header.
639 If
640 .B IP_PKTINFO
641 is passed to
642 .BR sendmsg (2)
643 and
644 .\" This field is grossly misnamed
645 .I ipi_spec_dst
646 is not zero, then it is used as the local source address for the routing
647 table lookup and for setting up IP source route options.
648 When
649 .I ipi_ifindex
650 is not zero, the primary local address of the interface specified by the
651 index overwrites
652 .I ipi_spec_dst
653 for the routing table lookup.
654 .TP
655 .BR IP_RECVERR " (since Linux 2.2)"
656 .\" Precisely: 2.1.15
657 Enable extended reliable error message passing.
658 When enabled on a datagram socket, all
659 generated errors will be queued in a per-socket error queue.
660 When the user receives an error from a socket operation,
661 the errors can be received by calling
662 .BR recvmsg (2)
663 with the
664 .B MSG_ERRQUEUE
665 flag set.
666 The
667 .I sock_extended_err
668 structure describing the error will be passed in an ancillary message with
669 the type
670 .B IP_RECVERR
671 and the level
672 .BR IPPROTO_IP .
673 .\" or SOL_IP on Linux
674 This is useful for reliable error handling on unconnected sockets.
675 The received data portion of the error queue contains the error packet.
676 .IP
677 The
678 .B IP_RECVERR
679 control message contains a
680 .I sock_extended_err
681 structure:
682 .IP
683 .in +4n
684 .ne 18
685 .nf
686 #define SO_EE_ORIGIN_NONE    0
687 #define SO_EE_ORIGIN_LOCAL   1
688 #define SO_EE_ORIGIN_ICMP    2
689 #define SO_EE_ORIGIN_ICMP6   3
690
691 struct sock_extended_err {
692     uint32_t ee_errno;   /* error number */
693     uint8_t  ee_origin;  /* where the error originated */
694     uint8_t  ee_type;    /* type */
695     uint8_t  ee_code;    /* code */
696     uint8_t  ee_pad;
697     uint32_t ee_info;    /* additional information */
698     uint32_t ee_data;    /* other data */
699     /* More data may follow */
700 };
701
702 struct sockaddr *SO_EE_OFFENDER(struct sock_extended_err *);
703 .fi
704 .in
705 .IP
706 .I ee_errno
707 contains the
708 .I errno
709 number of the queued error.
710 .I ee_origin
711 is the origin code of where the error originated.
712 The other fields are protocol-specific.
713 The macro
714 .B SO_EE_OFFENDER
715 returns a pointer to the address of the network object
716 where the error originated from given a pointer to the ancillary message.
717 If this address is not known, the
718 .I sa_family
719 member of the
720 .I sockaddr
721 contains
722 .B AF_UNSPEC
723 and the other fields of the
724 .I sockaddr
725 are undefined.
726 .IP
727 IP uses the
728 .I sock_extended_err
729 structure as follows:
730 .I ee_origin
731 is set to
732 .B SO_EE_ORIGIN_ICMP
733 for errors received as an ICMP packet, or
734 .B SO_EE_ORIGIN_LOCAL
735 for locally generated errors.
736 Unknown values should be ignored.
737 .I ee_type
738 and
739 .I ee_code
740 are set from the type and code fields of the ICMP header.
741 .I ee_info
742 contains the discovered MTU for
743 .B EMSGSIZE
744 errors.
745 The message also contains the
746 .I sockaddr_in of the node
747 caused the error, which can be accessed with the
748 .B SO_EE_OFFENDER
749 macro.
750 The
751 .I sin_family
752 field of the
753 .B SO_EE_OFFENDER
754 address is
755 .B AF_UNSPEC
756 when the source was unknown.
757 When the error originated from the network, all IP options
758 .RB ( IP_OPTIONS ", " IP_TTL ", "
759 etc.) enabled on the socket and contained in the
760 error packet are passed as control messages.
761 The payload of the packet causing the error is returned as normal payload.
762 .\" FIXME . Is it a good idea to document that? It is a dubious feature.
763 .\" On
764 .\" .B SOCK_STREAM
765 .\" sockets,
766 .\" .B IP_RECVERR
767 .\" has slightly different semantics. Instead of
768 .\" saving the errors for the next timeout, it passes all incoming
769 .\" errors immediately to the user.
770 .\" This might be useful for very short-lived TCP connections which
771 .\" need fast error handling. Use this option with care:
772 .\" it makes TCP unreliable
773 .\" by not allowing it to recover properly from routing
774 .\" shifts and other normal
775 .\" conditions and breaks the protocol specification.
776 Note that TCP has no error queue;
777 .B MSG_ERRQUEUE
778 is not permitted on
779 .B SOCK_STREAM
780 sockets.
781 .B IP_RECVERR
782 is valid for TCP, but all errors are returned by socket function return or
783 .B SO_ERROR
784 only.
785 .IP
786 For raw sockets,
787 .B IP_RECVERR
788 enables passing of all received ICMP errors to the
789 application, otherwise errors are only reported on connected sockets
790 .IP
791 It sets or retrieves an integer boolean flag.
792 .B IP_RECVERR
793 defaults to off.
794 .TP
795 .BR IP_RECVOPTS " (since Linux 2.2)"
796 .\" Precisely: 2.1.15
797 Pass all incoming IP options to the user in a
798 .B IP_OPTIONS
799 control message.
800 The routing header and other options are already filled in
801 for the local host.
802 Not supported for
803 .B SOCK_STREAM
804 sockets.
805 .TP
806 .BR IP_RECVORIGDSTADDR " (since Linux 2.6.29)"
807 .\" commit e8b2dfe9b4501ed0047459b2756ba26e5a940a69
808 This boolean option enables the
809 .B IP_ORIGDSTADDR
810 ancillary message in
811 .BR recvmsg (2),
812 in which the kernel returns the original destination address
813 of the datagram being received.
814 The ancillary message contains a
815 .IR "struct sockaddr_in" .
816 .TP
817 .BR IP_RECVTOS " (since Linux 2.2)"
818 .\" Precisely: 2.1.68
819 If enabled, the
820 .B IP_TOS
821 ancillary message is passed with incoming packets.
822 It contains a byte which specifies the Type of Service/Precedence
823 field of the packet header.
824 Expects a boolean integer flag.
825 .TP
826 .BR IP_RECVTTL " (since Linux 2.2)"
827 .\" Precisely: 2.1.68
828 When this flag is set, pass a
829 .B IP_TTL
830 control message with the time to live
831 field of the received packet as a byte.
832 Not supported for
833 .B SOCK_STREAM
834 sockets.
835 .TP
836 .BR IP_RETOPTS " (since Linux 2.2)"
837 .\" Precisely: 2.1.15
838 Identical to
839 .BR IP_RECVOPTS ,
840 but returns raw unprocessed options with timestamp and route record
841 options not filled in for this hop.
842 .TP
843 .BR IP_ROUTER_ALERT " (since Linux 2.2)"
844 .\" Precisely: 2.1.68
845 Pass all to-be forwarded packets with the
846 IP Router Alert option set to this socket.
847 Only valid for raw sockets.
848 This is useful, for instance, for user-space RSVP daemons.
849 The tapped packets are not forwarded by the kernel; it is
850 the user's responsibility to send them out again.
851 Socket binding is ignored,
852 such packets are only filtered by protocol.
853 Expects an integer flag.
854 .TP
855 .BR IP_TOS " (since Linux 1.0)"
856 Set or receive the Type-Of-Service (TOS) field that is sent
857 with every IP packet originating from this socket.
858 It is used to prioritize packets on the network.
859 TOS is a byte.
860 There are some standard TOS flags defined:
861 .B IPTOS_LOWDELAY
862 to minimize delays for interactive traffic,
863 .B IPTOS_THROUGHPUT
864 to optimize throughput,
865 .B IPTOS_RELIABILITY
866 to optimize for reliability,
867 .B IPTOS_MINCOST
868 should be used for "filler data" where slow transmission doesn't matter.
869 At most one of these TOS values can be specified.
870 Other bits are invalid and shall be cleared.
871 Linux sends
872 .B IPTOS_LOWDELAY
873 datagrams first by default,
874 but the exact behavior depends on the configured queueing discipline.
875 .\" FIXME elaborate on this
876 Some high priority levels may require superuser privileges (the
877 .B CAP_NET_ADMIN
878 capability).
879 The priority can also be set in a protocol independent way by the
880 .RB ( SOL_SOCKET ", " SO_PRIORITY )
881 socket option (see
882 .BR socket (7)).
883 .\" Needs CAP_NET_ADMIN
884 .\" Boolean
885 .\" Since Linux 2.6.27
886 .\" Author: KOVACS Krisztian <hidden@sch.bme.hu>
887 .\" http://lwn.net/Articles/252545/
888 .TP
889 .BR IP_TRANSPARENT " (since Linux 2.6.24)"
890 .\" commit f5715aea4564f233767ea1d944b2637a5fd7cd2e
891 .\"     This patch introduces the IP_TRANSPARENT socket option: enabling that
892 .\"     will make the IPv4 routing omit the non-local source address check on
893 .\"     output. Setting IP_TRANSPARENT requires NET_ADMIN capability.
894 .\" http://lwn.net/Articles/252545/
895 Setting this boolean option enables transparent proxying on this socket.
896 This socket option allows
897 the calling application to bind to a nonlocal IP address and operate
898 both as a client and a server with the foreign address as the local endpoint.
899 NOTE: this requires that routing be set up in a way that
900 packets going to the foreign address are routed through the TProxy box
901 (i.e., the system hosting the application that employs the
902 .B IP_TRANSPARENT
903 socket option).
904 Enabling this socket option requires superuser privileges
905 (the
906 .BR CAP_NET_ADMIN
907 capability).
908 .IP
909 TProxy redirection with the iptables TPROXY target also requires that
910 this option be set on the redirected socket.
911 .TP
912 .BR IP_TTL " (since Linux 1.0)"
913 Set or retrieve the current time-to-live field that is used in every packet
914 sent from this socket.
915 .TP
916 .BR IP_UNBLOCK_SOURCE " (since Linux 2.4.22 / 2.5.68)"
917 Unblock previously blocked multicast source.
918 Returns
919 .BR EADDRNOTAVAIL
920 when given source is not being blocked.
921 .IP
922 Argument is an
923 .I ip_mreq_source
924 structure as described under
925 .BR IP_ADD_SOURCE_MEMBERSHIP .
926 .SS /proc interfaces
927 The IP protocol
928 supports a set of
929 .I /proc
930 interfaces to configure some global parameters.
931 The parameters can be accessed by reading or writing files in the directory
932 .IR /proc/sys/net/ipv4/ .
933 .\" FIXME As at 2.6.12, 14 Jun 2005, the following are undocumented:
934 .\"     ip_queue_maxlen
935 .\"     ip_conntrack_max
936 Interfaces described as
937 .I Boolean
938 take an integer value, with a nonzero value ("true") meaning that
939 the corresponding option is enabled, and a zero value ("false")
940 meaning that the option is disabled.
941 .\"
942 .TP
943 .IR ip_always_defrag " (Boolean; since Linux 2.2.13)"
944 [New with kernel 2.2.13; in earlier kernel versions this feature
945 was controlled at compile time by the
946 .B CONFIG_IP_ALWAYS_DEFRAG
947 option; this option is not present in 2.4.x and later]
948
949 When this boolean flag is enabled (not equal 0), incoming fragments
950 (parts of IP packets
951 that arose when some host between origin and destination decided
952 that the packets were too large and cut them into pieces) will be
953 reassembled (defragmented) before being processed, even if they are
954 about to be forwarded.
955
956 Only enable if running either a firewall that is the sole link
957 to your network or a transparent proxy; never ever use it for a
958 normal router or host.
959 Otherwise, fragmented communication can be disturbed
960 if the fragments travel over different links.
961 Defragmentation also has a large memory and CPU time cost.
962
963 This is automagically turned on when masquerading or transparent
964 proxying are configured.
965 .\"
966 .TP
967 .IR ip_autoconfig " (since Linux 2.2 to 2.6.17)"
968 .\" Precisely: since 2.1.68
969 .\" FIXME document ip_autoconfig
970 Not documented.
971 .\"
972 .TP
973 .IR ip_default_ttl " (integer; default: 64; since Linux 2.2)"
974 .\" Precisely: 2.1.15
975 Set the default time-to-live value of outgoing packets.
976 This can be changed per socket with the
977 .B IP_TTL
978 option.
979 .\"
980 .TP
981 .IR ip_dynaddr " (Boolean; default: disabled; since Linux 2.0.31)"
982 Enable dynamic socket address and masquerading entry rewriting on interface
983 address change.
984 This is useful for dialup interface with changing IP addresses.
985 0 means no rewriting, 1 turns it on and 2 enables verbose mode.
986 .\"
987 .TP
988 .IR ip_forward " (Boolean; default: disabled; since Linux 1.2)"
989 Enable IP forwarding with a boolean flag.
990 IP forwarding can be also set on a per-interface basis.
991 .\"
992 .TP
993 .IR ip_local_port_range " (since Linux 2.2)"
994 .\" Precisely: since 2.1.68
995 This file contains two integers that define the default local port range
996 allocated to sockets that are not explicitly bound to a port number\(emthat
997 is, the range used for
998 .IR "ephemeral ports" .
999 An ephemeral port is allocated to a socket in the following circumstances:
1000 .RS
1001 .IP * 3
1002 the port number in a socket address is specified as 0 when calling
1003 .BR bind (2);
1004 .IP *
1005 .BR listen (2)
1006 is called on a stream socket that was not previously bound;
1007 .IP *
1008 .BR connect (2)
1009 was called on a socket that was not not previously bound;
1010 .IP *
1011 .BR sendto (2)
1012 is called on a datagram socket that was not not previously bound.
1013 .RE
1014 .IP
1015 Allocation of ephemeral ports starts with the first number in
1016 .IR ip_local_port_range
1017 and ends with the second number.
1018 If the range of ephemeral ports is exhausted,
1019 then the relevant system call returns an error (but see BUGS)
1020 .IP
1021 Note that the port range in
1022 .IR ip_local_port_range
1023 should not conflict with the ports used by masquerading
1024 (although the case is handled).
1025 Also, arbitrary choices may cause problems with some firewall packet
1026 filters that make assumptions about the local ports in use.
1027 The first number should be at least greater than 1024,
1028 or better, greater than 4096, to avoid clashes
1029 with well known ports and to minimize firewall problems.
1030 .\"
1031 .TP
1032 .IR ip_no_pmtu_disc " (Boolean; default: disabled; since Linux 2.2)"
1033 .\" Precisely: 2.1.15
1034 If enabled, don't do Path MTU Discovery for TCP sockets by default.
1035 Path MTU discovery may fail if misconfigured firewalls (that drop
1036 all ICMP packets) or misconfigured interfaces (e.g., a point-to-point
1037 link where the both ends don't agree on the MTU) are on the path.
1038 It is better to fix the broken routers on the path than to turn off
1039 Path MTU Discovery globally, because not doing it incurs a high cost
1040 to the network.
1041 .\"
1042 .\" The following is from 2.6.12: Documentation/networking/ip-sysctl.txt
1043 .TP
1044 .IR ip_nonlocal_bind " (Boolean; default: disabled; since Linux 2.4)"
1045 .\" Precisely: patch-2.4.0-test10
1046 If set, allows processes to
1047 .BR bind (2)
1048 to nonlocal IP addresses,
1049 which can be quite useful, but may break some applications.
1050 .\"
1051 .\" The following is from 2.6.12: Documentation/networking/ip-sysctl.txt
1052 .TP
1053 .IR ip6frag_time " (integer; default: 30)"
1054 Time in seconds to keep an IPv6 fragment in memory.
1055 .\"
1056 .\" The following is from 2.6.12: Documentation/networking/ip-sysctl.txt
1057 .TP
1058 .IR ip6frag_secret_interval " (integer; default: 600)"
1059 Regeneration interval (in seconds) of the hash secret (or lifetime
1060 for the hash secret) for IPv6 fragments.
1061 .TP
1062 .IR ipfrag_high_thresh " (integer), " ipfrag_low_thresh " (integer)"
1063 If the amount of queued IP fragments reaches
1064 .IR ipfrag_high_thresh ,
1065 the queue is pruned down to
1066 .IR ipfrag_low_thresh .
1067 Contains an integer with the number of bytes.
1068 .TP
1069 .I neigh/*
1070 See
1071 .BR arp (7).
1072 .\" FIXME Document the conf/*/* interfaces
1073 .\" FIXME Document the route/* interfaces
1074 .\" FIXME document them all
1075 .SS Ioctls
1076 All ioctls described in
1077 .BR socket (7)
1078 apply to
1079 .BR ip .
1080 .\" 2006-04-02, mtk
1081 .\" commented out the following because ipchains is obsolete
1082 .\" .PP
1083 .\" The ioctls to configure firewalling are documented in
1084 .\" .BR ipfw (4)
1085 .\" from the
1086 .\" .B ipchains
1087 .\" package.
1088 .PP
1089 Ioctls to configure generic device parameters are described in
1090 .BR netdevice (7).
1091 .\" FIXME Add a discussion of multicasting
1092 .SH ERRORS
1093 .\" FIXME document all errors.
1094 .\"     We should really fix the kernels to give more uniform
1095 .\"     error returns (ENOMEM vs ENOBUFS, EPERM vs EACCES etc.)
1096 .TP
1097 .B EACCES
1098 The user tried to execute an operation without the necessary permissions.
1099 These include:
1100 sending a packet to a broadcast address without having the
1101 .B SO_BROADCAST
1102 flag set;
1103 sending a packet via a
1104 .I prohibit
1105 route;
1106 modifying firewall settings without superuser privileges (the
1107 .B CAP_NET_ADMIN
1108 capability);
1109 binding to a privileged port without superuser privileges (the
1110 .B CAP_NET_BIND_SERVICE
1111 capability).
1112 .TP
1113 .B EADDRINUSE
1114 Tried to bind to an address already in use.
1115 .TP
1116 .B EADDRNOTAVAIL
1117 A nonexistent interface was requested or the requested source
1118 address was not local.
1119 .TP
1120 .B EAGAIN
1121 Operation on a nonblocking socket would block.
1122 .TP
1123 .B EALREADY
1124 An connection operation on a nonblocking socket is already in progress.
1125 .TP
1126 .B ECONNABORTED
1127 A connection was closed during an
1128 .BR accept (2).
1129 .TP
1130 .B EHOSTUNREACH
1131 No valid routing table entry matches the destination address.
1132 This error can be caused by a ICMP message from a remote router or
1133 for the local routing table.
1134 .TP
1135 .B EINVAL
1136 Invalid argument passed.
1137 For send operations this can be caused by sending to a
1138 .I blackhole
1139 route.
1140 .TP
1141 .B EISCONN
1142 .BR connect (2)
1143 was called on an already connected socket.
1144 .TP
1145 .B EMSGSIZE
1146 Datagram is bigger than an MTU on the path and it cannot be fragmented.
1147 .TP
1148 .BR ENOBUFS ", " ENOMEM
1149 Not enough free memory.
1150 This often means that the memory allocation is limited by the socket
1151 buffer limits, not by the system memory, but this is not 100% consistent.
1152 .TP
1153 .B ENOENT
1154 .B SIOCGSTAMP
1155 was called on a socket where no packet arrived.
1156 .TP
1157 .B ENOPKG
1158 A kernel subsystem was not configured.
1159 .TP
1160 .BR ENOPROTOOPT " and " EOPNOTSUPP
1161 Invalid socket option passed.
1162 .TP
1163 .B ENOTCONN
1164 The operation is defined only on a connected socket, but the socket wasn't
1165 connected.
1166 .TP
1167 .B EPERM
1168 User doesn't have permission to set high priority, change configuration,
1169 or send signals to the requested process or group.
1170 .TP
1171 .B EPIPE
1172 The connection was unexpectedly closed or shut down by the other end.
1173 .TP
1174 .B ESOCKTNOSUPPORT
1175 The socket is not configured or an unknown socket type was requested.
1176 .PP
1177 Other errors may be generated by the overlaying protocols; see
1178 .BR tcp (7),
1179 .BR raw (7),
1180 .BR udp (7)
1181 and
1182 .BR socket (7).
1183 .SH NOTES
1184 .BR IP_FREEBIND ,
1185 .BR IP_MSFILTER ,
1186 .BR IP_MTU ,
1187 .BR IP_MTU_DISCOVER ,
1188 .BR IP_RECVORIGDSTADDR ,
1189 .BR IP_PKTINFO ,
1190 .BR IP_RECVERR ,
1191 .BR IP_ROUTER_ALERT ,
1192 and
1193 .BR IP_TRANSPARENT
1194 are Linux-specific.
1195 .\" IP_PASSSEC is Linux-specific
1196 .\" IP_XFRM_POLICY is Linux-specific
1197 .\" IP_IPSEC_POLICY is a nonstandard extension, also present on some BSDs
1198
1199 Be very careful with the
1200 .B SO_BROADCAST
1201 option \- it is not privileged in Linux.
1202 It is easy to overload the network
1203 with careless broadcasts.
1204 For new application protocols
1205 it is better to use a multicast group instead of broadcasting.
1206 Broadcasting is discouraged.
1207 .PP
1208 Some other BSD sockets implementations provide
1209 .B IP_RCVDSTADDR
1210 and
1211 .B IP_RECVIF
1212 socket options to get the destination address and the interface of
1213 received datagrams.
1214 Linux has the more general
1215 .B IP_PKTINFO
1216 for the same task.
1217 .PP
1218 Some BSD sockets implementations also provide an
1219 .B IP_RECVTTL
1220 option, but an ancillary message with type
1221 .B IP_RECVTTL
1222 is passed with the incoming packet.
1223 This is different from the
1224 .B IP_TTL
1225 option used in Linux.
1226 .PP
1227 Using
1228 .B SOL_IP
1229 socket options level isn't portable, BSD-based stacks use
1230 .B IPPROTO_IP
1231 level.
1232 .SS Compatibility
1233 For compatibility with Linux 2.0, the obsolete
1234 .BI "socket(AF_INET, SOCK_PACKET, " protocol )
1235 syntax is still supported to open a
1236 .BR packet (7)
1237 socket.
1238 This is deprecated and should be replaced by
1239 .BI "socket(AF_PACKET, SOCK_RAW, " protocol )
1240 instead.
1241 The main difference is the new
1242 .I sockaddr_ll
1243 address structure for generic link layer information instead of the old
1244 .BR sockaddr_pkt .
1245 .SH BUGS
1246 There are too many inconsistent error values.
1247 .PP
1248 The error used to diagnose exhaustion of the ephemeral port range differs
1249 across the various system calls
1250 .RB ( connect (2),
1251 .BR bind (2),
1252 .BR listen (2),
1253 .BR sendto (2))
1254 that can assign ephemeral ports.
1255 .PP
1256 The ioctls to configure IP-specific interface options and ARP tables are
1257 not described.
1258 .\" .PP
1259 .\" Some versions of glibc forget to declare
1260 .\" .IR in_pktinfo .
1261 .\" Workaround currently is to copy it into your program from this man page.
1262 .PP
1263 Receiving the original destination address with
1264 .B MSG_ERRQUEUE
1265 in
1266 .I msg_name
1267 by
1268 .BR recvmsg (2)
1269 does not work in some 2.2 kernels.
1270 .\" .SH AUTHORS
1271 .\" This man page was written by Andi Kleen.
1272 .SH SEE ALSO
1273 .BR recvmsg (2),
1274 .BR sendmsg (2),
1275 .BR byteorder (3),
1276 .BR ipfw (4),
1277 .BR capabilities (7),
1278 .BR icmp (7),
1279 .BR ipv6 (7),
1280 .BR netlink (7),
1281 .BR raw (7),
1282 .BR socket (7),
1283 .BR tcp (7),
1284 .BR udp (7)
1285 .PP
1286 RFC\ 791 for the original IP specification.
1287 RFC\ 1122 for the IPv4 host requirements.
1288 RFC\ 1812 for the IPv4 router requirements.
1289 .\" FIXME autobind INADDR REUSEADDR
1290 .SH COLOPHON
1291 This page is part of release 3.67 of the Linux
1292 .I man-pages
1293 project.
1294 A description of the project,
1295 information about reporting bugs,
1296 and the latest version of this page,
1297 can be found at
1298 \%http://www.kernel.org/doc/man\-pages/.