xref: /openbsd-src/share/man/man4/netintro.4 (revision 50483800d0aead5a0cd51bb901d1cc6a2076c56b)
1.\"	$OpenBSD: netintro.4,v 1.55 2024/09/23 20:38:49 kn 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 23 2024 $
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	char	ifr_name[IFNAMSIZ];		/* if name, e.g. "en0" */
205	union {
206		struct	sockaddr	ifru_addr;
207		struct	sockaddr	ifru_dstaddr;
208		struct	sockaddr	ifru_broadaddr;
209		short			ifru_flags;
210		int			ifru_metric;
211		int64_t			ifru_vnetid;
212		uint64_t		ifru_media;
213		caddr_t			ifru_data;
214		unsigned int		ifru_index;
215	} ifr_ifru;
216#define	ifr_addr	ifr_ifru.ifru_addr	/* address */
217#define	ifr_dstaddr	ifr_ifru.ifru_dstaddr	/* other end of p-to-p link */
218#define	ifr_broadaddr	ifr_ifru.ifru_broadaddr	/* broadcast address */
219#define	ifr_flags	ifr_ifru.ifru_flags	/* flags */
220#define	ifr_metric	ifr_ifru.ifru_metric	/* metric */
221#define	ifr_mtu		ifr_ifru.ifru_metric	/* mtu (overload) */
222#define	ifr_hardmtu	ifr_ifru.ifru_metric	/* hardmtu (overload) */
223#define	ifr_media	ifr_ifru.ifru_media	/* media options */
224#define	ifr_rdomainid	ifr_ifru.ifru_metric	/* VRF instance (overload) */
225#define ifr_vnetid	ifr_ifru.ifru_vnetid	/* Virtual Net Id */
226#define ifr_ttl		ifr_ifru.ifru_metric	/* tunnel TTL (overload) */
227#define ifr_df		ifr_ifru.ifru_metric	/* tunnel DF (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#define ifr_hdrprio	ifr_ifru.ifru_metric	/* header prio field config */
232#define ifr_pwe3	ifr_ifru.ifru_metric	/* PWE3 type */
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 SIOCSIFMTU Fa "struct ifreq *"
288Set the MTU of the interface.
289.It Dv SIOCGIFMTU Fa "struct ifreq *"
290Get the current MTU of the interface.
291.It Dv SIOCGIFHARDMTU Fa "struct ifreq *"
292Get the maximum hardware MTU of the interface.
293.It Dv SIOCSIFMEDIA Fa "struct ifreq *"
294Set the interface media settings.
295See
296.Xr ifmedia 4
297for possible values.
298.It Dv SIOCGIFMEDIA Fa "struct ifmediareq *"
299Get the interface media settings.
300The
301.Vt ifmediareq
302structure is as follows:
303.Bd -literal
304struct ifmediareq {
305	char		ifm_name[IFNAMSIZ];	/* if name, e.g. "en0" */
306	uint64_t	ifm_current;		/* get/set current media options */
307	uint64_t	ifm_mask;		/* don't care mask */
308	uint64_t	ifm_status;		/* media status */
309	uint64_t	ifm_active;		/* active options */
310	int		ifm_count;		/* # entries in ifm_ulist array */
311	uint64_t	*ifm_ulist;		/* media words */
312};
313.Ed
314.Pp
315See
316.Xr ifmedia 4
317for interpreting this value.
318.It Dv SIOCSIFMETRIC Fa "struct ifreq *"
319Set the interface routing metric.
320The metric is used only by user-level routers.
321.It Dv SIOCGIFMETRIC Fa "struct ifreq *"
322Get the interface metric.
323.It Dv SIOCSIFPRIORITY Fa "struct ifreq *"
324Set the interface routing priority.
325The interface routing priority influences the resulting routing priority of
326new static routes added to the kernel using the specified interface.
327The value is in the range of 0 to 16 with smaller numbers being better.
328.It Dv SIOCGIFPRIORITY Fa "struct ifreq *"
329Get the interface priority.
330.It Dv SIOCGIFRDOMAIN Fa "struct ifreq *"
331Get the interface routing domain.
332This identifies which routing table is used for the interface.
333.It Dv SIOCAIFADDR Fa "struct ifaliasreq *"
334An interface may have more than one address associated with it
335in some protocols.
336This request provides a means to add additional addresses (or modify
337characteristics of the primary address if the default address for the
338address family is specified).
339.Pp
340Rather than making separate calls to set destination or broadcast addresses,
341or network masks (now an integral feature of multiple protocols), a separate
342structure,
343.Vt ifaliasreq ,
344is used to specify all three facets simultaneously (see below).
345One would use a slightly tailored version of this structure specific
346to each family (replacing each
347.Vt sockaddr
348by one
349of the family-specific type).
350One should always set the length of a
351.Vt sockaddr ,
352as described in
353.Xr ioctl 2 .
354.Pp
355The
356.Vt ifaliasreq
357structure is as follows:
358.Bd -literal
359struct ifaliasreq {
360	char	ifra_name[IFNAMSIZ];		/* if name, e.g. "en0" */
361	union {
362		struct	sockaddr ifrau_addr;
363		int	ifrau_align;
364	 } ifra_ifrau;
365#ifndef ifra_addr
366#define ifra_addr	ifra_ifrau.ifrau_addr
367#endif
368	struct	sockaddr ifra_dstaddr;
369#define	ifra_broadaddr	ifra_dstaddr
370	struct	sockaddr ifra_mask;
371};
372.Ed
373.It Dv SIOCDIFADDR Fa "struct ifreq *"
374This request deletes the specified address from the list
375associated with an interface.
376It also uses the
377.Vt ifaliasreq
378structure to allow for the possibility of protocols allowing
379multiple masks or destination addresses, and also adopts the
380convention that specification of the default address means
381to delete the first address for the interface belonging to
382the address family in which the original socket was opened.
383.It Dv SIOCGIFCONF Fa "struct ifconf *"
384Get the interface configuration list.
385This request takes an
386.Vt ifconf
387structure (see below) as a value-result parameter.
388The
389.Va ifc_len
390field should be initially set to the size of the buffer
391pointed to by
392.Va ifc_buf .
393On return it will contain the length, in bytes, of the
394configuration list.
395.Pp
396Alternately, if the
397.Va ifc_len
398passed in is set to 0,
399.Dv SIOCGIFCONF
400will set
401.Va ifc_len
402to the size that
403.Va ifc_buf
404needs to be to fit the entire configuration list and will not
405fill in the other parameters.
406This is useful for determining the exact size that
407.Va ifc_buf
408needs to be in advance.
409Note, however, that this is an extension
410that not all operating systems support.
411.Bd -literal
412struct	ifconf {
413	int	ifc_len;		/* size of associated buffer */
414	union {
415		caddr_t	ifcu_buf;
416		struct	ifreq *ifcu_req;
417	} ifc_ifcu;
418#define	ifc_buf	ifc_ifcu.ifcu_buf	/* buffer address */
419#define	ifc_req	ifc_ifcu.ifcu_req	/* array of structures returned */
420};
421.Ed
422.It Dv SIOCIFCREATE Fa "struct ifreq *"
423Attempt to create the specified interface.
424.It Dv SIOCIFDESTROY Fa "struct ifreq *"
425Attempt to destroy the specified interface.
426.It Dv SIOCIFGCLONERS Fa "struct if_clonereq *"
427Get the list of clonable interfaces.
428This request takes an
429.Vt if_clonereq
430structure pointer (see below) as a value-result parameter.
431The
432.Va ifcr_count
433field should be set to the number of
434.Dv IFNAMSIZ Ns -sized
435strings that can fit in the buffer pointed to by
436.Va ifcr_buffer .
437On return,
438.Va ifcr_total
439will be set to the number of clonable interfaces, and the buffer pointed
440to by
441.Va ifcr_buffer
442will be filled with the names of clonable interfaces aligned on
443.Dv IFNAMSIZ
444boundaries.
445.Pp
446The
447.Vt if_clonereq
448structure is as follows:
449.Bd -literal
450struct if_clonereq {
451	int   ifcr_total;  /* total cloners (out) */
452	int   ifcr_count;  /* room for this many in user buffer */
453	char *ifcr_buffer; /* buffer for cloner names */
454};
455.Ed
456.It Dv SIOCAIFGROUP Fa "struct ifgroupreq *"
457Associate the interface named by
458.Va ifgr_name
459with the interface group named by
460.Va ifgr_group .
461The
462.Vt ifgroupreq
463structure is as follows:
464.Bd -literal
465struct ifg_req {
466	union {
467		char			 ifgrqu_group[IFNAMSIZ];
468		char			 ifgrqu_member[IFNAMSIZ];
469	} ifgrq_ifgrqu;
470#define	ifgrq_group	ifgrq_ifgrqu.ifgrqu_group
471#define	ifgrq_member	ifgrq_ifgrqu.ifgrqu_member
472};
473
474struct ifgroupreq {
475	char	ifgr_name[IFNAMSIZ];
476	u_int	ifgr_len;
477	union {
478		char			 ifgru_group[IFNAMSIZ];
479		struct	ifg_req		*ifgru_groups;
480		struct	ifg_attrib	 ifgru_attrib;
481	} ifgr_ifgru;
482#define ifgr_group	ifgr_ifgru.ifgru_group
483#define ifgr_groups	ifgr_ifgru.ifgru_groups
484#define ifgr_attrib	ifgr_ifgru.ifgru_attrib
485};
486.Ed
487.It Dv SIOCGIFGROUP Fa "struct ifgroupreq *"
488Retrieve the list of groups for which an interface is a member.
489The interface is named by
490.Va ifgr_name .
491On enter, the amount of memory in which the group names will
492be written is stored in
493.Va ifgr_len ,
494and the group names themselves will be written to the memory
495pointed to by
496.Va ifgr_groups .
497On return, the amount of memory actually written is returned in
498.Va ifgr_len .
499.Pp
500Alternately, if the
501.Va ifgr_len
502passed in is set to 0,
503.Dv SIOCGIFGROUP
504will set
505.Va ifgr_len
506to the size that
507.Va ifgr_groups
508needs to be to fit the entire group list and will not
509fill in the other parameters.
510This is useful for determining the exact size that
511.Va ifgr_groups
512needs to be in advance.
513.It Dv SIOCDIFGROUP Fa "struct ifgroupreq *"
514Remove the membership of the interface named by
515.Va ifgr_name
516from the group
517.Va ifgr_group .
518.El
519.Sh SEE ALSO
520.Xr netstat 1 ,
521.Xr ioctl 2 ,
522.Xr socket 2 ,
523.Xr arp 4 ,
524.Xr bridge 4 ,
525.Xr ifmedia 4 ,
526.Xr inet 4 ,
527.Xr intro 4 ,
528.Xr ip 4 ,
529.Xr ip6 4 ,
530.Xr lo 4 ,
531.Xr mpe 4 ,
532.Xr pf 4 ,
533.Xr tcp 4 ,
534.Xr udp 4 ,
535.Xr unix 4 ,
536.Xr hosts 5 ,
537.Xr bgpd 8 ,
538.Xr config 8 ,
539.Xr ifconfig 8 ,
540.Xr mrouted 8 ,
541.Xr netstart 8 ,
542.Xr ospfd 8 ,
543.Xr ripd 8 ,
544.Xr route 8
545.Sh HISTORY
546The
547.Nm
548manual appeared in
549.Bx 4.3 Tahoe .
550