xref: /openbsd-src/share/man/man4/netintro.4 (revision f6aab3d83b51b91c24247ad2c2573574de475a82)
1.\"	$OpenBSD: netintro.4,v 1.53 2018/07/09 09:18:52 schwarze 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: July 9 2018 $
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 SYNOPSIS section of each network interface entry gives a sample
94specification of the related drivers for use in providing a system description
95to the
96.Xr config 8
97program.
98The DIAGNOSTICS section lists messages which may appear on the console
99and/or in the system error log,
100.Pa /var/log/messages
101(see
102.Xr syslogd 8 ) ,
103due to errors in device operation.
104.Pp
105Network interfaces may be collected together into interface groups.
106An interface group is a container that can be used generically when
107referring to any interface related by some criteria.
108When an action is performed on an interface group, such as packet
109filtering by the
110.Xr pf 4
111subsystem, the operation will be applied to each member interface in the
112group, if supported by the subsystem.
113The
114.Xr ifconfig 8
115utility can be used to view and assign membership of an interface to an
116interface group with the
117.Cm group
118modifier.
119.Sh PROTOCOLS
120The system currently supports the
121Internet protocols (IPv4 and IPv6),
122MPLS,
123and a few others.
124Raw socket interfaces are provided to the IP protocol
125layer of the
126Internet.
127Consult the appropriate manual pages in this section for more
128information regarding the support for each protocol family.
129.Sh ADDRESSING
130Associated with each protocol family is an address
131format.
132All network addresses adhere to a general structure, called a
133.Vt sockaddr ,
134described below.
135However, each protocol imposes a finer, more specific structure, generally
136renaming the variant, which is discussed in the protocol family manual
137page alluded to above.
138.Bd -literal -offset indent
139struct sockaddr {
140	u_int8_t	sa_len;		/* total length */
141	sa_family_t	sa_family;	/* address family */
142	char		sa_data[14];	/* actually longer */
143};
144.Ed
145.Pp
146The field
147.Va sa_len
148contains the total length of the structure,
149which may exceed 16 bytes.
150The following address values for
151.Va sa_family
152are known to the system
153(and additional formats are defined for possible future implementation):
154.Bd -literal
155#define AF_UNIX		1	/* local to host */
156#define AF_INET		2	/* internetwork: UDP, TCP, etc. */
157#define AF_INET6	24	/* IPv6 */
158#define AF_MPLS		33	/* Multiprotocol Label Switching */
159.Ed
160.Pp
161The
162.Va sa_data
163field contains the actual address value.
164Note that it may be longer than 14 bytes.
165.Sh ROUTING
166.Ox
167provides some packet routing facilities.
168The kernel maintains a routing information database, which
169is used in selecting the appropriate network interface when
170transmitting packets.
171.Pp
172A user process (or possibly multiple co-operating processes)
173maintains this database by sending messages over a special kind
174of socket.
175This supplants fixed-size
176.Xr ioctl 2 Ns s
177used in earlier releases.
178.Pp
179This facility is described in
180.Xr route 4 .
181.Sh INTERFACES
182Each network interface in a system corresponds to a
183path through which messages may be sent and received.
184A network interface usually has a hardware device associated with it,
185though certain interfaces such as the loopback interface,
186.Xr lo 4 ,
187do not.
188.Pp
189The following
190.Xr ioctl 2
191calls may be used to manipulate network interfaces.
192The
193.Xr ioctl 2
194is made on a socket (typically of type
195.Dv SOCK_DGRAM )
196in the desired domain.
197Most of the requests
198take an
199.Vt ifreq
200structure pointer as their parameter.
201This structure is as follows:
202.Bd -literal
203struct	ifreq {
204#define IFNAMSIZ 16
205	char	ifr_name[IFNAMSIZ];	/* if name, e.g. "en0" */
206	union {
207		struct	sockaddr	ifru_addr;
208		struct	sockaddr	ifru_dstaddr;
209		struct	sockaddr	ifru_broadaddr;
210		short			ifru_flags;
211		int			ifru_metric;
212		int64_t			ifru_vnetid;
213		uint64_t		ifru_media;
214		caddr_t			ifru_data;
215		unsigned int		ifru_index;
216	} ifr_ifru;
217#define	ifr_addr	ifr_ifru.ifru_addr	/* address */
218#define	ifr_dstaddr	ifr_ifru.ifru_dstaddr	/* other end of p-to-p link */
219#define	ifr_broadaddr	ifr_ifru.ifru_broadaddr	/* broadcast address */
220#define	ifr_flags	ifr_ifru.ifru_flags	/* flags */
221#define	ifr_metric	ifr_ifru.ifru_metric	/* metric */
222#define	ifr_mtu		ifr_ifru.ifru_metric	/* mtu (overload) */
223#define	ifr_hardmtu	ifr_ifru.ifru_metric	/* hardmtu (overload) */
224#define	ifr_media	ifr_ifru.ifru_media	/* media options */
225#define	ifr_rdomainid	ifr_ifru.ifru_metric	/* VRF instance (overload) */
226#define	ifr_vnetid	ifr_ifru.ifru_vnetid	/* Virtual Net Id */
227#define	ifr_ttl		ifr_ifru.ifru_metric	/* tunnel TTL (overload) */
228#define	ifr_data	ifr_ifru.ifru_data	/* for use by interface */
229#define	ifr_index	ifr_ifru.ifru_index	/* interface index */
230#define	ifr_llprio	ifr_ifru.ifru_metric	/* link layer priority */
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	uint64_t	ifm_current;	/* current media options */
303	uint64_t	ifm_mask;	/* don't care mask */
304	uint64_t	ifm_status;	/* media status */
305	uint64_t	ifm_active;	/* active options */
306	int		ifm_count;	/* #entries in ifm_ulist array */
307	uint64_t	*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 arp 4 ,
507.Xr bridge 4 ,
508.Xr ifmedia 4 ,
509.Xr inet 4 ,
510.Xr intro 4 ,
511.Xr ip 4 ,
512.Xr ip6 4 ,
513.Xr lo 4 ,
514.Xr mpe 4 ,
515.Xr pf 4 ,
516.Xr tcp 4 ,
517.Xr udp 4 ,
518.Xr unix 4 ,
519.Xr hosts 5 ,
520.Xr bgpd 8 ,
521.Xr config 8 ,
522.Xr ifconfig 8 ,
523.Xr mrouted 8 ,
524.Xr netstart 8 ,
525.Xr ospfd 8 ,
526.Xr ripd 8 ,
527.Xr route 8
528.Sh HISTORY
529The
530.Nm
531manual appeared in
532.Bx 4.3 Tahoe .
533