1 <!-- Copyright (C) 2003 Red Hat, Inc. -->
2 <!-- This material may be distributed only subject to the terms -->
3 <!-- and conditions set forth in the Open Publication License, v1.0 -->
4 <!-- or later (the latest version is presently available at -->
5 <!-- http://www.opencontent.org/openpub/). -->
6 <!-- Distribution of the work or derivative of the work in any -->
7 <!-- standard (paper) book form is prohibited unless prior -->
8 <!-- permission is obtained from the copyright holder. -->
12 >Synthetic Target Ethernet Driver</TITLE
13 ><meta name="MSSmartTagsPreventParsing" content="TRUE">
16 CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
19 TITLE="eCos Reference Manual"
20 HREF="ecos-ref.html"><LINK
22 TITLE="Synthetic Target Ethernet Driver"
23 HREF="devs-eth-synth-ecosynth-ref.html"><LINK
25 TITLE="Synthetic Target Ethernet Driver"
26 HREF="devs-eth-synth-ecosynth-ref.html"><LINK
28 TITLE="Synthetic Target Watchdog Device"
29 HREF="devs-watchdog-synth-ref.html"></HEAD
40 SUMMARY="Header navigation table"
49 >eCos Reference Manual</TH
57 HREF="devs-eth-synth-ecosynth-ref.html"
71 HREF="devs-watchdog-synth-ref.html"
82 NAME="DEVS-ETH-SYNTH-ECOSYNTH">Synthetic Target Ethernet Driver</H1
90 >Synthetic Target Ethernet Support -- Allow synthetic target applications to perform ethernet I/O</DIV
99 >The synthetic target ethernet package can provide up to four network
107 be used directly by the eCos application or, more commonly, by a
108 TCP/IP stack that is linked with the eCos application. Each eCos
109 device can be mapped on to a real Linux network device. For example,
110 if the Linux PC has two ethernet cards and <TT
114 not currently being used by Linux itself, then one of the eCos devices
115 can be mapped on to this Linux device. Alternatively, it is possible
116 to map some or all of the eCos devices on to the ethertap support
117 provided by the Linux kernel.
120 >The ethernet package depends on the I/O auxiliary provided by the
121 synthetic target architectural HAL package. During initialization the
122 eCos application will attempt to instantiate the desired devices, by
123 sending a request to the auxiliary. This will load a Tcl script
127 > that is responsible for handling the
128 instantiation request and subsequent I/O operations, for example
129 transmitting an ethernet packet. However, some of the low-level I/O
130 operations cannot conveniently be done by a Tcl script so
134 > will actually run a separate program
138 > to interact with the Linux network device.
141 CLASS="INFORMALFIGURE"
156 >On the target-side there are configuration options to control which
157 network devices should be present. For many applications a single
158 device will be sufficient, but if the final eCos application is
159 something like a network bridge then the package can support multiple
160 devices. On the host-side each eCos network device needs to be mapped
161 on to a Linux one, either a real ethernet device or an ethertap
162 device. This is handled by an entry in the target definition file:
171 CLASS="PROGRAMLISTING"
172 >synth_device ethernet {
174 eth1 ethertap tap3 00:01:02:03:FE:05
181 >The ethernet package also comes with support for packet logging,
182 and provides various facilities for use by user Tcl scripts.
188 NAME="DEVS-ETH-ECOSYNTH-INSTALL"
193 >Before a synthetic target eCos application can access ethernet devices
194 it is necessary to build and install host-side support. The relevant
195 code resides in the <TT
199 subdirectory of the synthetic target ethernet package, and building it
200 involves the standard <B
211 The build involves a new executable <B
215 must be able to access a raw Linux network device. This is achieved by
216 installing it suid root, so the <B
220 has to be run with superuser privileges.
244 > suid root introduces a
245 potential security problem. Although normally
249 > is executed only by the I/O auxiliary,
250 theoretically it can be run by any program. Effectively it gives any
251 user the ability to monitor all ethernet traffic and to inject
252 arbitrary packets into the network. Also, as with any suid root
253 programs there may be as yet undiscovered exploits. Users and system
254 administrators should consider the risks before running <B
265 >There are two main ways of building the host-side software. It is
266 possible to build both the generic host-side software and all
267 package-specific host-side software, including the ethernet support,
268 in a single build tree. This involves using the
272 > script at the toplevel of the eCos
273 repository. For more information on this, see the
277 > file at the top of the repository.
278 Note that if you have an existing build tree which does not include
279 the synthetic target ethernet support then it will be necessary to
280 rerun the toplevel configure script: the search for appropriate
281 packages happens at configure time.
284 >The alternative is to build just the host-side for this package.
285 This requires a separate build directory, building directly in the
286 source tree is disallowed. The <B
290 are much the same as for a build from the toplevel, and the
294 > file can be consulted for more
295 details. It is essential that the ethernet support be configured with
299 > option as other eCos host-side
300 software, especially the I/O auxiliary provided by the architectural
301 synthetic target HAL package, otherwise the I/O auxiliary will be
302 unable to locate the ethernet support.
308 NAME="DEVS-ETH-ECOSYNTH-OPTIONS"
311 >Target-side Configuration Options</H2
313 >The target-side code can be configured to support up to four ethernet
324 > is enabled if the configuration
325 includes a TCP/IP stack, otherwise it is disabled. The other three
326 devices are always disabled by default. If any of the devices are
327 enabled then there will also be the usual configuration options
328 related to building this package. Other options related to network
329 devices, for example whether or not to use DHCP, are provided by
330 the generic network device package.
336 NAME="DEVS-ETH-ECOSYNTH-REAL"
341 >One obvious way of providing a synthetic target eCos application with
342 ethernet I/O is to use a real ethernet device in the PC: transmitted
343 packets go out on a real network, and packets on the network addressed
344 to the right MAC address are passed on to eCos. This way synthetic
345 target networking behaves just like networking on a real target with
346 ethernet hardware. For example, if there is a DHCP server anywhere on
347 the network then eCos will be able to contact it during networking
348 startup and get hold of IP address information.
351 >Configuring the ethernet support to use a real ethernet device
352 requires a simple entry in the target definition file:
361 CLASS="PROGRAMLISTING"
362 >synth_device ethernet {
363 <eCos device> real <linux device>
370 >For example, to map the eCos network device <TT
386 CLASS="PROGRAMLISTING"
387 >synth_device ethernet {
395 >It is not possible for an ethernet device to be shared by both the
396 eCos TCP/IP stack and the Linux one: there would be no simple way to
397 work out which stack incoming packets are intended for. In theory
398 it might be possible to do some demultiplexing using distinct IP
399 addresses, but it would be impossible to support some functionality
400 such as DHCP. Therefore the <B
404 refuse to access any ethernet device already in use. On a typical
408 > will be used for Linux
409 networking, and the PC will have to be equipped with additional
410 ethernet devices for use by eCos.
416 > program will access the hardware via
417 the appropriate Linux device driver, so it is important that the
418 system is set up such that the relevant module will be automatically
419 loaded or is already loaded. The details of this will depend on the
420 installed distribution and version, but typically it will involve an
423 >/etc/modules.conf</TT
430 NAME="DEVS-ETH-ECOSYNTH-ETHERTAP"
435 >The Linux kernel's ethertap facility provides a virtual network
436 interface. A Linux application, for example the
440 > program, can open a special character
448 > calls, and then <TT
455 > ethernet packets. When the device is
456 opened the Linux kernel automatically creates a new network interface,
460 >. The Linux TCP/IP stack can be
461 made to use this network interface like any other interface, receiving
462 and transmitting ethernet packets. The net effect is a virtual network
463 connecting just the Linux and eCos TCP/IP stacks, with no other nodes
464 attached. By default all traffic remains inside this virtual network
465 and is never forwarded to a real network.
468 >Support for the ethertap facility may or may not be provided
469 automatically, depending on your Linux distribution and version. If
470 your system does not have a device <TT
477 > then the appropriate kernel
478 documentation should be consulted, for example
481 >/usr/src/linux-2.4/Documentation/networking/tuntap.txt</TT
483 If you are using an old Linux kernel then the ethertap functionality
484 may be missing completely. When the <B
488 program is configured and built, the <B
492 script will check for a file <TT
494 >/usr/include/linux/if_tun.h</TT
496 file is missing then <B
499 > will be built without
500 ethertap functionality, and only real ethernet interfaces will be
504 >The target definition file is used to map eCos network devices on to
505 ethertap devices. The simplest usage is:
514 CLASS="PROGRAMLISTING"
515 >synth_device ethernet {
523 >The Linux kernel will automatically allocate the next available tap
524 network interface. Usually this will be <TT
528 other software is using the ethertap facility, for example to
529 implement a VPN, then a different number may be allocated. Usually it
530 will be better to specify the particular tap device that should be
531 used for each eCos device, for example:
540 CLASS="PROGRAMLISTING"
541 >synth_device ethernet {
550 >The user now knows exactly which eCos device is mapped onto which
551 Linux device, avoiding much potential confusion. Because the virtual
552 devices are emulated ethernet devices, they require MAC addresses.
553 There is no physical hardware to provide these addresses, so normally
554 MAC addresses will be invented. That means that each time the eCos
555 application is run it will have different MAC addresses, which makes
556 it more difficult to compare the results of different runs. To get
557 more deterministic behaviour it is possible to specify the MAC
558 addresses in the target definition file:
567 CLASS="PROGRAMLISTING"
568 >synth_device ethernet {
569 eth0 ethertap tap3 00:01:02:03:FE:05
570 eth1 ethertap tap4 00:01:02:03:FE:06
577 >During the initialization phase the eCos application will instantiate
578 the various network devices. This will cause the I/O auxiliary to load
586 > processes, which in turn will
594 perform the appropriate <TT
597 > calls. On the Linux
598 side there will now be new network interfaces such as
602 >, and these can be configured like any other
603 network interface using commands such as <B
607 In addition, if the Linux system is set up with hotplug support then
608 it may be possible to arrange for the network interface to become
609 active automatically. On a Red Hat Linux system this would require
613 >/etc/sysconfig/network-scripts/ifcfg-tap3</TT
615 containing data like:
624 CLASS="PROGRAMLISTING"
629 NETMASK="255.255.255.0"
636 >This gives the Linux interface the address <TT
643 >. The eCos network device
644 should be configured with a compatible address. One way of doing this
645 would be to enable <TT
647 >CYGHWR_NET_DRIVER_ETH0_ADDRS</TT
651 >CYGHWR_NET_DRIVER_ETH0_ADDRS_IP</TT
656 >, and similarly update the
674 >It should be noted that the ethertap facility provides a virtual
675 network, and any packets transmitted by the eCos application will
676 not appear on a real network. Therefore usually there will no
677 accessible DHCP server, and eCos cannot use DHCP or BOOTP to obtain IP
678 address information. Instead the eCos configuration should use manual
682 >An alternative approach would be to set up the Linux box as a network
683 bridge, using commands like <B
687 virtual network interface <TT
691 network interface such as <TT
694 >. Any packets sent by
695 the eCos application will get forwarded automatically to the real
696 network, and some packets on the real network will get forwarded over
697 the virtual network to the eCos application. Note that the eCos
698 application might also get some packets that were not intended for it,
699 but usually those will just be discarded by the eCos TCP/IP stack. The
700 exact details of setting up a network bridge are left as an exercise
707 NAME="DEVS-ETH-ECOSYNTH-LOGGING"
712 >The ethernet support comes with support for logging the various
713 packets that are transferred, including a simple protocol analyser.
714 This generates simple text output using the filter mechanisms provided
715 by the I/O auxiliary, so it is possible to control the appearance and
716 visibility of different types of output. For example the user might
717 want to see IPv4 headers and all ICMPv4 and ARP operations, but not
718 TCP headers or any of the packet data.
721 >The protocol analyser is not intended to be a fully functional
722 analyser with knowledge of many different TCP/IP protocols, advanced
723 search facilities, graphical traffic displays, and so on.
724 Functionality like that is already provided by other tools such as
732 >. Achieving similar levels of
733 functionality would require a lot of work, for very little gain. It is
734 still useful to have some protocol analysis functionality available
735 because the output will be interleaved with other output, for example
739 > calls from the application. That may make
740 it easier to understand the sequence of events.
743 >One problem with logging ethernet traffic is that it can involve very
744 large amounts of data. If the application is expected to run for a
745 long time or is very I/O intensive then it is easy to end up with many
746 megabytes. When running in graphical mode all the logging data will be
747 held in memory, even data that is not currently visible. At some point
748 the system will begin to run low on memory and performance will
749 suffer. To avoid problems, the ethernet script maintains a flag that
750 controls whether or not packet logging is active. The default is to
751 run with logging disabled, but this can be changed in the target
761 CLASS="PROGRAMLISTING"
762 >synth_device ethernet {
770 >The ethernet script will add a toolbar button that allows this flag to
771 be changed at run-time, allowing the user to capture traffic for
772 certain periods of time while the application continues running.
775 >The target definition file can contain the following entries for the
776 various packet logging filters:
785 CLASS="PROGRAMLISTING"
786 >synth_device ethernet {
788 filter ether -hide 0 -background LightBlue -foreground "#000080"
789 filter arp -hide 0 -background LightBlue -foreground "#000050"
790 filter ipv4 -hide 0 -background LightBlue -foreground "#000040"
791 filter ipv6 -hide 1 -background LightBlue -foreground "#000040"
792 filter icmpv4 -hide 0 -background LightBlue -foreground "#000070"
793 filter icmpv6 -hide 1 -background LightBlue -foreground "#000070"
794 filter udp -hide 0 -background LightBlue -foreground "#000030"
795 filter tcp -hide 0 -background LightBlue -foreground "#000020"
796 filter hexdata -hide 1 -background LightBlue -foreground "#000080"
797 filter asciidata -hide 1 -background LightBlue -foreground "#000080"
803 >All output will show the eCos network device, for example
807 >, and the direction relative to the eCos
808 application. Some of the filters will show packet headers, for example
812 > gives details of the ethernet packet header
816 > gives information about TCP headers such as
817 whether or not the SYN flag is set. The TCP and UDP filters will also
818 show source and destination addresses, using numerical addresses and
819 if possible host names. However, host names will only be shown if the
824 lookups while the data is being captured would add significantly to
825 complexity and overhead. The <TT
832 > filters show the remainder of the packets
833 after the ethernet, IP and TCP or UDP headers have been stripped.
836 >Some of the filters will provide raw dumps of some of the packet data.
837 Showing up to 1500 bytes of data for each packet would be expensive,
838 and often the most interesting information is near the start of the
839 packet. Therefore it is possible to set a limit on the number of bytes
840 that will be shown using the target definition file. The default limit
850 CLASS="PROGRAMLISTING"
851 >synth_device ethernet {
862 NAME="DEVS-ETH-ECOSYNTH-GUI"
865 >User Interface Additions</H2
867 >When running in graphical mode the ethernet script extends the user
868 interface in two ways: a button is added to the toolbar so that users
869 can enable or disable packet logging; and an entry is added to the
873 > menu for the ethernet-specific documentation.
879 NAME="DEVS-ETH-ECOSYNTH-ARGS"
882 >Command Line Arguments</H2
884 >The synthetic target ethernet support does not use any command line
885 arguments. All configuration is handled through the target definition
892 NAME="DEVS-ETH-ECOSYNTH-HOOKS"
897 >The ethernet support defines two hooks that can be used by other
898 scripts, especially user scripts: <TT
905 >. The tx hook is called whenever eCos
906 tries to transmit a packet. The rx hook is called whenever an incoming
907 packet is passed to the eCos application. Note that this may be a
908 little bit after the packet was actually received by the I/O auxiliary
909 since it can buffer some packets. Both hooks are called with two
910 arguments, the name of the network device and the packet being
911 transferred. Typical usage might look like:
920 CLASS="PROGRAMLISTING"
921 > proc my_tx_hook { arg_list } {
922 set dev [lindex $arg_list 0]
923 incr ::my_ethernet_tx_packets($dev)
924 incr ::my_ethernet_tx_bytes($dev) [string length [lindex $arg_list 1]]
926 proc my_rx_hook { arg_list } {
927 set dev [lindex $arg_list 0]
928 incr ::my_ethernet_rx_packets($dev)
929 incr ::my_ethernet_rx_bytes($dev) [string length [lindex $arg_list 1]]
931 synth::hook_add "ethernet_tx" my_tx_hook
932 synth::hook_add "ethernet_rx" my_rx_hook</PRE
937 >The global arrays <TT
939 >my_ethernet_tx_packets</TT
941 now be updated whenever there is ethernet traffic. Other code,
942 probably running at regular intervals by use of the Tcl
946 > procedure, can then use this information to
947 update a graphical monitor of some sort.
953 NAME="DEVS-ETH-ECOSYNTH-TCL"
956 >Additional Tcl Procedures</H2
958 >The ethernet support provides one additional Tcl procedure that can be
959 used by other scripts;
968 CLASS="PROGRAMLISTING"
969 >ethernet::devices_get_list </PRE
974 >This procedure returns a list of the ethernet devices that have been
975 instantiated, for example <TT
986 SUMMARY="Footer navigation table"
997 HREF="devs-eth-synth-ecosynth-ref.html"
1006 HREF="ecos-ref.html"
1015 HREF="devs-watchdog-synth-ref.html"
1025 >Synthetic Target Ethernet Driver</TD
1031 HREF="devs-eth-synth-ecosynth-ref.html"
1039 >Synthetic Target Watchdog Device</TD