#!/bin/sh /etc/rc.common ### # # RO.B.IN - 2007 by Antonio Anselmi # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # ### # /init.d/configure START=24 ME="configure" yes="1" ME_NET=$(uci get mesh.iface.net) AP_IF=$(uci get mesh.ap.device) AP_NET=$(uci get mesh.ap.net) AP_PREFIX=$(uci get mesh.ap.prefix) MyAP_NET=$(uci get mesh.Myap.net) MyAP_PREFIX=$(uci get mesh.Myap.prefix) AP1_bridge=$(uci get iprules.filter.AP1_bridge) AP2_bridge=$(uci get iprules.filter.AP2_bridge) ap1_time=$(uci get dhcpd.lease.ap1_time) ap2_time=$(uci get dhcpd.lease.ap2_time) if [ "$ap1_time" -eq 0 ] ; then ap1_lease_time="infinite" else ap1_lease_time="${ap1_time}h" fi if [ "$ap2_time" -eq 0 ] ; then ap2_lease_time="infinite" else ap2_lease_time="${ap2_time}h" fi my_MAC=$(uci get node.general.myMAC) # path NODE_CONF="/etc/config/node" BAT_CONF="/etc/config/batman" RESOLV_CONF="/etc/resolv.conf" DNSMASQ_AP="/etc/dnsmasq.ap.conf" DNSMASQ_MyAP="/etc/dnsmasq.Myap.conf" hex2dec () { local i=$1 let x=0x$(echo $my_MAC | cut $i) echo $x } get_IP4 () { local iface=$1 case $iface in mesh) IP_mesh="${ME_NET}.$(hex2dec -c10-11).$(hex2dec -c13-14).$(hex2dec -c16-17)" uci set network.mesh.ipaddr=$IP_mesh uci set node.general.IP_mesh=$IP_mesh logger -s -t "$ME" "ath0 IP is $IP_mesh" ;; ap) IP_ap="${AP_NET}.$(hex2dec -c13-14).$(hex2dec -c16-17)" ap_ssid="open-mesh_$(hex2dec -c16-17)" ap1_ipaddr="${IP_ap}.1" ap_s_lease="${IP_ap}.10" ; ap_e_lease="${IP_ap}.110" IP_ap="${IP_ap}.1/${AP_PREFIX}" logger -s -t "$ME" "ath1 IP is $IP_ap" uci set node.general.ap_ssid="${ap_ssid}" uci set node.general.IP_ap=$IP_ap ;; Myap) IP_Myap="${MyAP_NET}.$(hex2dec -c13-14).$(hex2dec -c16-17)" uci set network.ap2.ipaddr="${IP_Myap}.129" Myap_s_lease="${IP_Myap}.140" ; Myap_e_lease="${IP_Myap}.240" IP_Myap="${IP_Myap}.129/${MyAP_PREFIX}" logger -s -t "$ME" "ath2 IP is $IP_Myap" uci set node.general.IP_Myap=$IP_Myap ;; esac } discover_role () { ACK_LEASE=$(uci get gps.switches.sw_2) case $ACK_LEASE in "1") # we are a GATEWAY uci set batman.node.node_type=gateway node_role=1 captive_iface=$AP_IF ipaddr=$(ifconfig eth0 | grep 'inet addr:'| cut -d: -f2 | awk '{ print $1}') netmask=$(ifconfig eth0 | grep 'Mask:'| cut -d: -f4) uci set network.lan.ipaddr=$ipaddr uci set network.lan.netmask=$netmask uci commit network ;; "0") # we are a REPEATER uci set batman.node.node_type=client node_role=3 if [ "$(uci get management.enable.bridge)" -eq 0 ] ; then node_role=2 captive_iface=$AP_IF else node_role=3 captive_iface="br-lan" fi ;; esac uci commit batman } configure_VAP1 () { local eth0_inet="192.168.84.1" get_IP4 ap case $node_role in 1) # gateway logger -s -t "$ME" "node is a gateway" uci set wireless.public.network="ap1" uci del network.lan.type # network.lan.ipaddr and netmask already configured uci set network.ap1.ipaddr=$ap1_ipaddr uci set network.ap1.netmask="255.255.255.128" uci commit network ;; 2) # default repeater logger -s -t "$ME" "node is a repeater" uci set wireless.public.network="ap1" uci del network.lan.type uci set network.lan.ipaddr=$eth0_inet uci set network.lan.netmask="255.255.255.0" uci set network.ap1.ipaddr=$ap1_ipaddr uci set network.ap1.netmask="255.255.255.128" uci commit network ;; 3) # LAN-WIFI.PUBLIC bridged repeater logger -s -t "$ME" "node is a repeater" uci set wireless.public.network="lan" uci set network.lan.type="bridge" uci set network.lan.ipaddr=$ap1_ipaddr uci set network.lan.netmask="255.255.255.128" uci del network.ap1.ipaddr uci del network.ap1.netmask uci commit network ;; esac uci set wireless.public.isolate="${AP1_bridge}" uci commit wireless eval $(ipcalc -m $IP_ap) range="${ap_s_lease},${ap_e_lease},${NETMASK},${ap1_lease_time}" pippo="${AP_NET}.$(hex2dec -c13-14).$(hex2dec -c16-17).1" rm -f $DNSMASQ_AP > /dev/null 2>&1 cat >> $DNSMASQ_AP << fine port=5353 domain-needed bogus-priv filterwin2k dhcp-authoritative dhcp-leasefile=/tmp/dhcp.ap.leases dhcp-range=$range dhcp-option=3,$pippo dhcp-option=6,$pippo fine # } configure_VAP2 () { get_IP4 Myap uci set wireless.private.isolate="${AP2_bridge}" uci commit wireless eval $(ipcalc -m $IP_Myap) range="${Myap_s_lease},${Myap_e_lease},${NETMASK},${ap2_lease_time}" pippo="${MyAP_NET}.$(hex2dec -c13-14).$(hex2dec -c16-17).129" rm -f $DNSMASQ_MyAP > /dev/null 2>&1 cat >> $DNSMASQ_MyAP << fine port=5354 dhcp-authoritative domain-needed bogus-priv filterwin2k dhcp-leasefile=/tmp/dhcp.Myap.leases dhcp-range=$range dhcp-option=3,$pippo dhcp-option=6,$pippo fine # } start () { get_IP4 mesh discover_role configure_VAP1 configure_VAP2 case $(uci get management.enable.captive_portal) in sputnik) ;; nodogsplash) cp /etc/nodogsplash/nodogsplash.conf.std /tmp/nodog.conf echo "GatewayInterface " $captive_iface >> /tmp/nodog.conf cp /tmp/nodog.conf /etc/nodogsplash/nodogsplash.conf ;; wifidog) echo "# Autogenerated Gateway Info: " >> /tmp/wifidog.conf echo "GatewayID" $my_MAC >> /tmp/wifidog.conf # We're not using experimental, so it's gate0 echo "ExternalInterface gate0" >> /tmp/wifidog.conf echo "GatewayInterface" $captive_iface >> /tmp/wifidog.conf cat /etc/wifidog/wifidog.conf.tail >> /tmp/wifidog.conf rm /etc/wifidog.conf cp /tmp/wifidog.conf /etc/wifidog.conf ;; *) ;; esac uci commit } #