xref: /openbsd-src/share/man/man4/netintro.4 (revision daf88648c0e349d5c02e1504293082072c981640)
1.\"	$OpenBSD: netintro.4,v 1.33 2005/06/08 04:17:43 henning 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 September 3, 1994
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, Novell's IPX protocols,
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_IPX		23	/* Novell Internet Protocol */
166#define AF_INET6	24	/* IPv6 */
167#define AF_NATM		27	/* native ATM access */
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 SIOCAIFADDR Fa "struct ifaliasreq *"
314An interface may have more than one address associated with it
315in some protocols.
316This request provides a means to add additional addresses (or modify
317characteristics of the primary address if the default address for the
318address family is specified).
319.Pp
320Rather than making separate calls to set destination or broadcast addresses,
321or network masks (now an integral feature of multiple protocols), a separate
322structure,
323.Vt ifaliasreq ,
324is used to specify all three facets simultaneously (see below).
325One would use a slightly tailored version of this structure specific
326to each family (replacing each
327.Vt sockaddr
328by one
329of the family-specific type).
330One should always set the length of a
331.Vt sockaddr ,
332as described in
333.Xr ioctl 2 .
334.Pp
335The
336.Vt ifaliasreq
337structure is as follows:
338.Bd -literal
339struct ifaliasreq {
340	char	ifra_name[IFNAMSIZ];	/* if name, e.g. "en0" */
341	struct	sockaddr ifra_addr;
342	struct	sockaddr ifra_dstaddr;
343#define ifra_broadaddr ifra_dstaddr
344	struct	sockaddr ifra_mask;
345};
346.Ed
347.It Dv SIOCDIFADDR Fa "struct ifreq *"
348This request deletes the specified address from the list
349associated with an interface.
350It also uses the
351.Vt ifaliasreq
352structure to allow for the possibility of protocols allowing
353multiple masks or destination addresses, and also adopts the
354convention that specification of the default address means
355to delete the first address for the interface belonging to
356the address family in which the original socket was opened.
357.It Dv SIOCGIFCONF Fa "struct ifconf *"
358Get the interface configuration list.
359This request takes an
360.Vt ifconf
361structure (see below) as a value-result parameter.
362The
363.Va ifc_len
364field should be initially set to the size of the buffer
365pointed to by
366.Va ifc_buf .
367On return it will contain the length, in bytes, of the
368configuration list.
369.Pp
370Alternately, if the
371.Va ifc_len
372passed in is set to 0,
373.Dv SIOCGIFCONF
374will set
375.Va ifc_len
376to the size that
377.Va ifc_buf
378needs to be to fit the entire configuration list and will not
379fill in the other parameters.
380This is useful for determining the exact size that
381.Va ifc_buf
382needs to be in advance.
383Note, however, that this is an extension
384that not all operating systems support.
385.Bd -literal
386struct ifconf {
387	int	ifc_len;	  /* size of associated buffer */
388	union {
389		caddr_t	ifcu_buf;
390		struct	ifreq *ifcu_req;
391	} ifc_ifcu;
392#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
393#define ifc_req ifc_ifcu.ifcu_req /* array of structures ret'd */
394};
395.Ed
396.It Dv SIOCIFCREATE Fa "struct ifreq *"
397Attempt to create the specified interface.
398.It Dv SIOCIFDESTROY Fa "struct ifreq *"
399Attempt to destroy the specified interface.
400.It Dv SIOCIFGCLONERS Fa "struct if_clonereq *"
401Get the list of clonable interfaces.
402This request takes an
403.Vt if_clonereq
404structure pointer (see below) as a value-result parameter.
405The
406.Va ifcr_count
407field should be set to the number of
408.Dv IFNAMSIZ Ns -sized
409strings that can fit in the buffer pointed to by
410.Va ifcr_buffer .
411On return,
412.Va ifcr_total
413will be set to the number of clonable interfaces, and the buffer pointed
414to by
415.Va ifcr_buffer
416will be filled with the names of clonable interfaces aligned on
417.Dv IFNAMSIZ
418boundaries.
419.Pp
420The
421.Vt if_clonereq
422structure is as follows:
423.Bd -literal
424struct if_clonereq {
425	int   ifcr_total;  /* total cloners (out) */
426	int   ifcr_count;  /* room for this many in user buf */
427	char *ifcr_buffer; /* buffer for cloner names */
428};
429.Ed
430.It Dv SIOCAIFGROUP Fa "struct ifgroupreq *"
431Associate the interface named by
432.Va ifgr_name
433with the interface group named by
434.Va ifgr_group .
435The
436.Vt ifgroupreq
437structure is as follows:
438.Bd -literal
439struct ifg_req {
440	char			 ifgrq_group[IFNAMSIZ];
441};
442
443struct ifgroupreq {
444	char	ifgr_name[IFNAMSIZ];
445	u_int	ifgr_len;
446	union {
447		char	ifgru_group[IFNAMSIZ];
448		struct	ifg_req *ifgru_groups;
449	} ifgr_ifgru;
450#define ifgr_group	ifgr_ifgru.ifgru_group
451#define ifgr_groups	ifgr_ifgru.ifgru_groups
452};
453.Ed
454.It Dv SIOCGIFGROUP Fa "struct ifgroupreq *"
455Retrieve the list of groups for which an interface is a member.
456The interface is named by
457.Va ifgr_name .
458On enter, the amount of memory in which the group names will
459be written is stored in
460.Va ifgr_len ,
461and the group names themselves will be written to the memory
462pointed to by
463.Va ifgr_groups .
464On return, the amount of memory actually written is returned in
465.Va ifgr_len .
466.Pp
467Alternately, if the
468.Va ifgr_len
469passed in is set to 0,
470.Dv SIOCGIFGROUP
471will set
472.Va ifgr_len
473to the size that
474.Va ifgr_groups
475needs to be to fit the entire group list and will not
476fill in the other parameters.
477This is useful for determining the exact size that
478.Va ifgr_groups
479needs to be in advance.
480.It Dv SIOCDIFGROUP Fa "struct ifgroupreq *"
481Remove the membership of the interface named by
482.Va ifgr_name
483from the group
484.Va ifgr_group .
485.El
486.Sh SEE ALSO
487.Xr netstat 1 ,
488.Xr ioctl 2 ,
489.Xr socket 2 ,
490.Xr inet 3 ,
491.Xr ipx 3 ,
492.Xr arp 4 ,
493.Xr bridge 4 ,
494.Xr ifmedia 4 ,
495.Xr inet 4 ,
496.Xr intro 4 ,
497.Xr ip 4 ,
498.Xr ip6 4 ,
499.Xr lo 4 ,
500.Xr pf 4 ,
501.Xr tcp 4 ,
502.Xr udp 4 ,
503.Xr hosts 5 ,
504.Xr networks 5 ,
505.Xr config 8 ,
506.Xr ifconfig 8 ,
507.Xr netstart 8 ,
508.Xr route 8 ,
509.Xr routed 8
510.Sh HISTORY
511The
512.Nm
513manual appeared in
514.Bx 4.3 Tahoe .
515