xref: /openbsd/share/man/man4/netintro.4 (revision 898184e3)
1.\"	$OpenBSD: netintro.4,v 1.42 2012/11/23 20:13:26 sthen 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: November 23 2012 $
34.Dt NETINTRO 4
35.Os
36.Sh NAME
37.Nm netintro
38.Nd introduction to networking facilities
39.Sh SYNOPSIS
40.Fd #include <sys/socket.h>
41.Fd #include <net/route.h>
42.Fd #include <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),
126Appletalk,
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 (pipes, portals) */
162#define AF_INET		2	/* internetwork: UDP, TCP, etc. */
163#define AF_HYLINK	15	/* NSC Hyperchannel */
164#define AF_APPLETALK	16	/* AppleTalk */
165#define AF_INET6	24	/* IPv6 */
166#define AF_NATM		27	/* native ATM access */
167#define AF_BLUETOOTH	32	/* Bluetooth */
168.Ed
169.Pp
170The
171.Va sa_data
172field contains the actual address value.
173Note that it may be longer than 14 bytes.
174.Sh ROUTING
175.Ox
176provides some packet routing facilities.
177The kernel maintains a routing information database, which
178is used in selecting the appropriate network interface when
179transmitting packets.
180.Pp
181A user process (or possibly multiple co-operating processes)
182maintains this database by sending messages over a special kind
183of socket.
184This supplants fixed-size
185.Xr ioctl 2 Ns s
186used in earlier releases.
187.Pp
188This facility is described in
189.Xr route 4 .
190.Sh INTERFACES
191Each network interface in a system corresponds to a
192path through which messages may be sent and received.
193A network interface usually has a hardware device associated with it,
194though certain interfaces such as the loopback interface,
195.Xr lo 4 ,
196do not.
197.Pp
198The following
199.Xr ioctl 2
200calls may be used to manipulate network interfaces.
201The
202.Xr ioctl 2
203is made on a socket (typically of type
204.Dv SOCK_DGRAM )
205in the desired domain.
206Most of the requests
207take an
208.Vt ifreq
209structure pointer as their parameter.
210This structure is as follows:
211.Bd -literal
212struct	ifreq {
213#define IFNAMSIZ 16
214	char	ifr_name[IFNAMSIZ];	/* if name, e.g. "en0" */
215	union {
216		struct	sockaddr ifru_addr;
217		struct	sockaddr ifru_dstaddr;
218		struct	sockaddr ifru_broadaddr;
219		short	ifru_flags;
220		int	ifru_metric;
221		caddr_t	ifru_data;
222	} ifr_ifru;
223#define ifr_addr	ifr_ifru.ifru_addr	/* address */
224#define ifr_dstaddr	ifr_ifru.ifru_dstaddr	/* p-to-p peer */
225#define ifr_broadaddr	ifr_ifru.ifru_broadaddr	/* broadcast address */
226#define ifr_flags	ifr_ifru.ifru_flags	/* flags */
227#define ifr_metric	ifr_ifru.ifru_metric	/* metric */
228#define ifr_mtu		ifr_ifru.ifru_metric	/* mtu (overload) */
229#define ifr_media	ifr_ifru.ifru_metric	/* media options */
230#define ifr_data	ifr_ifru.ifru_data	/* used by interface */
231};
232.Ed
233.Pp
234The supported
235.Xr ioctl 2
236requests are:
237.Bl -tag -width Ds
238.It Dv SIOCSIFADDR Fa "struct ifreq *"
239Set the interface address for a protocol family.
240Following the address assignment, the
241.Dq initialization
242routine for the
243interface is called.
244.Pp
245This call has been deprecated and superseded by the
246.Dv SIOCAIFADDR
247call, described below.
248.It Dv SIOCSIFDSTADDR Fa "struct ifreq *"
249Set the point-to-point address for a protocol family and interface.
250.Pp
251This call has been deprecated and superseded by the
252.Dv SIOCAIFADDR
253call, described below.
254.It Dv SIOCSIFBRDADDR Fa "struct ifreq *"
255Set the broadcast address for a protocol family and interface.
256.Pp
257This call has been deprecated and superseded by the
258.Dv SIOCAIFADDR
259call, described below.
260.It Dv SIOCGIFADDR Fa "struct ifreq *"
261Get the interface address for a protocol family.
262.It Dv SIOCGIFDSTADDR Fa "struct ifreq *"
263Get the point-to-point address for a protocol family and interface.
264.It Dv SIOCGIFBRDADDR Fa "struct ifreq *"
265Get the broadcast address for a protocol family and interface.
266.It Dv SIOCGIFDESCR Fa "struct ifreq *"
267Get the interface description, returned in the
268.Va ifru_data
269field.
270.It Dv SIOCSIFDESCR Fa "struct ifreq *"
271Set the interface description to the value of the
272.Va ifru_data
273field, limited to the size of
274.Dv IFDESCRSIZE .
275.It Dv SIOCSIFFLAGS Fa "struct ifreq *"
276Set the interface flags.
277If the interface is marked down, any processes currently routing packets
278through the interface are notified; some interfaces may be reset so that
279incoming packets are no longer received.
280When marked up again, the interface is reinitialized.
281.It Dv SIOCGIFFLAGS Fa "struct ifreq *"
282Get the interface flags.
283.It Dv SIOCGIFXFLAGS Fa "struct ifreq *"
284Get the extended interface flags.
285.It Dv SIOCGIFMTU Fa "struct ifreq *"
286Get the current MTU of the interface.
287.It Dv SIOCGIFHARDMTU Fa "struct ifreq *"
288Get the maximum hardware MTU of the interface.
289.It Dv SIOCSIFMEDIA Fa "struct ifreq *"
290Set the interface media settings.
291See
292.Xr ifmedia 4
293for possible values.
294.It Dv SIOCGIFMEDIA Fa "struct ifmediareq *"
295Get the interface media settings.
296The
297.Vt ifmediareq
298structure is as follows:
299.Bd -literal
300struct ifmediareq {
301	char	 ifm_name[IFNAMSIZ];	/* if name, e.g. "en0" */
302	int	 ifm_current;	/* current media options */
303	int	 ifm_mask;	/* don't care mask */
304	int	 ifm_status;	/* media status */
305	int	 ifm_active;	/* active options */
306	int	 ifm_count;	/* #entries in ifm_ulist array */
307	int	*ifm_ulist;	/* media words */
308};
309.Ed
310.Pp
311See
312.Xr ifmedia 4
313for interpreting this value.
314.It Dv SIOCSIFMETRIC Fa "struct ifreq *"
315Set the interface routing metric.
316The metric is used only by user-level routers.
317.It Dv SIOCGIFMETRIC Fa "struct ifreq *"
318Get the interface metric.
319.It Dv SIOCSIFPRIORITY Fa "struct ifreq *"
320Set the interface routing priority.
321The interface routing priority influences the resulting routing priority of
322new static routes added to the kernel using the specified interface.
323The value is in the range of 0 to 16 with smaller numbers being better.
324.It Dv SIOCGIFPRIORITY Fa "struct ifreq *"
325Get the interface priority.
326.It Dv SIOCGIFRDOMAIN Fa "struct ifreq *"
327Get the interface routing domain.
328This identifies which routing table is used for the interface.
329.It Dv SIOCAIFADDR Fa "struct ifaliasreq *"
330An interface may have more than one address associated with it
331in some protocols.
332This request provides a means to add additional addresses (or modify
333characteristics of the primary address if the default address for the
334address family is specified).
335.Pp
336Rather than making separate calls to set destination or broadcast addresses,
337or network masks (now an integral feature of multiple protocols), a separate
338structure,
339.Vt ifaliasreq ,
340is used to specify all three facets simultaneously (see below).
341One would use a slightly tailored version of this structure specific
342to each family (replacing each
343.Vt sockaddr
344by one
345of the family-specific type).
346One should always set the length of a
347.Vt sockaddr ,
348as described in
349.Xr ioctl 2 .
350.Pp
351The
352.Vt ifaliasreq
353structure is as follows:
354.Bd -literal
355struct ifaliasreq {
356	char	ifra_name[IFNAMSIZ];	/* if name, e.g. "en0" */
357	struct	sockaddr ifra_addr;
358	struct	sockaddr ifra_dstaddr;
359#define ifra_broadaddr ifra_dstaddr
360	struct	sockaddr ifra_mask;
361};
362.Ed
363.It Dv SIOCDIFADDR Fa "struct ifreq *"
364This request deletes the specified address from the list
365associated with an interface.
366It also uses the
367.Vt ifaliasreq
368structure to allow for the possibility of protocols allowing
369multiple masks or destination addresses, and also adopts the
370convention that specification of the default address means
371to delete the first address for the interface belonging to
372the address family in which the original socket was opened.
373.It Dv SIOCGIFCONF Fa "struct ifconf *"
374Get the interface configuration list.
375This request takes an
376.Vt ifconf
377structure (see below) as a value-result parameter.
378The
379.Va ifc_len
380field should be initially set to the size of the buffer
381pointed to by
382.Va ifc_buf .
383On return it will contain the length, in bytes, of the
384configuration list.
385.Pp
386Alternately, if the
387.Va ifc_len
388passed in is set to 0,
389.Dv SIOCGIFCONF
390will set
391.Va ifc_len
392to the size that
393.Va ifc_buf
394needs to be to fit the entire configuration list and will not
395fill in the other parameters.
396This is useful for determining the exact size that
397.Va ifc_buf
398needs to be in advance.
399Note, however, that this is an extension
400that not all operating systems support.
401.Bd -literal
402struct ifconf {
403	int	ifc_len;	  /* size of associated buffer */
404	union {
405		caddr_t	ifcu_buf;
406		struct	ifreq *ifcu_req;
407	} ifc_ifcu;
408#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
409#define ifc_req ifc_ifcu.ifcu_req /* array of structures ret'd */
410};
411.Ed
412.It Dv SIOCIFCREATE Fa "struct ifreq *"
413Attempt to create the specified interface.
414.It Dv SIOCIFDESTROY Fa "struct ifreq *"
415Attempt to destroy the specified interface.
416.It Dv SIOCIFGCLONERS Fa "struct if_clonereq *"
417Get the list of clonable interfaces.
418This request takes an
419.Vt if_clonereq
420structure pointer (see below) as a value-result parameter.
421The
422.Va ifcr_count
423field should be set to the number of
424.Dv IFNAMSIZ Ns -sized
425strings that can fit in the buffer pointed to by
426.Va ifcr_buffer .
427On return,
428.Va ifcr_total
429will be set to the number of clonable interfaces, and the buffer pointed
430to by
431.Va ifcr_buffer
432will be filled with the names of clonable interfaces aligned on
433.Dv IFNAMSIZ
434boundaries.
435.Pp
436The
437.Vt if_clonereq
438structure is as follows:
439.Bd -literal
440struct if_clonereq {
441	int   ifcr_total;  /* total cloners (out) */
442	int   ifcr_count;  /* room for this many in user buf */
443	char *ifcr_buffer; /* buffer for cloner names */
444};
445.Ed
446.It Dv SIOCAIFGROUP Fa "struct ifgroupreq *"
447Associate the interface named by
448.Va ifgr_name
449with the interface group named by
450.Va ifgr_group .
451The
452.Vt ifgroupreq
453structure is as follows:
454.Bd -literal
455struct ifg_req {
456	char			 ifgrq_group[IFNAMSIZ];
457};
458
459struct ifgroupreq {
460	char	ifgr_name[IFNAMSIZ];
461	u_int	ifgr_len;
462	union {
463		char	ifgru_group[IFNAMSIZ];
464		struct	ifg_req *ifgru_groups;
465	} ifgr_ifgru;
466#define ifgr_group	ifgr_ifgru.ifgru_group
467#define ifgr_groups	ifgr_ifgru.ifgru_groups
468};
469.Ed
470.It Dv SIOCGIFGROUP Fa "struct ifgroupreq *"
471Retrieve the list of groups for which an interface is a member.
472The interface is named by
473.Va ifgr_name .
474On enter, the amount of memory in which the group names will
475be written is stored in
476.Va ifgr_len ,
477and the group names themselves will be written to the memory
478pointed to by
479.Va ifgr_groups .
480On return, the amount of memory actually written is returned in
481.Va ifgr_len .
482.Pp
483Alternately, if the
484.Va ifgr_len
485passed in is set to 0,
486.Dv SIOCGIFGROUP
487will set
488.Va ifgr_len
489to the size that
490.Va ifgr_groups
491needs to be to fit the entire group list and will not
492fill in the other parameters.
493This is useful for determining the exact size that
494.Va ifgr_groups
495needs to be in advance.
496.It Dv SIOCDIFGROUP Fa "struct ifgroupreq *"
497Remove the membership of the interface named by
498.Va ifgr_name
499from the group
500.Va ifgr_group .
501.El
502.Sh SEE ALSO
503.Xr netstat 1 ,
504.Xr ioctl 2 ,
505.Xr socket 2 ,
506.Xr inet 3 ,
507.Xr arp 4 ,
508.Xr bluetooth 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 pf 4 ,
517.Xr tcp 4 ,
518.Xr udp 4 ,
519.Xr hosts 5 ,
520.Xr networks 5 ,
521.Xr bgpd 8 ,
522.Xr config 8 ,
523.Xr ifconfig 8 ,
524.Xr mrouted 8 ,
525.Xr netstart 8 ,
526.Xr ospfd 8 ,
527.Xr ripd 8 ,
528.Xr route 8
529.Sh HISTORY
530The
531.Nm
532manual appeared in
533.Bx 4.3 Tahoe .
534