xref: /freebsd/share/man/man4/netintro.4 (revision 4b9d6057)
1.\" Copyright (c) 1983, 1990, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.Dd October 14, 2020
29.Dt NETINTRO 4
30.Os
31.Sh NAME
32.Nm networking
33.Nd introduction to networking facilities
34.Sh SYNOPSIS
35.In sys/types.h
36.In sys/time.h
37.In sys/socket.h
38.In net/if.h
39.In net/route.h
40.Sh DESCRIPTION
41This section is a general introduction to the networking facilities
42available in the system.
43Documentation in this part of section
444 is broken up into three areas:
45.Em protocol families
46(domains),
47.Em protocols ,
48and
49.Em network interfaces .
50.Pp
51All network protocols are associated with a specific
52.Em protocol family .
53A protocol family provides basic services to the protocol
54implementation to allow it to function within a specific
55network environment.
56These services may include
57packet fragmentation and reassembly, routing, addressing, and
58basic transport.
59A protocol family may support multiple
60methods of addressing, though the current protocol implementations
61do not.
62A protocol family is normally comprised of a number of protocols, one per
63.Xr socket 2
64type.
65It is not required that a protocol family support all socket types.
66A protocol family may contain multiple
67protocols supporting the same socket abstraction.
68.Pp
69A protocol supports one of the socket abstractions detailed in
70.Xr socket 2 .
71A specific protocol may be accessed either by creating a
72socket of the appropriate type and protocol family, or
73by requesting the protocol explicitly when creating a socket.
74Protocols normally accept only one type of address format,
75usually determined by the addressing structure inherent in
76the design of the protocol family/network architecture.
77Certain semantics of the basic socket abstractions are
78protocol specific.
79All protocols are expected to support
80the basic model for their particular socket type, but may,
81in addition, provide non-standard facilities or extensions
82to 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
94entry gives a sample specification
95of the related drivers for use in providing
96a system description to the
97.Xr config 8
98program.
99The DIAGNOSTICS section lists messages which may appear on the console
100and/or in the system error log,
101.Pa /var/log/messages
102(see
103.Xr syslogd 8 ) ,
104due to errors in device operation.
105.Sh PROTOCOLS
106The system currently supports the
107Internet
108protocols, the Xerox Network Systems(tm) protocols,
109and some of the
110.Tn ISO OSI
111protocols.
112Raw socket interfaces are provided to the
113.Tn IP
114protocol
115layer of the
116Internet, and to the
117.Tn IDP
118protocol of Xerox
119.Tn NS .
120Consult the appropriate manual pages in this section for more
121information regarding the support for each protocol family.
122.Sh ADDRESSING
123Associated with each protocol family is an address
124format.
125All network addresses adhere to a general structure,
126called a sockaddr, described below.
127However, each protocol
128imposes finer and more specific structure, generally renaming
129the variant, which is discussed in the protocol family manual
130page alluded to above.
131.Bd -literal -offset indent
132struct sockaddr {
133    u_char	sa_len;
134    u_char	sa_family;
135    char	sa_data[14];
136};
137.Ed
138.Pp
139The field
140.Va sa_len
141contains the total length of the structure,
142which may exceed 16 bytes.
143The following address values for
144.Va sa_family
145are known to the system
146(and additional formats are defined for possible future implementation):
147.Bd -literal
148#define    AF_UNIX      1    /* local to host (pipes, portals) */
149#define    AF_INET      2    /* internetwork: UDP, TCP, etc. */
150#define    AF_NS        6    /* Xerox NS protocols */
151#define    AF_CCITT     10   /* CCITT protocols, X.25 etc */
152#define    AF_HYLINK    15   /* NSC Hyperchannel */
153#define    AF_ISO       18   /* ISO protocols */
154.Ed
155.Sh ROUTING
156.Fx
157provides some packet routing facilities.
158The kernel maintains a routing information database, which
159is used in selecting the appropriate network interface when
160transmitting packets.
161.Pp
162A user process (or possibly multiple co-operating processes)
163maintains this database by sending messages over a special kind
164of socket.
165This supplants fixed size
166.Xr ioctl 2
167used in earlier releases.
168.Pp
169This facility is described in
170.Xr route 4 .
171.Sh INTERFACES
172Each network interface in a system corresponds to a
173path through which messages may be sent and received.
174A network interface usually has a hardware device associated with it, though
175certain interfaces such as the loopback interface,
176.Xr lo 4 ,
177do not.
178.Pp
179The following
180.Xr ioctl 2
181calls may be used to manipulate network interfaces.
182The
183.Fn ioctl
184is made on a socket (typically of type
185.Dv SOCK_DGRAM )
186in the desired domain.
187Most of the requests supported in earlier releases
188take an
189.Vt ifreq
190structure as its parameter.
191This structure has the form
192.Bd -literal
193struct	ifreq {
194#define    IFNAMSIZ    16
195    char    ifr_name[IFNAMSIZ];        /* if name, e.g. "en0" */
196    union {
197        struct    sockaddr ifru_addr;
198        struct    sockaddr ifru_dstaddr;
199        struct    sockaddr ifru_broadaddr;
200        struct    ifreq_buffer ifru_buffer;
201        short     ifru_flags[2];
202        short     ifru_index;
203        int       ifru_metric;
204        int       ifru_mtu;
205        int       ifru_phys;
206        int       ifru_media;
207        caddr_t   ifru_data;
208        int       ifru_cap[2];
209    } ifr_ifru;
210#define ifr_addr      ifr_ifru.ifru_addr      /* address */
211#define ifr_dstaddr   ifr_ifru.ifru_dstaddr   /* other end of p-to-p link */
212#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
213#define ifr_buffer    ifr_ifru.ifru_buffer    /* user supplied buffer with its length */
214#define ifr_flags     ifr_ifru.ifru_flags[0]  /* flags (low 16 bits) */
215#define ifr_flagshigh ifr_ifru.ifru_flags[1]  /* flags (high 16 bits) */
216#define ifr_metric    ifr_ifru.ifru_metric    /* metric */
217#define ifr_mtu       ifr_ifru.ifru_mtu       /* mtu */
218#define ifr_phys      ifr_ifru.ifru_phys      /* physical wire */
219#define ifr_media     ifr_ifru.ifru_media     /* physical media */
220#define ifr_data      ifr_ifru.ifru_data      /* for use by interface */
221#define ifr_reqcap    ifr_ifru.ifru_cap[0]    /* requested capabilities */
222#define ifr_curcap    ifr_ifru.ifru_cap[1]    /* current capabilities */
223#define ifr_index     ifr_ifru.ifru_index     /* interface index */
224};
225.Ed
226.Pp
227.Fn Ioctl
228requests to obtain addresses and requests both to set and
229retrieve other data are still fully supported
230and use the
231.Vt ifreq
232structure:
233.Bl -tag -width SIOCGIFBRDADDR
234.It Dv SIOCGIFADDR
235Get interface address for protocol family.
236.It Dv SIOCGIFDSTADDR
237Get point to point address for protocol family and interface.
238.It Dv SIOCGIFBRDADDR
239Get broadcast address for protocol family and interface.
240.It Dv SIOCSIFCAP
241Attempt to set the enabled capabilities field for the interface
242to the value of the
243.Va ifr_reqcap
244field of the
245.Vt ifreq
246structure.
247Note that, depending on the particular interface features,
248some capabilities may appear hard-coded to enabled, or toggling
249a capability may affect the status of other ones.
250The supported capabilities field is read-only, and the
251.Va ifr_curcap
252field is unused by this call.
253.It Dv SIOCGIFCAP
254Get the interface capabilities fields.
255The values for supported and enabled capabilities will be returned in the
256.Va ifr_reqcap
257and
258.Va ifr_curcap
259fields of the
260.Vt ifreq
261structure, respectively.
262.It Dv SIOCGIFDESCR
263Get the interface description, returned in the
264.Va buffer
265field of
266.Va ifru_buffer
267struct.
268The user supplied buffer length should be defined in the
269.Va length
270field of
271.Va ifru_buffer
272struct passed in as parameter, and the length would include
273the terminating nul character.
274If there is not enough space to hold the interface length,
275no copy would be done and the
276.Va buffer
277field of
278.Va ifru_buffer
279would be set to NULL.
280The kernel will store the buffer length in the
281.Va length
282field upon return, regardless whether the buffer itself is
283sufficient to hold the data.
284.It Dv SIOCSIFDESCR
285Set the interface description to the value of the
286.Va buffer
287field of
288.Va ifru_buffer
289struct, with
290.Va length
291field specifying its length (counting the terminating nul).
292.It Dv SIOCSIFFLAGS
293Set interface flags field.
294If the interface is marked down,
295any processes currently routing packets through the interface
296are notified;
297some interfaces may be reset so that incoming packets are no longer received.
298When marked up again, the interface is reinitialized.
299.It Dv SIOCGIFFLAGS
300Get interface flags.
301.It Dv SIOCSIFMETRIC
302Set interface routing metric.
303The metric is used only by user-level routers.
304.It Dv SIOCGIFMETRIC
305Get interface metric.
306.It Dv SIOCIFCREATE
307Attempt to create the specified interface.
308If the interface name is given without a unit number the system
309will attempt to create a new interface with an arbitrary unit number.
310On successful return the
311.Va ifr_name
312field will contain the new interface name.
313.It Dv SIOCIFDESTROY
314Attempt to destroy the specified interface.
315.El
316.Pp
317There are two requests that make use of a new structure:
318.Bl -tag -width SIOCGIFBRDADDR
319.It Dv SIOCAIFADDR
320An interface may have more than one address associated with it
321in some protocols.
322This request provides a means to
323add additional addresses (or modify characteristics of the
324primary address if the default address for the address family
325is specified).
326Rather than making separate calls to
327set destination or broadcast addresses, or network masks
328(now an integral feature of multiple protocols)
329a separate structure is used to specify all three facets simultaneously
330(see below).
331One would use a slightly tailored version of this struct specific
332to each family (replacing each sockaddr by one
333of the family-specific type).
334Where the sockaddr itself is larger than the
335default size, one needs to modify the
336.Fn ioctl
337identifier itself to include the total size, as described in
338.Fn ioctl .
339.It Dv SIOCDIFADDR
340This requests deletes the specified address from the list
341associated with an interface.
342It also uses the
343.Vt ifaliasreq
344structure to allow for the possibility of protocols allowing
345multiple masks or destination addresses, and also adopts the
346convention that specification of the default address means
347to delete the first address for the interface belonging to
348the address family in which the original socket was opened.
349.It Dv SIOCGIFALIAS
350This request provides means to get additional addresses
351together with netmask and broadcast/destination from an
352interface.
353It also uses the
354.Vt ifaliasreq
355structure.
356.It Dv SIOCGIFCONF
357Get interface configuration list.
358This request takes an
359.Vt ifconf
360structure (see below) as a value-result parameter.
361The
362.Va ifc_len
363field should be initially set to the size of the buffer
364pointed to by
365.Va ifc_buf .
366On return it will contain the length, in bytes, of the
367configuration list.
368.It Dv SIOCIFGCLONERS
369Get list of clonable interfaces.
370This request takes an
371.Vt if_clonereq
372structure (see below) as a value-result parameter.
373The
374.Va ifcr_count
375field should be set to the number of
376.Dv IFNAMSIZ
377sized strings that can be fit in the buffer pointed to by
378.Va ifcr_buffer .
379On return,
380.Va ifcr_total
381will be set to the number of clonable interfaces and the buffer pointed
382to by
383.Va ifcr_buffer
384will be filled with the names of clonable interfaces aligned on
385.Dv IFNAMSIZ
386boundaries.
387.El
388.Bd -literal
389/*
390* Structure used in SIOCAIFADDR request.
391*/
392struct ifaliasreq {
393        char    ifra_name[IFNAMSIZ];   /* if name, e.g. "en0" */
394        struct  sockaddr        ifra_addr;
395        struct  sockaddr        ifra_broadaddr;
396        struct  sockaddr        ifra_mask;
397};
398.Ed
399.Bd -literal
400/*
401* Structure used in SIOCGIFCONF request.
402* Used to retrieve interface configuration
403* for machine (useful for programs which
404* must know all networks accessible).
405*/
406struct ifconf {
407    int   ifc_len;		/* size of associated buffer */
408    union {
409        caddr_t    ifcu_buf;
410        struct     ifreq *ifcu_req;
411    } ifc_ifcu;
412#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
413#define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */
414};
415.Ed
416.Bd -literal
417/* Structure used in SIOCIFGCLONERS request. */
418struct if_clonereq {
419        int     ifcr_total;     /* total cloners (out) */
420        int     ifcr_count;     /* room for this many in user buffer */
421        char    *ifcr_buffer;   /* buffer for cloner names */
422};
423.Ed
424.Bd -literal
425/* Structure used in SIOCGIFDESCR and SIOCSIFDESCR requests */
426struct ifreq_buffer {
427        size_t  length;         /* length of the buffer */
428        void   *buffer;         /* pointer to userland space buffer */
429};
430.Ed
431.Sh SEE ALSO
432.Xr ioctl 2 ,
433.Xr socket 2 ,
434.Xr intro 4 ,
435.Xr config 8 ,
436.Xr routed 8 ,
437.Xr ifnet 9
438.Sh HISTORY
439The
440.Nm netintro
441manual appeared in
442.Bx 4.3 tahoe .
443