Merge pull request #1818 from dibdot/lxc_fix
[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 protocols="4"
11 if [ "$ipv6_enabled" = 1 ] && [ "$has_ipv6" == "1" ]; then
12         protocols="4 6"
13 fi
14
15 for proto in $protocols; do
16
17         cfg="olsrd"
18         [ "$proto" == "6" ] && cfg="olsrd6"
19
20         # Rename interface for $netrenamed
21         handle_interface() {
22                 config_get interface "$1" Interface
23                 if [ "$interface" == "$netrenamed" ]; then
24                         if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
25                                 section_rename $cfg $1 $netrenamed
26                         fi
27                 fi
28         }
29
30         config_foreach handle_interface Interface
31
32         # Setup new interface for $netrenamed
33
34         uci set $cfg.$netrenamed=Interface
35         set_defaults "olsr_interface_" $cfg.$net
36         uci set $cfg.$netrenamed.interface="$netrenamed"
37
38         uci_commitverbose "Setup olsr interface for $netrenamed." $cfg
39
40         if [ "$proto" = "4" ]; then
41                 # If dhcp-network is inside the mesh_network then add HNA for it
42
43                 dhcprange=$(uci -q get meshwizard.netconfig.$net\_dhcprange)
44                 uci -q delete $cfg.${netrenamed}clients
45
46                 if [ -n "$dhcprange" ]; then
47                         meshnet="$(uci get profile_$community.profile.mesh_network)"
48                         dhcpinmesh="$($dir/helpers/check-range-in-range.sh $dhcprange $meshnet)"
49
50                         if [ "$dhcpinmesh" == 1 ] && [ -n "$meshnet" ]; then
51                                 uci set $cfg.${netrenamed}clients="Hna4"
52                                 eval $(sh $dir/helpers/ipcalc-cidr.sh $dhcprange)
53                                 uci set $cfg.${netrenamed}clients.netaddr="$NETWORK"
54                                 uci set $cfg.${netrenamed}clients.netmask="$NETMASK"
55                                 uci_commitverbose "Setup HNA for network $dhcprange" $cfg
56                         fi
57                 fi
58         fi
59
60         if [ "$proto" = "6" ]; then
61                 # Set Hna entry for ipv6 net for static ipv6 config
62                 uci -q delete $cfg.${netrenamed}static
63                 if [ "$ipv6_config" = "static" ]; then
64                         v6range="$(uci -q get meshwizard.netconfig.$net\_ip6addr)"
65                         v6net="$(echo $v6range | cut -d '/' -f 1)"
66                         v6mask="$(echo $v6range | cut -d '/' -f 2)"
67                         if [ -n "$v6net" ] && [ -n "$v6mask" ]; then
68                                 uci set $cfg.${netrenamed}static="Hna6"
69                                 uci set $cfg.${netrenamed}static.netaddr="$v6net"
70                                 uci set $cfg.${netrenamed}static.prefix="$v6mask"
71                                 uci_commitverbose "Setup HNA for network $v6range" $cfg
72                         fi
73                 fi
74         fi
75
76 done