date and time created 87/11/21 14:33:27 by karels
[unix-history] / usr / src / share / man / man4 / netintro.4
CommitLineData
804b4358
KM
1.\" Copyright (c) 1983 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
6613a54c 5.\" @(#)netintro.4 6.5 (Berkeley) %G%
804b4358 6.\"
18b4c4a1 7.TH NETINTRO 4 ""
804b4358
KM
8.UC 5
9.SH NAME
10networking \- introduction to networking facilities
11.SH SYNOPSIS
12.nf
13.ft B
14#include <sys/socket.h>
15#include <net/route.h>
16#include <net/if.h>
17.fi R
18.fi
19.SH DESCRIPTION
20.de _d
21.if t .ta .6i 2.1i 2.6i
22.\" 2.94 went to 2.6, 3.64 to 3.30
23.if n .ta .84i 2.6i 3.30i
24..
25.de _f
26.if t .ta .5i 1.25i 2.5i
27.\" 3.5i went to 3.8i
28.if n .ta .7i 1.75i 3.8i
29..
30This section briefly describes the networking facilities
31available in the system.
32Documentation in this part of section
334 is broken up into three areas:
72ccc903
MK
34.I "protocol families
35(domains),
804b4358
KM
36.IR protocols ,
37and
38.IR "network interfaces" .
72ccc903
MK
39Entries describing a protocol family are marked ``4F,''
40while entries describing protocol use are marked ``4P.''
804b4358
KM
41Hardware support for network interfaces are found
42among the standard ``4'' entries.
43.PP
44All network protocols are associated with a specific
72ccc903
MK
45.IR "protocol family" .
46A protocol family provides basic services to the protocol
804b4358
KM
47implementation to allow it to function within a specific
48network environment. These services may include
49packet fragmentation and reassembly, routing, addressing, and
72ccc903 50basic transport. A protocol family may support multiple
804b4358 51methods of addressing, though the current protocol implementations
72ccc903 52do not. A protocol family is normally comprised of a number
804b4358
KM
53of protocols, one per
54.IR socket (2)
72ccc903
MK
55type. It is not required that a protocol family support
56all socket types. A protocol family may contain multiple
804b4358
KM
57protocols supporting the same socket abstraction.
58.PP
59A protocol supports one of the socket abstractions detailed
60in
61.IR socket (2).
62A specific protocol may be accessed either by creating a
72ccc903 63socket of the appropriate type and protocol family, or
804b4358
KM
64by requesting the protocol explicitly when creating a socket.
65Protocols normally accept only one type of address format,
66usually determined by the addressing structure inherent in
72ccc903 67the design of the protocol family/network architecture.
804b4358
KM
68Certain semantics of the basic socket abstractions are
69protocol specific. All protocols are expected to support
70the basic model for their particular socket type, but may,
71in addition, provide non-standard facilities or extensions
72to a mechanism. For example, a protocol supporting the
73SOCK_STREAM
74abstraction may allow more than one byte of out-of-band
75data to be transmitted per out-of-band message.
76.PP
77A network interface is similar to a device interface.
78Network interfaces comprise the lowest layer of the
79networking subsystem, interacting with the actual transport
80hardware. An interface may support one or more protocol
72ccc903 81families and/or address formats.
804b4358
KM
82The SYNOPSIS section of each network interface
83entry gives a sample specification
84of the related drivers for use in providing
85a system description to the
86.IR config (8)
87program.
88The DIAGNOSTICS section lists messages which may appear on the console
72ccc903 89and/or in the system error log,
804b4358 90.I /usr/adm/messages
72ccc903
MK
91(see
92.IR syslogd (8)),
804b4358
KM
93due to errors in device operation.
94.SH PROTOCOLS
72ccc903
MK
95The system currently supports the DARPA Internet
96protocols and the Xerox Network Systems(tm) protocols.
97Raw socket interfaces are provided to the IP protocol
804b4358 98layer of the DARPA Internet, to the IMP link layer (1822), and to
72ccc903 99the IDP protocol of Xerox NS.
804b4358
KM
100Consult the appropriate manual pages in this section for more
101information regarding the support for each protocol family.
102.SH ADDRESSING
103Associated with each protocol family is an address
4c631ca5
MS
104format. The following address formats are used by the system (and additional
105formats are defined for possible future implementation):
804b4358
KM
106.sp 1
107.nf
108._d
109#define AF_UNIX 1 /* local to host (pipes, portals) */
110#define AF_INET 2 /* internetwork: UDP, TCP, etc. */
111#define AF_IMPLINK 3 /* arpanet imp addresses */
112#define AF_PUP 4 /* pup protocols: e.g. BSP */
4c631ca5
MS
113#define AF_NS 6 /* Xerox NS protocols */
114#define AF_HYLINK 15 /* NSC Hyperchannel */
804b4358
KM
115.fi
116.SH ROUTING
117The network facilities provided limited packet routing.
118A simple set of data structures comprise a ``routing table''
119used in selecting the appropriate network interface when
120transmitting packets. This table contains a single entry for
121each route to a specific network or host. A user process,
122the routing daemon, maintains this data base with the aid
4c631ca5 123of two socket-specific
804b4358
KM
124.IR ioctl (2)
125commands, SIOCADDRT and SIOCDELRT. The commands allow
126the addition and deletion of a single routing
127table entry, respectively. Routing table manipulations may
128only be carried out by super-user.
129.PP
130A routing table entry has the following form, as defined
131in
132.RI < net/route.h >;
133.sp 1
134._f
135.nf
136struct rtentry {
137 u_long rt_hash;
138 struct sockaddr rt_dst;
139 struct sockaddr rt_gateway;
140 short rt_flags;
141 short rt_refcnt;
142 u_long rt_use;
143 struct ifnet *rt_ifp;
144};
145.sp 1
146.fi
147with
148.I rt_flags
149defined from,
150.sp 1
151.nf
152._d
153#define RTF_UP 0x1 /* route usable */
154#define RTF_GATEWAY 0x2 /* destination is a gateway */
155#define RTF_HOST 0x4 /* host entry (net otherwise) */
72ccc903 156#define RTF_DYNAMIC 0x10 /* created dynamically (by redirect) */
804b4358
KM
157.fi
158.PP
159Routing table entries come in three flavors: for a specific
160host, for all hosts on a specific network, for any destination
161not matched by entries of the first two types (a wildcard route).
72ccc903
MK
162When the system is booted and addresses are assigned
163to the network interfaces, each protocol family
164installs a routing table entry for each interface when it is ready for traffic.
165Normally the protocol specifies the route
166through each interface as a ``direct'' connection to the destination host
804b4358
KM
167or network. If the route is direct, the transport layer of
168a protocol family usually requests the packet be sent to the
169same host specified in the packet. Otherwise, the interface
72ccc903
MK
170is requested to address the packet to the gateway listed in the routing entry
171(i.e. the packet is forwarded).
804b4358
KM
172.PP
173Routing table entries installed by a user process may not specify
174the hash, reference count, use, or interface fields; these are filled
175in by the routing routines. If
176a route is in use when it is deleted
177.RI ( rt_refcnt
178is non-zero),
72ccc903
MK
179the routing entry will be marked down and removed from the routing table,
180but the resources associated with it will not
181be reclaimed until all references to it are released.
804b4358
KM
182The routing code returns EEXIST if
183requested to duplicate an existing entry, ESRCH if
4c631ca5 184requested to delete a non-existent entry,
804b4358
KM
185or ENOBUFS if insufficient resources were available
186to install a new route.
804b4358
KM
187User processes read the routing tables through the
188.I /dev/kmem
189device.
804b4358
KM
190The
191.I rt_use
192field contains the number of packets sent along the route.
72ccc903
MK
193.PP
194When routing a packet,
195the kernel will first attempt to find a route to the destination host.
196Failing that, a search is made for a route to the network of the destination.
197Finally, any route to a default (``wildcard'') gateway is chosen.
198If multiple routes are present in the table,
199the first route found will be used.
200If no entry is found, the destination is declared to be unreachable.
804b4358
KM
201.PP
202A wildcard routing entry is specified with a zero
203destination address value. Wildcard routes are used
204only when the system fails to find a route to the
205destination host and network. The combination of wildcard
206routes and routing redirects can provide an economical
207mechanism for routing traffic.
208.SH INTERFACES
209Each network interface in a system corresponds to a
210path through which messages may be sent and received. A network
211interface usually has a hardware device associated with it, though
212certain interfaces such as the loopback interface,
213.IR lo (4),
214do not.
215.PP
804b4358
KM
216The following
217.I ioctl
72ccc903
MK
218calls may be used to manipulate network interfaces.
219The
220.I ioctl
221is made on a socket (typically of type SOCK_DGRAM)
222in the desired domain.
223Unless specified otherwise, the request takes an
804b4358
KM
224.I ifrequest
225structure as its parameter. This structure has the form
226.PP
227.nf
228.DT
229struct ifreq {
6613a54c
KB
230#define IFNAMSIZ 16
231 char ifr_name[IFNAMSIZE]; /* if name, e.g. "en0" */
804b4358
KM
232 union {
233 struct sockaddr ifru_addr;
234 struct sockaddr ifru_dstaddr;
72ccc903 235 struct sockaddr ifru_broadaddr;
804b4358 236 short ifru_flags;
72ccc903 237 int ifru_metric;
6613a54c 238 caddr_t ifru_data;
804b4358
KM
239 } ifr_ifru;
240#define ifr_addr ifr_ifru.ifru_addr /* address */
241#define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */
72ccc903 242#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
804b4358 243#define ifr_flags ifr_ifru.ifru_flags /* flags */
6613a54c
KB
244#define ifr_metric ifr_ifru.ifru_metric /* metric */
245#define ifr_data ifr_ifru.ifru_data /* for use by interface */
804b4358
KM
246};
247.fi
248.TP
249SIOCSIFADDR
72ccc903 250Set interface address for protocol family. Following the address
804b4358
KM
251assignment, the ``initialization'' routine for
252the interface is called.
253.TP
254SIOCGIFADDR
72ccc903 255Get interface address for protocol family.
804b4358
KM
256.TP
257SIOCSIFDSTADDR
72ccc903 258Set point to point address for protocol family and interface.
804b4358
KM
259.TP
260SIOCGIFDSTADDR
72ccc903
MK
261Get point to point address for protocol family and interface.
262.TP
263SIOCSIFBRDADDR
264Set broadcast address for protocol family and interface.
265.TP
266SIOCGIFBRDADDR
267Get broadcast address for protocol family and interface.
804b4358
KM
268.TP
269SIOCSIFFLAGS
270Set interface flags field. If the interface is marked down,
271any processes currently routing packets through the interface
72ccc903
MK
272are notified;
273some interfaces may be reset so that incoming packets are no longer received.
274When marked up again, the interface is reinitialized.
804b4358
KM
275.TP
276SIOCGIFFLAGS
277Get interface flags.
278.TP
72ccc903
MK
279SIOCSIFMETRIC
280Set interface routing metric.
281The metric is used only by user-level routers.
282.TP
283SIOCGIFMETRIC
284Get interface metric.
285.TP
804b4358
KM
286SIOCGIFCONF
287Get interface configuration list. This request takes an
288.I ifconf
289structure (see below) as a value-result parameter. The
290.I ifc_len
291field should be initially set to the size of the buffer
292pointed to by
293.IR ifc_buf .
294On return it will contain the length, in bytes, of the
295configuration list.
296.PP
297.nf
298.DT
299/*
300 * Structure used in SIOCGIFCONF request.
301 * Used to retrieve interface configuration
302 * for machine (useful for programs which
303 * must know all networks accessible).
304 */
305struct ifconf {
306 int ifc_len; /* size of associated buffer */
307 union {
308 caddr_t ifcu_buf;
309 struct ifreq *ifcu_req;
310 } ifc_ifcu;
311#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
312#define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */
313};
314.fi
315.SH SEE ALSO
18b4c4a1 316socket(2), ioctl(2), intro(4), config(8), routed(8C)