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