lantiq: add runtime generation of /etc/config/network
[openwrt/svn-archive/archive.git] / target / linux / lantiq / base-files / etc / uci-defaults / network
1 #!/bin/sh
2 #
3 # Copyright (C) 2011 OpenWrt.org
4 #
5
6 set_interface_loopback() {
7 uci batch <<EOF
8 set network.loopback='interface'
9 set network.loopback.ifname='lo'
10 set network.loopback.proto='static'
11 set network.loopback.ipaddr='127.0.0.1'
12 set network.loopback.netmask='255.0.0.0'
13 EOF
14 }
15
16 set_interface_raw() {
17 local cfg=$1
18 local ifname=$2
19
20 uci batch <<EOF
21 set network.$cfg='interface'
22 set network.$cfg.ifname='$ifname'
23 set network.$cfg.proto='none'
24 EOF
25 }
26
27 set_interface_lan() {
28 local ifname=$1
29
30 uci batch <<EOF
31 set network.lan='interface'
32 set network.lan.ifname='$ifname'
33 set network.lan.type='bridge'
34 set network.lan.proto='static'
35 set network.lan.ipaddr='192.168.1.1'
36 set network.lan.netmask='255.255.255.0'
37 EOF
38 }
39
40 set_interface_wan() {
41 local ifname=$1
42
43 uci batch <<EOF
44 set network.wan='interface'
45 set network.wan.ifname='$ifname'
46 set network.wan.proto='dhcp'
47 EOF
48 }
49
50 set_atm_wan() {
51 local vpi=$1
52 local vci=$2
53 local encaps=$3
54 local payload=$4
55
56 uci batch <<EOF
57 set network.atm='atm-bridge'
58 set network.atm.unit='0'
59 set network.atm.vpi='$vpi'
60 set network.atm.vci='$vci'
61 set network.atm.encaps='$encaps'
62 set network.atm.payload='$payload'
63 set network.wan='interface'
64 set network.wan.ifname='nas0'
65 set network.wan.proto='pppoe'
66 set network.wan.username='foo'
67 set network.wan.password='bar'
68 EOF
69 }
70
71 set_interfaces_lan_wan() {
72 local lan_ifname=$1
73 local wan_ifname=$2
74
75 set_interface_lan "$lan_ifname"
76 set_interface_wan "$wan_ifname"
77 }
78
79 add_switch() {
80 local name=$1
81 local reset=$2
82 local enable=$3
83 uci batch <<EOF
84 add network switch
85 set network.@switch[-1].name='$name'
86 set network.@switch[-1].reset='$reset'
87 set network.@switch[-1].enable_vlan='$enable'
88 EOF
89 }
90
91 add_switch_vlan() {
92 local device=$1
93 local vlan=$2
94 local ports=$3
95 uci batch <<EOF
96 add network switch_vlan
97 set network.@switch_vlan[-1].device='$device'
98 set network.@switch_vlan[-1].vlan='$vlan'
99 set network.@switch_vlan[-1].ports='$ports'
100 EOF
101 }
102
103 [ -e /etc/config/network ] && exit 0
104
105 . /lib/lantiq.sh
106
107 touch /etc/config/network
108
109 set_interface_loopback
110 set_interface_lan 'eth0'
111
112 dsl=$(lantiq_soc_has_adsl)
113 [ -z "$dsl" ] || set_atm_wan '1' '32' 'llc' 'bridged'
114
115 board=$(lantiq_board_name)
116
117 case "$board" in
118 *)
119 # custom foo goes here
120 true
121 ;;
122 esac
123
124 uci commit network
125
126 exit 0