From 7c0b1137efbc1e60e74e9c351878c40fc0ac460c Mon Sep 17 00:00:00 2001 From: Manuel Munz Date: Fri, 8 Aug 2014 21:20:56 +0000 Subject: [PATCH] contrib/meshwizard: use seperate config files for olsrd4 and olsrd6 --- .../usr/bin/meshwizard/helpers/setup_olsrd.sh | 194 +++++++++++------- .../helpers/setup_olsrd_interface.sh | 94 +++++---- 2 files changed, 173 insertions(+), 115 deletions(-) diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_olsrd.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_olsrd.sh index 2717803386..9d18a582ac 100755 --- a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_olsrd.sh +++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_olsrd.sh @@ -4,100 +4,142 @@ . /lib/functions.sh . $dir/functions.sh -# Clean the config, remove interface wlan -handle_interface() { - config_get interface "$1" interface - if [ "$interface" = "wlan" ]; then - uci delete olsrd.$1 - fi +local protocols="4" +if [ "$ipv6_enabled" = 1 ] && [ "$has_ipv6" == "1" ]; then + protocols="4 6" +fi + +clean_config() { + # Clean the config, remove interface wlan + handle_interface() { + config_get interface "$1" interface + if [ "$interface" = "wlan" ]; then + uci delete $cfg.$1 + fi + } + config_foreach handle_interface Interface } -config_load olsrd -config_foreach handle_interface Interface -#Rename olsrd basic settings -handle_olsrd() { +rename_olsrd() { + #Rename olsrd basic settings + handle_olsrd() { if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then - section_rename olsrd $1 olsrd + section_rename $cfg $1 olsrd fi + } + config_foreach handle_olsrd olsrd } -config_foreach handle_olsrd olsrd -# Rename interface defaults -handle_interfacedefaults() { - if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then - section_rename olsrd $1 InterfaceDefaults - fi +rename_interface_defaults() { + # Rename interface defaults + handle_interfacedefaults() { + if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then + section_rename $cfg $1 InterfaceDefaults + fi + } + config_foreach handle_interfacedefaults InterfaceDefaults } -config_foreach handle_interfacedefaults InterfaceDefaults -# Set basic olsrd settings -if [ "$ipv6_enabled" = 1 ] && [ "$has_ipv6" == "1" ]; then - uci set olsrd.olsrd.IpVersion="6and4" -fi +cleanup_plugins() { + # Rename nameservice, dyngw and httpinfo plugins + handle_plugin() { + config_get library "$1" library + if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then + new="$(echo $library | cut -d '.' -f 1)" + section_rename $cfg "$1" "$new" + fi + } + config_foreach handle_plugin LoadPlugin + uci -q delete $cfg.olsrd_httpinfo + uci -q delete $cfg.olsrd_dyn_gw +} +setup_nameservice() { + # Setup nameservice plugin + if [ -n "$profile_suffix" ]; then + suffix=".$profile_suffix" + else + suffix=".olsr" + fi + local llfile="/var/run/latlon.js" + local hosts="/var/etc/hosts.olsr" + local services="/var/run/services_olsr" + + if [ "$proto" = "6" ]; then + local llfile="/var/run/latlon.js.ipv6" + local hosts="/var/etc/hosts.olsr.ipv6" + local services="/var/run/services_olsr.ipv6" + fi + + uci batch <<- EOF + set $cfg.olsrd_nameservice=LoadPlugin + set $cfg.olsrd_nameservice.library="olsrd_nameservice.so.0.3" + set $cfg.olsrd_nameservice.latlon_file="$llfile" + set $cfg.olsrd_nameservice.hosts_file="$hosts" + set $cfg.olsrd_nameservice.sighup_pid_file="/var/run/dnsmasq.pid" + set $cfg.olsrd_nameservice.services_file="$services" + set $cfg.olsrd_nameservice.suffix="$suffix" + EOF + + uci_commitverbose "Setup olsr nameservice plugin" $cfg +} -# Setup new InterfaceDefaults -uci set olsrd.InterfaceDefaults=InterfaceDefaults -set_defaults "olsr_interfacedefaults_" olsrd.InterfaceDefaults +setup_dyngw_plain() { + # Setup dyngw_plain + # If Sharing of Internet is enabled then enable dyngw_plain plugin -# Rename nameservice, dyngw and httpinfo plugins + if [ "$general_sharenet" == 1 ]; then + uci set $cfg.dyngw_plain=LoadPlugin + uci set $cfg.dyngw_plain.ignore=0 + uci set $cfg.dyngw_plain.library="olsrd_dyn_gw_plain.so.0.4" + uci_commitverbose "Setup olsrd_dyngw_plain plugin" $cfg + fi -handle_plugin() { - config_get library "$1" library - if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then - new="$(echo $library | cut -d '.' -f 1)" - section_rename olsrd "$1" "$new" - fi } -config_foreach handle_plugin LoadPlugin -uci -q delete olsrd.olsrd_httpinfo -uci -q delete olsrd.olsrd_dyn_gw - -uci_commitverbose "Cleanup olsrd config" olsrd +setup_watchdog() { + # Setup watchdog + local watchdogfile="/var/run/olsrd.watchdog" + if [ "$proto" = "6" ]; then + watchdogfile="/var/run/olsrd.watchdog.ipv6" + fi + + uci batch <<- EOF + set $cfg.olsrd_watchdog=LoadPlugin + set $cfg.olsrd_watchdog.library="olsrd_watchdog.so.0.1" + set $cfg.olsrd_watchdog.file="$watchdogfile" + set $cfg.olsrd_watchdog.interval=30 + EOF + uci_commitverbose "Setup olsr watchdog plugin" $cfg -# Setup nameservice plugin -if [ -n "$profile_suffix" ]; then - suffix=".$profile_suffix" -else - suffix=".olsr" -fi -uci batch << EOF - set olsrd.olsrd_nameservice=LoadPlugin - set olsrd.olsrd_nameservice.library="olsrd_nameservice.so.0.3" - set olsrd.olsrd_nameservice.latlon_file="/var/run/latlon.js" - set olsrd.olsrd_nameservice.hosts_file="/var/etc/hosts.olsr" - set olsrd.olsrd_nameservice.sighup_pid_file="/var/run/dnsmasq.pid" - set olsrd.olsrd_nameservice.services_file="/var/run/services_olsr" - set olsrd.olsrd_nameservice.suffix="$suffix" -EOF +} -uci_commitverbose "Setup olsr nameservice plugin" olsrd +setup_jsoninfo() { + # Setup jsoninfo + uci batch <<- EOF + set $cfg.olsrd_jsoninfo=LoadPlugin + set $cfg.olsrd_jsoninfo.library="olsrd_jsoninfo.so.0.0" + EOF + uci_commitverbose "Setup olsr jsoninfo plugin" $cfg +} -# Setup dyngw_plain -# If Sharing of Internet is enabled then enable dyngw_plain plugin +for proto in $protocols; do + cfg="olsrd" + [ "$proto" == "6" ] && cfg="olsrd6" + config_load $cfg + clean_config + rename_olsrd + cleanup_plugins -if [ "$general_sharenet" == 1 ]; then - uci set olsrd.dyngw_plain=LoadPlugin - uci set olsrd.dyngw_plain.ignore=0 - uci set olsrd.dyngw_plain.library="olsrd_dyn_gw_plain.so.0.4" + uci set $cfg.olsrd.IpVersion="$proto" + uci set $cfg.InterfaceDefaults=InterfaceDefaults + set_defaults "olsr_interfacedefaults_" $cfg.InterfaceDefaults + uci_commitverbose "Cleanup olsrd config" $cfg - uci_commitverbose "Setup olsrd_dyngw_plain plugin" olsrd -fi + setup_nameservice + setup_dyngw_plain + setup_watchdog + setup_jsoninfo -# Setup watchdog -uci batch << EOF - set olsrd.olsrd_watchdog=LoadPlugin - set olsrd.olsrd_watchdog.library="olsrd_watchdog.so.0.1" - set olsrd.olsrd_watchdog.file="/var/run/olsrd.watchdog" - set olsrd.olsrd_watchdog.interval=30 -EOF -uci_commitverbose "Setup olsr watchdog plugin" olsrd - -# Setup jsoninfo -uci batch << EOF - set olsrd.olsrd_jsoninfo=LoadPlugin - set olsrd.olsrd_jsoninfo.library="olsrd_jsoninfo.so.0.0" -EOF -uci_commitverbose "Setup olsr jsoninfo plugin" olsrd +done diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_olsrd_interface.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_olsrd_interface.sh index edb5eea434..8f21893a99 100755 --- a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_olsrd_interface.sh +++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_olsrd_interface.sh @@ -7,54 +7,70 @@ net=$1 . /lib/functions.sh . $dir/functions.sh -# Rename interface for $netrenamed -handle_interface() { - config_get interface "$1" Interface - if [ "$interface" == "$netrenamed" ]; then - if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then - section_rename olsrd $1 $netrenamed +local protocols="4" +if [ "$ipv6_enabled" = 1 ] && [ "$has_ipv6" == "1" ]; then + protocols="4 6" +fi + +for proto in $protocols; do + + cfg="olsrd" + [ "$proto" == "6" ] && cfg="olsrd6" + + # Rename interface for $netrenamed + handle_interface() { + config_get interface "$1" Interface + if [ "$interface" == "$netrenamed" ]; then + if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then + section_rename $cfg $1 $netrenamed + fi fi - fi -} + } -config_foreach handle_interface Interface + config_foreach handle_interface Interface -# Setup new interface for $netrenamed + # Setup new interface for $netrenamed -uci set olsrd.$netrenamed=Interface -set_defaults "olsr_interface_" olsrd.$net -uci set olsrd.$netrenamed.interface="$netrenamed" + uci set $cfg.$netrenamed=Interface + set_defaults "olsr_interface_" $cfg.$net + uci set $cfg.$netrenamed.interface="$netrenamed" -uci_commitverbose "Setup olsr interface for $netrenamed." olsrd + uci_commitverbose "Setup olsr interface for $netrenamed." $cfg -# If dhcp-network is inside the mesh_network then add HNA for it + if [ "$proto" = "4" ]; then + # If dhcp-network is inside the mesh_network then add HNA for it -dhcprange=$(uci -q get meshwizard.netconfig.$net\_dhcprange) -uci -q delete olsrd.${netrenamed}clients + dhcprange=$(uci -q get meshwizard.netconfig.$net\_dhcprange) + uci -q delete $cfg.${netrenamed}clients -if [ -n "$dhcprange" ]; then - meshnet="$(uci get profile_$community.profile.mesh_network)" - dhcpinmesh="$($dir/helpers/check-range-in-range.sh $dhcprange $meshnet)" + if [ -n "$dhcprange" ]; then + meshnet="$(uci get profile_$community.profile.mesh_network)" + dhcpinmesh="$($dir/helpers/check-range-in-range.sh $dhcprange $meshnet)" - if [ "$dhcpinmesh" == 1 ] && [ -n "$meshnet" ]; then - uci set olsrd.${netrenamed}clients="Hna4" - eval $(sh $dir/helpers/ipcalc-cidr.sh $dhcprange) - uci set olsrd.${netrenamed}clients.netaddr="$NETWORK" - uci set olsrd.${netrenamed}clients.netmask="$NETMASK" - uci_commitverbose "Setup HNA for network $dhcprange" olsrd + if [ "$dhcpinmesh" == 1 ] && [ -n "$meshnet" ]; then + uci set $cfg.${netrenamed}clients="Hna4" + eval $(sh $dir/helpers/ipcalc-cidr.sh $dhcprange) + uci set $cfg.${netrenamed}clients.netaddr="$NETWORK" + uci set $cfg.${netrenamed}clients.netmask="$NETMASK" + uci_commitverbose "Setup HNA for network $dhcprange" $cfg + fi + fi fi -fi -# Set Hna entry for ipv6 net for static ipv6 config -uci -q delete olsrd.${netrenamed}static -if [ "$ipv6_enabled" = "1" ] && [ "$ipv6_config" = "static" ]; then - local v6range="$(uci -q get meshwizard.netconfig.$net\_ip6addr)" - local v6net="$(echo $v6range | cut -d '/' -f 1)" - local v6mask="$(echo $v6range | cut -d '/' -f 2)" - if [ -n "$v6net" ] && [ -n "$v6mask" ]; then - uci set olsrd.${netrenamed}static="Hna6" - uci set olsrd.${netrenamed}static.netaddr="$v6net" - uci set olsrd.${netrenamed}static.prefix="$v6mask" - uci_commitverbose "Setup HNA for network $v6range" olsrd + if [ "$proto" = "6" ]; then + # Set Hna entry for ipv6 net for static ipv6 config + uci -q delete $cfg.${netrenamed}static + if [ "$ipv6_config" = "static" ]; then + local v6range="$(uci -q get meshwizard.netconfig.$net\_ip6addr)" + local v6net="$(echo $v6range | cut -d '/' -f 1)" + local v6mask="$(echo $v6range | cut -d '/' -f 2)" + if [ -n "$v6net" ] && [ -n "$v6mask" ]; then + uci set $cfg.${netrenamed}static="Hna6" + uci set $cfg.${netrenamed}static.netaddr="$v6net" + uci set $cfg.${netrenamed}static.prefix="$v6mask" + uci_commitverbose "Setup HNA for network $v6range" $cfg + fi + fi fi -fi + +done \ No newline at end of file -- 2.30.2