Δείγμα Γραπτών από Ελληνικό Πανεπιστήμιο

Ένα απολαυστικό δείγμα του υψηλού επιπέδου…

Τμήμα Επιστήμης και Τεχνολογίας Υλικών

(Ό,τι είναι μέσα σε πλαίσιο είναι αυτά που έγραψαν οι φοιτητές, τα υπόλοιπα είναι σχόλια του καθηγητή)

Διαβάστε περισσότερα στο: Καφές και Τσιγάρο – ΖΗΤΩ ΤΟ ΕΛΛΗΝΙΚΟ ΠΑΝΕΠΙΣΤΗΜΙΟ

more netroute2 hacks – new traffic shaper

On my previous post, more netroute2 hacks – high availability, one of the changed files was the dial_conn file. At the end of the diff there was a line with a # in front:
+ sleep 5
+ #/etc/bin/wshaper ppp0 192 1024

Inside netroute2 one can find the /etc-ro/ppp/wshaper file which is the traffic shaping script of the modem/router. Unfortunately it resides in the read-only section of the router so you can’t make changes directly to it. What I did was to make a copy of it on the writable /etc/bin/ and change a line in my /etc/bin/dial_conn to call it from there, right after (5 seconds later) the connection with the ISP has been established.

If you have followed the previous post about high availability the only thing you need to change is to edit your /etc/bin/dial_conn file and remove the # from the live above. Else…read the previous post 🙂

The first argument of the script is the device the rules will apply to, the second argument is the upload speed and the third is the download speed. Netroute2’s own traffic shaping script gets the 3 arguments while syncing with the dslam. The problem with adsl lines here in Greece, and I guess in many other countries as well, is that the speed the modem syncs with the dslam has nothing to do with the real speed you actually get. So shaping for 256kbit upload while never reaching more than 200 is a bit foolish imho. What I did was lower the upload so that I am always (or mostly always) sure that this is my max upload speed at the time. I can now create rules based on the assumption that my upload speed is 192kbit. If the upload speed your modem syncs is 192kbit I would advise you not to put more than 128kbit as the first argument. It’s a trial and error situation.

While lowering my shaped upload speed and keeping the rest of the script intact already made a difference I knew that I could do some more tweaking.
The first thing one has to know before creating any traffic shaping script is to learn what the TOS field is:

#TOS FIELD
# 0x10 – (minimize delay)
# 0x08 (maximize throughput),
# 0x04 (maximize reliability),
# 0x02 (minimize cost)
# 0x00 (best effort)

You can then create rules with iptables to change the TOS field of certain packets, for example:
$IPTABLES -t mangle -A POSTROUTING -o $DEV -p tcp --syn -m length --length 40:68 -j TOS --set-tos 0x10
$IPTABLES -t mangle -A POSTROUTING -o $DEV -p tcp --tcp-flags ALL ACK,FIN -j TOS --set-tos 0x10

A great rule to add to any of your scripts is to speed up ACK packets,(2) by adding them to the highest priority class (on netroute2 that’s 1:10):
$TC filter add dev $DEV parent 1: protocol ip prio 1 u32 \
match ip protocol 6 0xff \
match u8 0x05 0x0f at 0 \
match u16 0x0000 0xffc0 at 2 \
match u8 0x10 0xff at 33 \
flowid 1:10

What is also very very helpfull is to specify the port your torrent client uses (eg 17777) and add it to the lowest priority class (on netroute2 that 1:30):
$TC filter add dev $DEV parent 1:0 protocol ip prio 3 u32 match ip sport 17777 0xffff flowid 1:30
$TC filter add dev $DEV parent 1:0 protocol ip prio 3 u32 match ip dport 17777 0xffff flowid 1:30

Of course you can create your own classes inside /etc/bin/wshaper. If you are carefull enough with the rules you add you will be more than happy with the result 🙂

To monitor how your traffic shaping is going you can download a great perl script from here: http://qos.kallenberg.dk/ called qos.pl. This script reads a machine’s qos classes and priorities and creates graphs like the ones on the site. The problem with netroute2 is that it doesn’t have perl included, so one has to modify qos.pl to make it read netroute2’s qos performance while running from another machine. This is done by making the script run its commands through ssh-ing to netroute2 using public key auth. If you don’t know how to enable this on netroute2 please read part F of my older post: Intracom netroute2 hacks/.

What you need to change on the qos.pl script is:
a) change the $tc line with something like this:
$tc = "ssh root\@NETROUTE2.IP.GOES.HERE /usr/sbin/tc";
b) Find any occurances of “eth2” and replace with “ppp0” (there must be 2 occurances only).

now run the qos.pl script and it will start creating some graphs (png files) and an index.html on the directory from which you executed it. qos.pl depends on gnuplot, so you must install it before you run it.

The graphs are a great visual aid to to tweak your new traffic shaping script more and more.

more netroute2 hacks – high availability

The following post is going to be a one in a series of 2-3 posts regarding netroute2 (the link is in Greek) and some of my hacks/modifications on it. All hacks refer to netroute2 firmware 577 that I have previously posted on my blog. For those who haven’t noticed yet, firmware 577 is unlocked, you can now connect to any ISP you like.

Netroute2 has a strange bug and sometimes (not always) cannot reconnect to the ISP when the connection for some strange reason goes down. To cope with that, the netroute2 developers at Intracom have created a script named high_avail that runs every 5 minutes from crontab. For some even stranger reason this script did not work for me as it should, so I patched it to make it _always_ work.

The problem I faced at the very beggining was that the “high_avail” script resided in the read-only section of netroute2’s flash (/usr/bin/high_avail). My solution to that problem was to create a directory named /etc/bin/ and store there all my new scripts and changes since the /etc dir is writable.

My changes to the high_avail script are these:
--- usr/bin/high_avail 2007-07-03 20:59:21.000000000 +0300
+++ etc/bin/high_avail 2007-07-04 03:31:54.000000000 +0300
@@ -15,25 +15,32 @@
if [ -s /var/run/dial ]; then
act_conn=`$CAT /var/run/dial`
fi
-adsl_iface=$ADSL_BASE
+if [ -z "$act_conn" ]; then
+ act_conn="/etc/wan/current/CHANGEME"
+fi
+
+adsl_iface=$ADSL_BASE
+echo "$act_conn"
reload_module() {
/bin/hangup
+ killall -9 pppd
+ ifconfig eth2 down
/sbin/rmmod $loaded_mod
if [ $? -eq 0 ]; then
$ECHO "done"
else
$ECHO "failed"
$ECHO "ERROR: high_avail: Failed to unload $loaded_mod"
- exit 13
+# exit 13
fi
- [ -n "$act_conn" ] && /usr/bin/dial $act_conn
+ [ -n "$act_conn" ] && /etc/bin/dial $act_conn
}
HIGH_AVAIL_IP=`$GREP HIGH_AVAIL_IP /etc/net.conf | $CUT -d'=' -f2`
-
#Check Current Modem status
if [ -z "$loaded_mod" ]; then
$ECHO "high_avail: No Module found loaded."
+ reload_module
exit 1
elif [ "`/usr/bin/modem_wrap halt`" = "yes" ]; then
$ECHO "high_avail: Module $loaded_mod found in HALTED state"
@@ -41,6 +48,7 @@
exit 11
elif [ -z "$act_conn" ]; then
$ECHO "high_avail: No WAN Connection dialed ..."
+ reload_module
exit 2
elif [ -z "$HIGH_AVAIL_IP" ]; then
$ECHO "high_avail: No Ping Target IP Found ..."

and the whole new script resides here: /etc/bin/high_avail. (You need to gunzip it).

What you need to change for your connection is the part that says CHANGEME. You can replace that with what you can find inside the /etc/wan/current/ directory.

I noticed that when the module for the modem was loaded then the modem was unable to reconnect to the ISP, but upon unloading and reloading of the module, and then trying to connect again, all came back to normal. So what I changed in the high_avail script was making sure the module gets unloaded properly and reloaded when there’s no connection active.

One might notice that inside high_avail I’ve also changed a path from /usr/bin/dial to /etc/bin/dial.
This script is used to call another script that actually makes the call to the isp.

--- usr/bin/dial 2007-07-03 21:00:13.000000000 +0300
+++ etc/bin/dial 2007-07-04 03:39:45.000000000 +0300
@@ -1,25 +1,16 @@
#!/bin/sh
ECHO=/bin/echo
-
conn="$1"
#ATM encapsulation mode for modem
encmode=0
-
$ECHO "Dialing $conn ...."
-
if [ $# -lt 1 -o ! -e $conn ]; then
-
$ECHO "Usage: dial <connection> [ppp_option]"
$ECHO "connection: connection name"
$ECHO "[ppp_option]: optional argument passed to PPPD"
-
exit 1
-
else
-
#Bring down previous processes
/bin/hangup
-
- /usr/bin/dial_conn $conn primary_conn $2
-
+ /etc/bin/dial_conn $conn primary_conn $2
fi

These are my changes to /usr/bin/dial script that is now placed under /etc/bin/dial
The whole scripts resides here: /etc/bin/dial. (You need to gunzip it).

As said before, this script in turn calls another one, dial_conn which is used to actually make the call. My changes to /usr/bin/dial_conn which now becomes /etc/bin/dial_conn:


--- usr/bin/dial_conn 2007-07-03 21:00:13.000000000 +0300
+++ etc/bin/dial_conn 2007-07-04 03:43:11.000000000 +0300
@@ -154,14 +154,13 @@
exit 1
fi
done
-
fi
-
if [ "$2" = "primary_conn" ]; then
#Start the high-availability service
- $ECHO "*/5 * * * * root $PIDOF high_avail > /dev/null 2>&1 || /usr/bin/high_avail > /var/run/high_avail 2>&1" > /etc/cron.d/cron_high_avail
+ $ECHO "*/5 * * * * root $PIDOF high_avail > /dev/null 2>&1 || /etc/bin/high_avail > /var/run/high_avail 2>&1" > /etc/cron.d/cron_high_avail
$CHMOD 755 /etc/cron.d/cron_high_avail
fi
-
+ sleep 5
+ #/etc/bin/wshaper ppp0 192 1024
exit 0
fi

the whole file resides here: /etc/bin/dial_conn. (You need to gunzip it).

What I’ve changed here is the line that gets stored on crontab and calls the high_avail script every 5 minutes to check whether our connection is active or not. The rest of the changes will be the subject of the next post about netroute2 on this blog.

What is left now is to make netroute2 calls these new scripts from /etc/bin/ on boot instead of the ones from /usr/bin.

a) Copy /bin/dial_current to /etc/bin/dial_current, edit it with vi and go to line 5 and change the line that says /usr/bin/dial with /etc/bin/dial.
b) Edit /etc/init.d/rc-run, go to line 243 and change all occurences of /bin/dial_current with /etc/bin/dial_current. There must be 2.
c) Edit /etc/rc.d/rc.dialcurrent with vi, go to line 8 and change /usr/bin/dial to /etc/bin/dial.

So, if you have done it right, you should now have 4 scripts inside your netroute2’s /etc/bin:
a) /etc/bin/high_avail
b) /etc/bin/dial
c) /etc/bin/dial_conn
d) /etc/bin/dial_current
and you should have also changed 2 scripts, /etc/init.d/rc-run and /etc/rc.d/rc.dialcurrent

That’s all. Now save your changes with /etc/init.d/checkpoint and upon reboot your modem will have a nice new high_avail script that will (hopefully) always work.