1.\" $OpenBSD: netintro.4,v 1.49 2015/09/11 13:04:05 stsp Exp $ 2.\" $NetBSD: netintro.4,v 1.4 1995/10/19 08:03:40 jtc Exp $ 3.\" 4.\" Copyright (c) 1983, 1990, 1991, 1993 5.\" The Regents of the University of California. All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 3. Neither the name of the University nor the names of its contributors 16.\" may be used to endorse or promote products derived from this software 17.\" without specific prior written permission. 18.\" 19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29.\" SUCH DAMAGE. 30.\" 31.\" @(#)netintro.4 8.2 (Berkeley) 11/30/93 32.\" 33.Dd $Mdocdate: September 11 2015 $ 34.Dt NETINTRO 4 35.Os 36.Sh NAME 37.Nm netintro 38.Nd introduction to networking facilities 39.Sh SYNOPSIS 40.In sys/socket.h 41.In net/route.h 42.In net/if.h 43.Sh DESCRIPTION 44This section is a general introduction to the networking facilities 45available in the system. 46Documentation in this part of section 474 is broken up into three areas: 48.Em protocol families 49(domains), 50.Em protocols , 51and 52.Em network interfaces . 53.Pp 54All network protocols are associated with a specific 55.Em protocol family . 56A protocol family provides basic services to the protocol 57implementation to allow it to function within a specific 58network environment. 59These services may include packet fragmentation and reassembly, routing, 60addressing, and basic transport. 61A protocol family may support multiple methods of addressing, though 62the current protocol implementations do not. 63A protocol family is normally comprised of a number of protocols, one per 64.Xr socket 2 65type. 66It is not required that a protocol family support all socket types. 67A protocol family may contain multiple protocols supporting the same socket 68abstraction. 69.Pp 70A protocol supports one of the socket abstractions detailed in 71.Xr socket 2 . 72A specific protocol may be accessed either by creating a 73socket of the appropriate type and protocol family, or 74by requesting the protocol explicitly when creating a socket. 75Protocols normally accept only one type of address format, 76usually determined by the addressing structure inherent in 77the design of the protocol family/network architecture. 78Certain semantics of the basic socket abstractions are 79protocol specific. 80All protocols are expected to support the basic model for their particular 81socket type, but may, in addition, provide non-standard facilities or 82extensions to a mechanism. 83For example, a protocol supporting the 84.Dv SOCK_STREAM 85abstraction may allow more than one byte of out-of-band 86data to be transmitted per out-of-band message. 87.Pp 88A network interface is similar to a device interface. 89Network interfaces comprise the lowest layer of the 90networking subsystem, interacting with the actual transport 91hardware. 92An interface may support one or more protocol families and/or address formats. 93The 94.Sx SYNOPSIS 95section of each network interface entry gives a sample 96specification of the related drivers for use in providing a system description 97to the 98.Xr config 8 99program. 100The 101.Sx DIAGNOSTICS 102section lists messages which may appear on the console 103and/or in the system error log, 104.Pa /var/log/messages 105(see 106.Xr syslogd 8 ) , 107due to errors in device operation. 108.Pp 109Network interfaces may be collected together into interface groups. 110An interface group is a container that can be used generically when 111referring to any interface related by some criteria. 112When an action is performed on an interface group, such as packet 113filtering by the 114.Xr pf 4 115subsystem, the operation will be applied to each member interface in the 116group, if supported by the subsystem. 117The 118.Xr ifconfig 8 119utility can be used to view and assign membership of an interface to an 120interface group with the 121.Cm group 122modifier. 123.Sh PROTOCOLS 124The system currently supports the 125Internet protocols (IPv4 and IPv6), 126MPLS, 127and a few others. 128Raw socket interfaces are provided to the 129.Tn IP 130protocol 131layer of the 132Internet. 133Consult the appropriate manual pages in this section for more 134information regarding the support for each protocol family. 135.Sh ADDRESSING 136Associated with each protocol family is an address 137format. 138All network addresses adhere to a general structure, called a 139.Vt sockaddr , 140described below. 141However, each protocol imposes a finer, more specific structure, generally 142renaming the variant, which is discussed in the protocol family manual 143page alluded to above. 144.Bd -literal -offset indent 145struct sockaddr { 146 u_int8_t sa_len; /* total length */ 147 sa_family_t sa_family; /* address family */ 148 char sa_data[14]; /* actually longer */ 149}; 150.Ed 151.Pp 152The field 153.Va sa_len 154contains the total length of the structure, 155which may exceed 16 bytes. 156The following address values for 157.Va sa_family 158are known to the system 159(and additional formats are defined for possible future implementation): 160.Bd -literal 161#define AF_LOCAL 1 /* local to host */ 162#define AF_INET 2 /* internetwork: UDP, TCP, etc. */ 163#define AF_INET6 24 /* IPv6 */ 164#define AF_MPLS 33 /* Multiprotocol Label Switching */ 165.Ed 166.Pp 167The 168.Va sa_data 169field contains the actual address value. 170Note that it may be longer than 14 bytes. 171.Sh ROUTING 172.Ox 173provides some packet routing facilities. 174The kernel maintains a routing information database, which 175is used in selecting the appropriate network interface when 176transmitting packets. 177.Pp 178A user process (or possibly multiple co-operating processes) 179maintains this database by sending messages over a special kind 180of socket. 181This supplants fixed-size 182.Xr ioctl 2 Ns s 183used in earlier releases. 184.Pp 185This facility is described in 186.Xr route 4 . 187.Sh INTERFACES 188Each network interface in a system corresponds to a 189path through which messages may be sent and received. 190A network interface usually has a hardware device associated with it, 191though certain interfaces such as the loopback interface, 192.Xr lo 4 , 193do not. 194.Pp 195The following 196.Xr ioctl 2 197calls may be used to manipulate network interfaces. 198The 199.Xr ioctl 2 200is made on a socket (typically of type 201.Dv SOCK_DGRAM ) 202in the desired domain. 203Most of the requests 204take an 205.Vt ifreq 206structure pointer as their parameter. 207This structure is as follows: 208.Bd -literal 209struct ifreq { 210#define IFNAMSIZ 16 211 char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 212 union { 213 struct sockaddr ifru_addr; 214 struct sockaddr ifru_dstaddr; 215 struct sockaddr ifru_broadaddr; 216 short ifru_flags; 217 int ifru_metric; 218 uint64_t ifru_media; 219 caddr_t ifru_data; 220 } ifr_ifru; 221#define ifr_addr ifr_ifru.ifru_addr /* address */ 222#define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */ 223#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */ 224#define ifr_flags ifr_ifru.ifru_flags /* flags */ 225#define ifr_metric ifr_ifru.ifru_metric /* metric */ 226#define ifr_mtu ifr_ifru.ifru_metric /* mtu (overload) */ 227#define ifr_hardmtu ifr_ifru.ifru_metric /* hardmtu (overload) */ 228#define ifr_media ifr_ifru.ifru_media /* media options */ 229#define ifr_rdomainid ifr_ifru.ifru_metric /* VRF instance (overload) */ 230#define ifr_vnetid ifr_ifru.ifru_metric /* Virtual Net Id (overload) */ 231#define ifr_ttl ifr_ifru.ifru_metric /* tunnel TTL (overload) */ 232#define ifr_data ifr_ifru.ifru_data /* for use by interface */ 233}; 234.Ed 235.Pp 236The supported 237.Xr ioctl 2 238requests are: 239.Bl -tag -width Ds 240.It Dv SIOCSIFADDR Fa "struct ifreq *" 241Set the interface address for a protocol family. 242Following the address assignment, the 243.Dq initialization 244routine for the 245interface is called. 246.Pp 247This call has been deprecated and superseded by the 248.Dv SIOCAIFADDR 249call, described below. 250.It Dv SIOCSIFDSTADDR Fa "struct ifreq *" 251Set the point-to-point address for a protocol family and interface. 252.Pp 253This call has been deprecated and superseded by the 254.Dv SIOCAIFADDR 255call, described below. 256.It Dv SIOCSIFBRDADDR Fa "struct ifreq *" 257Set the broadcast address for a protocol family and interface. 258.Pp 259This call has been deprecated and superseded by the 260.Dv SIOCAIFADDR 261call, described below. 262.It Dv SIOCGIFADDR Fa "struct ifreq *" 263Get the interface address for a protocol family. 264.It Dv SIOCGIFDSTADDR Fa "struct ifreq *" 265Get the point-to-point address for a protocol family and interface. 266.It Dv SIOCGIFBRDADDR Fa "struct ifreq *" 267Get the broadcast address for a protocol family and interface. 268.It Dv SIOCGIFDESCR Fa "struct ifreq *" 269Get the interface description, returned in the 270.Va ifru_data 271field. 272.It Dv SIOCSIFDESCR Fa "struct ifreq *" 273Set the interface description to the value of the 274.Va ifru_data 275field, limited to the size of 276.Dv IFDESCRSIZE . 277.It Dv SIOCSIFFLAGS Fa "struct ifreq *" 278Set the interface flags. 279If the interface is marked down, any processes currently routing packets 280through the interface are notified; some interfaces may be reset so that 281incoming packets are no longer received. 282When marked up again, the interface is reinitialized. 283.It Dv SIOCGIFFLAGS Fa "struct ifreq *" 284Get the interface flags. 285.It Dv SIOCGIFXFLAGS Fa "struct ifreq *" 286Get the extended interface flags. 287.It Dv SIOCGIFMTU Fa "struct ifreq *" 288Get the current MTU of the interface. 289.It Dv SIOCGIFHARDMTU Fa "struct ifreq *" 290Get the maximum hardware MTU of the interface. 291.It Dv SIOCSIFMEDIA Fa "struct ifreq *" 292Set the interface media settings. 293See 294.Xr ifmedia 4 295for possible values. 296.It Dv SIOCGIFMEDIA Fa "struct ifmediareq *" 297Get the interface media settings. 298The 299.Vt ifmediareq 300structure is as follows: 301.Bd -literal 302struct ifmediareq { 303 char ifm_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 304 uint64_t ifm_current; /* current media options */ 305 uint64_t ifm_mask; /* don't care mask */ 306 uint64_t ifm_status; /* media status */ 307 uint64_t ifm_active; /* active options */ 308 int ifm_count; /* #entries in ifm_ulist array */ 309 uint64_t *ifm_ulist; /* media words */ 310}; 311.Ed 312.Pp 313See 314.Xr ifmedia 4 315for interpreting this value. 316.It Dv SIOCSIFMETRIC Fa "struct ifreq *" 317Set the interface routing metric. 318The metric is used only by user-level routers. 319.It Dv SIOCGIFMETRIC Fa "struct ifreq *" 320Get the interface metric. 321.It Dv SIOCSIFPRIORITY Fa "struct ifreq *" 322Set the interface routing priority. 323The interface routing priority influences the resulting routing priority of 324new static routes added to the kernel using the specified interface. 325The value is in the range of 0 to 16 with smaller numbers being better. 326.It Dv SIOCGIFPRIORITY Fa "struct ifreq *" 327Get the interface priority. 328.It Dv SIOCGIFRDOMAIN Fa "struct ifreq *" 329Get the interface routing domain. 330This identifies which routing table is used for the interface. 331.It Dv SIOCAIFADDR Fa "struct ifaliasreq *" 332An interface may have more than one address associated with it 333in some protocols. 334This request provides a means to add additional addresses (or modify 335characteristics of the primary address if the default address for the 336address family is specified). 337.Pp 338Rather than making separate calls to set destination or broadcast addresses, 339or network masks (now an integral feature of multiple protocols), a separate 340structure, 341.Vt ifaliasreq , 342is used to specify all three facets simultaneously (see below). 343One would use a slightly tailored version of this structure specific 344to each family (replacing each 345.Vt sockaddr 346by one 347of the family-specific type). 348One should always set the length of a 349.Vt sockaddr , 350as described in 351.Xr ioctl 2 . 352.Pp 353The 354.Vt ifaliasreq 355structure is as follows: 356.Bd -literal 357struct ifaliasreq { 358 char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 359 struct sockaddr ifra_addr; 360 struct sockaddr ifra_dstaddr; 361#define ifra_broadaddr ifra_dstaddr 362 struct sockaddr ifra_mask; 363}; 364.Ed 365.It Dv SIOCDIFADDR Fa "struct ifreq *" 366This request deletes the specified address from the list 367associated with an interface. 368It also uses the 369.Vt ifaliasreq 370structure to allow for the possibility of protocols allowing 371multiple masks or destination addresses, and also adopts the 372convention that specification of the default address means 373to delete the first address for the interface belonging to 374the address family in which the original socket was opened. 375.It Dv SIOCGIFCONF Fa "struct ifconf *" 376Get the interface configuration list. 377This request takes an 378.Vt ifconf 379structure (see below) as a value-result parameter. 380The 381.Va ifc_len 382field should be initially set to the size of the buffer 383pointed to by 384.Va ifc_buf . 385On return it will contain the length, in bytes, of the 386configuration list. 387.Pp 388Alternately, if the 389.Va ifc_len 390passed in is set to 0, 391.Dv SIOCGIFCONF 392will set 393.Va ifc_len 394to the size that 395.Va ifc_buf 396needs to be to fit the entire configuration list and will not 397fill in the other parameters. 398This is useful for determining the exact size that 399.Va ifc_buf 400needs to be in advance. 401Note, however, that this is an extension 402that not all operating systems support. 403.Bd -literal 404struct ifconf { 405 int ifc_len; /* size of associated buffer */ 406 union { 407 caddr_t ifcu_buf; 408 struct ifreq *ifcu_req; 409 } ifc_ifcu; 410#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */ 411#define ifc_req ifc_ifcu.ifcu_req /* array of structures ret'd */ 412}; 413.Ed 414.It Dv SIOCIFCREATE Fa "struct ifreq *" 415Attempt to create the specified interface. 416.It Dv SIOCIFDESTROY Fa "struct ifreq *" 417Attempt to destroy the specified interface. 418.It Dv SIOCIFGCLONERS Fa "struct if_clonereq *" 419Get the list of clonable interfaces. 420This request takes an 421.Vt if_clonereq 422structure pointer (see below) as a value-result parameter. 423The 424.Va ifcr_count 425field should be set to the number of 426.Dv IFNAMSIZ Ns -sized 427strings that can fit in the buffer pointed to by 428.Va ifcr_buffer . 429On return, 430.Va ifcr_total 431will be set to the number of clonable interfaces, and the buffer pointed 432to by 433.Va ifcr_buffer 434will be filled with the names of clonable interfaces aligned on 435.Dv IFNAMSIZ 436boundaries. 437.Pp 438The 439.Vt if_clonereq 440structure is as follows: 441.Bd -literal 442struct if_clonereq { 443 int ifcr_total; /* total cloners (out) */ 444 int ifcr_count; /* room for this many in user buf */ 445 char *ifcr_buffer; /* buffer for cloner names */ 446}; 447.Ed 448.It Dv SIOCAIFGROUP Fa "struct ifgroupreq *" 449Associate the interface named by 450.Va ifgr_name 451with the interface group named by 452.Va ifgr_group . 453The 454.Vt ifgroupreq 455structure is as follows: 456.Bd -literal 457struct ifg_req { 458 char ifgrq_group[IFNAMSIZ]; 459}; 460 461struct ifgroupreq { 462 char ifgr_name[IFNAMSIZ]; 463 u_int ifgr_len; 464 union { 465 char ifgru_group[IFNAMSIZ]; 466 struct ifg_req *ifgru_groups; 467 } ifgr_ifgru; 468#define ifgr_group ifgr_ifgru.ifgru_group 469#define ifgr_groups ifgr_ifgru.ifgru_groups 470}; 471.Ed 472.It Dv SIOCGIFGROUP Fa "struct ifgroupreq *" 473Retrieve the list of groups for which an interface is a member. 474The interface is named by 475.Va ifgr_name . 476On enter, the amount of memory in which the group names will 477be written is stored in 478.Va ifgr_len , 479and the group names themselves will be written to the memory 480pointed to by 481.Va ifgr_groups . 482On return, the amount of memory actually written is returned in 483.Va ifgr_len . 484.Pp 485Alternately, if the 486.Va ifgr_len 487passed in is set to 0, 488.Dv SIOCGIFGROUP 489will set 490.Va ifgr_len 491to the size that 492.Va ifgr_groups 493needs to be to fit the entire group list and will not 494fill in the other parameters. 495This is useful for determining the exact size that 496.Va ifgr_groups 497needs to be in advance. 498.It Dv SIOCDIFGROUP Fa "struct ifgroupreq *" 499Remove the membership of the interface named by 500.Va ifgr_name 501from the group 502.Va ifgr_group . 503.El 504.Sh SEE ALSO 505.Xr netstat 1 , 506.Xr ioctl 2 , 507.Xr socket 2 , 508.Xr arp 4 , 509.Xr bridge 4 , 510.Xr ifmedia 4 , 511.Xr inet 4 , 512.Xr intro 4 , 513.Xr ip 4 , 514.Xr ip6 4 , 515.Xr lo 4 , 516.Xr mpe 4 , 517.Xr pf 4 , 518.Xr tcp 4 , 519.Xr udp 4 , 520.Xr hosts 5 , 521.Xr networks 5 , 522.Xr bgpd 8 , 523.Xr config 8 , 524.Xr ifconfig 8 , 525.Xr mrouted 8 , 526.Xr netstart 8 , 527.Xr ospfd 8 , 528.Xr ripd 8 , 529.Xr route 8 530.Sh HISTORY 531The 532.Nm 533manual appeared in 534.Bx 4.3 Tahoe . 535