OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [devs/] [eth/] [synth/] [ecosynth/] [v2_0/] [doc/] [syntheth.sgml] - Blame information for rev 27

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
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
 
34
35
 
36
37
38
  Synthetic Target Ethernet Driver
39
 
40
41
  
42
    Synthetic Target Ethernet Driver
43
  
44
  
45
    Synthetic Target Ethernet Support
46
    Allow synthetic target applications to perform ethernet I/O
47
  
48
 
49
  Overview
50
    
51
The synthetic target ethernet package can provide up to four network
52
devices, eth0 to eth3. These can
53
be used directly by the eCos application or, more commonly, by a
54
TCP/IP stack that is linked with the eCos application. Each eCos
55
device can be mapped on to a real Linux network device. For example,
56
if the Linux PC has two ethernet cards and eth1 is
57
not currently being used by Linux itself, then one of the eCos devices
58
can be mapped on to this Linux device. Alternatively, it is possible
59
to map some or all of the eCos devices on to the ethertap support
60
provided by the Linux kernel.
61
    
62
    
63
The ethernet package depends on the I/O auxiliary provided by the
64
synthetic target architectural HAL package. During initialization the
65
eCos application will attempt to instantiate the desired devices, by
66
sending a request to the auxiliary. This will load a Tcl script
67
ethernet.tcl that is responsible for handling the
68
instantiation request and subsequent I/O operations, for example
69
transmitting an ethernet packet. However, some of the low-level I/O
70
operations cannot conveniently be done by a Tcl script so
71
ethernet.tcl will actually run a separate program
72
rawether to interact with the Linux network device.
73
    
74
    
75
      
76
        
77
          
78
        
79
      
80
    
81
    
82
On the target-side there are configuration options to control which
83
network devices should be present. For many applications a single
84
device will be sufficient, but if the final eCos application is
85
something like a network bridge then the package can support multiple
86
devices. On the host-side each eCos network device needs to be mapped
87
on to a Linux one, either a real ethernet device or an ethertap
88
device. This is handled by an entry in the target definition file:
89
    
90
    
91
synth_device ethernet {
92
    eth0 real eth1
93
    eth1 ethertap tap3 00:01:02:03:FE:05
94
95
}
96
97
    
98
The ethernet package also comes with support for packet logging,
99
and provides various facilities for use by user Tcl scripts.
100
    
101
  
102
 
103
  Installation
104
    
105
Before a synthetic target eCos application can access ethernet devices
106
it is necessary to build and install host-side support. The relevant
107
code resides in the host
108
subdirectory of the synthetic target ethernet package, and building it
109
involves the standard configure,
110
make and make install steps.
111
The build involves a new executable rawether which
112
must be able to access a raw Linux network device. This is achieved by
113
installing it suid root, so the make install step
114
has to be run with superuser privileges.
115
    
116
    
117
Installing rawether suid root introduces a
118
potential security problem. Although normally
119
rawether is executed only by the I/O auxiliary,
120
theoretically it can be run by any program. Effectively it gives any
121
user the ability to monitor all ethernet traffic and to inject
122
arbitrary packets into the network. Also, as with any suid root
123
programs there may be as yet undiscovered exploits. Users and system
124
administrators should consider the risks before running make
125
install.
126
    
127
    
128
There are two main ways of building the host-side software. It is
129
possible to build both the generic host-side software and all
130
package-specific host-side software, including the ethernet support,
131
in a single build tree. This involves using the
132
configure script at the toplevel of the eCos
133
repository. For more information on this, see the
134
README.host file at the top of the repository.
135
Note that if you have an existing build tree which does not include
136
the synthetic target ethernet support then it will be necessary to
137
rerun the toplevel configure script: the search for appropriate
138
packages happens at configure time.
139
    
140
    
141
The alternative is to build just the host-side for this package.
142
This requires a separate build directory, building directly in the
143
source tree is disallowed. The configure options
144
are much the same as for a build from the toplevel, and the
145
README.host file can be consulted for more
146
details. It is essential that the ethernet support be configured with
147
the same  option as other eCos host-side
148
software, especially the I/O auxiliary provided by the architectural
149
synthetic target HAL package, otherwise the I/O auxiliary will be
150
unable to locate the ethernet support.
151
    
152
  
153
 
154
  Target-side Configuration Options
155
    
156
The target-side code can be configured to support up to four ethernet
157
devices, eth0 to eth3. By
158
default eth0 is enabled if the configuration
159
includes a TCP/IP stack, otherwise it is disabled. The other three
160
devices are always disabled by default. If any of the devices are
161
enabled then there will also be the usual configuration options
162
related to building this package. Other options related to network
163
devices, for example whether or not to use DHCP, are provided by
164
the generic network device package.
165
    
166
  
167
 
168
  Real Ethernet
169
    
170
One obvious way of providing a synthetic target eCos application with
171
ethernet I/O is to use a real ethernet device in the PC: transmitted
172
packets go out on a real network, and packets on the network addressed
173
to the right MAC address are passed on to eCos. This way synthetic
174
target networking behaves just like networking on a real target with
175
ethernet hardware. For example, if there is a DHCP server anywhere on
176
the network then eCos will be able to contact it during networking
177
startup and get hold of IP address information.
178
    
179
    
180
Configuring the ethernet support to use a real ethernet device
181
requires a simple entry in the target definition file:
182
    
183
    
184
synth_device ethernet {
185
    <eCos device> real <linux device>
186
187
}
188
189
    
190
For example, to map the eCos network device eth0 to
191
the Linux device eth1:
192
    
193
    
194
synth_device ethernet {
195
    eth0 real eth1
196
197
}
198
199
    
200
It is not possible for an ethernet device to be shared by both the
201
eCos TCP/IP stack and the Linux one: there would be no simple way to
202
work out which stack incoming packets are intended for. In theory
203
it might be possible to do some demultiplexing using distinct IP
204
addresses, but it would be impossible to support some functionality
205
such as DHCP. Therefore the rawether program will
206
refuse to access any ethernet device already in use. On a typical
207
Linux system eth0 will be used for Linux
208
networking, and the PC will have to be equipped with additional
209
ethernet devices for use by eCos.
210
    
211
    
212
The rawether program will access the hardware via
213
the appropriate Linux device driver, so it is important that the
214
system is set up such that the relevant module will be automatically
215
loaded or is already loaded. The details of this will depend on the
216
installed distribution and version, but typically it will involve an
217
entry in /etc/modules.conf.
218
    
219
  
220
 
221
  Ethertap
222
    
223
The Linux kernel's ethertap facility provides a virtual network
224
interface. A Linux application, for example the
225
rawether program, can open a special character
226
device /dev/net/tun, perform various
227
ioctl calls, and then write
228
and read ethernet packets. When the device is
229
opened the Linux kernel automatically creates a new network interface,
230
for example tap0. The Linux TCP/IP stack can be
231
made to use this network interface like any other interface, receiving
232
and transmitting ethernet packets. The net effect is a virtual network
233
connecting just the Linux and eCos TCP/IP stacks, with no other nodes
234
attached. By default all traffic remains inside this virtual network
235
and is never forwarded to a real network.
236
    
237
    
238
Support for the ethertap facility may or may not be provided
239
automatically, depending on your Linux distribution and version. If
240
your system does not have a device /dev/net/tun
241
or a module tun.o then the appropriate kernel
242
documentation should be consulted, for example
243
/usr/src/linux-2.4/Documentation/networking/tuntap.txt.
244
If you are using an old Linux kernel then the ethertap functionality
245
may be missing completely. When the rawether
246
program is configured and built, the configure
247
script will check for a file 
248
class="headerfile">/usr/include/linux/if_tun.h. If that
249
file is missing then rawether will be built without
250
ethertap functionality, and only real ethernet interfaces will be
251
supported.
252
    
253
    
254
The target definition file is used to map eCos network devices on to
255
ethertap devices. The simplest usage is:
256
    
257
    
258
synth_device ethernet {
259
    eth0 ethertap
260
261
}
262
263
    
264
The Linux kernel will automatically allocate the next available tap
265
network interface. Usually this will be tap0 but if
266
other software is using the ethertap facility, for example to
267
implement a VPN, then a different number may be allocated. Usually it
268
will be better to specify the particular tap device that should be
269
used for each eCos device, for example:
270
    
271
    
272
synth_device ethernet {
273
    eth0 ethertap tap3
274
    eth1 ethertap tap4
275
276
}
277
278
    
279
The user now knows exactly which eCos device is mapped onto which
280
Linux device, avoiding much potential confusion. Because the virtual
281
devices are emulated ethernet devices, they require MAC addresses.
282
There is no physical hardware to provide these addresses, so normally
283
MAC addresses will be invented. That means that each time the eCos
284
application is run it will have different MAC addresses, which makes
285
it more difficult to compare the results of different runs. To get
286
more deterministic behaviour it is possible to specify the MAC
287
addresses in the target definition file:
288
    
289
    
290
synth_device ethernet {
291
    eth0 ethertap tap3 00:01:02:03:FE:05
292
    eth1 ethertap tap4 00:01:02:03:FE:06
293
294
}
295
296
    
297
During the initialization phase the eCos application will instantiate
298
the various network devices. This will cause the I/O auxiliary to load
299
the ethernet.tcl script and spawn
300
rawether processes, which in turn will
301
open /dev/net/tun and
302
perform the appropriate ioctl calls. On the Linux
303
side there will now be new network interfaces such as
304
tap3, and these can be configured like any other
305
network interface using commands such as ifconfig.
306
In addition, if the Linux system is set up with hotplug support then
307
it may be possible to arrange for the network interface to become
308
active automatically. On a Red Hat Linux system this would require
309
files such as
310
/etc/sysconfig/network-scripts/ifcfg-tap3,
311
containing data like:
312
    
313
    
314
DEVICE="tap3"
315
BOOTPROTO="none"
316
BROADCAST=10.2.2.255
317
IPADDR="10.2.2.1"
318
NETMASK="255.255.255.0"
319
NETWORK=10.2.2.0
320
ONBOOT="no"
321
322
    
323
This gives the Linux interface the address 10.2.2.1
324
on the network 10.2.2.0. The eCos network device
325
should be configured with a compatible address. One way of doing this
326
would be to enable CYGHWR_NET_DRIVER_ETH0_ADDRS,
327
set CYGHWR_NET_DRIVER_ETH0_ADDRS_IP to
328
10.2.2.2, and similarly update the
329
NETMASK, BROADCAST,
330
GATEWAY and SERVER configuration
331
options.
332
    
333
    
334
It should be noted that the ethertap facility provides a virtual
335
network, and any packets transmitted by the eCos application will
336
not appear on a real network. Therefore usually there will no
337
accessible DHCP server, and eCos cannot use DHCP or BOOTP to obtain IP
338
address information. Instead the eCos configuration should use manual
339
or static addresses.
340
    
341
    
342
An alternative approach would be to set up the Linux box as a network
343
bridge, using commands like brctl to connect the
344
virtual network interface tap3 to a physical
345
network interface such as eth0. Any packets sent by
346
the eCos application will get forwarded automatically to the real
347
network, and some packets on the real network will get forwarded over
348
the virtual network to the eCos application. Note that the eCos
349
application might also get some packets that were not intended for it,
350
but usually those will just be discarded by the eCos TCP/IP stack. The
351
exact details of setting up a network bridge are left as an exercise
352
to the reader.
353
    
354
  
355
 
356
  Packet Logging
357
    
358
The ethernet support comes with support for logging the various
359
packets that are transferred, including a simple protocol analyser.
360
This generates simple text output using the filter mechanisms provided
361
by the I/O auxiliary, so it is possible to control the appearance and
362
visibility of different types of output. For example the user might
363
want to see IPv4 headers and all ICMPv4 and ARP operations, but not
364
TCP headers or any of the packet data.
365
    
366
    
367
The protocol analyser is not intended to be a fully functional
368
analyser with knowledge of many different TCP/IP protocols, advanced
369
search facilities, graphical traffic displays, and so on.
370
Functionality like that is already provided by other tools such as
371
ethereal and
372
tcpdump. Achieving similar levels of
373
functionality would require a lot of work, for very little gain. It is
374
still useful to have some protocol analysis functionality available
375
because the output will be interleaved with other output, for example
376
printf calls from the application. That may make
377
it easier to understand the sequence of events.
378
    
379
    
380
One problem with logging ethernet traffic is that it can involve very
381
large amounts of data. If the application is expected to run for a
382
long time or is very I/O intensive then it is easy to end up with many
383
megabytes. When running in graphical mode all the logging data will be
384
held in memory, even data that is not currently visible. At some point
385
the system will begin to run low on memory and performance will
386
suffer. To avoid problems, the ethernet script maintains a flag that
387
controls whether or not packet logging is active. The default is to
388
run with logging disabled, but this can be changed in the target
389
definition file:
390
    
391
    
392
synth_device ethernet {
393
394
    logging 1
395
}
396
397
    
398
The ethernet script will add a toolbar button that allows this flag to
399
be changed at run-time, allowing the user to capture traffic for
400
certain periods of time while the application continues running.
401
    
402
    
403
The target definition file can contain the following entries for the
404
various packet logging filters:
405
    
406
    
407
synth_device ethernet {
408
409
    filter ether  -hide 0 -background LightBlue -foreground "#000080"
410
    filter arp    -hide 0 -background LightBlue -foreground "#000050"
411
    filter ipv4   -hide 0 -background LightBlue -foreground "#000040"
412
    filter ipv6   -hide 1 -background LightBlue -foreground "#000040"
413
    filter icmpv4 -hide 0 -background LightBlue -foreground "#000070"
414
    filter icmpv6 -hide 1 -background LightBlue -foreground "#000070"
415
    filter udp    -hide 0 -background LightBlue -foreground "#000030"
416
    filter tcp    -hide 0 -background LightBlue -foreground "#000020"
417
    filter hexdata   -hide 1 -background LightBlue -foreground "#000080"
418
    filter asciidata -hide 1 -background LightBlue -foreground "#000080"
419
}
420
421
    
422
All output will show the eCos network device, for example
423
eth0, and the direction relative to the eCos
424
application. Some of the filters will show packet headers, for example
425
ether gives details of the ethernet packet header
426
and tcp gives information about TCP headers such as
427
whether or not the SYN flag is set. The TCP and UDP filters will also
428
show source and destination addresses, using numerical addresses and
429
if possible host names. However, host names will only be shown if the
430
host appears in /etc/hosts: doing full DNS
431
lookups while the data is being captured would add significantly to
432
complexity and overhead. The hexdata and
433
asciidata filters show the remainder of the packets
434
after the ethernet, IP and TCP or UDP headers have been stripped.
435
    
436
    
437
Some of the filters will provide raw dumps of some of the packet data.
438
Showing up to 1500 bytes of data for each packet would be expensive,
439
and often the most interesting information is near the start of the
440
packet. Therefore it is possible to set a limit on the number of bytes
441
that will be shown using the target definition file. The default limit
442
is 64 bytes.
443
    
444
    
445
synth_device ethernet {
446
447
    max_show 128
448
}
449
450
  
451
 
452
  User Interface Additions
453
    
454
When running in graphical mode the ethernet script extends the user
455
interface in two ways: a button is added to the toolbar so that users
456
can enable or disable packet logging; and an entry is added to the
457
Help menu for the ethernet-specific documentation.
458
    
459
  
460
 
461
  Command Line Arguments
462
    
463
The synthetic target ethernet support does not use any command line
464
arguments. All configuration is handled through the target definition
465
file.
466
    
467
  
468
 
469
  Hooks
470
    
471
The ethernet support defines two hooks that can be used by other
472
scripts, especially user scripts: ethernet_tx and
473
ethernet_rx. The tx hook is called whenever eCos
474
tries to transmit a packet. The rx hook is called whenever an incoming
475
packet is passed to the eCos application. Note that this may be a
476
little bit after the packet was actually received by the I/O auxiliary
477
since it can buffer some packets. Both hooks are called with two
478
arguments, the name of the network device and the packet being
479
transferred. Typical usage might look like:
480
    
481
    
482
  proc my_tx_hook { arg_list } {
483
    set dev [lindex $arg_list 0]
484
    incr ::my_ethernet_tx_packets($dev)
485
    incr ::my_ethernet_tx_bytes($dev) [string length [lindex $arg_list 1]]
486
  }
487
  proc my_rx_hook { arg_list } {
488
    set dev [lindex $arg_list 0]
489
    incr ::my_ethernet_rx_packets($dev)
490
    incr ::my_ethernet_rx_bytes($dev) [string length [lindex $arg_list 1]]
491
  }
492
  synth::hook_add "ethernet_tx" my_tx_hook
493
  synth::hook_add "ethernet_rx" my_rx_hook
494
495
    
496
The global arrays my_ethernet_tx_packets etc. will
497
now be updated whenever there is ethernet traffic. Other code,
498
probably running at regular intervals by use of the Tcl
499
after procedure, can then use this information to
500
update a graphical monitor of some sort.
501
    
502
  
503
 
504
  Additional Tcl Procedures
505
    
506
The ethernet support provides one additional Tcl procedure that can be
507
used by other scripts;
508
    
509
    
510
ethernet::devices_get_list
511
512
    
513
This procedure returns a list of the ethernet devices that have been
514
instantiated, for example {eth0 eth1}.
515
    
516
  
517
 
518
519
520

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.