1 |
27 |
unneback |
|
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 |
|
|
TCP/IP Stack Support for eCos
|
34 |
|
|
|
35 |
|
|
|
36 |
|
|
The Common Networking for eCos package
|
37 |
|
|
provides support for a complete TCP/IP networking stack.
|
38 |
|
|
The design allows for the actual stack to be modular and at the
|
39 |
|
|
current time two different implementations, one based on OpenBSD
|
40 |
|
|
from 2000 and a new version based on FreeBSD, are available.
|
41 |
|
|
The particulars of each stack implementation are presented in
|
42 |
|
|
separate sections following this top-level discussion.
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
Ethernet Driver Design
|
47 |
|
|
Currently, the networking stack only supports ethernet based
|
48 |
|
|
networking.
|
49 |
|
|
The network drivers use a two-layer design. One layer is
|
50 |
|
|
hardware independent and contains all the stack specific code.
|
51 |
|
|
The other layer is platform dependent and communicates with the
|
52 |
|
|
hardware independent layer via a very simple API. In this way,
|
53 |
|
|
hardware device drivers can actually be used with other stacks,
|
54 |
|
|
if the same API can be provided by that stack. We designed the
|
55 |
|
|
drivers this way to encourage the development of other stacks in
|
56 |
|
|
eCos while allowing re-use of the actual hardware specific code.
|
57 |
|
|
More comprehensive documentation of the ethernet device driver and
|
58 |
|
|
the associated API can be found in the generic ethernet device driver
|
59 |
|
|
documentation
|
60 |
|
|
|
61 |
|
|
The driver and API is the same as the minimal debug stack used by
|
62 |
|
|
the RedBoot application. See the RedBoot documentation
|
63 |
|
|
|
64 |
|
|
for further
|
65 |
|
|
information.
|
66 |
|
|
|
67 |
|
|
|
68 |
|
|
Sample Code
|
69 |
|
|
Many examples using the networking support are provided.
|
70 |
|
|
These are arranged as eCos test programs, primarily for use in verifying
|
71 |
|
|
the package, but they can also serve as useful frameworks for program
|
72 |
|
|
design. We have taken a
|
73 |
|
|
KISS
|
74 |
|
|
approach to building programs which
|
75 |
|
|
use the network. A single include file
|
76 |
|
|
<network.h> is
|
77 |
|
|
all that is required to access the stack. A complete, annotated
|
78 |
|
|
test program can be found at
|
79 |
|
|
net/common/VERSION/tests/ftp_test.c,
|
80 |
|
|
with its associated files.
|
81 |
|
|
|
82 |
|
|
|
83 |
|
|
Configuring IP Addresses
|
84 |
|
|
Each interface (“eth0” and “eth1”)
|
85 |
|
|
has independent configuration of its setup. Each can be set up
|
86 |
|
|
manually (in which case you must write code to do this), or by using
|
87 |
|
|
BOOTP/DHCP,
|
88 |
|
|
or explicitly, with configured values. If additional
|
89 |
|
|
interfaces are added, these must be configured manually.
|
90 |
|
|
The configurable values are:
|
91 |
|
|
|
92 |
|
|
IP address
|
93 |
|
|
netmask
|
94 |
|
|
broadcast address
|
95 |
|
|
gateway/router
|
96 |
|
|
server address.
|
97 |
|
|
|
98 |
|
|
Server address is the DHCP server if applicable, but in addition,
|
99 |
|
|
many test cases use it as “the machine to talk to” in
|
100 |
|
|
whatever manner the test exercises the protocol stack.
|
101 |
|
|
The initialization is invoked by calling the C routine
|
102 |
|
|
|
103 |
|
|
void init_all_network_interfaces(void);
|
104 |
|
|
|
105 |
|
|
|
106 |
|
|
|
107 |
|
|
Additionally, if the system is configured to support IPv6 then each
|
108 |
|
|
interface may have an address assigned which is a composite of a 64 bit
|
109 |
|
|
prefix and the 32 bit IPv4 address for that interface.
|
110 |
|
|
The prefix is controlled by the CDL setting
|
111 |
|
|
CYGHWR_NET_DRIVER_ETH0_IPV6_PREFIX for “eth0”, etc.
|
112 |
|
|
This is a CDL booldata type, allowing this address to be suppressed if
|
113 |
|
|
not desired.
|
114 |
|
|
|
115 |
|
|
|
116 |
|
|
Refer to the test cases,
|
117 |
|
|
…/packages/net/common/VERSION/tests/ftp_test.c
|
118 |
|
|
for example usage, and the source files in
|
119 |
|
|
…/packages/net/common/VERSION/src/bootp_support.c
|
120 |
|
|
and
|
121 |
|
|
network_support.c
|
122 |
|
|
to see what that call does.
|
123 |
|
|
This assumes that the MAC address (also known as
|
124 |
|
|
ESA or Ethernet Station Address)
|
125 |
|
|
is already defined in the
|
126 |
|
|
serial EEPROM or however the particular target implements this;
|
127 |
|
|
support for setting the MAC address is hardware dependent.
|
128 |
|
|
DHCP support is active by default, and there are configuration
|
129 |
|
|
options to control it. Firstly, in the top level of the
|
130 |
|
|
“Networking” configuration
|
131 |
|
|
tree, “Use full DHCP instead of BOOTP” enables
|
132 |
|
|
DHCP, and it contains an option to have the system provide a thread
|
133 |
|
|
to renew DHCP leases and manage lease expiry. Secondly, the individual
|
134 |
|
|
interfaces “eth0” and “eth1” each
|
135 |
|
|
have new options within the “Use BOOTP/DHCP to
|
136 |
|
|
initialize ‘ethX’” to
|
137 |
|
|
select whether to use DHCP rather than BOOTP.
|
138 |
|
|
|
139 |
|
|
Note that you are completely at liberty to ignore this startup code and its
|
140 |
|
|
configuration in building your application.
|
141 |
|
|
init_all_network_interfaces()
|
142 |
|
|
is provided for three main purposes:
|
143 |
|
|
|
144 |
|
|
For use by Red Hat's own test programs.
|
145 |
|
|
As an easy “get you going” utility for
|
146 |
|
|
newcomers to eCos.
|
147 |
|
|
As readable example code from which further development
|
148 |
|
|
might start.
|
149 |
|
|
|
150 |
|
|
|
151 |
|
|
If your application has different requirements for bringing up
|
152 |
|
|
available network interfaces, setting up routes, determining IP addresses
|
153 |
|
|
and the like from the defaults that the example code provides, you can
|
154 |
|
|
write your own initialization code to use whatever sequence of
|
155 |
|
|
ioctl() function
|
156 |
|
|
calls carries out the desired setup. Analogously, in larger systems,
|
157 |
|
|
a sequence of “ifconfig&rdquo invocations is used; these mostly
|
158 |
|
|
map to ioctl() calls to manipulate the state of
|
159 |
|
|
the interface in question.
|
160 |
|
|
|
161 |
|
|
|
162 |
|
|
|
163 |
|
|
Tests and Demonstrations
|
164 |
|
|
|
165 |
|
|
Loopback tests
|
166 |
|
|
By default, only tests which can execute on any target
|
167 |
|
|
will be built. These therefore do not actually use external
|
168 |
|
|
network interfaces (though they may configure and initialize
|
169 |
|
|
them) but are limited to testing via the loopback
|
170 |
|
|
interface.
|
171 |
|
|
ping_lo_test - ping test of the loopback address
|
172 |
|
|
tcp_lo_select - simple test of select with TCP via loopback
|
173 |
|
|
tcp_lo_test - trivial TCP test via loopback
|
174 |
|
|
udp_lo_test - trivial UDP test via loopback
|
175 |
|
|
multi_lo_select - test of multiple select() calls simultaneously
|
176 |
|
|
|
177 |
|
|
|
178 |
|
|
Building the Network Tests
|
179 |
|
|
To build further network tests, ensure that the configuration
|
180 |
|
|
option CYGPKG_NET_BUILD_TESTS is set in your build
|
181 |
|
|
and then make the tests in the usual way. Alternatively
|
182 |
|
|
(with that option set) use
|
183 |
|
|
make -C net/common/VERSION/ tests
|
184 |
|
|
after building the eCos library, if you wish to build
|
185 |
|
|
only
|
186 |
|
|
the network tests.
|
187 |
|
|
This should give test executables in
|
188 |
|
|
install/tests/net/common/VERSION/tests
|
189 |
|
|
including
|
190 |
|
|
the following:
|
191 |
|
|
socket_test - trivial test of socket creation API
|
192 |
|
|
mbuf_test - trivial test of mbuf allocation API
|
193 |
|
|
ftp_test - simple FTP test, connects to “server”
|
194 |
|
|
ping_test - pings “server” and non-existent host to test timeout
|
195 |
|
|
dhcp_test - ping test, but also relinquishes and
|
196 |
|
|
reacquires DHCP leases periodically
|
197 |
|
|
flood - a flood ping test; use with care
|
198 |
|
|
tcp_echo - data forwarding program for performance test
|
199 |
|
|
nc_test_master - network characterization master
|
200 |
|
|
nc_test_slave - network characterization slave
|
201 |
|
|
server_test - a very simple server example
|
202 |
|
|
tftp_client_test - performs a tftp get and put from/to “server”
|
203 |
|
|
tftp_server_test - runs a tftp server for a short while
|
204 |
|
|
set_mac_address - set MAC address(es) of interfaces in NVRAM
|
205 |
|
|
bridge - contributed network bridge code
|
206 |
|
|
nc6_test_master - IPv4/IPv6 network characterization master
|
207 |
|
|
nc6_test_slave - IPv4/IPv6 network characterization slave
|
208 |
|
|
ga_server_test - a very simple IPv4/IPv6 server example
|
209 |
|
|
|
210 |
|
|
|
211 |
|
|
|
212 |
|
|
Standalone Tests
|
213 |
|
|
socket_test - trivial test of socket creation API
|
214 |
|
|
mbuf_test - trivial test of mbuf allocation API
|
215 |
|
|
These two do not communicate over the net; they just perform
|
216 |
|
|
simple API tests then exit.
|
217 |
|
|
ftp_test - simple FTP test, connects to “server”
|
218 |
|
|
This test initializes the interface(s) then connects to the
|
219 |
|
|
FTP server on the “server” machine for for each
|
220 |
|
|
active interface in turn, confirms that the connection was successful,
|
221 |
|
|
disconnects and exits. This tests interworking with the server.
|
222 |
|
|
ping_test - pings “server” and non-existent host to test timeout
|
223 |
|
|
This test initializes the interface(s) then pings the server
|
224 |
|
|
machine in the standard way, then pings address “32 up” from
|
225 |
|
|
the server in the expectation that there is no machine there. This
|
226 |
|
|
confirms that the successful ping is not a false positive, and tests
|
227 |
|
|
the receive timeout. If there is such a machine, of course the
|
228 |
|
|
2nd set of pings succeeds, confirming that we can talk to a machine
|
229 |
|
|
not previously mentioned by configuration or by bootp. It then does
|
230 |
|
|
the same thing on the other interface, eth1.
|
231 |
|
|
dhcp_test - ping test, but also manipulates DHCP leases
|
232 |
|
|
This test is very similar to the ping test, but in addition,
|
233 |
|
|
provided the network package is not configured to do this automatically,
|
234 |
|
|
it manually relinquishes and reclaims DHCP leases for all available
|
235 |
|
|
interfaces. This tests the external API to DHCP. See section below
|
236 |
|
|
describing this.
|
237 |
|
|
flood - a flood ping test; use with care
|
238 |
|
|
This test performs pings on all interfaces as quickly as possible,
|
239 |
|
|
and only prints status information periodically. Flood pinging is
|
240 |
|
|
bad for network performance; so do not use this test on general
|
241 |
|
|
purpose networks unless protected by a switch.
|
242 |
|
|
|
243 |
|
|
|
244 |
|
|
Performance Test
|
245 |
|
|
tcp_echo - data forwarding program for performance test
|
246 |
|
|
tcp_echo is one
|
247 |
|
|
part of the standard performance test we use. The other parts are
|
248 |
|
|
host programs tcp_source and tcp_sink.
|
249 |
|
|
To make these (under LINUX) cd to the tests source directory in
|
250 |
|
|
the eCos repository and type “make -f make.linux” -
|
251 |
|
|
this should build tcp_source and tcp_sink.
|
252 |
|
|
The LINUX program “tcp_source” sends
|
253 |
|
|
data to the target. On the target, “tcp_echo” sends
|
254 |
|
|
it onwards to “tcp_sink” running
|
255 |
|
|
on LINUX. So the target must receive and send on all the data that tcp_source sends
|
256 |
|
|
it; the time taken for this is measured and the data rate is calculated.
|
257 |
|
|
To invoke the test, first start tcp_echo on
|
258 |
|
|
the target board and wait for it to become quiescent - it will report
|
259 |
|
|
work to calibrate a CPU load which can be used to simulate real
|
260 |
|
|
operating conditions for the stack.
|
261 |
|
|
Then on your LINUX machine, in one terminal window, invoke tcp_sink giving
|
262 |
|
|
it the IP address (or hostname) of one interface of the target board.
|
263 |
|
|
For example “tcp_sink 10.130.39.66”.
|
264 |
|
|
tcp_echo on the target
|
265 |
|
|
will print something like “SINK connection
|
266 |
|
|
from 10.130.39.13:1143” when tcp_sink is
|
267 |
|
|
correctly invoked.
|
268 |
|
|
Next, in another LINUX terminal window, invoke tcp_source,
|
269 |
|
|
giving it the IP address (or hostname) of an interface of the target
|
270 |
|
|
board, and optionally a background load to apply to the target while
|
271 |
|
|
the test runs. For example, “tcp_source
|
272 |
|
|
194.130.39.66” to run the test with no
|
273 |
|
|
additional target CPU load, or “tcp_source
|
274 |
|
|
194.130.39.66 85” to load it up to 85% used.
|
275 |
|
|
The target load must be a multiple of 5. tcp_echo on
|
276 |
|
|
the target will print something like “SOURCE
|
277 |
|
|
connection from 194.130.39.13:1144” when
|
278 |
|
|
tcp_source is correctly invoked.
|
279 |
|
|
You can connect tcp_sink to one target interface
|
280 |
|
|
and tcp_source to another, or both to the same interface.
|
281 |
|
|
Similarly, you can run tcp_sink and tcp_source on
|
282 |
|
|
the same LINUX machine or different ones. TCP/IP and ARP
|
283 |
|
|
look after them finding one another, as intended.
|
284 |
|
|
nc_test_master - network characterization master
|
285 |
|
|
nc_test_slave - network characterization slave
|
286 |
|
|
These tests talk to each other to measure network performance.
|
287 |
|
|
They can each run on either a test target or a LINUX host computer
|
288 |
|
|
given some customization to your local environment. As provided, nc_test_slave must
|
289 |
|
|
run on the test target, and nc_test_master must
|
290 |
|
|
be run on a LINUX host, and be given the test target's
|
291 |
|
|
IP address or hostname.
|
292 |
|
|
The tests print network performance for various packet sizes
|
293 |
|
|
over UDP and TCP, versus various additional CPU loads on the target.
|
294 |
|
|
|
295 |
|
|
The programs nc6_test_slave
|
296 |
|
|
nc6_test_master
|
297 |
|
|
are additional forms which support both IPv4 and IPv6 addressing.
|
298 |
|
|
|
299 |
|
|
|
300 |
|
|
|
301 |
|
|
Interactive Tests
|
302 |
|
|
server_test - a very simple server example
|
303 |
|
|
This test simply awaits a connection on port 7734 and after
|
304 |
|
|
accepting a connection, gets a packet (with a timeout of a few seconds)
|
305 |
|
|
and prints it.
|
306 |
|
|
The connection is then closed. We then loop to await the next
|
307 |
|
|
connection, and so on. To use it, telnet to the target on port 7734
|
308 |
|
|
then type something (quickly!)
|
309 |
|
|
% telnet 172.16.19.171 7734
|
310 |
|
|
Hello target board
|
311 |
|
|
and the test program will print something like:
|
312 |
|
|
connection from 172.16.19.13:3369
|
313 |
|
|
buf = "Hello target board"
|
314 |
|
|
|
315 |
|
|
ga_server_test - another very simple server example
|
316 |
|
|
This is a variation on the ga_server_test test
|
317 |
|
|
with the difference being that it uses the getaddrinfo
|
318 |
|
|
function to set up its addresses. On a system with IPv6 enabled, it will
|
319 |
|
|
listen on port 7734 for a TCP connection via either IPv4 or IPv6.
|
320 |
|
|
|
321 |
|
|
|
322 |
|
|
tftp_client_test - performs a tftp get and put from/to “server”
|
323 |
|
|
This is only partially interactive. You need to set things
|
324 |
|
|
up on the “server” in order for this to work,
|
325 |
|
|
and you will need to look at the server afterwards to confirm that all
|
326 |
|
|
was well.
|
327 |
|
|
For each interface in turn, this test attempts to read by
|
328 |
|
|
tftp from the server, a file called
|
329 |
|
|
tftp_get
|
330 |
|
|
and
|
331 |
|
|
prints the status and contents it read (if any). It then writes
|
332 |
|
|
the same data to a file called
|
333 |
|
|
tftp_put
|
334 |
|
|
on
|
335 |
|
|
the same server.
|
336 |
|
|
In order for this to succeed, both files must already exist.
|
337 |
|
|
The TFTP protocol does not require that a WRQ request _create_ a
|
338 |
|
|
file, just that it can write it. The TFTP server on Linux certainly
|
339 |
|
|
will only allow writes to an existing file, given the appropriate
|
340 |
|
|
permission. Thus, you need to have these files in place, with proper permission,
|
341 |
|
|
before running the test.
|
342 |
|
|
The conventional place for the tftp server to operate in LINUX
|
343 |
|
|
is /tftpboot/; you will likely need root privileges
|
344 |
|
|
to create files there. The data contents of
|
345 |
|
|
tftp_get
|
346 |
|
|
can
|
347 |
|
|
be anything you like, but anything very large will waste lots of
|
348 |
|
|
time printing it on the test’s stdout, and anything above
|
349 |
|
|
32kB will cause a buffer overflow and unpredictable failure.
|
350 |
|
|
Creating an empty tftp_put file (eg. by copying /dev/null
|
351 |
|
|
to it) is neatest. So before the test you should have something
|
352 |
|
|
like:
|
353 |
|
|
-rw-rw-rw- 1 root 1076 May 1 11:39 tftp_get
|
354 |
|
|
-rw-rw-rw- 1 root 0 May 1 15:52 tftp_put
|
355 |
|
|
note that both files have public permissions wide open. After
|
356 |
|
|
running the test,
|
357 |
|
|
tftp_put
|
358 |
|
|
should
|
359 |
|
|
be a copy of
|
360 |
|
|
tftp_get.
|
361 |
|
|
-rw-rw-rw- 1 root 1076 May 1 11:39 tftp_get
|
362 |
|
|
-rw-rw-rw- 1 root 1076 May 1 15:52 tftp_put
|
363 |
|
|
|
364 |
|
|
|
365 |
|
|
tftp_server_test - runs a tftp server for a short while
|
366 |
|
|
This test is truly interactive, in that you can use a standard
|
367 |
|
|
tftp application to get and put files from the server, during the
|
368 |
|
|
5 minutes that it runs. The dummy filesystem which underlies the
|
369 |
|
|
server initially contains one file, called “uu” which contains
|
370 |
|
|
part of a familiar text and some padding. It also accommodates
|
371 |
|
|
creation of 3 further files of up to 1Mb in size and names of up
|
372 |
|
|
to 256 bytes. Exceeding these limits will cause a buffer overflow
|
373 |
|
|
and unpredictable failure.
|
374 |
|
|
The dummy filesystem is an implementation of the generic API
|
375 |
|
|
which allows a true filesystem to be attached to the tftp server
|
376 |
|
|
in the network stack.
|
377 |
|
|
We have been testing the tftp server by running the test on
|
378 |
|
|
the target board, then using two different host computers connecting
|
379 |
|
|
to the different target interfaces, putting a file from each, getting
|
380 |
|
|
the “uu” file, and getting the file from the other computer.
|
381 |
|
|
This verifies that data is preserved during the transfer as well
|
382 |
|
|
as interworking with standard tftp applications.
|
383 |
|
|
|
384 |
|
|
|
385 |
|
|
Maintenance Tools
|
386 |
|
|
set_mac_address - set MAC address(es) of interfaces in NVRAM
|
387 |
|
|
This program makes an example ioctl() call
|
388 |
|
|
SIOCSIFHWADDR
|
389 |
|
|
“Socket IO Set InterFace HardWare ADDRess”
|
390 |
|
|
to set the MAC address on targets
|
391 |
|
|
where this is supported and enabled in the configuration. You must
|
392 |
|
|
edit the source to choose a MAC address and further edit it to allow
|
393 |
|
|
this very dangerous operation. Not all ethernet drivers support
|
394 |
|
|
this operation, because most ethernet hardware does not support
|
395 |
|
|
it — or it comes pre-set from the factory.
|
396 |
|
|
Do not use this program.
|
397 |
|
|
|
398 |
|
|
|
399 |
|
|
|
400 |
|
|
Support Features
|
401 |
|
|
|
402 |
|
|
TFTP
|
403 |
|
|
The TFTP client and server are described in
|
404 |
|
|
tftp_support.h;
|
405 |
|
|
the client API is simple and can be easily understood by reading
|
406 |
|
|
tftp_client_test.c.
|
407 |
|
|
The server is more complex. It requires a filesystem implementation
|
408 |
|
|
to be supplied by the user, and attached to the tftp server by means
|
409 |
|
|
of a vector of function pointers:
|
410 |
|
|
struct tftpd_fileops {
|
411 |
|
|
int (*open)(const char *, int);
|
412 |
|
|
int (*close)(int);
|
413 |
|
|
int (*write)(int, const void *, int);
|
414 |
|
|
int (*read)(int, void *, int);
|
415 |
|
|
};
|
416 |
|
|
These functions have the obvious semantics. The structure
|
417 |
|
|
describing the filesystem is an argument to the tftpd_start(int,
|
418 |
|
|
struct tftpd_fileops *); call.
|
419 |
|
|
The first argument is the port to use for the server.
|
420 |
|
|
As discussed in the description of the tftp_server_test
|
421 |
|
|
above, an example filesystem is provided in
|
422 |
|
|
net/common/VERSION/src/tftp_dummy_file.c
|
423 |
|
|
for
|
424 |
|
|
use by the tftp server test. The dummy filesystem is not a supported
|
425 |
|
|
part of the network stack, it exists purely for demonstration purposes.
|
426 |
|
|
|
427 |
|
|
|
428 |
|
|
DHCP
|
429 |
|
|
This API publishes a routine to maintain DHCP state, and a
|
430 |
|
|
semaphore that is signalled when a lease requires attention: this
|
431 |
|
|
is your clue to call the aforementioned routine.
|
432 |
|
|
The intent with this API is that a simple DHCP client thread,
|
433 |
|
|
which maintains the state of the interfaces, can go as follows:
|
434 |
|
|
(after init_all_network_interfaces() is
|
435 |
|
|
called from elsewhere)
|
436 |
|
|
while ( 1 ) {
|
437 |
|
|
while ( 1 ) {
|
438 |
|
|
cyg_semaphore_wait( &dhcp_needs_attention );
|
439 |
|
|
if ( ! dhcp_bind() ) // a lease expired
|
440 |
|
|
break; // If we need to re-bind
|
441 |
|
|
}
|
442 |
|
|
dhcp_halt(); // tear everything down
|
443 |
|
|
init_all_network_interfaces(); // re-initialize
|
444 |
|
|
}
|
445 |
|
|
and if the application does not want to suffer the overhead
|
446 |
|
|
of a separate thread and its stack for this, this functionality
|
447 |
|
|
can be placed in the app’s server loop in an obvious fashion.
|
448 |
|
|
That is the goal of breaking out these internal elements. For example,
|
449 |
|
|
some server might be arranged to poll DHCP from time to time like
|
450 |
|
|
this:
|
451 |
|
|
while ( 1 ) {
|
452 |
|
|
init_all_network_interfaces();
|
453 |
|
|
open-my-listen-sockets();
|
454 |
|
|
while ( 1 ) {
|
455 |
|
|
serve-one-request();
|
456 |
|
|
// sleeps if no connections, but not forever;
|
457 |
|
|
// so this loop is polled a few times a minute...
|
458 |
|
|
if ( cyg_semaphore_trywait( &dhcp_needs_attention )) {
|
459 |
|
|
if ( ! dhcp_bind() ) {
|
460 |
|
|
close-my-listen-sockets();
|
461 |
|
|
dhcp_halt();
|
462 |
|
|
break;
|
463 |
|
|
}
|
464 |
|
|
}
|
465 |
|
|
}
|
466 |
|
|
}
|
467 |
|
|
If the configuration option CYGOPT_NET_DHCP_DHCP_THREAD
|
468 |
|
|
is defined, then eCos provides a thread as described initially.
|
469 |
|
|
Independent of this option, initialization of the interfaces still
|
470 |
|
|
occurs in init_all_network_interfaces() and
|
471 |
|
|
your startup code can call that. It will start the DHCP management
|
472 |
|
|
thread if configured. If a lease fails to be renewed, the management
|
473 |
|
|
thread will shut down all interfaces and attempt to initialize all
|
474 |
|
|
the interfaces again from scratch. This may cause chaos in the
|
475 |
|
|
app, which is why managing the DHCP state in an application aware
|
476 |
|
|
thread is actually better, just far less convenient for testing.
|
477 |
|
|
|
478 |
|
|
|
479 |
|
|
&net-common-tcpip-manpages-sgml;
|
480 |
|
|
|