From fbc58d6554a386343ee43172eacdf9ad7c6b27fa Mon Sep 17 00:00:00 2001 From: Matthias Strubel Date: Mon, 16 Feb 2015 11:46:06 +0100 Subject: [PATCH] last convert of existing modules --- .../piratebox/bin/find_interface_name.sh | 72 ++++++++++++++ piratebox/piratebox/bin/install_piratebox.sh | 2 +- .../piratebox/bin/piratebox_setup_wlan.sh | 98 ------------------- .../piratebox/conf/modules_conf/bridge.conf | 8 +- .../piratebox/conf/modules_conf/dnsmasq.conf | 5 +- .../piratebox/conf/modules_conf/hostap.conf | 2 +- .../piratebox/conf/modules_conf/network.conf | 7 +- .../piratebox/conf/modules_conf/radvd.conf | 2 +- piratebox/piratebox/init.d/piratebox_alt | 43 -------- .../modules.available/bridge_add_wifi | 67 +++++++++++++ .../piratebox/modules.available/bridge_create | 35 +++++++ piratebox/piratebox/modules.available/dnsmasq | 16 ++- piratebox/piratebox/modules.available/network | 59 +++++++++++ piratebox/piratebox/modules.available/radvd | 17 +++- 14 files changed, 274 insertions(+), 159 deletions(-) create mode 100755 piratebox/piratebox/bin/find_interface_name.sh delete mode 100755 piratebox/piratebox/bin/piratebox_setup_wlan.sh create mode 100644 piratebox/piratebox/modules.available/bridge_add_wifi create mode 100644 piratebox/piratebox/modules.available/bridge_create create mode 100644 piratebox/piratebox/modules.available/network diff --git a/piratebox/piratebox/bin/find_interface_name.sh b/piratebox/piratebox/bin/find_interface_name.sh new file mode 100755 index 0000000..60f0ead --- /dev/null +++ b/piratebox/piratebox/bin/find_interface_name.sh @@ -0,0 +1,72 @@ +#!/bin/sh + +. /opt/piratebox/conf/piratebox.conf + +module_enabled="${PIRATEBOX_FOLDER}/bin/piratebox_moduless.sh enabled" + +## Reads the following module configuration and +## tries to find out, which interface name is relevant for +## the caller, based upon given parameters. + +### 1st Parameter : Caller Type ( service | network ) +### 2nd Parameter: Callers's variable + +## During processing the folowing module configuration is loaded +## bridge.conf +## network.conf +## hostap.conf + +RC=255 +RESULT_VALUE="" + + +check_bridge(){ + return $module_enabled "bridge_add" || $module_enabled "bridge_create" +} + +do_bridge_check(){ + # Only detect correct interface, when own variable not set (default) + if check_bridge ; then + . "${MODULE_CONFIG}\bridge.conf" + RESULT_VALUE="$BRIDGE_NAME" + RC=0 + fi + return $RC + +} + +test_for_interface(){ + local i_type="$1" + local i_var="$2" + + if [ -n "$i_var" ] ; then + RESULT_VALUE="$i_var" + RC=0 + return 0 + fi + + if ! do_bridge_check ; then + if [ "i_type" = "service" ] ; then + . "${MODULE_CONFIG}\network.conf" + test_for_interface "network" "$IFCONFIG_INTERFACE" + fi + if [ "i_type" = "network" ] ; then + . "${MODULE_CONFIG}\hostap.conf" + if $module_enabled "hostapd" && [ -n "$HOSTAP_INTERFACE" ] ; then + RESULT_VALUE="$HOSTAP_INTERFACE" + RC=0 + fi + fi + +} + + +test_for_interface "$1" "$2" + +if [ "$RC" = "0" ] ; then + echo $RESULT_VALUE +else + echo "ERROR: No valid interface could be found" +fi + +exit $RC diff --git a/piratebox/piratebox/bin/install_piratebox.sh b/piratebox/piratebox/bin/install_piratebox.sh index 8157870..3ee8aeb 100755 --- a/piratebox/piratebox/bin/install_piratebox.sh +++ b/piratebox/piratebox/bin/install_piratebox.sh @@ -6,7 +6,7 @@ PIRATEBOX_CONFIG="/opt/piratebox/conf/piratebox.conf" ##Modules for Creating Wifi and IP setting -DEFAULT_MODULES="hostap" +DEFAULT_MODULES="hostap network " ##Modules for housekeeping and so on DEFAULT_MODULES="${DEFAULT_MODULES} cleanup_tmp_folder generate_config_hosts generate_json_config" ##Modules for serving IPs" diff --git a/piratebox/piratebox/bin/piratebox_setup_wlan.sh b/piratebox/piratebox/bin/piratebox_setup_wlan.sh deleted file mode 100755 index 9cd63d7..0000000 --- a/piratebox/piratebox/bin/piratebox_setup_wlan.sh +++ /dev/null @@ -1,98 +0,0 @@ -#!/bin/bash - -# Author: Matthias Strubel (c) 2011-2014 GPL-3 -# Script for setting up the wlan interface -# Parameter 1 i used for the config file providing the parameters - -# IP-Adress IPv4 + IPv6 -# Netmask -# Interface - - -PIRATEBOX_CONFIG="/opt/piratebox/conf/piratebox.conf" - - - - -# Load configfile - -if [ -z $1 ] then - echo "Usage piratebox_setup_wlan.sh " - exit 1 -fi - - -. $PIRATEBOX_CONFIG -. "${MODULE_CONFIG}"/wifi.conf -. "${MODULE_CONFIG}"/ - - -### Check config -if [ -z $INTERFACE ]; then - echo "Please define i.e. " - echo " INTERFACE=wlan0 " - exit 1 -fi - -if [ -z $IP ] ; then - echo "Please define i.e. " - echo " IP=192.268.46.2 " - exit 1 -fi - -if [ -z $NETMASK ] ; then - echo "Please define i.e. " - echo " NETMASK=255.255.255.0 " - exit 1 -fi - - - -### Do the stuff - -if [ $2 = "start" ] ; then - - echo "Bringing up wifi interface $INTERFACE " - ifconfig $INTERFACE up - - if [ $? -ne 0 ] ; then - echo "..failed "; - exit 1 - fi - - echo "Setting up $INTERFACE" - ifconfig $INTERFACE $IP netmask $NETMASK - - if [ $? -ne 0 ] ; then - echo "..failed "; - exit 1 - fi - - if [ $IPV6_ENABLE = "yes" ] ; then - echo "Setting up IPv6 stuff" - IPv6="$IPV6_IP"/"$IPV6_MASK" - echo " $INTERFACE -->$IPv6<--" - ifconfig $INTERFACE add $IPv6 - #That ip is a local IP only - ip addr change $IPv6 dev $INTERFACE scope link - fi - - . $NODE_CONFIG - - if [ "$NODE_CONFIG_ACTIVE" == "yes" ] && [ "$NODE_IPV6_SET_IP" == "yes" ]; then - echo "Setting up IPv6 Mesh-Node IP on interface $NODE_INTERFACE" - ifconfig $NODE_INTERFACE add $NODE_IPV6_IP"$NODE_IPV6_MASK" - fi - -elif [ $2 = "stop" ] ; then - echo "Stopping wifi interface $INTERFACE " - ifconfig $INTERFACE down - - if [ "$NODE_CONFIG_ACTIVE" == "yes" ] && [ "$NODE_IPV6_SET_IP" == "yes" ] ; then - echo "Removing the Node-Address again..." - ifconfig $NODE_INTERFACE del $NODE_IPV6_IP"$NODE_IPV6_MASK" - fi -fi - - - diff --git a/piratebox/piratebox/conf/modules_conf/bridge.conf b/piratebox/piratebox/conf/modules_conf/bridge.conf index 8f9467a..bdd6a3f 100644 --- a/piratebox/piratebox/conf/modules_conf/bridge.conf +++ b/piratebox/piratebox/conf/modules_conf/bridge.conf @@ -1,5 +1,5 @@ #Brdige add interfacce (setr yes to enable bridging) -DO_BRIDGE="no" -ADD_INTERFACES_TO_BRIDGE="wlan0" -ADD_TO_BRIDGE="br-lan" - +## you can add multiple existing interfaces, if space separated. ! +## if empty, hostap interface is used +BRIDGE_PHY_INTERFACES="" +BRIDGE_NAME="br0" \ No newline at end of file diff --git a/piratebox/piratebox/conf/modules_conf/dnsmasq.conf b/piratebox/piratebox/conf/modules_conf/dnsmasq.conf index 7593af0..d94943e 100644 --- a/piratebox/piratebox/conf/modules_conf/dnsmasq.conf +++ b/piratebox/piratebox/conf/modules_conf/dnsmasq.conf @@ -1,6 +1,7 @@ # On which interface DNSMASQ should listen. -i is the parameter for dnsmasq -# Make it empty to disable -DNSMASQ_INTERFACE="wlan0" +# if empty, a detection starts, on which interface it should run +# if set to "IGNORE" , the limitation is not generated +DNSMASQ_INTERFACE="" #DHCP LEASE Start START_LEASE=10 diff --git a/piratebox/piratebox/conf/modules_conf/hostap.conf b/piratebox/piratebox/conf/modules_conf/hostap.conf index 4651cb3..1461f0e 100644 --- a/piratebox/piratebox/conf/modules_conf/hostap.conf +++ b/piratebox/piratebox/conf/modules_conf/hostap.conf @@ -1,5 +1,5 @@ # Configuration for hostap -HOSTAP_INTERFACE="$AP_INTERFACE" +HOSTAP_INTERFACE="wlan0" # Wifi channel HOSTAP_CHANNEL=1 diff --git a/piratebox/piratebox/conf/modules_conf/network.conf b/piratebox/piratebox/conf/modules_conf/network.conf index 3eccf46..f8cf475 100644 --- a/piratebox/piratebox/conf/modules_conf/network.conf +++ b/piratebox/piratebox/conf/modules_conf/network.conf @@ -1,8 +1,5 @@ -#Do network config -DO_IFCONFIG="yes" - -# Name of the wlan interface -IFCONFIG_INTERFACE="wlan0" +# Name of the wlan interface, if empty it will detect +IFCONFIG_INTERFACE="" #Network NET=192.168.77 diff --git a/piratebox/piratebox/conf/modules_conf/radvd.conf b/piratebox/piratebox/conf/modules_conf/radvd.conf index f3e6991..ed7364b 100644 --- a/piratebox/piratebox/conf/modules_conf/radvd.conf +++ b/piratebox/piratebox/conf/modules_conf/radvd.conf @@ -1,5 +1,5 @@ ## Work on the same interface -RADVD_INTERFACE="$DNSMASQ_INTERFACE" +RADVD_INTERFACE="" RADVD_PID="${PIRATEBOX_FOLDER}/tmp/radvd.pid" RADVD_CONFIG_FILE="${PIRATEBOX_FOLDER}/conf/generated/radvd.conf" \ No newline at end of file diff --git a/piratebox/piratebox/init.d/piratebox_alt b/piratebox/piratebox/init.d/piratebox_alt index 7f5459f..ae5fae6 100755 --- a/piratebox/piratebox/init.d/piratebox_alt +++ b/piratebox/piratebox/init.d/piratebox_alt @@ -62,56 +62,13 @@ case "$1" in - if [ "$DO_IFCONFIG" = "yes" ] ; then - echo " Setting up wlan" - #Setting up WLAN Interface - piratebox_setup_wlan.sh $CONF start - if [ $? -ne 0 ] ; then - echo "failed setting up Interface" - exit 255 - fi - fi - #BRIDGE - if [ "$DO_BRIDGE" = "yes" ] ; then - echo "Adding $INTERFACE to bridge $BRIDGE // brctl addif $BRIDGE $INTERFACE " - sleep 1 - BR_CMD="brctl addif $BRIDGE $INTERFACE" - ( $BR_CMD ; ) - if [ $? -ne 0 ] ; then - echo "failed :( " - fi - fi - - - - - - - - fi - - ;; stop) echo "Stopping script piratebox" - if [ "$DO_IFCONFIG" = "yes" ] ; then - piratebox_setup_wlan.sh $CONF stop - fi - #BRIDGE - if [ "$DO_BRIDGE" = "yes" ] ; then - echo "Remove $INTERFACE to bridge $BRIDGE // brctl addif -$BRIDGE $INTERFACE " - sleep 1 - BR_CMD="brctl delif $BRIDGE $INTERFACE" - ( $BR_CMD ; ) - if [ $? -ne 0 ] ; then - echo "failed :( " - fi - fi ;; *) diff --git a/piratebox/piratebox/modules.available/bridge_add_wifi b/piratebox/piratebox/modules.available/bridge_add_wifi new file mode 100644 index 0000000..c136bac --- /dev/null +++ b/piratebox/piratebox/modules.available/bridge_add_wifi @@ -0,0 +1,67 @@ +#!/bin/sh + +## Addes one or more interfaces to an existing bridge. +## uses bridge config +## To create a new bridge enable "bridge_create" module +## IF BRIDGE_PHY_INTERFACES is empty, hostap interface is used. + +MODULE_LIST="$MODULE_LIST bridge_add_wifi" + +bridge_add_wifi_myself="bridge_add_wifi" +bridge_add_wifi_start_order=99 +bridge_add_wifi_stop_order=01 +bridge_add_wifi_needed_config="bridge.conf hostap.conf" +bridge_add_wifi_crucial="no" + +func_bridge_add_wifi_start(){ + #Start here the bridge_add_wifi i.e. + if [ -z "$BRIDGE_PHY_INTERFACES" ] ; then + BRIDGE_PHY_INTERFACES="$HOSTAP_INTERFACE" + fi + local high_rc=0 + local RC=0 + echo "" + for iface in $BRIDGE_PHY_INTERFACES ; do + echo ".. adding $iface to $BRIDGE_NAME" + local BR_CMD="brctl addif $BRIDGE_NAME $iface" + ( $BR_CMD ; ) + local RC=$? + if [ "$RC" != "0" ] ; then + high_rc=$RC + fi + done + RC=$high_rc + _check_rc_ "$bridge_add_wifi_myself" "$RC" "$bridge_add_wifi_crucial" + return $RC +} + +func_bridge_add_wifi_stop(){ + if [ -z "$BRIDGE_PHY_INTERFACES" ] ; then + BRIDGE_PHY_INTERFACES="$HOSTAP_INTERFACE" + fi + local high_rc=0 + local RC=0 + echo "" + for iface in $BRIDGE_PHY_INTERFACES ; do + echo ".. removing $iface from $BRIDGE_NAME" + local BR_CMD="brctl delif $BRIDGE_NAME $iface" + ( $BR_CMD ; ) + local RC=$? + if [ "$RC" != "0" ] ; then + high_rc=$RC + fi + done + RC=$high_rc + _check_rc_ "$bridge_add_wifi_myself" "$RC" + return $RC +} + +func_bridge_add_wifi_get_config(){ + echo $bridge_add_wifi_needed_config +} +func_bridge_add_wifi_get_start_order(){ + echo $bridge_add_wifi_start_order +} +func_bridge_add_wifi_get_stop_order(){ + echo $bridge_add_wifi_stop_order +} \ No newline at end of file diff --git a/piratebox/piratebox/modules.available/bridge_create b/piratebox/piratebox/modules.available/bridge_create new file mode 100644 index 0000000..36c20fa --- /dev/null +++ b/piratebox/piratebox/modules.available/bridge_create @@ -0,0 +1,35 @@ +#!/bin/sh + +MODULE_LIST="$MODULE_LIST bridge_create" + +bridge_create_myself="bridge_create" +bridge_create_start_order=24 +bridge_create_stop_order=73 +bridge_create_needed_config="bridge.conf" +bridge_create_crucial="yes" + +func_bridge_create_start(){ + #Start here the bridge_create i.e. + + brctl addbr $BRIDGE_NAME + local RC=$? + _check_rc_ "$bridge_create_myself" "$RC" "$bridge_create_crucial" + return $RC +} + +func_bridge_create_stop(){ + brctl delbr $BRIDGE_NAME + local RC=$? + _check_rc_ "$bridge_create_myself" "$RC" + return $RC +} + +func_bridge_create_get_config(){ + echo $bridge_create_needed_config +} +func_bridge_create_get_start_order(){ + echo $bridge_create_start_order +} +func_bridge_create_get_stop_order(){ + echo $bridge_create_stop_order +} \ No newline at end of file diff --git a/piratebox/piratebox/modules.available/dnsmasq b/piratebox/piratebox/modules.available/dnsmasq index 35eb235..f742cb9 100644 --- a/piratebox/piratebox/modules.available/dnsmasq +++ b/piratebox/piratebox/modules.available/dnsmasq @@ -5,18 +5,28 @@ MODULE_LIST="$MODULE_LIST dnsmasq" dnsmasq_myself="dnsmasq" dnsmasq_start_order=31 dnsmasq_stop_order=70 -dnsmasq_needed_config="network.conf config_generation.conf dnsmasq.conf" +dnsmasq_needed_config="bridge.conf network.conf config_generation.conf dnsmasq.conf" dnsmasq_crucial="no" func_dnsmasq_start(){ #Start here the dnsmasq i.e. + + local interface=$( $PIRATEBOX_FOLDER/bin/find_interface_name.sh service "$DNSMASQ_INTERFACE" ) + if [ "$?" != "0" ] ; then + echo "" + echo "... $interface" + echo "" + _check_rc_ "$dnsmasq_myself" 255 + return 255 + fi + # pidfile is written by dnsmasq # Command Line for DNSMASQ, use extra config file generated from command above [ "$DNSMASQ_GENERATE_CONF" = "yes" ] && \ func_dnsmasq_generate_config "$NET" "$IP_SHORT" \ "$START_LEASE" "$END_LEASE" \ - "$LEASE_DURATION" "$DNSMASQ_INTERFACE" + "$LEASE_DURATION" "$interface" local CMD_DNSMASQ="-x $DNSMASQ_PIDFILE -C $DNSMASQ_CONF " start-stop-daemon -S -q -x /usr/sbin/dnsmasq -- $CMD_DNSMASQ @@ -54,7 +64,7 @@ func_dnsmasq_generate_config (){ cat $DNSMASQ_DEFAULT_CONF > $DNSMASQ_CONF #Add interface line if filled - [ -n $dnsmasq_interface ] && echo "interface=$dnsmasq_interface" >> $DNSMASQ_CONF + [ "$dnsmasq_interface" != "IGNORE" ] && echo "interface=$dnsmasq_interface" >> $DNSMASQ_CONF local lease_line="$net.$lease_start,$net.$lease_end,$lease_time" echo "dhcp-range=$lease_line" >> $DNSMASQ_CONF diff --git a/piratebox/piratebox/modules.available/network b/piratebox/piratebox/modules.available/network new file mode 100644 index 0000000..62f0ea6 --- /dev/null +++ b/piratebox/piratebox/modules.available/network @@ -0,0 +1,59 @@ +#!/bin/sh + +MODULE_LIST="$MODULE_LIST network" + +network_myself="network" +network_start_order=24 +network_stop_order=71 +network_needed_config="network.conf network_ipv6.conf" +network_crucial="yes" + +func_network_start(){ + local RC=0 + local interface=$( $PIRATEBOX_FOLDER/bin/find_interface_name.sh service "$IFCONFIG_INTERFACE" ) + if [ "$?" != "0" ] ; then + echo "" + echo "... $interface" + echo "" + _check_rc_ "$network_myself" 255 + return 255 + fi + + ifconfig $interface $IP netmask $NETMASK up + RC=$? + [ $RC -ne 0 ] && _check_rc_ "$network_myself" "$RC" "$network_crucial" && return $RC + + + if [ $IPV6_ENABLE = "yes" ] ; then + local IPv6="$IPV6_IP"/"$IPV6_MASK" + ifconfig $interface add $IPv6 + [ $RC -ne 0 ] && _check_rc_ "$network_myself" "$RC" "$network_crucial" && return $RC + fi + _check_rc_ "$network_myself" "$RC" "$network_crucial" + return $RC +} + +func_network_stop(){ + local interface=$( $PIRATEBOX_FOLDER/bin/find_interface_name.sh service "$IFCONFIG_INTERFACE" ) + if [ "$?" != "0" ] ; then + echo "" + echo "... $interface" + echo "" + _check_rc_ "$network_myself" 255 + return 255 + fi + ifconfig $interface down + local RC=$? + _check_rc_ "$network_myself" "$RC" + return $RC +} + +func_network_get_config(){ + echo $network_needed_config +} +func_network_get_start_order(){ + echo $network_start_order +} +func_network_get_stop_order(){ + echo $network_stop_order +} \ No newline at end of file diff --git a/piratebox/piratebox/modules.available/radvd b/piratebox/piratebox/modules.available/radvd index 8b6b305..ee7fbc4 100644 --- a/piratebox/piratebox/modules.available/radvd +++ b/piratebox/piratebox/modules.available/radvd @@ -14,8 +14,23 @@ radvd_crucial="no" func_radvd_start(){ #Start here the radvd i.e. + local iface="$RADVD_INTERFACE" + # We additional try to use the dnsmasq interface, if set. + if [ -z "$iface" ] ; then + iface="$DNSMASQ_INTERFACE" + fi + + local interface=$( $PIRATEBOX_FOLDER/bin/find_interface_name.sh service "$iface" ) + if [ "$?" != "0" ] ; then + echo "" + echo "... $interface" + echo "" + _check_rc_ "$radvd_myself" 255 + return 255 + fi - func_radvd_generate_configuration "$IPV6_PREFIX" "$IPV6_MASK" "$RADVD_INTERFACE" + + func_radvd_generate_configuration "$IPV6_PREFIX" "$IPV6_MASK" "$interface" start-stop-daemon -S -q -x radvd -- -p $RADVD_PID -C $RADVD_CONFIG_FILE