]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - share/man/man4/netintro.4
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / share / man / man4 / netintro.4
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 January 26, 2012
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
48 This section is a general introduction to the networking facilities
49 available in the system.
50 Documentation in this part of section
51 4 is broken up into three areas:
52 .Em protocol families
53 (domains),
54 .Em protocols ,
55 and
56 .Em network interfaces .
57 .Pp
58 All network protocols are associated with a specific
59 .Em protocol family .
60 A protocol family provides basic services to the protocol
61 implementation to allow it to function within a specific
62 network environment.
63 These services may include
64 packet fragmentation and reassembly, routing, addressing, and
65 basic transport.
66 A protocol family may support multiple
67 methods of addressing, though the current protocol implementations
68 do not.
69 A protocol family is normally comprised of a number of protocols, one per
70 .Xr socket 2
71 type.
72 It is not required that a protocol family support all socket types.
73 A protocol family may contain multiple
74 protocols supporting the same socket abstraction.
75 .Pp
76 A protocol supports one of the socket abstractions detailed in
77 .Xr socket 2 .
78 A specific protocol may be accessed either by creating a
79 socket of the appropriate type and protocol family, or
80 by requesting the protocol explicitly when creating a socket.
81 Protocols normally accept only one type of address format,
82 usually determined by the addressing structure inherent in
83 the design of the protocol family/network architecture.
84 Certain semantics of the basic socket abstractions are
85 protocol specific.
86 All protocols are expected to support
87 the basic model for their particular socket type, but may,
88 in addition, provide non-standard facilities or extensions
89 to a mechanism.
90 For example, a protocol supporting the
91 .Dv SOCK_STREAM
92 abstraction may allow more than one byte of out-of-band
93 data to be transmitted per out-of-band message.
94 .Pp
95 A network interface is similar to a device interface.
96 Network interfaces comprise the lowest layer of the
97 networking subsystem, interacting with the actual transport
98 hardware.
99 An interface may support one or more protocol families and/or address formats.
100 The SYNOPSIS section of each network interface
101 entry gives a sample specification
102 of the related drivers for use in providing
103 a system description to the
104 .Xr config 8
105 program.
106 The DIAGNOSTICS section lists messages which may appear on the console
107 and/or in the system error log,
108 .Pa /var/log/messages
109 (see
110 .Xr syslogd 8 ) ,
111 due to errors in device operation.
112 .Sh PROTOCOLS
113 The system currently supports the
114 Internet
115 protocols, the Xerox Network Systems(tm) protocols,
116 and some of the
117 .Tn ISO OSI
118 protocols.
119 Raw socket interfaces are provided to the
120 .Tn IP
121 protocol
122 layer of the
123 Internet, and to the
124 .Tn IDP
125 protocol of Xerox
126 .Tn NS .
127 Consult the appropriate manual pages in this section for more
128 information regarding the support for each protocol family.
129 .Sh ADDRESSING
130 Associated with each protocol family is an address
131 format.
132 All network addresses adhere to a general structure,
133 called a sockaddr, described below.
134 However, each protocol
135 imposes finer and more specific structure, generally renaming
136 the variant, which is discussed in the protocol family manual
137 page alluded to above.
138 .Bd -literal -offset indent
139 struct sockaddr {
140     u_char      sa_len;
141     u_char      sa_family;
142     char        sa_data[14];
143 };
144 .Ed
145 .Pp
146 The field
147 .Va sa_len
148 contains the total length of the structure,
149 which may exceed 16 bytes.
150 The following address values for
151 .Va sa_family
152 are 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
164 provides some packet routing facilities.
165 The kernel maintains a routing information database, which
166 is used in selecting the appropriate network interface when
167 transmitting packets.
168 .Pp
169 A user process (or possibly multiple co-operating processes)
170 maintains this database by sending messages over a special kind
171 of socket.
172 This supplants fixed size
173 .Xr ioctl 2
174 used in earlier releases.
175 .Pp
176 This facility is described in
177 .Xr route 4 .
178 .Sh INTERFACES
179 Each network interface in a system corresponds to a
180 path through which messages may be sent and received.
181 A network interface usually has a hardware device associated with it, though
182 certain interfaces such as the loopback interface,
183 .Xr lo 4 ,
184 do not.
185 .Pp
186 The following
187 .Xr ioctl 2
188 calls may be used to manipulate network interfaces.
189 The
190 .Fn ioctl
191 is made on a socket (typically of type
192 .Dv SOCK_DGRAM )
193 in the desired domain.
194 Most of the requests supported in earlier releases
195 take an
196 .Vt ifreq
197 structure as its parameter.
198 This structure has the form
199 .Bd -literal
200 struct  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         struct    ifreq_buffer ifru_buffer;
208         short     ifru_flags[2];
209         short     ifru_index;
210         int       ifru_metric;
211         int       ifru_mtu;
212         int       ifru_phys;
213         int       ifru_media;
214         caddr_t   ifru_data;
215         int       ifru_cap[2];
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_buffer    ifr_ifru.ifru_buffer    /* user supplied buffer with its length */
221 #define ifr_flags     ifr_ifru.ifru_flags[0]  /* flags (low 16 bits) */
222 #define ifr_flagshigh ifr_ifru.ifru_flags[1]  /* flags (high 16 bits) */
223 #define ifr_metric    ifr_ifru.ifru_metric    /* metric */
224 #define ifr_mtu       ifr_ifru.ifru_mtu       /* mtu */
225 #define ifr_phys      ifr_ifru.ifru_phys      /* physical wire */
226 #define ifr_media     ifr_ifru.ifru_media     /* physical media */
227 #define ifr_data      ifr_ifru.ifru_data      /* for use by interface */
228 #define ifr_reqcap    ifr_ifru.ifru_cap[0]    /* requested capabilities */
229 #define ifr_curcap    ifr_ifru.ifru_cap[1]    /* current capabilities */
230 #define ifr_index     ifr_ifru.ifru_index     /* interface index */
231 };
232 .Ed
233 .Pp
234 .Fn Ioctl
235 requests to obtain addresses and requests both to set and
236 retrieve other data are still fully supported
237 and use the
238 .Vt ifreq
239 structure:
240 .Bl -tag -width SIOCGIFBRDADDR
241 .It Dv SIOCGIFADDR
242 Get interface address for protocol family.
243 .It Dv SIOCGIFDSTADDR
244 Get point to point address for protocol family and interface.
245 .It Dv SIOCGIFBRDADDR
246 Get broadcast address for protocol family and interface.
247 .It Dv SIOCSIFCAP
248 Attempt to set the enabled capabilities field for the interface
249 to the value of the
250 .Va ifr_reqcap
251 field of the
252 .Vt ifreq
253 structure.
254 Note that, depending on the particular interface features,
255 some capabilities may appear hard-coded to enabled, or toggling
256 a capability may affect the status of other ones.
257 The supported capabilities field is read-only, and the
258 .Va ifr_curcap
259 field is unused by this call.
260 .It Dv SIOCGIFCAP
261 Get the interface capabilities fields.
262 The values for supported and enabled capabilities will be returned in the
263 .Va ifr_reqcap
264 and
265 .Va ifr_curcap
266 fields of the
267 .Vt ifreq
268 structure, respectively.
269 .It Dv SIOCGIFDESCR
270 Get the interface description, returned in the
271 .Va buffer
272 field of
273 .Va ifru_buffer
274 struct.
275 The user supplied buffer length should be defined in the
276 .Va length
277 field of
278 .Va ifru_buffer
279 struct passed in as parameter, and the length would include
280 the terminating nul character.
281 If there is not enough space to hold the interface length,
282 no copy would be done and the
283 .Va buffer
284 field of
285 .Va ifru_buffer
286 would be set to NULL.
287 The kernel will store the buffer length in the
288 .Va length
289 field upon return, regardless whether the buffer itself is
290 sufficient to hold the data.
291 .It Dv SIOCSIFDESCR
292 Set the interface description to the value of the
293 .Va buffer
294 field of
295 .Va ifru_buffer
296 struct, with
297 .Va length
298 field specifying its length (counting the terminating nul).
299 .It Dv SIOCSIFFLAGS
300 Set interface flags field.
301 If the interface is marked down,
302 any processes currently routing packets through the interface
303 are notified;
304 some interfaces may be reset so that incoming packets are no longer received.
305 When marked up again, the interface is reinitialized.
306 .It Dv SIOCGIFFLAGS
307 Get interface flags.
308 .It Dv SIOCSIFMETRIC
309 Set interface routing metric.
310 The metric is used only by user-level routers.
311 .It Dv SIOCGIFMETRIC
312 Get interface metric.
313 .It Dv SIOCIFCREATE
314 Attempt to create the specified interface.
315 If the interface name is given without a unit number the system
316 will attempt to create a new interface with an arbitrary unit number.
317 On successful return the
318 .Va ifr_name
319 field will contain the new interface name.
320 .It Dv SIOCIFDESTROY
321 Attempt to destroy the specified interface.
322 .El
323 .Pp
324 There are two requests that make use of a new structure:
325 .Bl -tag -width SIOCGIFBRDADDR
326 .It Dv SIOCAIFADDR
327 An interface may have more than one address associated with it
328 in some protocols.
329 This request provides a means to
330 add additional addresses (or modify characteristics of the
331 primary address if the default address for the address family
332 is specified).
333 Rather than making separate calls to
334 set destination or broadcast addresses, or network masks
335 (now an integral feature of multiple protocols)
336 a separate structure is used to specify all three facets simultaneously
337 (see below).
338 One would use a slightly tailored version of this struct specific
339 to each family (replacing each sockaddr by one
340 of the family-specific type).
341 Where the sockaddr itself is larger than the
342 default size, one needs to modify the
343 .Fn ioctl
344 identifier itself to include the total size, as described in
345 .Fn ioctl .
346 .It Dv SIOCDIFADDR
347 This requests deletes the specified address from the list
348 associated with an interface.
349 It also uses the
350 .Vt ifaliasreq
351 structure to allow for the possibility of protocols allowing
352 multiple masks or destination addresses, and also adopts the
353 convention that specification of the default address means
354 to delete the first address for the interface belonging to
355 the address family in which the original socket was opened.
356 .It Dv SIOCGIFCONF
357 Get interface configuration list.
358 This request takes an
359 .Vt ifconf
360 structure (see below) as a value-result parameter.
361 The
362 .Va ifc_len
363 field should be initially set to the size of the buffer
364 pointed to by
365 .Va ifc_buf .
366 On return it will contain the length, in bytes, of the
367 configuration list.
368 .It Dv SIOCIFGCLONERS
369 Get list of clonable interfaces.
370 This request takes an
371 .Vt if_clonereq
372 structure (see below) as a value-result parameter.
373 The
374 .Va ifcr_count
375 field should be set to the number of
376 .Dv IFNAMSIZ
377 sized strings that can be fit in the buffer pointed to by
378 .Va ifcr_buffer .
379 On return,
380 .Va ifcr_total
381 will be set to the number of clonable interfaces and the buffer pointed
382 to by
383 .Va ifcr_buffer
384 will be filled with the names of clonable interfaces aligned on
385 .Dv IFNAMSIZ
386 boundaries.
387 .El
388 .Bd -literal
389 /*
390 * Structure used in SIOCAIFADDR request.
391 */
392 struct 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 */
406 struct 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. */
418 struct 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 */
426 struct 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
439 The
440 .Nm netintro
441 manual appeared in
442 .Bx 4.3 tahoe .