1 |
786 |
skrzyp |
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
|
|
|
9 |
|
|
|
10 |
|
|
|
11 |
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
|
|
|
15 |
|
|
|
16 |
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
|
|
|
20 |
|
|
|
21 |
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
|
26 |
|
|
|
27 |
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
|
|
|
32 |
|
|
|
33 |
|
|
|
34 |
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
|
42 |
|
|
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
|
|
|
52 |
|
|
|
53 |
|
|
|
54 |
|
|
|
55 |
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
|
|
|
59 |
|
|
|
60 |
|
|
|
61 |
|
|
|
62 |
|
|
OpenBSD networking facilities
|
63 |
|
|
|
64 |
|
|
|
65 |
|
|
NAME
|
66 |
|
|
networking - introduction to networking facilities
|
67 |
|
|
|
68 |
|
|
SYNOPSIS
|
69 |
|
|
#include <sys/socket.h>
|
70 |
|
|
#include <net/route.h>
|
71 |
|
|
#include <net/if.h>
|
72 |
|
|
|
73 |
|
|
DESCRIPTION
|
74 |
|
|
This section is a general introduction to the networking facilities
|
75 |
|
|
available in the system. The general introduction on this page is
|
76 |
|
|
broken up into three areas: protocol families (domains), protocols,
|
77 |
|
|
and network interfaces.
|
78 |
|
|
|
79 |
|
|
All network protocols are associated with a specific protocol family. A
|
80 |
|
|
protocol family provides basic services to the protocol implementation
|
81 |
|
|
to allow it to function within a specific network environment. These
|
82 |
|
|
services may include packet fragmentation and reassembly, routing,
|
83 |
|
|
addressing, and basic transport. A protocol family may support multiple
|
84 |
|
|
methods of addressing, though the current protocol implementations do not.
|
85 |
|
|
A protocol family is normally comprised of a number of protocols, one per
|
86 |
|
|
socket type. It is not required that a protocol family support all
|
87 |
|
|
socket types. A protocol family may contain multiple protocols support-
|
88 |
|
|
ing the same socket abstraction.
|
89 |
|
|
|
90 |
|
|
A protocol supports one of the socket abstractions detailed in socket.
|
91 |
|
|
A specific protocol may be accessed either by creating a socket of the
|
92 |
|
|
appropriate type and protocol family, or by requesting the protocol ex-
|
93 |
|
|
plicitly when creating a socket. Protocols normally accept only one type
|
94 |
|
|
of address format, usually determined by the addressing structure inher-
|
95 |
|
|
ent in the design of the protocol family/network architecture. Certain
|
96 |
|
|
semantics of the basic socket abstractions are protocol specific. All
|
97 |
|
|
protocols are expected to support the basic model for their particular
|
98 |
|
|
socket type, but may, in addition, provide non-standard facilities or ex-
|
99 |
|
|
tensions to a mechanism. For example, a protocol supporting the
|
100 |
|
|
SOCK_STREAM abstraction may allow more than one byte of out-of-band data
|
101 |
|
|
to be transmitted per out-of-band message.
|
102 |
|
|
|
103 |
|
|
A network interface is similar to a device interface. Network interfaces
|
104 |
|
|
comprise the lowest layer of the networking subsystem, interacting with
|
105 |
|
|
the actual transport hardware. An interface may support one or more pro-
|
106 |
|
|
tocol families and/or address formats.
|
107 |
|
|
|
108 |
|
|
PROTOCOL
|
109 |
|
|
The system currently supports the Internet protocols. Raw socket interfaces
|
110 |
|
|
are provided to the IP protocol layer of the Internet.
|
111 |
|
|
|
112 |
|
|
ADDRESSING
|
113 |
|
|
Associated with each protocol family is an address format. All network
|
114 |
|
|
addresses adhere to a general structure, called a sockaddr, described be-
|
115 |
|
|
low. However, each protocol imposes a finer, more specific structure,
|
116 |
|
|
generally renaming the variant, which is discussed in the protocol family
|
117 |
|
|
manual page alluded to above.
|
118 |
|
|
|
119 |
|
|
struct sockaddr {
|
120 |
|
|
u_int8_t sa_len;
|
121 |
|
|
sa_family_t sa_family;
|
122 |
|
|
char sa_data[14];
|
123 |
|
|
};
|
124 |
|
|
|
125 |
|
|
The field sa_len contains the total length of the structure, which may
|
126 |
|
|
exceed 16 bytes. The following address values for sa_family are known to
|
127 |
|
|
the system (and additional formats are defined for possible future imple-
|
128 |
|
|
mentation):
|
129 |
|
|
|
130 |
|
|
#define AF_UNIX 1 /* local to host (pipes, portals) */
|
131 |
|
|
#define AF_INET 2 /* internetwork: UDP, TCP, etc. */
|
132 |
|
|
#define AF_NS 6 /* Xerox NS protocols */
|
133 |
|
|
#define AF_CCITT 10 /* CCITT protocols, X.25 etc */
|
134 |
|
|
#define AF_HYLINK 15 /* NSC Hyperchannel */
|
135 |
|
|
#define AF_APPLETALK 16 /* AppleTalk */
|
136 |
|
|
#define AF_ISO 18 /* ISO protocols */
|
137 |
|
|
#define AF_IPX 23 /* Novell Internet Protocol */
|
138 |
|
|
#define AF_INET6 24 /* IPv6 */
|
139 |
|
|
#define AF_NATM 27 /* native ATM access */
|
140 |
|
|
|
141 |
|
|
ROUTING
|
142 |
|
|
OpenBSD provides some packet routing facilities. The kernel maintains a
|
143 |
|
|
routing information database, which is used in selecting the appropriate
|
144 |
|
|
network interface when transmitting packets.
|
145 |
|
|
|
146 |
|
|
This facility is however, untested in eCos ports.
|
147 |
|
|
|
148 |
|
|
INTERFACES
|
149 |
|
|
Each network interface in a system corresponds to a path through which
|
150 |
|
|
messages may be sent and received. A network interface usually has a
|
151 |
|
|
hardware device associated with it, though certain interfaces such as the
|
152 |
|
|
loopback interface, lo, do not.
|
153 |
|
|
|
154 |
|
|
The following ioctl calls may be used to manipulate network interfaces
|
155 |
|
|
The ioctl is made on a socket (typically of type SOCK_DGRAM) in the desired
|
156 |
|
|
domain. Most of the requests supported in earlier releases take an ifreq
|
157 |
|
|
structure as its parameter. This structure has the form
|
158 |
|
|
|
159 |
|
|
struct ifreq {
|
160 |
|
|
#define IFNAMSIZ 16
|
161 |
|
|
char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
|
162 |
|
|
union {
|
163 |
|
|
struct sockaddr ifru_addr;
|
164 |
|
|
struct sockaddr ifru_dstaddr;
|
165 |
|
|
struct sockaddr ifru_broadaddr;
|
166 |
|
|
short ifru_flags;
|
167 |
|
|
int ifru_metric;
|
168 |
|
|
caddr_t ifru_data;
|
169 |
|
|
} ifr_ifru;
|
170 |
|
|
#define ifr_addr ifr_ifru.ifru_addr /* address */
|
171 |
|
|
#define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */
|
172 |
|
|
#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
|
173 |
|
|
#define ifr_flags ifr_ifru.ifru_flags /* flags */
|
174 |
|
|
#define ifr_metric ifr_ifru.ifru_metric /* metric */
|
175 |
|
|
#define ifr_media ifr_ifru.ifru_metric /* media options (overload) */
|
176 |
|
|
#define ifr_data ifr_ifru.ifru_data /* for use by interface */
|
177 |
|
|
};
|
178 |
|
|
|
179 |
|
|
Calls which are now deprecated are:
|
180 |
|
|
|
181 |
|
|
SIOCSIFADDR Set interface address for protocol family. Following the
|
182 |
|
|
address assignment, the ``initialization'' routine for
|
183 |
|
|
the interface is called.
|
184 |
|
|
|
185 |
|
|
SIOCSIFDSTADDR Set point to point address for protocol family and inter-
|
186 |
|
|
face.
|
187 |
|
|
|
188 |
|
|
SIOCSIFBRDADDR Set broadcast address for protocol family and interface.
|
189 |
|
|
|
190 |
|
|
ioctl requests to obtain addresses and requests both to set and retrieve
|
191 |
|
|
other data are still fully supported and use the ifreq structure:
|
192 |
|
|
|
193 |
|
|
SIOCGIFADDR Get interface address for protocol family.
|
194 |
|
|
|
195 |
|
|
SIOCGIFDSTADDR Get point to point address for protocol family and inter-
|
196 |
|
|
face.
|
197 |
|
|
|
198 |
|
|
SIOCGIFBRDADDR Get broadcast address for protocol family and interface.
|
199 |
|
|
|
200 |
|
|
SIOCSIFFLAGS Set interface flags field. If the interface is marked
|
201 |
|
|
down, any processes currently routing packets through the
|
202 |
|
|
interface are notified; some interfaces may be reset so
|
203 |
|
|
that incoming packets are no longer received. When
|
204 |
|
|
marked up again, the interface is reinitialized.
|
205 |
|
|
|
206 |
|
|
SIOCGIFFLAGS Get interface flags.
|
207 |
|
|
|
208 |
|
|
SIOCSIFMEDIA Set interface media. See ifmedia(4) for possible values.
|
209 |
|
|
|
210 |
|
|
SIOCGIFMEDIA Get interface media. See ifmedia(4) for interpreting
|
211 |
|
|
this value.
|
212 |
|
|
|
213 |
|
|
SIOCSIFMETRIC Set interface routing metric. The metric is used only by
|
214 |
|
|
user-level routers.
|
215 |
|
|
|
216 |
|
|
SIOCGIFMETRIC Get interface metric.
|
217 |
|
|
|
218 |
|
|
There are two requests that make use of a new structure:
|
219 |
|
|
|
220 |
|
|
SIOCAIFADDR An interface may have more than one address associated
|
221 |
|
|
with it in some protocols. This request provides a means
|
222 |
|
|
to add additional addresses (or modify characteristics of
|
223 |
|
|
the primary address if the default address for the ad-
|
224 |
|
|
dress family is specified). Rather than making separate
|
225 |
|
|
calls to set destination or broadcast addresses, or net-
|
226 |
|
|
work masks (now an integral feature of multiple proto-
|
227 |
|
|
cols) a separate structure is used to specify all three
|
228 |
|
|
facets simultaneously (see below). One would use a
|
229 |
|
|
slightly tailored version of this struct specific to each
|
230 |
|
|
family (replacing each sockaddr by one of the family-spe-
|
231 |
|
|
cific type). Where the sockaddr itself is larger than
|
232 |
|
|
the default size, one needs to modify the ioctl(2) iden-
|
233 |
|
|
tifier itself to include the total size, as described in
|
234 |
|
|
ioctl(2).
|
235 |
|
|
|
236 |
|
|
SIOCDIFADDR This request deletes the specified address from the list
|
237 |
|
|
associated with an interface. It also uses the
|
238 |
|
|
if_aliasreq structure to allow for the possibility of
|
239 |
|
|
protocols allowing multiple masks or destination address-
|
240 |
|
|
es, and also adopts the convention that specification of
|
241 |
|
|
the default address means to delete the first address for
|
242 |
|
|
the interface belonging to the address family in which
|
243 |
|
|
the original socket was opened.
|
244 |
|
|
|
245 |
|
|
SIOCGIFCONF Get interface configuration list. This request takes an
|
246 |
|
|
ifconf structure (see below) as a value-result parameter.
|
247 |
|
|
The ifc_len field should be initially set to the size of
|
248 |
|
|
the buffer pointed to by ifc_buf. On return it will con-
|
249 |
|
|
tain the length, in bytes, of the configuration list.
|
250 |
|
|
Alternately, if the ifc_len passed in is set to 0,
|
251 |
|
|
SIOCGIFCONF will set ifc_len to the size that ifc_buf
|
252 |
|
|
needs to be to fit the entire configuration list and not
|
253 |
|
|
fill in the other parameters. This is useful for deter-
|
254 |
|
|
mining the exact size that ifc_buf needs to be in ad-
|
255 |
|
|
vance. Note, however, that this is an extension that not
|
256 |
|
|
all operating systems support.
|
257 |
|
|
|
258 |
|
|
/*
|
259 |
|
|
* Structure used in SIOCAIFADDR request.
|
260 |
|
|
*/
|
261 |
|
|
struct ifaliasreq {
|
262 |
|
|
char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */
|
263 |
|
|
struct sockaddr ifra_addr;
|
264 |
|
|
struct sockaddr ifra_broadaddr;
|
265 |
|
|
struct sockaddr ifra_mask;
|
266 |
|
|
};
|
267 |
|
|
|
268 |
|
|
/*
|
269 |
|
|
* Structure used in SIOCGIFCONF request.
|
270 |
|
|
* Used to retrieve interface configuration
|
271 |
|
|
* for machine (useful for programs which
|
272 |
|
|
* must know all networks accessible).
|
273 |
|
|
*/
|
274 |
|
|
struct ifconf {
|
275 |
|
|
int ifc_len; /* size of associated buffer */
|
276 |
|
|
union {
|
277 |
|
|
caddr_t ifcu_buf;
|
278 |
|
|
struct ifreq *ifcu_req;
|
279 |
|
|
} ifc_ifcu;
|
280 |
|
|
#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
|
281 |
|
|
#define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */
|
282 |
|
|
};
|
283 |
|
|
|
284 |
|
|
SEE ALSO
|
285 |
|
|
bridge, spanning-tree
|
286 |
|
|
|
287 |
|
|
|
288 |
|
|
|
289 |
|
|
|
290 |
|
|
|
308 |
|
|
|