xref: /openbsd-src/share/man/man4/netintro.4 (revision a28daedfc357b214be5c701aa8ba8adb29a7f1c2)
1.\"	$OpenBSD: netintro.4,v 1.40 2009/01/29 19:35:27 claudio 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: January 29 2009 $
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 '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 SIOCSIFMEDIA Fa "struct ifreq *"
284Set the interface media settings.
285See
286.Xr ifmedia 4
287for possible values.
288.It Dv SIOCGIFMEDIA Fa "struct ifmediareq *"
289Get the interface media settings.
290The
291.Vt ifmediareq
292structure is as follows:
293.Bd -literal
294struct ifmediareq {
295	char	 ifm_name[IFNAMSIZ];	/* if name, e.g. "en0" */
296	int	 ifm_current;	/* current media options */
297	int	 ifm_mask;	/* don't care mask */
298	int	 ifm_status;	/* media status */
299	int	 ifm_active;	/* active options */
300	int	 ifm_count;	/* #entries in ifm_ulist array */
301	int	*ifm_ulist;	/* media words */
302};
303.Ed
304.Pp
305See
306.Xr ifmedia 4
307for interpreting this value.
308.It Dv SIOCSIFMETRIC Fa "struct ifreq *"
309Set the interface routing metric.
310The metric is used only by user-level routers.
311.It Dv SIOCGIFMETRIC Fa "struct ifreq *"
312Get the interface metric.
313.It Dv SIOCSIFPRIORITY Fa "struct ifreq *"
314Set the interface routing priority.
315The interface routing priority influences the resulting routing priority of
316new static routes added to the kernel using the specified interface.
317The value is in the range of 0 to 16 with smaller numbers being better.
318.It Dv SIOCGIFPRIORITY Fa "struct ifreq *"
319Get the interface priority.
320.It Dv SIOCAIFADDR Fa "struct ifaliasreq *"
321An interface may have more than one address associated with it
322in some protocols.
323This request provides a means to add additional addresses (or modify
324characteristics of the primary address if the default address for the
325address family is specified).
326.Pp
327Rather than making separate calls to set destination or broadcast addresses,
328or network masks (now an integral feature of multiple protocols), a separate
329structure,
330.Vt ifaliasreq ,
331is used to specify all three facets simultaneously (see below).
332One would use a slightly tailored version of this structure specific
333to each family (replacing each
334.Vt sockaddr
335by one
336of the family-specific type).
337One should always set the length of a
338.Vt sockaddr ,
339as described in
340.Xr ioctl 2 .
341.Pp
342The
343.Vt ifaliasreq
344structure is as follows:
345.Bd -literal
346struct ifaliasreq {
347	char	ifra_name[IFNAMSIZ];	/* if name, e.g. "en0" */
348	struct	sockaddr ifra_addr;
349	struct	sockaddr ifra_dstaddr;
350#define ifra_broadaddr ifra_dstaddr
351	struct	sockaddr ifra_mask;
352};
353.Ed
354.It Dv SIOCDIFADDR Fa "struct ifreq *"
355This request deletes the specified address from the list
356associated with an interface.
357It also uses the
358.Vt ifaliasreq
359structure to allow for the possibility of protocols allowing
360multiple masks or destination addresses, and also adopts the
361convention that specification of the default address means
362to delete the first address for the interface belonging to
363the address family in which the original socket was opened.
364.It Dv SIOCGIFCONF Fa "struct ifconf *"
365Get the interface configuration list.
366This request takes an
367.Vt ifconf
368structure (see below) as a value-result parameter.
369The
370.Va ifc_len
371field should be initially set to the size of the buffer
372pointed to by
373.Va ifc_buf .
374On return it will contain the length, in bytes, of the
375configuration list.
376.Pp
377Alternately, if the
378.Va ifc_len
379passed in is set to 0,
380.Dv SIOCGIFCONF
381will set
382.Va ifc_len
383to the size that
384.Va ifc_buf
385needs to be to fit the entire configuration list and will not
386fill in the other parameters.
387This is useful for determining the exact size that
388.Va ifc_buf
389needs to be in advance.
390Note, however, that this is an extension
391that not all operating systems support.
392.Bd -literal
393struct ifconf {
394	int	ifc_len;	  /* size of associated buffer */
395	union {
396		caddr_t	ifcu_buf;
397		struct	ifreq *ifcu_req;
398	} ifc_ifcu;
399#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
400#define ifc_req ifc_ifcu.ifcu_req /* array of structures ret'd */
401};
402.Ed
403.It Dv SIOCIFCREATE Fa "struct ifreq *"
404Attempt to create the specified interface.
405.It Dv SIOCIFDESTROY Fa "struct ifreq *"
406Attempt to destroy the specified interface.
407.It Dv SIOCIFGCLONERS Fa "struct if_clonereq *"
408Get the list of clonable interfaces.
409This request takes an
410.Vt if_clonereq
411structure pointer (see below) as a value-result parameter.
412The
413.Va ifcr_count
414field should be set to the number of
415.Dv IFNAMSIZ Ns -sized
416strings that can fit in the buffer pointed to by
417.Va ifcr_buffer .
418On return,
419.Va ifcr_total
420will be set to the number of clonable interfaces, and the buffer pointed
421to by
422.Va ifcr_buffer
423will be filled with the names of clonable interfaces aligned on
424.Dv IFNAMSIZ
425boundaries.
426.Pp
427The
428.Vt if_clonereq
429structure is as follows:
430.Bd -literal
431struct if_clonereq {
432	int   ifcr_total;  /* total cloners (out) */
433	int   ifcr_count;  /* room for this many in user buf */
434	char *ifcr_buffer; /* buffer for cloner names */
435};
436.Ed
437.It Dv SIOCAIFGROUP Fa "struct ifgroupreq *"
438Associate the interface named by
439.Va ifgr_name
440with the interface group named by
441.Va ifgr_group .
442The
443.Vt ifgroupreq
444structure is as follows:
445.Bd -literal
446struct ifg_req {
447	char			 ifgrq_group[IFNAMSIZ];
448};
449
450struct ifgroupreq {
451	char	ifgr_name[IFNAMSIZ];
452	u_int	ifgr_len;
453	union {
454		char	ifgru_group[IFNAMSIZ];
455		struct	ifg_req *ifgru_groups;
456	} ifgr_ifgru;
457#define ifgr_group	ifgr_ifgru.ifgru_group
458#define ifgr_groups	ifgr_ifgru.ifgru_groups
459};
460.Ed
461.It Dv SIOCGIFGROUP Fa "struct ifgroupreq *"
462Retrieve the list of groups for which an interface is a member.
463The interface is named by
464.Va ifgr_name .
465On enter, the amount of memory in which the group names will
466be written is stored in
467.Va ifgr_len ,
468and the group names themselves will be written to the memory
469pointed to by
470.Va ifgr_groups .
471On return, the amount of memory actually written is returned in
472.Va ifgr_len .
473.Pp
474Alternately, if the
475.Va ifgr_len
476passed in is set to 0,
477.Dv SIOCGIFGROUP
478will set
479.Va ifgr_len
480to the size that
481.Va ifgr_groups
482needs to be to fit the entire group list and will not
483fill in the other parameters.
484This is useful for determining the exact size that
485.Va ifgr_groups
486needs to be in advance.
487.It Dv SIOCDIFGROUP Fa "struct ifgroupreq *"
488Remove the membership of the interface named by
489.Va ifgr_name
490from the group
491.Va ifgr_group .
492.El
493.Sh SEE ALSO
494.Xr netstat 1 ,
495.Xr ioctl 2 ,
496.Xr socket 2 ,
497.Xr inet 3 ,
498.Xr arp 4 ,
499.Xr bluetooth 4 ,
500.Xr bridge 4 ,
501.Xr ifmedia 4 ,
502.Xr inet 4 ,
503.Xr intro 4 ,
504.Xr ip 4 ,
505.Xr ip6 4 ,
506.Xr lo 4 ,
507.Xr pf 4 ,
508.Xr tcp 4 ,
509.Xr udp 4 ,
510.Xr hosts 5 ,
511.Xr networks 5 ,
512.Xr bgpd 8 ,
513.Xr config 8 ,
514.Xr ifconfig 8 ,
515.Xr mrouted 8 ,
516.Xr netstart 8 ,
517.Xr ospfd 8 ,
518.Xr ripd 8 ,
519.Xr route 8
520.Sh HISTORY
521The
522.Nm
523manual appeared in
524.Bx 4.3 Tahoe .
525