forked from freifunk-franken/firmware
Add package fff-ipv4snat
With this package it is possible to make NAT with IPv4 on the router Signed-off-by: Christian Dresel <freifunk@dresel.systems>
This commit is contained in:
parent
87e627ba29
commit
a5b6355582
34
src/packages/fff/fff-ipv4snat/Makefile
Normal file
34
src/packages/fff/fff-ipv4snat/Makefile
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
|
PKG_NAME:=fff-ipv4snat
|
||||||
|
PKG_RELEASE:=1
|
||||||
|
|
||||||
|
PKG_BUILD_DIR:=$(BUILD_DIR)/fff-ipv4snat
|
||||||
|
|
||||||
|
include $(INCLUDE_DIR)/package.mk
|
||||||
|
|
||||||
|
define Package/fff-ipv4snat
|
||||||
|
SECTION:=base
|
||||||
|
CATEGORY:=Freifunk
|
||||||
|
TITLE:=Freifunk-Franken layer3 configuration with nat
|
||||||
|
URL:=https://www.freifunk-franken.de
|
||||||
|
DEPENDS:= \
|
||||||
|
+iptables-mod-nat-extra \
|
||||||
|
+fff-firewall \
|
||||||
|
+fff-layer3-config
|
||||||
|
|
||||||
|
endef
|
||||||
|
|
||||||
|
define Package/fff-ipv4snat/description
|
||||||
|
With this package it is possible to make NAT with IPv4 on the router
|
||||||
|
endef
|
||||||
|
|
||||||
|
define Build/Compile
|
||||||
|
# nothing
|
||||||
|
endef
|
||||||
|
|
||||||
|
define Package/fff-ipv4snat/install
|
||||||
|
$(CP) ./files/* $(1)/
|
||||||
|
endef
|
||||||
|
|
||||||
|
$(eval $(call BuildPackage,fff-ipv4snat))
|
|
@ -0,0 +1,53 @@
|
||||||
|
# First read IP adresses
|
||||||
|
if ! ipaddr=$(uci get gateway.@client[0].ipaddr); then
|
||||||
|
echo "WARNING: No ipaddr set!"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# configure-layer3 -c do nothing
|
||||||
|
|
||||||
|
# Check if NAT is set
|
||||||
|
# If NAT is set
|
||||||
|
if uci -q get gateway.@client[0].nat; then
|
||||||
|
if ! peer_ip=$(uci get gateway.meta.peer_ip); then
|
||||||
|
echo "WARNING: No peer_ip set! For NAT you must set a peer_ip"
|
||||||
|
fi
|
||||||
|
# configure-layer3 -t - reload set the iptables rule not rebootsafe
|
||||||
|
reload() {
|
||||||
|
# first we flush the table
|
||||||
|
iptables -t nat --flush
|
||||||
|
# and load the new settings
|
||||||
|
iptables -t nat -A POSTROUTING -s $ipaddr -j SNAT --to-source $peer_ip
|
||||||
|
}
|
||||||
|
|
||||||
|
# configure-layer3 -a - apply write iptables rule to firewall and set rule again
|
||||||
|
# because it is possible that the rule is not set here but we need it here
|
||||||
|
apply() {
|
||||||
|
echo "iptables -t nat -A POSTROUTING -s $ipaddr -j SNAT --to-source $peer_ip" > /usr/lib/firewall.d/30-NAT
|
||||||
|
iptables -t nat --flush
|
||||||
|
iptables -t nat -A POSTROUTING -s $ipaddr -j SNAT --to-source $peer_ip
|
||||||
|
}
|
||||||
|
# If NAT is not set
|
||||||
|
else
|
||||||
|
# configure-layer3 -t - reload flush the iptables
|
||||||
|
reload() {
|
||||||
|
# we only flush the table
|
||||||
|
iptables -t nat --flush
|
||||||
|
}
|
||||||
|
|
||||||
|
# configure-layer3 -a - apply flush iptables rule and delete firewall rule
|
||||||
|
apply() {
|
||||||
|
# we flush the table
|
||||||
|
iptables -t nat --flush
|
||||||
|
# and delete the firewall
|
||||||
|
rm /usr/lib/firewall.d/30-NAT
|
||||||
|
# nobody need NAT we win! \o/
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
|
||||||
|
# revert is the same whether NAT set or not
|
||||||
|
revert() {
|
||||||
|
# first we flush the table
|
||||||
|
iptables -t nat --flush
|
||||||
|
# and load the old settings
|
||||||
|
. /usr/lib/firewall.d/30-NAT
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=fff-layer3
|
PKG_NAME:=fff-layer3
|
||||||
PKG_RELEASE:=7
|
PKG_RELEASE:=8
|
||||||
|
|
||||||
PKG_BUILD_DIR:=$(BUILD_DIR)/fff-layer3
|
PKG_BUILD_DIR:=$(BUILD_DIR)/fff-layer3
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ define Package/fff-layer3
|
||||||
+fff-babeld \
|
+fff-babeld \
|
||||||
+fff-boardname \
|
+fff-boardname \
|
||||||
+fff-dhcp \
|
+fff-dhcp \
|
||||||
|
+fff-ipv4snat \
|
||||||
+fff-layer3-config \
|
+fff-layer3-config \
|
||||||
+fff-network \
|
+fff-network \
|
||||||
+fff-ra \
|
+fff-ra \
|
||||||
|
|
Loading…
Reference in New Issue
Block a user