Mercurial > flash_v2
changeset 947:cf8d8ca2ed1d
* host/rawether.c (tap_init): Set the persistent flag on the tap
device if requested by the user. This allows dhcpd and radvd to
keep running on the tap device between invocations of the synth
target.
* doc/syntheth.sgml: Documentation for the persistent option.
| author | asl |
|---|---|
| date | Tue, 15 Apr 2003 10:31:21 +0000 |
| parents | b4d06891fe1a |
| children | 83ca3aef4a92 |
| files | packages/devs/eth/synth/ecosynth/current/ChangeLog packages/devs/eth/synth/ecosynth/current/doc/syntheth.sgml packages/devs/eth/synth/ecosynth/current/host/ethernet.tcl packages/devs/eth/synth/ecosynth/current/host/rawether.c |
| diffstat | 4 files changed, 83 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/packages/devs/eth/synth/ecosynth/current/ChangeLog +++ b/packages/devs/eth/synth/ecosynth/current/ChangeLog @@ -1,3 +1,11 @@ +2003-04-08 Andrew Lunn <lunn@londo> + + * host/rawether.c (tap_init): Set the persistent flag on the tap + device if requested by the user. This allows dhcpd and radvd to + keep running on the tap device between invocations of the synth + target. + * doc/syntheth.sgml: Documentation for the persistent option. + 2003-04-01 Andrew Lunn <andrew.lunn@ascom.ch> * src/syntheth.c (synth_eth_init): Set the flag IFF_ALLMULTI when
--- a/packages/devs/eth/synth/ecosynth/current/doc/syntheth.sgml +++ b/packages/devs/eth/synth/ecosynth/current/doc/syntheth.sgml @@ -339,6 +339,30 @@ address information. Instead the eCos co or static addresses. </para> <para> +When <command>rawether</command> exits, the tap interface is removed +by the kernel. By adding the parameter persistent +<command>rawether</command> will set the persistent flag on the tap +device. + </para> + <programlisting> +synth_device ethernet { + eth0 ethertap tap3 00:01:02:03:FE:05 + eth1 ethertap tap4 00:01:02:03:FE:06 persistent + … +} +</programlisting> + <para> +With this flag set the kernel will not remove the interface when +<command>rawether</command> exits. This means applications such as +<command>dhcpd</command>, <command>radvd</command>, and +<command>tcpdump</command> will continue to run on the interface +between invocations of synthetic targets. As a result the target can +dynamically obtain its IP addresses from these daemons. Note it is a +good idea to specify a MAC address otherwise a different random MAC +address will be used each time and the dhcpd daemon will not be able +to reissue the same IP address. + </para> + <para> An alternative approach would be to set up the Linux box as a network bridge, using commands like <command>brctl</command> to connect the virtual network interface <varname>tap3</varname> to a physical
--- a/packages/devs/eth/synth/ecosynth/current/host/ethernet.tcl +++ b/packages/devs/eth/synth/ecosynth/current/host/ethernet.tcl @@ -165,7 +165,7 @@ namespace eval ethernet { # Do some validation here, before the rawether process is started. # Typical entries would look like # eth0 real eth1 - # eth1 ethertap [[tap-device] [MAC]] + # eth1 ethertap [[tap-device] [MAC] [persistent]] set junk "" set optional "" set mac "" @@ -176,7 +176,7 @@ namespace eval ethernet { if { ! [regexp -- {^tap[0-9]+\s*(.*)$} $optional junk mac ] } { synth::report_error "Cannot instantiate ethernet device $name\n \ Invalid entry \"$use\" in target definition file $synth::target_definition\n \ - Should be \"ethertap \[<tap-device> \[<MAC address>\]\]\"\n" + Should be \"ethertap \[<tap-device> \[<MAC address>\]\] [persistent]\"\n" return "" } if { "" != $mac } {
--- a/packages/devs/eth/synth/ecosynth/current/host/rawether.c +++ b/packages/devs/eth/synth/ecosynth/current/host/rawether.c @@ -32,7 +32,7 @@ //#####DESCRIPTIONBEGIN#### // // Author(s): bartv -// Contact(s): bartv +// Contact(s): bartv, andrew.lunn@ascom.ch // Date: 2002/08/07 // Version: 0.01 // Description: @@ -525,6 +525,8 @@ tap_init(int argc, char** argv) { char* devname = NULL; struct ifreq ifr; + int persistent = 0; + int have_mac = 0; tx_fn = &tap_handle_tx; rx_fn = &tap_handle_rx; @@ -542,31 +544,46 @@ tap_init(int argc, char** argv) // but the user can specify one to avoid a source of randomness. // This MAC address is not actually needed by any of the code here, // but should be returned to eCos. - if (2 == argc) { + if (2 <= argc) { unsigned int mac_data[6]; // sscanf() needs unsigned ints - int result = sscanf(argv[1], "%x:%x:%x:%x:%x:%x", - &(mac_data[0]), &(mac_data[1]), &(mac_data[2]), - &(mac_data[3]), &(mac_data[4]), &(mac_data[5])); - if (6 != result) { - snprintf(msg, MSG_SIZE, "Invalid MAC address %s\n", argv[1]); - report_error(msg); - } - MAC[0] = mac_data[0]; - MAC[1] = mac_data[1]; - MAC[2] = mac_data[2]; - MAC[3] = mac_data[3]; - MAC[4] = mac_data[4]; - MAC[5] = mac_data[5]; - } else { - srand(time(NULL)); - MAC[0] = 0; - MAC[1] = 0x0FF; - MAC[2] = rand() & 0x0FF; - MAC[3] = rand() & 0x0FF; - MAC[4] = rand() & 0x0FF; - MAC[5] = rand() & 0x0FF; + int result = sscanf(argv[1], "%x:%x:%x:%x:%x:%x", + &(mac_data[0]), &(mac_data[1]), &(mac_data[2]), + &(mac_data[3]), &(mac_data[4]), &(mac_data[5])); + if (6 != result) { + if (strncmp(argv[1], "persistent", 10)) { + snprintf(msg, MSG_SIZE, "Invalid MAC address %s\n", argv[1]); + report_error(msg); + } + } else { + MAC[0] = mac_data[0]; + MAC[1] = mac_data[1]; + MAC[2] = mac_data[2]; + MAC[3] = mac_data[3]; + MAC[4] = mac_data[4]; + MAC[5] = mac_data[5]; + argv += 1; + argc -= 1; + have_mac = 1; + } + } + if ( 1 != have_mac) { + srand(time(NULL)); + MAC[0] = 0; + MAC[1] = 0x0FF; + MAC[2] = rand() & 0x0FF; + MAC[3] = rand() & 0x0FF; + MAC[4] = rand() & 0x0FF; + MAC[5] = rand() & 0x0FF; } + // Should we make the TAP device persistent. When persistence is + // enabled, the tap device is not removed when rawether + // exits. This makes daemons happier. They can keep running + // between invocations of rawether. + if (2 <= argc ) { + persistent = !strncmp(argv[1], "persistent", 10); + } + ether_fd = open("/dev/net/tun", O_RDWR); if (ether_fd < 0) { snprintf(msg, MSG_SIZE, "Failed to open /dev/net/tun, errno %s (%d)\n", (errno < sys_nerr) ? sys_errlist[errno] : "<unknown>", errno); @@ -586,6 +603,14 @@ tap_init(int argc, char** argv) // Supporting multicasts is a no-op multicast_supported = 1; + if (persistent) { + if (ioctl(ether_fd, TUNSETPERSIST, 1) < 0) { + snprintf(msg, MSG_SIZE, "Failed to set persistent flag, errno %s (%d)\n", + ( errno < sys_nerr) ? + sys_errlist[errno] : "<unknown>", errno); + report_error(msg); + } + } // All done. } #else @@ -770,3 +795,4 @@ main(int argc, char**argv) return 0; } +
