1.\" Copyright (c) 1983, 1991, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 3. All advertising materials mentioning features or use of this software 13.\" must display the following acknowledgement: 14.\" This product includes software developed by the University of 15.\" California, Berkeley and its contributors. 16.\" 4. Neither the name of the University nor the names of its contributors 17.\" may be used to endorse or promote products derived from this software 18.\" without specific prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" From: @(#)inet.4 8.1 (Berkeley) 6/5/93 33.\" $FreeBSD$ 34.\" 35.Dd August 15, 2004 36.Dt INET 4 37.Os 38.Sh NAME 39.Nm inet 40.Nd Internet protocol family 41.Sh SYNOPSIS 42.In sys/types.h 43.In netinet/in.h 44.Sh DESCRIPTION 45The Internet protocol family is a collection of protocols 46layered atop the 47.Em Internet Protocol 48.Pq Tn IP 49transport layer, and utilizing the Internet address format. 50The Internet family provides protocol support for the 51.Dv SOCK_STREAM , SOCK_DGRAM , 52and 53.Dv SOCK_RAW 54socket types; the 55.Dv SOCK_RAW 56interface provides access to the 57.Tn IP 58protocol. 59.Sh ADDRESSING 60Internet addresses are four byte quantities, stored in 61network standard format (on little endian machines, such as the 62.Tn alpha , 63.Tn amd64 , 64.Tn i386 65and 66.Tn ia64 67these are word and byte reversed). 68The include file 69.In netinet/in.h 70defines this address 71as a discriminated union. 72.Pp 73Sockets bound to the Internet protocol family utilize 74the following addressing structure, 75.Bd -literal -offset indent 76struct sockaddr_in { 77 uint8_t sin_len; 78 sa_family_t sin_family; 79 in_port_t sin_port; 80 struct in_addr sin_addr; 81 char sin_zero[8]; 82}; 83.Ed 84.Pp 85Sockets may be created with the local address 86.Dv INADDR_ANY 87to affect 88.Dq wildcard 89matching on incoming messages. 90The address in a 91.Xr connect 2 92or 93.Xr sendto 2 94call may be given as 95.Dv INADDR_ANY 96to mean 97.Dq this host . 98The distinguished address 99.Dv INADDR_BROADCAST 100is allowed as a shorthand for the broadcast address on the primary 101network if the first network configured supports broadcast. 102.Sh PROTOCOLS 103The Internet protocol family is comprised of 104the 105.Tn IP 106network protocol, Internet Control 107Message Protocol 108.Pq Tn ICMP , 109Internet Group Management Protocol 110.Pq Tn IGMP , 111Transmission Control 112Protocol 113.Pq Tn TCP , 114and User Datagram Protocol 115.Pq Tn UDP . 116.Tn TCP 117is used to support the 118.Dv SOCK_STREAM 119abstraction while 120.Tn UDP 121is used to support the 122.Dv SOCK_DGRAM 123abstraction. 124A raw interface to 125.Tn IP 126is available 127by creating an Internet socket of type 128.Dv SOCK_RAW . 129The 130.Tn ICMP 131message protocol is accessible from a raw socket. 132.Pp 133The 32-bit Internet address contains both network and host parts. 134However, direct examination of addresses is discouraged. 135For those 136programs which absolutely need to break addresses into their component 137parts, the following 138.Xr ioctl 2 139commands are provided for a datagram socket in the Internet domain; 140they have the same form as the 141.Dv SIOCIFADDR 142command (see 143.Xr intro 4 ) . 144.Pp 145.Bl -tag -width SIOCSIFNETMASK 146.It Dv SIOCSIFNETMASK 147Set interface network mask. 148The network mask defines the network part of the address; 149if it contains more of the address than the address type would indicate, 150then subnets are in use. 151.It Dv SIOCGIFNETMASK 152Get interface network mask. 153.El 154.Sh ROUTING 155The current implementation of Internet protocols includes some routing-table 156adaptations to provide enhanced caching of certain end-to-end 157information necessary for Transaction TCP and Path MTU Discovery. 158The 159following changes are the most significant: 160.Bl -enum 161.It 162All IP routes, except those with the 163.Dv RTF_CLONING 164flag and those to multicast destinations, have the 165.Dv RTF_PRCLONING 166flag forcibly enabled (they are thus said to be 167.Dq "protocol cloning" ) . 168.It 169When the last reference to an IP route is dropped, the route is 170examined to determine if it was created by cloning such a route. 171If this is the case, the 172.Dv RTF_PROTO3 173flag is turned on, and the expiration timer is initialized to go off 174in net.inet.ip.rtexpire seconds. 175If such a route is re-referenced, 176the flag and expiration timer are reset. 177.It 178A kernel timeout runs once every ten minutes, or sooner if there are 179soon-to-expire routes in the kernel routing table, and deletes the 180expired routes. 181.El 182.Pp 183A dynamic process is in place to modify the value of 184net.inet.ip.rtexpire if the number of cached routes grows too large. 185If after an expiration run there are still more than 186net.inet.ip.rtmaxcache unreferenced routes remaining, the rtexpire 187value is multiplied by 3/4, and any routes which have longer 188expiration times have those times adjusted. 189This process is damped somewhat by specification of a minimum rtexpire value 190(net.inet.ip.rtminexpire), and by restricting the reduction to once in 191a ten-minute period. 192.Pp 193If some external process deletes the original route from which a 194protocol-cloned route was generated, the 195.Dq child route 196is deleted. 197(This is actually a generic mechanism in the routing code support for 198protocol-requested cloning.) 199.Pp 200No attempt is made to manage routes which were not created by protocol 201cloning; these are assumed to be static, under the management of an 202external routing process, or under the management of a link layer 203(e.g., 204.Tn ARP 205for Ethernets). 206.Pp 207Only certain types of network activity will result in the cloning of a 208route using this mechanism. 209Specifically, those protocols (such as 210.Tn TCP 211and 212.Tn UDP ) 213which themselves cache a long-lasting reference to route for a destination 214will trigger the mechanism; whereas raw 215.Tn IP 216packets, whether locally-generated or forwarded, will not. 217.Ss MIB Variables 218A number of variables are implemented in the net.inet branch of the 219.Xr sysctl 3 220MIB. 221In addition to the variables supported by the transport protocols 222(for which the respective manual pages may be consulted), 223the following general variables are defined: 224.Bl -tag -width IPCTL_FASTFORWARDING 225.It Dv IPCTL_FORWARDING 226.Pq ip.forwarding 227Boolean: enable/disable forwarding of IP packets. 228Defaults to off. 229.It Dv IPCTL_FASTFORWARDING 230.Pq ip.fastforwarding 231Boolean: enable/disable the use of fast IP forwarding code. 232Defaults to off. 233When fast forwarding is enabled, IP packets are forwarded directly to 234the appropriate network interface with a minimal validity checking, which 235greatly improves the throughput. 236On the other hand, they bypass the 237standard procedures, such as IP option processing and 238.Xr ipfirewall 4 239checking. 240It is not guaranteed that every packet will be fast-forwarded. 241.It Dv IPCTL_SENDREDIRECTS 242.Pq ip.redirect 243Boolean: enable/disable sending of ICMP redirects in response to 244unforwardable 245.Tn IP 246packets. 247Defaults to on. 248.It Dv IPCTL_DEFTTL 249.Pq ip.ttl 250Integer: default time-to-live 251.Pq Dq TTL 252to use for outgoing 253.Tn IP 254packets. 255.It Dv IPCTL_ACCEPTSOURCEROUTE 256.Pq ip.accept_sourceroute 257Boolean: enable/disable accepting of source-routed IP packets (default false). 258.It Dv IPCTL_SOURCEROUTE 259.Pq ip.sourceroute 260Boolean: enable/disable forwarding of source-routed IP packets (default false). 261.It Dv IPCTL_RTEXPIRE 262.Pq ip.rtexpire 263Integer: lifetime in seconds of protocol-cloned 264.Tn IP 265routes after the last reference drops (default one hour). 266This value varies dynamically as described above. 267.It Dv IPCTL_RTMINEXPIRE 268.Pq ip.rtminexpire 269Integer: minimum value of ip.rtexpire (default ten seconds). 270This value has no effect on user modifications, but restricts the dynamic 271adaptation described above. 272.It Dv IPCTL_RTMAXCACHE 273.Pq ip.rtmaxcache 274Integer: trigger level of cached, unreferenced, protocol-cloned routes 275which initiates dynamic adaptation (default 128). 276.It Va ip.process_options 277Integer: control IP options processing. 278By setting this variable to 0, all IP options in the incoming packets 279will be ignored, and the packets will be passed unmodified. 280By setting to 1, IP options in the incoming packets will be processed 281accordingly. 282By setting to 2, an 283.Tn ICMP 284.Dq "prohibited by filter" 285message will be sent back in respose to incoming packets with IP options. 286Default is 1. 287This 288.Xr sysctl 8 289variable affects packets destined for a local host as well as packets 290forwarded to some other host. 291.It Va ip.random_id 292Boolean: control IP IDs generation behaviour. 293Setting this 294.Xr sysctl 8 295to non-zero causes the ID field in IP packets to be randomized instead of 296incremented by 1 with each packet generated. 297This closes a minor information leak which allows remote observers to 298determine the rate of packet generation on the machine by watching the 299counter. 300In the same time, on high-speed links, it can decrease the ID reuse 301cycle greatly. 302Default is 0 (sequential IP IDs). 303IPv6 flow IDs and fragment IDs are always random. 304.El 305.Sh SEE ALSO 306.Xr ioctl 2 , 307.Xr socket 2 , 308.Xr sysctl 3 , 309.Xr icmp 4 , 310.Xr intro 4 , 311.Xr ip 4 , 312.Xr ipfirewall 4 , 313.Xr tcp 4 , 314.Xr ttcp 4 , 315.Xr udp 4 316.Rs 317.%T "An Introductory 4.3 BSD Interprocess Communication Tutorial" 318.%B PS1 319.%N 7 320.Re 321.Rs 322.%T "An Advanced 4.3 BSD Interprocess Communication Tutorial" 323.%B PS1 324.%N 8 325.Re 326.Sh CAVEAT 327The Internet protocol support is subject to change as 328the Internet protocols develop. 329Users should not depend 330on details of the current implementation, but rather 331the services exported. 332.Sh HISTORY 333The 334.Nm 335protocol interface appeared in 336.Bx 4.2 . 337The 338.Dq protocol cloning 339code appeared in 340.Fx 2.1 . 341