]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/devs/eth/synth/ecosynth/v2_0/doc/syntheth.sgml
Initial revision
[karo-tx-redboot.git] / packages / devs / eth / synth / ecosynth / v2_0 / doc / syntheth.sgml
1 <!-- DOCTYPE refentry  PUBLIC "-//OASIS//DTD DocBook V3.1//EN" -->
2
3 <!-- {{{ Banner                         -->
4
5 <!-- =============================================================== -->
6 <!--                                                                 -->
7 <!--     syntheth.sgml                                               -->
8 <!--                                                                 -->
9 <!--     Synthetic target ethernet support package.                  -->
10 <!--                                                                 -->
11 <!-- =============================================================== -->
12 <!-- ####COPYRIGHTBEGIN####                                          -->
13 <!--                                                                 -->
14 <!-- =============================================================== -->
15 <!-- Copyright (C) 2002 Bart Veer                                    -->
16 <!-- This material may be distributed only subject to the terms      -->
17 <!-- and conditions set forth in the Open Publication License, v1.0  -->
18 <!-- or later (the latest version is presently available at          -->
19 <!-- http://www.opencontent.org/openpub/)                            -->
20 <!-- =============================================================== -->
21 <!--                                                                 -->      
22 <!-- ####COPYRIGHTEND####                                            -->
23 <!-- =============================================================== -->
24 <!-- #####DESCRIPTIONBEGIN####                                       -->
25 <!--                                                                 -->
26 <!-- Author(s):   bartv                                              -->
27 <!-- Contact(s):  bartv                                              -->
28 <!-- Date:        2002/08/20                                         -->
29 <!-- Version:     0.01                                               -->
30 <!--                                                                 -->
31 <!-- ####DESCRIPTIONEND####                                          -->
32 <!-- =============================================================== -->
33
34 <!-- }}} -->
35
36 <part id="devs-eth-synth-ecosynth-ref">
37 <!-- reference id="devs-eth-synth-ecosynth-ref" -->
38   <title>Synthetic Target Ethernet Driver</title>
39
40 <refentry id="devs-eth-synth-ecosynth">
41   <refmeta>
42     <refentrytitle>Synthetic Target Ethernet Driver</refentrytitle>
43   </refmeta>
44   <refnamediv>
45     <refname>Synthetic Target Ethernet Support</refname>
46     <refpurpose>Allow synthetic target applications to perform ethernet I/O</refpurpose> 
47   </refnamediv>
48
49   <refsect1><title>Overview</title>
50     <para>
51 The synthetic target ethernet package can provide up to four network
52 devices, <varname>eth0</varname> to <varname>eth3</varname>. 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 <varname>eth1</varname> 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     </para>
62     <para>
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 <filename>ethernet.tcl</filename> 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 <filename>ethernet.tcl</filename> will actually run a separate program
72 <command>rawether</command> to interact with the Linux network device. 
73     </para>
74     <informalfigure PgWide=1>
75       <mediaobject>
76         <imageobject>
77           <imagedata fileref="overview.png" Scalefit=1 Align="Center">
78         </imageobject>
79       </mediaobject>
80     </informalfigure>
81     <para>
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     </para>
90     <programlisting>
91 synth_device ethernet {
92     eth0 real eth1
93     eth1 ethertap tap3 00:01:02:03:FE:05
94     &hellip;
95 }
96 </programlisting>
97     <para>
98 The ethernet package also comes with support for packet logging,
99 and provides various facilities for use by user Tcl scripts.
100     </para>
101   </refsect1>
102
103   <refsect1 id="devs-eth-ecosynth-install"><title>Installation</title>
104     <para>
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 <filename class="directory">host</filename>
108 subdirectory of the synthetic target ethernet package, and building it
109 involves the standard <command>configure</command>,
110 <command>make</command> and <command>make install</command> steps.
111 The build involves a new executable <command>rawether</command> which
112 must be able to access a raw Linux network device. This is achieved by
113 installing it suid root, so the <command>make install</command> step
114 has to be run with superuser privileges.
115     </para>
116     <caution><para>
117 Installing <command>rawether</command> suid root introduces a
118 potential security problem. Although normally
119 <command>rawether</command> 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 <command>make
125 install</command>. 
126     </para></caution>
127     <para>
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 <command>configure</command> script at the toplevel of the eCos
133 repository. For more information on this, see the
134 <filename>README.host</filename> 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     </para>
140     <para>
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 <command>configure</command> options
144 are much the same as for a build from the toplevel, and the
145 <filename>README.host</filename> file can be consulted for more
146 details. It is essential that the ethernet support be configured with
147 the same <option>--prefix</option> 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     </para>
152   </refsect1>
153
154   <refsect1 id="devs-eth-ecosynth-options"><title>Target-side Configuration Options</title>
155     <para>
156 The target-side code can be configured to support up to four ethernet
157 devices, <varname>eth0</varname> to <varname>eth3</varname>. By
158 default <varname>eth0</varname> 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     </para>
166   </refsect1>
167
168   <refsect1 id="devs-eth-ecosynth-real"><title>Real Ethernet</title>
169     <para>
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     </para>
179     <para>
180 Configuring the ethernet support to use a real ethernet device
181 requires a simple entry in the target definition file:
182     </para>
183     <programlisting>
184 synth_device ethernet {
185     &lt;eCos device&gt; real &lt;linux device&gt;
186     &hellip;
187 }
188 </programlisting>
189     <para>
190 For example, to map the eCos network device <varname>eth0</varname> to
191 the Linux device <varname>eth1</varname>:
192     </para>
193     <programlisting>
194 synth_device ethernet {
195     eth0 real eth1
196     &hellip;
197 }
198 </programlisting>
199     <para>
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 <command>rawether</command> program will
206 refuse to access any ethernet device already in use. On a typical
207 Linux system <varname>eth0</varname> 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     </para>
211     <para>
212 The <command>rawether</command> 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 <filename>/etc/modules.conf</filename>.
218     </para>
219   </refsect1>
220
221   <refsect1 id="devs-eth-ecosynth-ethertap"><title>Ethertap</title>
222     <para>
223 The Linux kernel's ethertap facility provides a virtual network
224 interface. A Linux application, for example the
225 <command>rawether</command> program, can open a special character
226 device <filename>/dev/net/tun</filename>, perform various
227 <function>ioctl</function> calls, and then <filename>write</filename>
228 and <filename>read</filename> ethernet packets. When the device is
229 opened the Linux kernel automatically creates a new network interface,
230 for example <varname>tap0</varname>. 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     </para>
237     <para>
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 <filename>/dev/net/tun</filename>
241 or a module <filename>tun.o</filename> then the appropriate kernel
242 documentation should be consulted, for example
243 <filename>/usr/src/linux-2.4/Documentation/networking/tuntap.txt</filename>.
244 If you are using an old Linux kernel then the ethertap functionality
245 may be missing completely. When the <command>rawether</command>
246 program is configured and built, the <command>configure</command>
247 script will check for a file <filename
248 class="headerfile">/usr/include/linux/if_tun.h</filename>. If that
249 file is missing then <command>rawether</command> will be built without
250 ethertap functionality, and only real ethernet interfaces will be
251 supported.
252     </para>
253     <para>
254 The target definition file is used to map eCos network devices on to
255 ethertap devices. The simplest usage is:
256     </para>
257     <programlisting>
258 synth_device ethernet {
259     eth0 ethertap
260     &hellip;
261 }
262 </programlisting>
263     <para>
264 The Linux kernel will automatically allocate the next available tap
265 network interface. Usually this will be <varname>tap0</varname> 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     </para>
271     <programlisting>
272 synth_device ethernet {
273     eth0 ethertap tap3
274     eth1 ethertap tap4
275     &hellip;
276 }
277 </programlisting>
278     <para>
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     </para>
289     <programlisting>
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     &hellip;
294 }
295 </programlisting>
296     <para>
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 <filename>ethernet.tcl</filename> script and spawn
300 <command>rawether</command> processes, which in turn will
301 <function>open</function> <filename>/dev/net/tun</filename> and
302 perform the appropriate <filename>ioctl</filename> calls. On the Linux
303 side there will now be new network interfaces such as
304 <varname>tap3</varname>, and these can be configured like any other
305 network interface using commands such as <command>ifconfig</command>.
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 <filename>/etc/sysconfig/network-scripts/ifcfg-tap3</filename>,
311 containing data like:
312     </para>
313     <programlisting>
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 </programlisting>
322     <para>
323 This gives the Linux interface the address <literal>10.2.2.1</literal>
324 on the network <literal>10.2.2.0</literal>. The eCos network device
325 should be configured with a compatible address. One way of doing this
326 would be to enable <varname>CYGHWR_NET_DRIVER_ETH0_ADDRS</varname>,
327 set <varname>CYGHWR_NET_DRIVER_ETH0_ADDRS_IP</varname> to
328 <literal>10.2.2.2</literal>, and similarly update the
329 <varname>NETMASK</varname>, <varname>BROADCAST</varname>,
330 <varname>GATEWAY</varname> and <varname>SERVER</varname> configuration
331 options. 
332     </para>
333     <para>
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     </para>
341     <para>
342 When <command>rawether</command> exits, the tap interface is removed
343 by the kernel. By adding the parameter persistent
344 <command>rawether</command> will set the persistent flag on the tap
345 device.
346     </para>
347     <programlisting>
348 synth_device ethernet {
349     eth0 ethertap tap3 00:01:02:03:FE:05
350     eth1 ethertap tap4 00:01:02:03:FE:06 persistent
351     &hellip;
352 }
353 </programlisting>
354     <para>
355 With this flag set the kernel will not remove the interface when
356 <command>rawether</command> exits. This means applications such as
357 <command>dhcpd</command>, <command>radvd</command>, and
358 <command>tcpdump</command> will continue to run on the interface
359 between invocations of synthetic targets. As a result the target can
360 dynamically obtain its IP addresses from these daemons. Note it is a
361 good idea to specify a MAC address otherwise a different random MAC
362 address will be used each time and the dhcpd daemon will not be able
363 to reissue the same IP address.
364     </para>
365     <para>
366 Host daemons like dhcpd, ntpd, radvd etc are started at boot
367 time. Since the tap device does not exists at this point in time it is
368 not possible for these daemons to bind to the tap device. A simple
369 solution is to use the program
370 <command>install/bin/mktap</command>. This takes one parameter, the
371 name of the tap device it should create. eg,
372 <literal>tap3</literal>. 
373     </para>
374     <para>
375 An alternative approach would be to set up the Linux box as a network
376 bridge, using commands like <command>brctl</command> to connect the
377 virtual network interface <varname>tap3</varname> to a physical
378 network interface such as <varname>eth0</varname>. Any packets sent by
379 the eCos application will get forwarded automatically to the real
380 network, and some packets on the real network will get forwarded over
381 the virtual network to the eCos application. Note that the eCos
382 application might also get some packets that were not intended for it,
383 but usually those will just be discarded by the eCos TCP/IP stack. The
384 exact details of setting up a network bridge are left as an exercise
385 to the reader.
386     </para>
387   </refsect1>
388
389   <refsect1 id="devs-eth-ecosynth-logging"><title>Packet Logging</title>
390     <para>
391 The ethernet support comes with support for logging the various
392 packets that are transferred, including a simple protocol analyser.
393 This generates simple text output using the filter mechanisms provided
394 by the I/O auxiliary, so it is possible to control the appearance and
395 visibility of different types of output. For example the user might
396 want to see IPv4 headers and all ICMPv4 and ARP operations, but not
397 TCP headers or any of the packet data.
398     </para>
399     <para>
400 The protocol analyser is not intended to be a fully functional
401 analyser with knowledge of many different TCP/IP protocols, advanced
402 search facilities, graphical traffic displays, and so on.
403 Functionality like that is already provided by other tools such as
404 <application>ethereal</application> and
405 <application>tcpdump</application>. Achieving similar levels of
406 functionality would require a lot of work, for very little gain. It is
407 still useful to have some protocol analysis functionality available
408 because the output will be interleaved with other output, for example
409 <filename>printf</filename> calls from the application. That may make
410 it easier to understand the sequence of events.
411     </para>
412     <para>
413 One problem with logging ethernet traffic is that it can involve very
414 large amounts of data. If the application is expected to run for a
415 long time or is very I/O intensive then it is easy to end up with many
416 megabytes. When running in graphical mode all the logging data will be
417 held in memory, even data that is not currently visible. At some point
418 the system will begin to run low on memory and performance will
419 suffer. To avoid problems, the ethernet script maintains a flag that
420 controls whether or not packet logging is active. The default is to
421 run with logging disabled, but this can be changed in the target
422 definition file:
423     </para>
424     <programlisting>
425 synth_device ethernet {
426     &hellip;
427     logging 1
428 }
429 </programlisting>
430     <para>
431 The ethernet script will add a toolbar button that allows this flag to
432 be changed at run-time, allowing the user to capture traffic for
433 certain periods of time while the application continues running.
434     </para>
435     <para>
436 The target definition file can contain the following entries for the
437 various packet logging filters:
438     </para>
439     <programlisting width=72>
440 synth_device ethernet {
441     &hellip;
442     filter ether  -hide 0 -background LightBlue -foreground "#000080"
443     filter arp    -hide 0 -background LightBlue -foreground "#000050"
444     filter ipv4   -hide 0 -background LightBlue -foreground "#000040"
445     filter ipv6   -hide 1 -background LightBlue -foreground "#000040"
446     filter icmpv4 -hide 0 -background LightBlue -foreground "#000070"
447     filter icmpv6 -hide 1 -background LightBlue -foreground "#000070"
448     filter udp    -hide 0 -background LightBlue -foreground "#000030"
449     filter tcp    -hide 0 -background LightBlue -foreground "#000020"
450     filter hexdata   -hide 1 -background LightBlue -foreground "#000080"
451     filter asciidata -hide 1 -background LightBlue -foreground "#000080"
452 }
453 </programlisting>
454     <para>
455 All output will show the eCos network device, for example
456 <literal>eth0</literal>, and the direction relative to the eCos
457 application. Some of the filters will show packet headers, for example
458 <literal>ether</literal> gives details of the ethernet packet header
459 and <literal>tcp</literal> gives information about TCP headers such as
460 whether or not the SYN flag is set. The TCP and UDP filters will also
461 show source and destination addresses, using numerical addresses and
462 if possible host names. However, host names will only be shown if the
463 host appears in <filename>/etc/hosts</filename>: doing full DNS
464 lookups while the data is being captured would add significantly to
465 complexity and overhead. The <literal>hexdata</literal> and
466 <literal>asciidata</literal> filters show the remainder of the packets
467 after the ethernet, IP and TCP or UDP headers have been stripped.
468     </para>
469     <para>
470 Some of the filters will provide raw dumps of some of the packet data.
471 Showing up to 1500 bytes of data for each packet would be expensive,
472 and often the most interesting information is near the start of the
473 packet. Therefore it is possible to set a limit on the number of bytes
474 that will be shown using the target definition file. The default limit
475 is 64 bytes.
476     </para>
477     <programlisting width=72>
478 synth_device ethernet {
479     &hellip;
480     max_show 128
481 }
482 </programlisting>
483   </refsect1>
484
485   <refsect1 id="devs-eth-ecosynth-gui"><title>User Interface Additions</title>
486     <para>
487 When running in graphical mode the ethernet script extends the user
488 interface in two ways: a button is added to the toolbar so that users
489 can enable or disable packet logging; and an entry is added to the
490 <guimenu>Help</guimenu> menu for the ethernet-specific documentation.
491     </para>
492   </refsect1>
493
494   <refsect1 id="devs-eth-ecosynth-args"><title>Command Line Arguments</title>
495     <para>
496 The synthetic target ethernet support does not use any command line
497 arguments. All configuration is handled through the target definition
498 file. 
499     </para>
500   </refsect1>
501
502   <refsect1 id="devs-eth-ecosynth-hooks"><title>Hooks</title>
503     <para>
504 The ethernet support defines two hooks that can be used by other
505 scripts, especially user scripts: <literal>ethernet_tx</literal> and
506 <literal>ethernet_rx</literal>. The tx hook is called whenever eCos
507 tries to transmit a packet. The rx hook is called whenever an incoming
508 packet is passed to the eCos application. Note that this may be a
509 little bit after the packet was actually received by the I/O auxiliary
510 since it can buffer some packets. Both hooks are called with two
511 arguments, the name of the network device and the packet being
512 transferred. Typical usage might look like:
513     </para>
514     <programlisting>
515   proc my_tx_hook { arg_list } {
516     set dev [lindex $arg_list 0]
517     incr ::my_ethernet_tx_packets($dev)
518     incr ::my_ethernet_tx_bytes($dev) [string length [lindex $arg_list 1]]
519   }
520   proc my_rx_hook { arg_list } {
521     set dev [lindex $arg_list 0]
522     incr ::my_ethernet_rx_packets($dev)
523     incr ::my_ethernet_rx_bytes($dev) [string length [lindex $arg_list 1]]
524   }
525   synth::hook_add "ethernet_tx" my_tx_hook
526   synth::hook_add "ethernet_rx" my_rx_hook
527 </programlisting>
528     <para>
529 The global arrays <varname>my_ethernet_tx_packets</varname> etc. will
530 now be updated whenever there is ethernet traffic. Other code,
531 probably running at regular intervals by use of the Tcl
532 <command>after</command> procedure, can then use this information to
533 update a graphical monitor of some sort.
534     </para>  
535   </refsect1>
536
537   <refsect1 id="devs-eth-ecosynth-tcl"><title>Additional Tcl Procedures</title>
538     <para>
539 The ethernet support provides one additional Tcl procedure that can be
540 used by other scripts;
541     </para>
542     <programlisting>
543 ethernet::devices_get_list    
544 </programlisting>
545     <para>
546 This procedure returns a list of the ethernet devices that have been
547 instantiated, for example <literal>{eth0 eth1}</literal>.
548     </para>
549   </refsect1>
550
551 </refentry>
552 </part>
553 <!-- /reference -->