NOTE: If you find this interesting have a look at the wiki too: http://openwrt.org/CentralNvramMaps
First, thank you for answering my question on nvram policy. I have thought about a configuration scheme along the same lines that tries to be more flexible to configure than nvrams notion of wan/lan interfaces and more straight forward to understand and customize than currently.
Today I have roughly sketched the files I am attaching, note that I am quite a bash novice, but I hope you can understand what is meant and could help or throw in some more ideas.
I'd suggest to first look into the "interfaces" file then domains and firewall. They are supposed to be sourced from a init.d or helper scripts similar to functions.sh. Instead of invoking nvram_get directly with a logic that tends to be specific to only a subset of possible setups, the logic could iterate over whatever interfaces are defined.
dhcpd-conf.sh could become such a init.d scipt that sets up the dhcpd.
-Chris
Attachment didn't seem to work.
# /etc/sysconfig/interfaces
# The OpenWRT interface configuration.
#
# This file maps the various nvram settings
# into a more flexible scheme.
#
# You can either change your nvram settings by issuing the command
# nvram set <key>="<value>" and a subsequent "nvram commit"
# to configure OpenWRT.
# Or, you can take full advantage of OpenWRT configurability and specify
# your configuration directly in this file, save it to jffs2 and leave
# the nvram stuff untouched.
# This will allow you to freely define special interfaces for use as
# client mode wlan, WDS, DMZ etc.
#
#
# OpenWRT defaults to the following interface naming conventions:
#
# vlan0 is the ethernet port labeled Internet or WAN
#
# vlan1 to vlan4 are the individual ethernet ports
# vlan5 (or better 15?) by default refers to all numbered ports
#
# wlan0 is the wireless interface
#
#
iface () {
interfaces="$interfaces $1"
}
# vlan0 interface configuration
#
# ( Factory wise labeled WAN or Internet )
iface vlan0
vlan0_conf_method=$(nvram_get wan_proto)
vlan0_address=$(nvram_get wan_ipaddr)
vlan0_hwadress=$(nvram_get wan_hwaddr)
vlan0_netmask=$(nvram_get wan_netmask)
vlan0_gateway=$(nvram_get wan_gateway)
# PPP protocol configuration
#
#
ppp_username=$(nvram_get ppp_username)
ppp_password=$(nvram_get ppp_passwd)
ppp_redial=$(nvram_get ppp_redialperiod)
ppp_idletime=$(nvram_get ppp_idletime)
# br0 bridge configuration
#
# ( Factory settings bridge wlan and
# local network together. That is not recommended
# because direct wireless access to your private net
# is not secure! )
#
# if you want it nevertheless you need to
# uncomment the following and modify
# /etc/sysconfig/dhcpd further settings for
# interfaces that are part of a bridge will
# be ignored.
# iface br0
# br0_conf_method=$(nvram_get lan_proto)
# br0_ports=$(nvram_get lan_ifnames)
# br0_stp=$(nvram_get lan_stp)
# br0_address=$(nvram_get lan_ipaddr)
# br0_hwadress=$(nvram_get lan_hwaddr)
# br0_netmask =$(nvram_get lan_netmask)
# ethernet port configuration
#
# (by default all local ports are configured as single
# vlan5 interface, but you can define individual
# interfaces (vlan1-4) for each port by
# altering the following)
# put admcfg stuff here
# vlan5 interface configuration
#
# (uses your previous nvram "lan" settings
# as default, if br0 is not enabed)
iface vlan5
vlan5_conf_method=$(nvram_get lan_proto)
vlan5_address=$(nvram_get lan_ipaddr)
vlan5_hwadress=$(nvram_get lan_hwaddr)
vlan5_netmask=$(nvram_get lan_netmask)
# wlan0 interface configuration
#
#
iface wlan0
wlan0_conf_method=static
wlan0_address=192.168.0.1
wlan0_hwaddress=
wlan0_netmask=255.255.255.0
wlan0_essid=$(nvram_get wl0_ssid)
wlan0_channel=$(nvram_get wl0_channel)
wlan0_mode=$(nvram_get wl0_mode) # master,managed,ap or sta
wlan0_key=$(nvram_get wl0_key1)
# /etc/sysconfig/domains
# DNS and dhcpd configuration
#
#
# The hostname of this router
HOSTNAME=$(nvram_get wan_hostame)
# Parent DNS server to use, will be overridden if another
# address is aquired by dhcp or ppp
parent_dns=$(nvram_get wan_dns)
dhcpd_enable=$(nvram_get dhcp_enable)
dhcpd_iface () {
dhcpd_interfaces="$dhcpd_interfaces $1"
}
dhcpd_iface vlan5
dhcpd_vlan5_startip=# somthing like "vlan5_address AND netmask + $(nvram_get dhcp_start)"
dhcpd_vlan5_endip=$(nvram_get dhcp_start)+$(nvram_get dhcp_num)
dhcpd_vlan5_maxleases=200
dhcpd_vlan5_domain=openwrt.lan
dhcpd_vlan5_leasetime=86400
dhcpd_iface wlan0
dhcpd_wlan0_startip=# somthing like "wlan0_address AND netmask + $(nvram_get dhcp_start)"
dhcpd_wlan0_endip=$(nvram_get dhcp_start)+$(nvram_get dhcp_num)
dhcpd_wlan0_maxleases=200
dhcpd_wlan0_domain=wireless.lan
dhcpd_wlan0_leasetime=7200
# if you really want to use bridging have only the following section activated:
#
# dhcpd_iface="br0"
# dhcpd_br0_startip=# somthing like "br0_address AND netmask + $(nvram_get dhcp_start)"
# dhcpd_br0_endip=$(nvram_get dhcp_start)+$(nvram_get dhcp_num)
# dhcpd_br0_maxleases=200
# dhcpd_br0_domain=home.lan
# dhcpd_br0_leasetime=7200
# /etc/sysconfig/firewall
# from which the FireHOL script generates iptables rules.
version 5
interface ppp+ red
protection strong 10/sec 10
server ident reject with tcp-reset
interface wlan0 blue
protection strong 10/sec 10
server ssh accept
interface vlan5 green
policy reject
server "dns icmp dhcp http ssh " accept
router green2red inface vlan5 outface ppp+
masquerade
route all accept
client ident reject with tcp-reset
router blue2red inface wlan0 outface ppp+
masquerade
route all accept
client ident reject with tcp-reset
#!/bin/sh
# /etc/init.d/dhcpd-conf.sh
#
# generate dhcp server configuration file
# according to nvram settings if /etc/udhcpd.conf
# is not a real fle. (is a symlink to /tmp/etc/)
# source OpenWRT settings or nvram mapping
. /etc/sysconfig/interfaces
. /etc/sysconfig/domains
if [ dhcpd_enable != 1 ] exit
# first add some general settings
cat >> /tmp/etc/udhcpd.conf << EOF
lase_file /tmp/udhcpd.leases
pidfile /tmp/udhcp.pid
EOF
for $if in $dhcpd_interfaces do {
cat >> /tmp/etc/udhcpd.conf << EOF
interface $if
start $dhcpd_$if_startip
end $dhcpd_$if_endip
max_leases $dhcpd_$if_maxleases
lease $dhcpd_$if_leasetime
domain $if_domain
option dns $if_address
option subnet $if_netmask
option router $if_address
EOF
}
# force respawn of udhcpd ?
killall udhcpd