Assign unique peer address
This commit is contained in:
parent
2fa22c4d04
commit
7702692aec
|
@ -32,21 +32,21 @@ PROJECT_NAME='freedombone'
|
||||||
COMPLETION_FILE=/root/${PROJECT_NAME}-completed.txt
|
COMPLETION_FILE=/root/${PROJECT_NAME}-completed.txt
|
||||||
|
|
||||||
if [[ $1 == "start" ]]; then
|
if [[ $1 == "start" ]]; then
|
||||||
# install avahi
|
# install avahi
|
||||||
sed -i "s|#host-name=.*|host-name=$(hostname)|g" /etc/avahi/avahi-daemon.conf
|
sed -i "s|#host-name=.*|host-name=$(hostname)|g" /etc/avahi/avahi-daemon.conf
|
||||||
sed -i "s|host-name=.*|host-name=$(hostname)|g" /etc/avahi/avahi-daemon.conf
|
sed -i "s|host-name=.*|host-name=$(hostname)|g" /etc/avahi/avahi-daemon.conf
|
||||||
sed -i "s|use-ipv4=.*|use-ipv4=yes|g" /etc/avahi/avahi-daemon.conf
|
sed -i "s|use-ipv4=.*|use-ipv4=yes|g" /etc/avahi/avahi-daemon.conf
|
||||||
sed -i "s|use-ipv6=.*|use-ipv6=no|g" /etc/avahi/avahi-daemon.conf
|
sed -i "s|use-ipv6=.*|use-ipv6=no|g" /etc/avahi/avahi-daemon.conf
|
||||||
sed -i "s|#disallow-other-stacks=.*|disallow-other-stacks=yes|g" /etc/avahi/avahi-daemon.conf
|
sed -i "s|#disallow-other-stacks=.*|disallow-other-stacks=yes|g" /etc/avahi/avahi-daemon.conf
|
||||||
sed -i "s|hosts:.*|hosts: files mdns4_minimal dns mdns4 mdns|g" /etc/nsswitch.conf
|
sed -i "s|hosts:.*|hosts: files mdns4_minimal dns mdns4 mdns|g" /etc/nsswitch.conf
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Mesh definition
|
# Mesh definition
|
||||||
WIFI_SSID=
|
WIFI_SSID=
|
||||||
if ! grep -q "WIFI_SSID:" $COMPLETION_FILE; then
|
if ! grep -q "WIFI_SSID:" $COMPLETION_FILE; then
|
||||||
WIFI_SSID='mesh'
|
WIFI_SSID='mesh'
|
||||||
else
|
else
|
||||||
WIFI_SSID=$(cat $COMPLETION_FILE | grep "WIFI_SSID:" | awk -F ':' '{print $2}')
|
WIFI_SSID=$(cat $COMPLETION_FILE | grep "WIFI_SSID:" | awk -F ':' '{print $2}')
|
||||||
fi
|
fi
|
||||||
sed -i "s|WIFI_SSID:.*|WIFI_SSID:${WIFI_SSID}|g" $COMPLETION_FILE
|
sed -i "s|WIFI_SSID:.*|WIFI_SSID:${WIFI_SSID}|g" $COMPLETION_FILE
|
||||||
|
|
||||||
|
@ -54,9 +54,9 @@ CELLID='any'
|
||||||
|
|
||||||
CHANNEL=
|
CHANNEL=
|
||||||
if ! grep -q "Wifi channel:" $COMPLETION_FILE; then
|
if ! grep -q "Wifi channel:" $COMPLETION_FILE; then
|
||||||
CHANNEL=2
|
CHANNEL=2
|
||||||
else
|
else
|
||||||
CHANNEL=$(cat $COMPLETION_FILE | grep "Wifi channel:" | awk -F ':' '{print $2}')
|
CHANNEL=$(cat $COMPLETION_FILE | grep "Wifi channel:" | awk -F ':' '{print $2}')
|
||||||
fi
|
fi
|
||||||
sed -i "s|Wifi channel:.*|Wifi channel:${CHANNEL}|g" $COMPLETION_FILE
|
sed -i "s|Wifi channel:.*|Wifi channel:${CHANNEL}|g" $COMPLETION_FILE
|
||||||
|
|
||||||
|
@ -69,170 +69,187 @@ IFACE='wlan0'
|
||||||
EIFACE=eth0
|
EIFACE=eth0
|
||||||
|
|
||||||
if [[ $IFACE == "wlan0" ]]; then
|
if [[ $IFACE == "wlan0" ]]; then
|
||||||
if grep -q "wlan1" /proc/net/dev; then
|
if grep -q "wlan1" /proc/net/dev; then
|
||||||
IFACE=wlan1
|
IFACE=wlan1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [[ $IFACE == "wlan0" ]]; then
|
if [[ $IFACE == "wlan0" ]]; then
|
||||||
if grep -q "wlan2" /proc/net/dev; then
|
if grep -q "wlan2" /proc/net/dev; then
|
||||||
IFACE=wlan2
|
IFACE=wlan2
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [[ $IFACE == "wlan0" ]]; then
|
if [[ $IFACE == "wlan0" ]]; then
|
||||||
if grep -q "wlan3" /proc/net/dev; then
|
if grep -q "wlan3" /proc/net/dev; then
|
||||||
IFACE=wlan3
|
IFACE=wlan3
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -e /etc/default/batctl ]; then
|
if [ -e /etc/default/batctl ]; then
|
||||||
. /etc/default/batctl
|
. /etc/default/batctl
|
||||||
fi
|
fi
|
||||||
|
|
||||||
function status {
|
function status {
|
||||||
batctl o
|
batctl o
|
||||||
}
|
}
|
||||||
|
|
||||||
function stop {
|
function stop {
|
||||||
if [ -z "$IFACE" ]; then
|
if [ -z "$IFACE" ]; then
|
||||||
echo 'error: unable to find wifi interface, not enabling batman-adv mesh'
|
echo 'error: unable to find wifi interface, not enabling batman-adv mesh'
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
if [ "$EIFACE" ]; then
|
if [ "$EIFACE" ]; then
|
||||||
brctl delif $BRIDGE bat0
|
brctl delif $BRIDGE bat0
|
||||||
brctl delif $BRIDGE $EIFACE
|
brctl delif $BRIDGE $EIFACE
|
||||||
ifconfig $BRIDGE down || true
|
ifconfig $BRIDGE down || true
|
||||||
brctl delbr $BRIDGE
|
brctl delbr $BRIDGE
|
||||||
ifconfig $EIFACE down -promisc
|
ifconfig $EIFACE down -promisc
|
||||||
fi
|
fi
|
||||||
|
|
||||||
avahi-autoipd -k $BRIDGE
|
avahi-autoipd -k $BRIDGE
|
||||||
avahi-autoipd -k $IFACE
|
avahi-autoipd -k $IFACE
|
||||||
ifconfig bat0 down -promisc
|
ifconfig bat0 down -promisc
|
||||||
|
|
||||||
batctl if del $IFACE
|
batctl if del $IFACE
|
||||||
rmmod batman-adv
|
rmmod batman-adv
|
||||||
ifconfig $IFACE mtu 1500
|
ifconfig $IFACE mtu 1500
|
||||||
ifconfig $IFACE down
|
ifconfig $IFACE down
|
||||||
iwconfig $IFACE mode managed
|
iwconfig $IFACE mode managed
|
||||||
|
|
||||||
iptables -D INPUT -p tcp --dport 548 -j ACCEPT
|
iptables -D INPUT -p tcp --dport 548 -j ACCEPT
|
||||||
iptables -D INPUT -p udp --dport 548 -j ACCEPT
|
iptables -D INPUT -p udp --dport 548 -j ACCEPT
|
||||||
iptables -D INPUT -p tcp --dport 5353 -j ACCEPT
|
iptables -D INPUT -p tcp --dport 5353 -j ACCEPT
|
||||||
iptables -D INPUT -p udp --dport 5353 -j ACCEPT
|
iptables -D INPUT -p udp --dport 5353 -j ACCEPT
|
||||||
iptables -D INPUT -p tcp --dport 5354 -j ACCEPT
|
iptables -D INPUT -p tcp --dport 5354 -j ACCEPT
|
||||||
iptables -D INPUT -p udp --dport 5354 -j ACCEPT
|
iptables -D INPUT -p udp --dport 5354 -j ACCEPT
|
||||||
iptables -D INPUT -p tcp --dport $ZERONET_PORT -j ACCEPT
|
iptables -D INPUT -p tcp --dport $ZERONET_PORT -j ACCEPT
|
||||||
iptables -D INPUT -p udp --dport $ZERONET_PORT -j ACCEPT
|
iptables -D INPUT -p udp --dport $ZERONET_PORT -j ACCEPT
|
||||||
iptables -D INPUT -p tcp --dport $IPFS_PORT -j ACCEPT
|
iptables -D INPUT -p tcp --dport $IPFS_PORT -j ACCEPT
|
||||||
|
|
||||||
systemctl restart network-manager
|
systemctl restart network-manager
|
||||||
}
|
}
|
||||||
|
|
||||||
function verify {
|
function verify {
|
||||||
tempfile="$(mktemp)"
|
tempfile="$(mktemp)"
|
||||||
batctl o > $tempfile
|
batctl o > $tempfile
|
||||||
if grep -q "disabled" $tempfile; then
|
if grep -q "disabled" $tempfile; then
|
||||||
echo $'B.A.T.M.A.N. not enabled'
|
echo $'B.A.T.M.A.N. not enabled'
|
||||||
rm $tempfile
|
rm $tempfile
|
||||||
stop
|
stop
|
||||||
exit 726835
|
exit 726835
|
||||||
fi
|
fi
|
||||||
echo $'B.A.T.M.A.N. is running'
|
echo $'B.A.T.M.A.N. is running'
|
||||||
rm $tempfile
|
rm $tempfile
|
||||||
|
}
|
||||||
|
|
||||||
|
function assign_peer_address {
|
||||||
|
for i in {1..6}; do
|
||||||
|
number=$RANDOM
|
||||||
|
let "number %= 255"
|
||||||
|
octet=$(echo "obase=16;$number" | bc)
|
||||||
|
if [ ${#octet} -lt 2 ]; then
|
||||||
|
octet="0${octet}"
|
||||||
|
fi
|
||||||
|
if [ $i -gt 1 ]; then
|
||||||
|
echo -n ":"
|
||||||
|
fi
|
||||||
|
echo -n "${octet}"
|
||||||
|
done
|
||||||
|
echo ''
|
||||||
}
|
}
|
||||||
|
|
||||||
function start {
|
function start {
|
||||||
if [ -z "$IFACE" ] ; then
|
if [ -z "$IFACE" ] ; then
|
||||||
echo 'error: unable to find wifi interface, not enabling batman-adv mesh'
|
echo 'error: unable to find wifi interface, not enabling batman-adv mesh'
|
||||||
exit 723657
|
exit 723657
|
||||||
fi
|
fi
|
||||||
echo "info: enabling batman-adv mesh network $WIFI_SSID on $IFACE"
|
echo "info: enabling batman-adv mesh network $WIFI_SSID on $IFACE"
|
||||||
|
|
||||||
systemctl stop network-manager
|
systemctl stop network-manager
|
||||||
sleep 5
|
sleep 5
|
||||||
|
|
||||||
# remove an avahi service which isn't used
|
# remove an avahi service which isn't used
|
||||||
if [ -f /etc/avahi/services/udisks.service ]; then
|
if [ -f /etc/avahi/services/udisks.service ]; then
|
||||||
sudo rm /etc/avahi/services/udisks.service
|
sudo rm /etc/avahi/services/udisks.service
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Might have to re-enable wifi
|
# Might have to re-enable wifi
|
||||||
rfkill unblock $(rfkill list|awk -F: "/phy/ {print $1}") || true
|
rfkill unblock $(rfkill list|awk -F: "/phy/ {print $1}") || true
|
||||||
|
|
||||||
ifconfig $IFACE down
|
ifconfig $IFACE down
|
||||||
ifconfig $IFACE mtu 1532
|
ifconfig $IFACE mtu 1532
|
||||||
iwconfig $IFACE enc off
|
ifconfig $IFACE hw ether $(assign_peer_address)
|
||||||
iwconfig $IFACE mode ad-hoc essid $WIFI_SSID channel $CHANNEL
|
iwconfig $IFACE enc off
|
||||||
sleep 1
|
iwconfig $IFACE mode ad-hoc essid $WIFI_SSID channel $CHANNEL
|
||||||
iwconfig $IFACE ap $CELLID
|
sleep 1
|
||||||
|
iwconfig $IFACE ap $CELLID
|
||||||
|
|
||||||
modprobe batman-adv
|
modprobe batman-adv
|
||||||
batctl if add $IFACE
|
batctl if add $IFACE
|
||||||
ifconfig $IFACE up
|
ifconfig $IFACE up
|
||||||
avahi-autoipd --force-bind --daemonize --wait $BRIDGE
|
avahi-autoipd --force-bind --daemonize --wait $BRIDGE
|
||||||
avahi-autoipd --force-bind --daemonize --wait $IFACE
|
avahi-autoipd --force-bind --daemonize --wait $IFACE
|
||||||
ifconfig bat0 up promisc
|
ifconfig bat0 up promisc
|
||||||
|
|
||||||
#Use persistent HWAddr
|
#Use persistent HWAddr
|
||||||
ether_new=$(ifconfig eth0 | grep HWaddr | sed -e "s/.*HWaddr //")
|
ether_new=$(ifconfig eth0 | grep HWaddr | sed -e "s/.*HWaddr //")
|
||||||
if [ ! -f /var/lib/mesh-node/bat0 ]; then
|
if [ ! -f /var/lib/mesh-node/bat0 ]; then
|
||||||
mkdir /var/lib/mesh-node
|
mkdir /var/lib/mesh-node
|
||||||
echo "${ether_new}" > /var/lib/mesh-node/bat0
|
echo "${ether_new}" > /var/lib/mesh-node/bat0
|
||||||
else
|
else
|
||||||
ether=$(cat /var/lib/mesh-node/bat0)
|
ether=$(cat /var/lib/mesh-node/bat0)
|
||||||
ifconfig bat0 hw ether ${ether}
|
ifconfig bat0 hw ether ${ether}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$EIFACE" ] ; then
|
if [ "$EIFACE" ] ; then
|
||||||
brctl addbr $BRIDGE
|
brctl addbr $BRIDGE
|
||||||
brctl addif $BRIDGE bat0
|
brctl addif $BRIDGE bat0
|
||||||
brctl addif $BRIDGE $EIFACE
|
brctl addif $BRIDGE $EIFACE
|
||||||
ifconfig bat0 0.0.0.0
|
ifconfig bat0 0.0.0.0
|
||||||
ifconfig $EIFACE 0.0.0.0
|
ifconfig $EIFACE 0.0.0.0
|
||||||
ifconfig $EIFACE up promisc
|
ifconfig $EIFACE up promisc
|
||||||
ifconfig $BRIDGE up
|
ifconfig $BRIDGE up
|
||||||
fi
|
fi
|
||||||
|
|
||||||
iptables -A INPUT -p tcp --dport 548 -j ACCEPT
|
iptables -A INPUT -p tcp --dport 548 -j ACCEPT
|
||||||
iptables -A INPUT -p udp --dport 548 -j ACCEPT
|
iptables -A INPUT -p udp --dport 548 -j ACCEPT
|
||||||
iptables -A INPUT -p tcp --dport 5353 -j ACCEPT
|
iptables -A INPUT -p tcp --dport 5353 -j ACCEPT
|
||||||
iptables -A INPUT -p udp --dport 5353 -j ACCEPT
|
iptables -A INPUT -p udp --dport 5353 -j ACCEPT
|
||||||
iptables -A INPUT -p tcp --dport 5354 -j ACCEPT
|
iptables -A INPUT -p tcp --dport 5354 -j ACCEPT
|
||||||
iptables -A INPUT -p udp --dport 5354 -j ACCEPT
|
iptables -A INPUT -p udp --dport 5354 -j ACCEPT
|
||||||
iptables -A INPUT -p tcp --dport $ZERONET_PORT -j ACCEPT
|
iptables -A INPUT -p tcp --dport $ZERONET_PORT -j ACCEPT
|
||||||
iptables -A INPUT -p udp --dport $ZERONET_PORT -j ACCEPT
|
iptables -A INPUT -p udp --dport $ZERONET_PORT -j ACCEPT
|
||||||
iptables -A INPUT -p tcp --dport $IPFS_PORT -j ACCEPT
|
iptables -A INPUT -p tcp --dport $IPFS_PORT -j ACCEPT
|
||||||
|
|
||||||
systemctl restart avahi-daemon
|
systemctl restart avahi-daemon
|
||||||
|
|
||||||
verify
|
verify
|
||||||
}
|
}
|
||||||
|
|
||||||
if ! grep -q "$IFACE" /proc/net/dev; then
|
if ! grep -q "$IFACE" /proc/net/dev; then
|
||||||
echo 'Interface $IFACE was not found'
|
echo 'Interface $IFACE was not found'
|
||||||
stop
|
stop
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
start|stop|status)
|
start|stop|status)
|
||||||
$1
|
$1
|
||||||
;;
|
;;
|
||||||
restart)
|
restart)
|
||||||
stop
|
stop
|
||||||
sleep 10
|
sleep 10
|
||||||
start
|
start
|
||||||
;;
|
;;
|
||||||
ping)
|
ping)
|
||||||
batctl ping $2
|
batctl ping $2
|
||||||
;;
|
;;
|
||||||
ls|list)
|
ls|list)
|
||||||
avahi-browse -atl
|
avahi-browse -atl
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "error: invalid parameter $1"
|
echo "error: invalid parameter $1"
|
||||||
echo 'usage: $0 {start|stop|restart|status|ping|ls|list}'
|
echo 'usage: $0 {start|stop|restart|status|ping|ls|list}'
|
||||||
exit 2
|
exit 2
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
exit 0
|
exit 0
|
||||||
|
|
Loading…
Reference in New Issue