Skip to content

Commit

Permalink
Import package 'batman-adv-auto-gw-mode' from altermesh-packages
Browse files Browse the repository at this point in the history
  • Loading branch information
altergui committed Jul 20, 2014
2 parents 0236f4d + 889d259 commit 0373196
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 0 deletions.
52 changes: 52 additions & 0 deletions packages/batman-adv-auto-gw-mode/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#
# Copyright (C) 2012 Gui Iribarren
#
# This is free software, licensed under the GNU General Public License v3.
#

include $(TOPDIR)/rules.mk

PKG_NAME:=batman-adv-auto-gw-mode
PKG_VERSION:=$(shell hg log --template "{date|shortdate}-{rev}\n" -l 1 .)
PKG_RELEASE:=1

include $(INCLUDE_DIR)/package.mk

define Package/batman-adv-auto-gw-mode
SECTION:=net
CATEGORY:=Network
SUBMENU:=Routing and Redirection
TITLE:=Changes batman-adv gw_mode to reflect internet availability
MAINTAINER:=Gui Iribarren <gui@altermundi.net>
DEPENDS:= \
+kmod-batman-adv \
+watchping \
+netifd \
+ubus \

endef

define Package/batman-adv-auto-gw-mode/description
Adds watchping hooks that set
gw_mode=server when WAN port gets internet access
gw_mode=client when connection is severed

Also adds a hotplug.d hook that sends a DHCP request
when another batman-adv router announces itself
as a gw_mode=server.

So if you install this package on every node of a batman-adv
mesh network, you can connect internet access to the WAN
port of any (one or more) nodes, it will be autodetected
and the rest of the nodes will route through it (or them)
endef

define Build/Compile
endef

define Package/batman-adv-auto-gw-mode/install
$(INSTALL_DIR) $(1)/
$(CP) ./files/* $(1)/
endef

$(eval $(call BuildPackage,batman-adv-auto-gw-mode))
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh

dhcp4_discover () {
ifup lan_dhcp
ifup lan_dhcpv6
}

dhcp4_kill () {
ifdown lan_dhcp
ifdown lan_dhcpv6
}

dnsmasq_start () {
uci revert -P/var/state dhcp.@dnsmasq[0].domainneeded
uci revert -P/var/state dhcp.@dnsmasq[0].boguspriv
uci revert -P/var/state dhcp.@dnsmasq[0].rebind_protection
uci revert -P/var/state dhcp.lan.ignore
/etc/init.d/dnsmasq restart
}

dnsmasq_stop () {
uci set -P/var/state dhcp.@dnsmasq[0].domainneeded=
uci set -P/var/state dhcp.@dnsmasq[0].boguspriv=
uci set -P/var/state dhcp.@dnsmasq[0].rebind_protection=0
uci set -P/var/state dhcp.lan.ignore=1
echo no-dhcp-interface=br-lan >> /var/etc/dnsmasq.conf
/etc/init.d/dnsmasq restart
}

if [ "$BATTYPE" = "gw" ] ; then
case "$BATACTION" in
add) dnsmasq_stop ; dhcp4_discover ;;
del) dhcp4_kill ; dnsmasq_start ;;
change) dhcp4_kill ; sleep 5 ; dhcp4_discover ;;
esac
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

uci batch <<EOF
set network.lan_dhcp=interface
set network.lan_dhcp.ifname=@lan
set network.lan_dhcp.proto=dhcp
set network.lan_dhcp.auto=0
set network.lan_dhcpv6=interface
set network.lan_dhcpv6.ifname=@lan
set network.lan_dhcpv6.proto=dhcpv6
set network.lan_dhcpv6.auto=0
commit network
EOF
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

# batman-adv gateway handling (DHCP mangling)
[ "$(uci -q get batman-adv.bat0.gw_mode)" == "client" ] || exit 0
if grep -q "^=>" /sys/kernel/debug/batman_adv/bat0/gateways ; then
BATTYPE=gw BATACTION=add /etc/hotplug.d/net/99-batman-gw
fi
batctl gw_mode client
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

# batman-adv gateway handling (DHCP mangling)
[ "$(uci -q get batman-adv.bat0.gw_mode)" == "client" ] || exit 0
if grep -q "^=>" /sys/kernel/debug/batman_adv/bat0/gateways ; then
BATTYPE=gw BATACTION=del /etc/hotplug.d/net/99-batman-gw
fi
batctl gw_mode server

0 comments on commit 0373196

Please sign in to comment.