OpenWRT Configuration Hacks [Part 1]
by kacang bawang
In this post I will talk about some configuration optimizations to OpenWRT 12.09 “Attitude Adjustment”. It is the first in a two part series (part 2). In this part we will deal with dropbear
configuration.
Problem:
I organize my home network in 3 interfaces: WAN, LAN and WIFI. I would like to run an ssh
server on the latter two. In stock installation it is accomplished like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
/etc/config/dropbear: config dropbear option PasswordAuth 'on' option RootPasswordAuth 'on' option Port '22' option Interface 'lan' config dropbear option PasswordAuth 'on' option RootPasswordAuth 'on' option Port '22' option Interface 'wifi' |
This works, but, it results in two instances of dropbear
running at all times, one for each interface.
1 2 3 4 5 |
#ps | grep dropbear ... /usr/sbin/dropbear -P /var/run/dropbear.1.pid -p 192.168.2.1:22 /usr/sbin/dropbear -P /var/run/dropbear.2.pid -p 192.168.3.1:22 ... |
However, dropbear
allows the following commandline when called manually:
1 |
/usr/sbin/dropbear -P /var/run/dropbear.1.pid -p 192.168.2.1:22 -p 192.168.3.1:22 |
Only one copy is running and it is listening on both interfaces where it is wanted.
How do we achieve this from the config files?
Solution:
We will modify /etc/init.d/dropbear
, the intermediate layer that takes configuration files as input and starts the dropbear
process with the desired options. The most logical solution would be to modify things in such a way that the following config would be accepted:
1 2 3 4 5 6 7 |
/etc/config/dropbear: config dropbear option PasswordAuth 'on' option RootPasswordAuth 'on' option Port '22' option Interface 'lan, wifi' |
Alas, “exploding” the Interface
string is a non-trivial task. But we have another option. OpenWRT
configs have an alternative to the option
called list
. It’s basically the same thing, but can be iterated. Thus, our config becomes:
1 2 3 4 5 6 7 8 |
/etc/config/dropbear: config dropbear option PasswordAuth 'on' option RootPasswordAuth 'on' option Port '22' list Interface 'lan' list Interface 'wifi' |
To parse this config, let’s modify /etc/init.d/dropbear
like this.
Now restart dropbear
. Both files before and after can be found here. (For the “before” go to file history).