meshwizard: ipv6 fixes, fix uhttpd setup
[project/luci.git] / contrib / package / meshwizard / files / usr / bin / meshwizard / helpers / setup_olsrd_interface.sh
1 #!/bin/sh
2 # Sets up olsrd interfaces
3 # arg $1 = net
4
5 net=$1
6
7 . /lib/functions.sh
8 . $dir/functions.sh
9
10 # Rename interface for $netrenamed
11 handle_interface() {
12 config_get interface "$1" Interface
13 if [ "$interface" == "$netrenamed" ]; then
14 if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
15 section_rename olsrd $1 $netrenamed
16 fi
17 fi
18 }
19
20 config_foreach handle_interface Interface
21
22 # Setup new interface for $netrenamed
23
24 uci set olsrd.$netrenamed=Interface
25 set_defaults "olsr_interface_" olsrd.$net
26 uci set olsrd.$netrenamed.interface="$netrenamed"
27
28 uci_commitverbose "Setup olsr interface for $netrenamed." olsrd
29
30 # If dhcp-network is inside the mesh_network then add HNA for it
31
32 dhcprange=$(uci -q get meshwizard.netconfig.$net\_dhcprange)
33 uci -q delete olsrd.${netrenamed}clients
34
35 if [ -n "$dhcprange" ]; then
36 meshnet="$(uci get profile_$community.profile.mesh_network)"
37 dhcpinmesh="$($dir/helpers/check-range-in-range.sh $dhcprange $meshnet)"
38
39 if [ "$dhcpinmesh" == 1 ] && [ -n "$meshnet" ]; then
40 uci set olsrd.${netrenamed}clients="Hna4"
41 eval $(sh $dir/helpers/ipcalc-cidr.sh $dhcprange)
42 uci set olsrd.${netrenamed}clients.netaddr="$NETWORK"
43 uci set olsrd.${netrenamed}clients.netmask="$NETMASK"
44 uci_commitverbose "Setup HNA for network $dhcprange" olsrd
45 fi
46 fi
47
48 # Set Hna entry for ipv6 net for static ipv6 config
49 uci -q delete olsrd.${netrenamed}static
50 if [ "$ipv6_enabled" = "1" ] && [ "$ipv6_config" = "static" ]; then
51 local v6range="$(uci -q get meshwizard.netconfig.$net\_ip6addr)"
52 local v6net="$(echo $v6range | cut -d '/' -f 1)"
53 local v6mask="$(echo $v6range | cut -d '/' -f 2)"
54 if [ -n "$v6net" ] && [ -n "$v6mask" ]; then
55 uci set olsrd.${netrenamed}static="Hna6"
56 uci set olsrd.${netrenamed}static.netaddr="$v6net"
57 uci set olsrd.${netrenamed}static.prefix="$v6mask"
58 uci_commitverbose "Setup HNA for network $v6range" olsrd
59 fi
60 fi