Integrating the NetworkManager with aiccu
I am using the service of SixXS to connect my laptop with the IPv6 internet. They provide an utility called aiccu to setup the tunnel. Getting it to work is really painless. Just do an “apt-get install aiccu”, configure your SixXS username and password and your done.
The aiccu package provides a traditional startup script which is placed in /etc/init.d and is added to the different run levels. Files on the different levels are executed in alphabetical order. The name of the aiccu script ensures that it is run after the network has been brought up. So as long as the networking on your system is statically configured through /etc/network/interfaces everything is fine.
Unfortunately i am (as most probably other desktop users also) using the NetworkManager to handle my network connections. This means that at the time that the aiccu startup script is run there is no network available which will make the tunnel setup fail.
What i would like to do is to run the aiccu script every time the NetworkManager has established a connection so that the tunnel is re-established. Fortunately NetworkManager provides a way to do this. It will run (in alphabetical order) all the scripts placed in /etc/NetworkManager/dispatcher.d/. The scripts are passed two variables, the interface name and if it is going up or down. The scripts are run as root.
Copy this script to /etc/NetworkManager/dispatcher.d/99aiccu to integrate aiccu with the NetworkManager. It should work with KDE and Gnome.
#!/bin/bash
IF=$1
ACTION=$2
if [ "$ACTION" == "up" ]; then
/etc/init.d/aiccu restart
fi
if [ "$ACTION" == "down" ]; then
/etc/init.d/aiccu stop
fi
Kubuntu 9.10 DNS/network troubles
After installing Kubuntu 9.10 RC1 networking became kind of flaky. It somehow worked but everything was slow and unpredictable. It was most visible while browsing the web. Some pages where loading for ages (5+ minutes), some never finishing to load at all while others were just fine after some initial delay. This problem was not only visible in firefox but also in konqueror.
I started wireshark to have a look on what was actually going on. It showed that my computer was sending DNS queries to my local DSL router (SpeedPort W303V; an ISP provided blackbox). This DSL router also works as a local DNS-cache which it is advertising via DHCP. This explains why the DNS queries are sent to the DSL router. The traffic log showed further that requests for A records (IPv4) were properly answered but requests asking for AAAA records (IPv6) were never blessed with a reply. The missing answer was triggering some retry mechanism which was resending the AAAA record request a few times. Only after this mechanism timed out, the browser was actually starting to load a page.
This nicely explains why some pages were loading fine after some initial delay (all content on one server) while others were loading forever (complex sites were a lot of addresses need to be resolved to load all content). It also explains why firefox and konqueror were both affected, DNS resolving is typically handled by the libc.
The DNS cache in my DSL router is apparently not handling requests for IPv6 address records. So far i was not able to figure out what exactly has changed between Kubuntu 9.04 and 9.10. Just replacing the /etc/resolv.conf with a version pointing to an external DNS server solved the problem for now.
Apart from that Kubuntu 9.10 looks very promising. A lot of the KDE4 problems which plagued me in 9.04 are gone.
OpenWrt Gemini 0.2
Paolo Scaffardi just released version 0.2 of his OpenWrt port for SL3516 based devices. The main change from the 0.1 release is that he switched to the OpenWrt trunk as base. The great benefit of this decision is that there are a lot more packages available (over 940 new packages). The pre-compiled firmware images worked without problems with my NAS4220 device. YMMV!
Webif^2 tutorial part 02
Last time we created a simple “hello world” page. Not very useful. For our NAS box we need a way to input/select configuration data. Web interfaces implement user input using HTML forms. Webif^2 provides some features to make it easier to work with them.
The following example allows us to enter the name (text) and job description (selecting a predefined value) of the person you want to cheer. I start with my explanation at the end of the script.

On the lines 11 to 21 we use the function display_form to create the output you can see in the screen shot. display_form is at its heart an AWK script. AWK works on a line by line basis so every line till the EOF marker will be processed on its own. Processing means that the lines are expanded into fragments that will make up the final form.
start_form/end_form are doing exactly what you expect them to do. What about line 13? display_form is not only generating a form, it also embeds the form elements together with other elements into a table. “field” will put the text following it into a cell of this table. Line 14 creates a drop down box. The following two lines add two options to this drop down box. By passing the value of the variable FORM_job we can preselect a particular option. This allows us to remember user input between script invocations (albeit only on the browser side).
The input field to enter the name is created on line 18. As the last step before finishing the form we add a submit button so we can send the form back to the server for processing (line 19). The action associated with the form will be the embedding page.
-
#!/usr/bin/webif-page
-
<?
-
. /usr/lib/webif/webif.sh
-
-
header "Test" "Cheers" "Cheers" ” "$SCRIPT_NAME"
-
-
empty "$FORM_name" || empty "$FORM_job" || {
-
echo "cheers to $FORM_name the $FORM_job!</br>"
-
}
-
-
display_form <<EOF
-
start_form|Who is to be cheered?
-
field|Job description
-
select|job|$FORM_job
-
option|Code Simian|Code simian
-
option|Code Monkey|Code monkey
-
field|Name
-
text|name|$name
-
submit|button_set_name|Set
-
end_form
-
EOF
-
-
footer
-
?>
-
-
<!–
-
##WEBIF:name:Test:50:Cheers
-
–>
To wrap up this tutorial we now only have to do something with the data submitted through the form. On line 07 we check if $FORM_name or $FORM_job are empty. If both of them contain a value we display a customized greeting message.
Where do these variables come from? Haserl is parsing POST/GET requests and places form variables into the context of the script it currently exectues. The variables are always prefixed with “FORM_”.
This example wasn’t extensive of course. display_form provides a number of additional features to create radio buttons, check boxes, text areas, …. For a complete list you have to look up files/usr/lib/webif/form.awk.
The time we will extend this example to do some input validation.
Webif^2 tutorial part 01
This article tries to explain how you can extend Webif^2 with your own functionality. I am myself new to Webif^2. The reason i am writing this article is to get acquainted enough with the code so i can decide if i would like to use it to create some NAS specific functionality.
Webif^2 runs on devices with some severe CPU and memory limits. Given that using one of the mainstream web development platforms was apparently off the table. Instead a combination of shell/awk and sed is used to generate dynamic content. Basically the way your father would have done it back in the days (given that there had been a web to develop for…) Having done some work with Ruby on Rails recently i am not too excited by this prospect but lets see how it goes.
My first goal is to have some pages which are displaying friendly greeting messages. These pages should be grouped into a new category in the main menu. I assume that you have checked out a copy of webif^2. All path references are relative to trunk/package/webif/.
Step1: Adding a new category.
files/www/cgi-bin/webif/.categories contains the entries of the main menu. We just add our entry here (”Test”).
-
##WEBIF:category:Info
-
##WEBIF:category:Graphs
-
##WEBIF:category:Status
-
##WEBIF:category:Log
-
##WEBIF:category:-
-
##WEBIF:category:System
-
##WEBIF:category:Network
-
##WEBIF:category:VPN
-
##WEBIF:category:Test
-
##WEBIF:category:-
-
##WEBIF:category:Logout
If you now reload your web browser you should see a new category “Test”. The next step will be to add content to this category.
Step2: Putting content into the new category.
I add the file test-hello.sh in files/www/cgi-bin/webif. The name of the file doesn’t matter but the convention seems to be to name it $(category)-$(name).sh.
-
#!/usr/bin/webif-page
-
<?
-
. /usr/lib/webif/webif.sh
-
-
header "Test" "Hello" "@TR<<Hello>>" ” "$SCRIPT_NAME"
-
-
echo "hello openWrt"
-
-
footer ?>
-
-
<!–
-
##WEBIF:name:Test:0:Hello
-
–>
Webif^2 uses an interpreter called Haserl. It will parse html files and execute the shell fragments it finds enclosed by <? … ?> (basically like it is done by php/jsp/…). The documentation for it can be found here.
The first line tells the linux kernel which interpreter to use when trying to execute this file (webif-page is the actual haserl program). The lines 02 to 09 contain the actual program that will generate our page. 03 pulls in webif.sh which is a library containing the functions we will use. 05 calls the header function (found in webif.sh). It will generate the html header, the head section of page and also the main- and sub-menu. $SCRIPT_NAME is set by haserl. On line 07 we say “hello” to openWrt. The only thing left now is to finish the page. To accomplish this we call the footer function (also found in webif.sh). This function will generate the content you see in the bottom section (”Apply Changes”, “Clear Changes”, …). It will also close the HTML document.
The last three lines contain a strange HTML comment. Lets have a closer look. When the main menu is generated webif^2 scans all files in files/www/cgi-bin/webif/ having the .sh extensions, looking for this special marker. The marker tells it to put an entry “Hello” into the category “Test”. The number can be used to allow a non-alphabetical ordering of the entries. The entry with the lowest number comes first. It will also be the page being selected by default of you click on the category.
So far so good. Next time we try to use some forms.
Webif^2 on a NAS box
Webif^2 aka. X-Wrt is a kick ass web interface used on OpenWrt systems. I really like it but as the main focus of OpenWrt is routers and related devices it is missing a lot of functionality which would be needed for a NAS box. Still its a good starting point. It has all the basic functions you would also need for a NAS box. Another point to consider is that most NAS devices have USB so they can be very easily turned into an access point or router where all this standard Webif^2 features would be very handy.
Up and running!
I managed to build and install the 0.1 release of OpenWrt for SL3516 based devices. It needed some small tweaks to make it compile but nothing too serious. The only pitfall was that you need to change the gcc version from 4.2 (pre-selected) to 4.1.2. If you don’t do this there will be no init process at the and of the kernel boot. There is something wrong with the toolchain. The produced kernels are fine but the userspace programs are not working. Thanks to Paolo Scaffardi for the hint.
BusyBox v1.4.2 (2008-03-13 22:32:26 CET) Built-in shell (ash)
Enter 'help' for a list of built-in commands.
_______ ________ __
| |.-----.-----.-----.| | | |.----.| |_
| - || _ | -__| || | | || _|| _|
|_______|| __|_____|__|__||________||__| |____|
|__| W I R E L E S S F R E E D O M
KAMIKAZE (7.09) -----------------------------------
* 10 oz Vodka Shake well with ice and strain
* 10 oz Triple sec mixture into 10 shot glasses.
* 10 oz lime juice Salute!
---------------------------------------------------
root@OpenWrt:/# uname -a
Linux OpenWrt 2.6.15 #2 Tue Mar 11 22:54:29 CET 2008 armv4l unknown
root@OpenWrt:/#
Crippled Redboot
From working with evaluation boards for the intel ixp4xx and ixp24xx i have some previous experience with Redboot and i always liked its power and flexibility. Given this i really don’t like the Redboot found on the NAS-4220 (and other SL351x based systems). It has been stripped of a lot of functionality i came to expect. StormLink, the vendor of the SL351x SOC, who also created the software distribution running on nearly all of these systems, has for instance removed the whole set of commands used to manipulate the internal flash (fis_*). These commands have been replaced with some simple pre-canned choices. I guess the idea behind this was to make future software upgrades easier for them because all manufactures using their SOC and software can be expected to have the same flash layout?
[ Update: I have been wrong on this one. You can actually delete and create new flash partitions through the menu system... ]
dm_crypt on the NAS-4220
According to Harald Welte who had a look at the GPL sources released by RaidSonic, the hardware crypto acceleration is not integrated with dm_crypt. It supports only the older and now deprecated crypto loop system. That is bad news. Getting this done might prove to be some work.