-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import package 'batman-adv-auto-gw-mode' from altermesh-packages
- Loading branch information
Showing
5 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
36 changes: 36 additions & 0 deletions
36
packages/batman-adv-auto-gw-mode/files/etc/hotplug.d/net/99-batman-gw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
14 changes: 14 additions & 0 deletions
14
packages/batman-adv-auto-gw-mode/files/etc/uci-defaults/network_add_lan_dhcp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
8 changes: 8 additions & 0 deletions
8
packages/batman-adv-auto-gw-mode/files/etc/watchping/wan-fail.d/batman-gw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
8 changes: 8 additions & 0 deletions
8
packages/batman-adv-auto-gw-mode/files/etc/watchping/wan-ok.d/batman-gw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |