From 2b1f691a64eff1b2b7bd59be673a2f0acbbba490 Mon Sep 17 00:00:00 2001 From: Claudio-Daniel Freire Date: Fri, 29 Jul 2011 17:28:13 +0200 Subject: [PATCH] TunChannel optimization: do not even format packets if there is no stderr output to write to --- .../testbeds/planetlab/scripts/tun_connect.py | 10 +++++++++- src/nepi/util/tunchannel.py | 18 +++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/nepi/testbeds/planetlab/scripts/tun_connect.py b/src/nepi/testbeds/planetlab/scripts/tun_connect.py index 8d2802b0..11266498 100644 --- a/src/nepi/testbeds/planetlab/scripts/tun_connect.py +++ b/src/nepi/testbeds/planetlab/scripts/tun_connect.py @@ -359,7 +359,7 @@ def tun_fwd(tun, remote): cipher_key = options.cipher_key, udp = options.udp, TERMINATE = TERMINATE, - stderr = open("/dev/null","w") + stderr = None ) @@ -520,6 +520,14 @@ try: + ["-w",options.pcap_capture,"-U"] * bool(options.pcap_capture) ) print >>sys.stderr, "Connected" + + # Try to give us high priority + try: + os.nice(-20) + except: + # Ignore errors, we might not have enough privileges, + # or perhaps there is no os.nice support in the system + pass tun_fwd(tun, remote) diff --git a/src/nepi/util/tunchannel.py b/src/nepi/util/tunchannel.py index 7967dc60..5c02a9d9 100644 --- a/src/nepi/util/tunchannel.py +++ b/src/nepi/util/tunchannel.py @@ -173,10 +173,11 @@ def tun_fwd(tun, remote, with_pi, ether_mode, cipher_key, udp, TERMINATE, stderr crypto_mode = False crypter = None - if crypto_mode: - print >>stderr, "Packets are transmitted in CIPHER" - else: - print >>stderr, "Packets are transmitted in PLAINTEXT" + if stderr is not None: + if crypto_mode: + print >>stderr, "Packets are transmitted in CIPHER" + else: + print >>stderr, "Packets are transmitted in PLAINTEXT" # Limited frame parsing, to preserve packet boundaries. # Which is needed, since /dev/net/tun is unbuffered @@ -213,14 +214,17 @@ def tun_fwd(tun, remote, with_pi, ether_mode, cipher_key, udp, TERMINATE, stderr if not udp: # in UDP mode, we ignore errors - packet loss man... raise - print >>stderr, '>', formatPacket(packet, ether_mode) + if stderr is not None: + print >>stderr, '>', formatPacket(packet, ether_mode) if tun in wrdy and packetReady(bkbuf, ether_mode): packet, bkbuf = pullPacket(bkbuf, ether_mode) - formatted = formatPacket(packet, ether_mode) + if stderr is not None: + formatted = formatPacket(packet, ether_mode) if with_pi: packet = piWrap(packet, ether_mode) os.write(tun.fileno(), packet) - print >>stderr, '<', formatted + if stderr is not None: + print >>stderr, '<', formatted # check incoming data packets if tun in rdrdy: -- 2.47.0