OSDN Git Service

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